/* das script benötigt folgende tabellen in der datenbank:
* ssh_auth_clients spalten -> serial [int 11], public_key [text]
* ssh_auth_server spalten -> id [int 11], public_key [text]
*
* du musst auf jeden fall den ping befehl anpassen und der pfad zum hostfile auf dem
* apache2 lautet '/home/httpd/.ssh/known_host', evtl müsste das verzeichnis .ssh erstellt werden
*
* that's it, works4me (TM)
*/
// $client = '16';
// $ip = '128.20.40.61';
// $op = 'reboot';
include('dbconn.php');
$pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.'');
while ($row = mysql_fetch_row ($pubkey)) {
// echo 'Client Public RSA-Key:
';
// echo $row[0].'
';
# schreiben der .ssh/known_hosts file mit dem public rsa key des client,
# um die "yes" abfrage zu vermeiden
$hostfile = fopen ("/home/httpd/.ssh/known_hosts","w");
fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);
fclose($hostfile);
# reboot des clients
passthru('/bin/ping -I eth0 -c 1 -W 1 -q '.$ip.' &> /dev/null && exit 0 || exit 1',$retval);
if($retval==0) {
echo strtoupper($op.'ing client "'.$ip.'" ...
');
system('/usr/bin/ssh -l root '.$ip.' /sbin/'.$op);
}
else echo strtoupper('Client not online, try again later...
');
}
echo '
';
?>