Magellan Linux

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

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

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

Legend:
Removed from v.1608  
changed lines
  Added in v.2020