Magellan Linux

Diff of /alx-src/branches/alx-web-070/include/common-functions.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

alx-src/branches/alx-web-060/include/common-functions.php revision 2021 by niro, Mon May 9 21:58:32 2011 UTC alx-src/branches/alx-web-070/include/common-functions.php revision 8510 by niro, Mon Feb 8 09:16:29 2016 UTC
# Line 1  Line 1 
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  ?>  ?>

Legend:
Removed from v.2021  
changed lines
  Added in v.8510