1 |
<? |
<? |
2 |
include("config.inc.php"); |
include('config.inc.php'); |
3 |
|
include('ppping.inc.php'); |
4 |
|
|
5 |
function exec_on_client($serial, $ip, $cmd, $verbose=0) |
function online($ip) |
6 |
{ |
{ |
7 |
global $sshcmd; |
$ping = new PPPing(); |
8 |
|
$ping->hostname = $ip; |
9 |
$pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$serial.''); |
$ping->timeout = "0.3"; |
10 |
while ($row = mysql_fetch_row ($pubkey)) |
$result = $ping->Ping(); |
|
{ |
|
|
# write known hosts |
|
|
$hostfile = fopen ($home."/.ssh/known_hosts","w"); |
|
|
fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1); |
|
|
fclose($hostfile); |
|
|
|
|
|
# exec the cmd |
|
|
echo "sshcmd: '".$sshcmd."'<br>"; |
|
|
|
|
|
exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $outarr, $err); |
|
|
if ($verbose == 1) |
|
|
{ |
|
|
echo "err: '".$err."'<br>"; |
|
|
foreach( $outarr as $i ) |
|
|
{ |
|
|
echo "outarr: '".$i."'<br>"; |
|
|
} |
|
|
} |
|
|
|
|
|
if($err != 0) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" *failed* on client #'.$serial.' .\')</script>'; |
|
|
else if ($verbose == 1) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" successfully run on client #'.$serial.' .\')</script>'; |
|
11 |
|
|
12 |
return $outarr; |
if($result<0) |
13 |
} |
{ |
14 |
|
echo "error: ".$ping->strError($result); |
15 |
|
$retval=1; |
16 |
} |
} |
17 |
|
else |
18 |
|
{ |
19 |
|
echo $result." ms"; |
20 |
|
$retval=0; |
21 |
|
} |
22 |
|
return $retval; |
23 |
|
} |
24 |
?> |
?> |