1 |
<? |
<? |
2 |
include('include/dbconn.php'); |
|
3 |
include('include/basesql.php'); |
include('include/dbconn.php'); |
4 |
|
include('include/basesql.php'); |
5 |
echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>'; |
include('include/common-functions.php'); |
6 |
?> |
|
7 |
<style type="text/css"> |
echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>'; |
8 |
div.left { margin-left:20%; } |
|
9 |
</style> |
?> |
10 |
<? |
|
11 |
function editvar($var, $value, $file) |
<style type="text/css"> |
12 |
{ |
div.left { margin-left:20%; } |
13 |
global $ip; |
</style> |
14 |
global $sshcmd; |
|
15 |
|
<? |
16 |
// sed cmd: ssh -l root 10.11.12.13 'sed -i -e "s|^\(VAR=\).*|\1\"VALUE\"| FILE' |
|
17 |
$str = $sshcmd.' '.$ip.' \'sed -i -e "s|^\\('.$var.'=\\).*|\\1\\"'.$value.'\\"|" '.$file.'\''; |
function update_client_settings() |
18 |
//echo $str.'<br>'; |
{ |
19 |
system($str); |
global $client; |
20 |
} |
|
21 |
|
// set verbose off |
22 |
$pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.''); |
ssh_editvar('VERBOSE', 'off', '/etc/mage.rc'); |
23 |
while ($row = mysql_fetch_row ($pubkey)) |
|
24 |
{ |
// update rsync server location |
25 |
# schreiben der .ssh/known_hosts file mit dem public rsa key des client, |
$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'); |
26 |
# um die "yes" abfrage zu vermeiden |
ssh_editvar('MAGE_RSYNC', $rsync, '/etc/alxconfig-ng/config.rc'); |
27 |
$hostfile = fopen ($home."/.ssh/known_hosts","w"); |
ssh_editvar('RSYNC', $rsync, '/etc/mage.rc'); |
28 |
fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1); |
|
29 |
fclose($hostfile); |
// update repository server location |
30 |
|
$repository = sqlfirst('select client_locations.repository from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'repository'); |
31 |
# reboot des clients |
ssh_editvar('MAGE_MIRRORS', $repository, '/etc/alxconfig-ng/config.rc'); |
32 |
passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1',$retval); |
ssh_editvar('MIRRORS', $repository, '/etc/mage.rc'); |
33 |
if($retval==0) |
|
34 |
{ |
// update samba update host |
35 |
if($op=="calc") |
$updateserver = sqlfirst('select client_locations.updateserver from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'updateserver'); |
36 |
{ |
ssh_editvar('SMB_UPDATE_HOST', $updateserver, '/etc/alxconfig-ng/config.rc'); |
37 |
echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...<br>'); |
|
38 |
exec($sshcmd.' '.$ip.' /sbin/mageupgrade --calc-bash',$out,$err); |
// update samba update user |
39 |
echo '<pre>'; |
$smbusername = sqlfirst('select client_locations.username from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'username'); |
40 |
echo '<table border="0">'; |
ssh_editvar('SMB_UPDATE_USER', $smbusername, '/etc/alxconfig-ng/config.rc'); |
41 |
if (array_key_exists("0", $out)) |
|
42 |
{ |
// update samba update password |
43 |
foreach( $out as $i) |
$smbpassword = sqlfirst('select client_locations.password from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'password'); |
44 |
{ |
ssh_editvar('SMB_UPDATE_PASS', $smbpassword, '/etc/alxconfig-ng/config.rc'); |
45 |
$item=explode(",",$i); |
} |
46 |
$pcat=$item[0]; |
|
47 |
$pname=$item[1]; |
// always update the client settings first |
48 |
$opver=$item[2]; |
update_client_settings(); |
49 |
$npver=$item[3]; |
|
50 |
|
if($op=="calc") |
51 |
echo '<tr><td>'; |
{ |
52 |
echo '<font color=green>'.$pcat.'/'.$pname.'</font>'; |
echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...<br>'); |
53 |
echo '<td>'; |
$out = sshdo('NOCOLORS=true /sbin/mage uppretend | egrep "\[.*\]" | sed "s:\[.*\]\ \(.*\):\1:" | sed "s:/:,:" | sed "s:\(.*\)-:\1,:" | sed "s:\(.*\)-:\1,:"', $ip); |
54 |
echo '<font color=blue> [ '.$opver.' -> '.$npver.' ] </font>'; |
echo '<pre>'; |
55 |
echo '</td>'; |
echo '<table border="0">'; |
56 |
echo '</td></tr>'; |
if (array_key_exists("0", $out[1])) |
57 |
} |
{ |
58 |
} |
foreach( $out[1] as $i) |
59 |
else echo 'No updates for client '.$client.' available.'; |
{ |
60 |
echo '</table>'; |
$item=explode(",",$i); |
61 |
echo '</pre>'; |
$pcat=$item[0]; |
62 |
} |
$pname=$item[1]; |
63 |
elseif($op=="update") |
$pver=$item[2]; |
64 |
{ |
$pbuild=$item[3]; |
65 |
echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>'); |
|
66 |
echo '<br>'; |
echo '<tr><td>'; |
67 |
echo '<pre><div align=left class=left>'; |
echo '<font color=green>'.$pcat.'/'.$pname.'</font>'; |
68 |
// hotfix copy a fixed mage.rc |
echo '<td>'; |
69 |
system('scp /var/www/localhost/htdocs/alx/he/mage.rc root@'.$ip.':/etc/mage.rc'); |
echo '<font color=blue> => [ '.$pver.'-'.$pbuild.' ] </font>'; |
70 |
// hotfix2 and a config.rc |
echo '</td>'; |
71 |
system('scp /var/www/localhost/htdocs/alx/he/config.rc root@'.$ip.':/etc/alxconfig-ng/config.rc'); |
echo '</td></tr>'; |
72 |
editvar("VERBOSE","off","/etc/mage.rc"); |
} |
73 |
|
} |
74 |
// update rsync server location |
else echo 'No updates for client '.$client.' available.'; |
75 |
$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 '</table>'; |
76 |
echo $rsync; |
echo '</pre>'; |
77 |
editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc"); |
} |
78 |
editvar("RSYNC",$rsync,"/etc/mage.rc"); |
elseif($op=="update") |
79 |
|
{ |
80 |
system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage update"'); |
echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>'); |
81 |
echo '</div></pre>'; |
echo '<br>'; |
82 |
echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>'; |
echo '<pre><div align=left class=left>'; |
83 |
} |
|
84 |
elseif($op=="upgrade") |
sshdo('NOCOLORS=true /sbin/mage update', $ip); |
85 |
{ |
|
86 |
echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>'); |
echo '</div></pre>'; |
87 |
echo '<br>'; |
echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>'; |
88 |
echo '<pre><div align=left class=left>'; |
} |
89 |
#echo 'forcing verbose=off <br>'; |
elseif($op=="upgrade") |
90 |
// hotfix copy a fixed mage.rc |
{ |
91 |
system('scp /var/www/localhost/htdocs/alx/he/mage.rc root@'.$ip.':/etc/mage.rc'); |
echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>'); |
92 |
// hotfix2 and a config.rc |
echo '<br>'; |
93 |
system('scp /var/www/localhost/htdocs/alx/he/config.rc root@'.$ip.':/etc/alxconfig-ng/config.rc'); |
echo '<pre><div align=left class=left>'; |
94 |
editvar("VERBOSE","off","/etc/mage.rc"); |
|
95 |
|
# check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first |
96 |
// update rsync server location |
$err = sshdo('[ -x /usr/sbin/update-alx ]', $ip); |
97 |
$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'); |
if($err[0]!=0) |
98 |
editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc"); |
{ |
99 |
editvar("RSYNC",$rsync,"/etc/mage.rc"); |
echo '"update-alx" missing on client "'.$client.'". Updating mage and alxconfig-ng first ...<br>'; |
100 |
|
sshdo('NOCOLORS=true mage install mage', $ip); |
101 |
// update repository server location |
sshdo('NOCOLORS=true mage install alxconfig-ng', $ip); |
102 |
$repository = sqlfirst('select client_locations.repository from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'repository'); |
} |
103 |
editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc"); |
$err = sshdo('NOCOLORS=true /usr/sbin/update-alx', $ip); |
104 |
editvar("MIRRORS",$repository,"/etc/mage.rc"); |
if ($err[0]!=0) echo '<script language="JavaScript">alert(\'Upgrade *failed* on client #'.$client.' .\')</script>'; |
105 |
|
else echo '<script language="JavaScript">alert(\'Upgrade successfully installed on client #'.$client.' .\')</script>'; |
106 |
// update samba update host |
echo '</div></pre>'; |
107 |
$updateserver = sqlfirst('select client_locations.updateserver from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'updateserver'); |
} |
108 |
editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc"); |
else echo 'unkown operation'; |
109 |
|
echo '</td></tr></table>'; |
110 |
// update samba update user |
|
111 |
$smbusername = sqlfirst('select client_locations.username from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'username'); |
?> |
|
editvar("SMB_UPDATE_USER",$smbusername,"/etc/alxconfig-ng/config.rc"); |
|
|
|
|
|
// update samba update password |
|
|
$smbpassword = sqlfirst('select client_locations.password from client_serials inner join client_locations on client_locations.location=client_serials.location and client_serials.serial='.$client, 'password'); |
|
|
editvar("SMB_UPDATE_PASS",$smbpassword,"/etc/alxconfig-ng/config.rc"); |
|
|
|
|
|
|
|
|
# check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first |
|
|
exec($sshcmd.' '.$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 ...<br>'; |
|
|
system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage install mage-alx"'); |
|
|
system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage install alxconfig-ng-alx"'); |
|
|
} |
|
|
//system($sshcmd.' '.$ip.' "NOCOLORS=true /usr/sbin/update-alx"'); |
|
|
exec($sshcmd.' '.$ip.' "NOCOLORS=true /usr/sbin/update-alx && exit 0 || exit 1"',$outarr,$err); |
|
|
echo '</div></pre>'; |
|
|
if ($err!=0) echo '<script language="JavaScript">alert(\'Upgrade *failed* on client #'.$client.' .\')</script>'; |
|
|
else echo '<script language="JavaScript">alert(\'Upgrade successfully installed on client #'.$client.' .\')</script>'; |
|
|
} |
|
|
else echo 'unkown operation'; |
|
|
} |
|
|
|
|
|
else echo '<img src="pics/offline.gif" align=top> '.strtoupper('Client not online, try again later...<br>'); |
|
|
} |
|
|
echo '</td></tr></table>'; |
|
|
?> |
|