';
?>
function editvar($var, $value, $file)
{
global $ip;
global $sshcmd;
// sed cmd: ssh -l root 10.11.12.13 'sed -i -e "s|^(VAR=).*|\"VALUE\"| FILE'
$str = $sshcmd.' -l root '.$ip.' \'sed -i -e "s|^\\('.$var.'=\\).*|\\1\\"'.$value.'\\"|" '.$file.'\'';
system($str);
}
$pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.'');
while ($row = mysql_fetch_row ($pubkey))
{
# schreiben der .ssh/known_hosts file mit dem public rsa key des client,
# um die "yes" abfrage zu vermeiden
$hostfile = fopen ($home."/.ssh/known_hosts","w");
fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);
fclose($hostfile);
# reboot des clients
passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1',$retval);
if($retval==0)
{
if($op=="calc")
{
echo ' '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')... ');
exec($sshcmd.' -l root '.$ip.' /sbin/mage uppretend',$out,$err);
echo '';
echo ' ';
if (array_key_exists("0", $out))
{
foreach( $out as $i)
{
$item=explode(",",$i);
$pcat=$item[0];
$pname=$item[1];
$opver=$item[2];
$npver=$item[3];
echo '';
echo ''.$pcat.'/'.$pname.'';
echo ' | ';
echo ' [ '.$opver.' -> '.$npver.' ] ';
echo ' | ';
echo ' ';
}
}
else echo 'No updates for client '.$client.' available.';
echo ' ';
echo '';
}
elseif($op=="update")
{
echo ' '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')... ');
echo ' ';
echo '';
editvar("VERBOSE","off","/etc/mage.rc");
// update rsync server location
$rsync = sqlfirst('select client_locations.rsync from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'rsync');
echo $rsync;
editvar("RSYNC",$rsync,"/etc/mage.rc");
system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /sbin/mage update"');
echo ' ';
echo '';
}
elseif($op=="upgrade")
{
echo ' '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')... ');
echo ' ';
echo '';
echo 'forcing verbose=off ';
editvar("VERBOSE","off","/etc/mage.rc");
// update repository server locations
$repo = sqlfirst('SELECT repository FROM client_locations WHERE location="HAT"', 'repository');
editvar("MIRRORS",$repo,"/etc/mage.rc");
# check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first
exec($sshcmd.' -l root '.$ip.' "[ -x /usr/sbin/update-alx ] && exit 0 || exit 1"',$outarr,$err);
if($err!=0)
{
echo '"/usr/sbin/update-alx" missing on client "'.$client.'". Updating mage-alx and alxconfig-ng-alx first ... ';
system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /sbin/mage install mage-alx"');
system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /sbin/mage install alxconfig-ng-alx"');
}
system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /usr/sbin/update-alx"');
echo ' ';
echo '';
}
else echo 'unkown operation';
}
else echo ' '.strtoupper('Client not online, try again later... ');
}
echo ' |