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 2017 by niro, Mon May 9 16:31:38 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.' /sbin/mageupgrade --calc-bash',$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   {   $item=explode(",",$i);
46   $item=explode(",",$i);   $pcat=$item[0];
47   $pcat=$item[0];   $pname=$item[1];
48   $pname=$item[1];   $opver=$item[2];
49   $opver=$item[2];   $npver=$item[3];
50   $npver=$item[3];  
51     echo '<tr><td>';
52   echo '<tr><td>';   echo '<font color=green>'.$pcat.'/'.$pname.'</font>';
53   echo '<font color=green>'.$pcat.'/'.$pname.'</font>';   echo '<td>';
54   echo '<td>';   echo '<font color=blue> [ '.$opver.' -> '.$npver.' ] </font>';
55   echo '<font color=blue> [ '.$opver.' -> '.$npver.' ] </font>';   echo '</td>';
56   echo '</td>';   echo '</td></tr>';
57   echo '</td></tr>';   }
58   }   }
59   }   else echo 'No updates for client '.$client.' available.';
60   else echo 'No updates for client '.$client.' available.';   echo '</table>';
61   echo '</table>';   echo '</pre>';
62   echo '</pre>';   }
63   }   elseif($op=="update")
64   elseif($op=="update")   {
65   {   echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>');
66   echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>');   echo '<br>';
67   echo '<br>';   echo '<pre><div align=left class=left>';
68   echo '<pre><div align=left class=left>';   // hotfix copy a fixed mage.rc
69   // hotfix copy a fixed mage.rc   system('scp '.$magerc.' root@'.$ip.':/etc/mage.rc');
70   system('scp /var/www/localhost/htdocs/alx/he/mage.rc root@'.$ip.':/etc/mage.rc');   // hotfix2 and a config.rc
71   // hotfix2 and a config.rc   system('scp '.$configrc.' root@'.$ip.':/etc/alxconfig-ng/config.rc');
72   system('scp /var/www/localhost/htdocs/alx/he/config.rc root@'.$ip.':/etc/alxconfig-ng/config.rc');   editvar("VERBOSE","off","/etc/mage.rc");
73   editvar("VERBOSE","off","/etc/mage.rc");  
74     // update rsync server location
75   // 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');
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');   echo $rsync;
77   echo $rsync;   editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc");
78   editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc");   editvar("RSYNC",$rsync,"/etc/mage.rc");
79   editvar("RSYNC",$rsync,"/etc/mage.rc");  
80     // update repository server location
81   system($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' "NOCOLORS=true /sbin/mage update"');   $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');
82   echo '</div></pre>';   editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc");
83   echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>';   editvar("MIRRORS",$repository,"/etc/mage.rc");
84   }  
85   elseif($op=="upgrade")   // update samba update host
86   {   $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');
87   echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>');   editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc");
88   echo '<br>';  
89   echo '<pre><div align=left class=left>';   // update samba update user
90   #echo 'forcing verbose=off <br>';   $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');
91   // hotfix copy a fixed mage.rc   editvar("SMB_UPDATE_USER",$smbusername,"/etc/alxconfig-ng/config.rc");
92   system('scp /var/www/localhost/htdocs/alx/he/mage.rc root@'.$ip.':/etc/mage.rc');  
93   // hotfix2 and a config.rc   // update samba update password
94   system('scp /var/www/localhost/htdocs/alx/he/config.rc root@'.$ip.':/etc/alxconfig-ng/config.rc');   $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');
95   editvar("VERBOSE","off","/etc/mage.rc");   editvar("SMB_UPDATE_PASS",$smbpassword,"/etc/alxconfig-ng/config.rc");
96     system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage update"');
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');   echo '</div></pre>';
99   editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc");   echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>';
100   editvar("RSYNC",$rsync,"/etc/mage.rc");   }
101     elseif($op=="upgrade")
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');   echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>');
104   editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc");   echo '<br>';
105   editvar("MIRRORS",$repository,"/etc/mage.rc");   echo '<pre><div align=left class=left>';
106     #echo 'forcing verbose=off <br>';
107   // update samba update host   // hotfix copy a fixed mage.rc
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');   system('scp '.$magerc.' root@'.$ip.':/etc/mage.rc');
109   editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc");   // hotfix2 and a config.rc
110     system('scp '.$configrc.' root@'.$ip.':/etc/alxconfig-ng/config.rc');
111   // update samba update user   editvar("VERBOSE","off","/etc/mage.rc");
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");   // update rsync server location
114     $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');
115   // update samba update password   editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc");
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');   editvar("RSYNC",$rsync,"/etc/mage.rc");
117   editvar("SMB_UPDATE_PASS",$smbpassword,"/etc/alxconfig-ng/config.rc");  
118     // update repository server location
119     $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');
120   # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first   editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc");
121   exec($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' "[ -x /usr/sbin/update-alx ] && exit 0 || exit 1"',$outarr,$err);   editvar("MIRRORS",$repository,"/etc/mage.rc");
122   if($err!=0)  
123   {   // update samba update host
124   echo '"/usr/sbin/update-alx" missing on client "'.$client.'". Updating mage-alx and alxconfig-ng-alx first ...<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');
125   system($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' "NOCOLORS=true /sbin/mage install mage-alx"');   editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc");
126   system($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' "NOCOLORS=true /sbin/mage install alxconfig-ng-alx"');  
127   }   // update samba update user
128   //system($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' "NOCOLORS=true /usr/sbin/update-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');
129   exec($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' "NOCOLORS=true /usr/sbin/update-alx && exit 0 || exit 1"',$outarr,$err);   editvar("SMB_UPDATE_USER",$smbusername,"/etc/alxconfig-ng/config.rc");
130   echo '</div></pre>';  
131   if ($err!=0) echo '<script language="JavaScript">alert(\'Upgrade *failed* on client #'.$client.' .\')</script>';   // update samba update password
132   else echo '<script language="JavaScript">alert(\'Upgrade successfully installed 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');
133   }   editvar("SMB_UPDATE_PASS",$smbpassword,"/etc/alxconfig-ng/config.rc");
134   else echo 'unkown operation';  
135   }  
136     # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first
137   else echo '<img src="pics/offline.gif" align=top> '.strtoupper('Client not online, try again later...<br>');   exec($sshcmd.' '.$ip.' "[ -x /usr/sbin/update-alx ] && exit 0 || exit 1"',$outarr,$err);
138   }   if($err!=0)
139   echo '</td></tr></table>';   {
140  ?>   echo '"/usr/sbin/update-alx" missing on client "'.$client.'". Updating mage-alx and alxconfig-ng-alx first ...<br>';
141     system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage install mage-alx"');
142     system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage install alxconfig-ng-alx"');
143     }
144     //system($sshcmd.' '.$ip.' "NOCOLORS=true /usr/sbin/update-alx"');
145     exec($sshcmd.' '.$ip.' "NOCOLORS=true /usr/sbin/update-alx && exit 0 || exit 1"',$outarr,$err);
146     echo '</div></pre>';
147     if ($err!=0) echo '<script language="JavaScript">alert(\'Upgrade *failed* on client #'.$client.' .\')</script>';
148     else echo '<script language="JavaScript">alert(\'Upgrade successfully installed on client #'.$client.' .\')</script>';
149     }
150     else echo 'unkown operation';
151     }
152    
153     else echo '<img src="pics/offline.gif" align=top> '.strtoupper('Client not online, try again later...<br>');
154     }
155     echo '</td></tr></table>';
156    ?>

Legend:
Removed from v.1600  
changed lines
  Added in v.2017