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

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