Contents of /alx-src/branches/alx-web-060/include/common-functions.php
Parent Directory | Revision Log
Revision 2022 -
(show annotations)
(download)
Mon May 9 22:13:37 2011 UTC (13 years, 4 months ago) by niro
File size: 1401 byte(s)
Mon May 9 22:13:37 2011 UTC (13 years, 4 months ago) by niro
File size: 1401 byte(s)
-some fixes
1 | <? |
2 | include("config.inc.php"); |
3 | |
4 | function exec_on_client($serial, $ip, $cmd, $failure=1, $verbose=0) |
5 | { |
6 | global $pingcmd; |
7 | 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 | # 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 | |
23 | # exec the cmd |
24 | exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $cmdout, $err); |
25 | if ($verbose == 1) |
26 | { |
27 | echo "err: '".$err."'<br>"; |
28 | foreach( $cmdout as $i ) |
29 | { |
30 | echo "cmdout: '".$i."'<br>"; |
31 | } |
32 | } |
33 | |
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 | } |
37 | else if ($failure == 1) echo '<script language="JavaScript">alert(\'Client #'.$serial.' with IP "'.$ip.'" is offline. Please try again later...\')</script>'; |
38 | } |
39 | |
40 | # return the output of $cmd |
41 | return $cmdout; |
42 | } |
43 | |
44 | ?> |