Magellan Linux

Annotation of /alx-src/branches/alx-web-060/include/common-functions.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2022 - (hide annotations) (download)
Mon May 9 22:13:37 2011 UTC (13 years ago) by niro
File size: 1401 byte(s)
-some fixes
1 niro 2021 <?
2     include("config.inc.php");
3    
4 niro 2022 function exec_on_client($serial, $ip, $cmd, $failure=1, $verbose=0)
5 niro 2021 {
6 niro 2022 global $pingcmd;
7 niro 2021 global $sshcmd;
8    
9     $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$serial.'');
10     while ($row = mysql_fetch_row ($pubkey))
11     {
12     # write known hosts
13     $hostfile = fopen ($home."/.ssh/known_hosts","w");
14     fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);
15     fclose($hostfile);
16    
17 niro 2022 # check if the client is online
18     passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1', $retval);
19     if ($retval == 0)
20     {
21     if ($verbose == 1) echo "sshcmd: '".$sshcmd."'<br>";
22 niro 2021
23 niro 2022 # exec the cmd
24     exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $cmdout, $err);
25     if ($verbose == 1)
26 niro 2021 {
27 niro 2022 echo "err: '".$err."'<br>";
28     foreach( $cmdout as $i )
29     {
30     echo "cmdout: '".$i."'<br>";
31     }
32 niro 2021 }
33 niro 2022
34     if($err != 0) if ($failure == 1) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" *failed* on client #'.$serial.' .\')</script>';
35     else if ($verbose == 1) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" successfully run on client #'.$serial.' .\')</script>';
36 niro 2021 }
37 niro 2022 else if ($failure == 1) echo '<script language="JavaScript">alert(\'Client #'.$serial.' with IP "'.$ip.'" is offline. Please try again later...\')</script>';
38     }
39 niro 2021
40 niro 2022 # return the output of $cmd
41     return $cmdout;
42 niro 2021 }
43    
44     ?>