Magellan Linux

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

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

revision 2021 by niro, Mon May 9 21:58:32 2011 UTC revision 2022 by niro, Mon May 9 22:13:37 2011 UTC
# Line 1  Line 1 
1  <?  <?
2   include("config.inc.php");   include("config.inc.php");
3    
4   function exec_on_client($serial, $ip, $cmd, $verbose=0)   function exec_on_client($serial, $ip, $cmd, $failure=1, $verbose=0)
5   {   {
6     global $pingcmd;
7   global $sshcmd;   global $sshcmd;
8    
9   $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$serial.'');   $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$serial.'');
# Line 13  Line 14 
14   fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);   fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);
15   fclose($hostfile);   fclose($hostfile);
16    
17   # exec the cmd   # check if the client is online
18   echo "sshcmd: '".$sshcmd."'<br>";   passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1', $retval);
19     if ($retval == 0)
  exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $outarr, $err);  
  if ($verbose == 1)  
20   {   {
21   echo "err: '".$err."'<br>";   if ($verbose == 1) echo "sshcmd: '".$sshcmd."'<br>";
22   foreach( $outarr as $i )  
23     # exec the cmd
24     exec($sshcmd.' '.$ip.' "source /etc/profile;'.$cmd.'"', $cmdout, $err);
25     if ($verbose == 1)
26   {   {
27   echo "outarr: '".$i."'<br>";   echo "err: '".$err."'<br>";
28     foreach( $cmdout as $i )
29     {
30     echo "cmdout: '".$i."'<br>";
31     }
32   }   }
  }  
33    
34   if($err != 0) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" *failed* on client #'.$serial.' .\')</script>';   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>';   else if ($verbose == 1) echo '<script language="JavaScript">alert(\'Cmd "'.$cmd.'" successfully run on client #'.$serial.' .\')</script>';
36     }
37   return $outarr;   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  ?>  ?>

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