Annotation of /alx-src/branches/alx-web-060/include/common-functions.php
Parent Directory | Revision Log
Revision 2021 -
(hide annotations)
(download)
Mon May 9 21:58:32 2011 UTC (13 years ago) by niro
File size: 987 byte(s)
Mon May 9 21:58:32 2011 UTC (13 years ago) by niro
File size: 987 byte(s)
-added common-functions.php which provides the exec_on_client() function
1 | niro | 2021 | <? |
2 | include("config.inc.php"); | ||
3 | |||
4 | function exec_on_client($serial, $ip, $cmd, $verbose=0) | ||
5 | { | ||
6 | global $sshcmd; | ||
7 | |||
8 | $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$serial.''); | ||
9 | while ($row = mysql_fetch_row ($pubkey)) | ||
10 | { | ||
11 | # write known hosts | ||
12 | $hostfile = fopen ($home."/.ssh/known_hosts","w"); | ||
13 | fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1); | ||
14 | fclose($hostfile); | ||
15 | |||
16 | # exec the cmd | ||
17 | echo "sshcmd: '".$sshcmd."'<br>"; | ||
18 | |||
19 | exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $outarr, $err); | ||
20 | if ($verbose == 1) | ||
21 | { | ||
22 | echo "err: '".$err."'<br>"; | ||
23 | foreach( $outarr as $i ) | ||
24 | { | ||
25 | echo "outarr: '".$i."'<br>"; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | if($err != 0) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" *failed* on client #'.$serial.' .\')</script>'; | ||
30 | else if ($verbose == 1) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" successfully run on client #'.$serial.' .\')</script>'; | ||
31 | |||
32 | return $outarr; | ||
33 | } | ||
34 | } | ||
35 | |||
36 | ?> |