Magellan Linux

Contents of /alx-src/branches/alx-web-060/mageupgrade.php

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *