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