Magellan Linux

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

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

revision 2017 by niro, Mon May 9 16:31:38 2011 UTC revision 2596 by niro, Tue Jul 5 16:24:21 2011 UTC
# Line 1  Line 1 
1  <?  <?
  include('include/dbconn.php');  
  include('include/basesql.php');  
2    
3   echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>';  include('include/dbconn.php');
4    include('include/basesql.php');
5    include('include/common-functions.php');
6    
7    echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>';
8    
9  ?>  ?>
10   <style type="text/css">  
11   div.left { margin-left:20%; }  <style type="text/css">
12   </style>   div.left { margin-left:20%; }
13    </style>
14    
15  <?  <?
  function editvar($var, $value, $file)  
  {  
  global $ip;  
  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.' '.$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    
24     // 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     ssh_editvar('MAGE_RSYNC', $rsync, '/etc/alxconfig-ng/config.rc');
27     ssh_editvar('RSYNC', $rsync, '/etc/mage.rc');
28    
29     // update repository server location
30     $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     ssh_editvar('MIRRORS', $repository, '/etc/mage.rc');
33    
34     // 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     ssh_editvar('SMB_UPDATE_HOST', $updateserver, '/etc/alxconfig-ng/config.rc');
37    
38     // update samba update user
39     $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     ssh_editvar('SMB_UPDATE_USER', $smbusername, '/etc/alxconfig-ng/config.rc');
41    
42     // 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     ssh_editvar('SMB_UPDATE_PASS', $smbpassword, '/etc/alxconfig-ng/config.rc');
45    }
46    
47    // get alx version info
48    $alxinfo = sqlfirst('SELECT * FROM client_version WHERE serial='.$client);
49    $alxos = $alxinfo[os];
50    $alxutils = $alxinfo[utils];
51    
52    // always update the client settings first
53    update_client_settings();
54    
55    if($op=="calc")
56    {
57     echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...<br>');
58    
59     if($alxos >= '0.6.0') {
60     $out = sshdo('NOCOLORS=true /sbin/mage uppretend | egrep "\[.*\]" | sed "s:\[.*\]\ \(.*\):\1:" | sed "s:/:,:" | sed "s:\(.*\)-:\1,:" | sed "s:\(.*\)-:\1,:"', $ip);
61     }
62     else {
63     $out = sshdo('NOCOLORS=true /sbin/mageupgrade --calc-bash | cut -d, -f1-2,4 | sed "s/\(.*\)-r\(.*\)/\1,r\2/"', $ip);
64   }   }
65     echo '<pre>';
66   $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.'');   echo '<table border="0">';
67   while ($row = mysql_fetch_row ($pubkey))   if (array_key_exists("0", $out))
68   {   {
69   # schreiben der .ssh/known_hosts file mit dem public rsa key des client,   foreach( $out as $i)
  # um die "yes" abfrage zu vermeiden  
  $hostfile = fopen ($home."/.ssh/known_hosts","w");  
  fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);  
  fclose($hostfile);  
   
  # reboot des clients  
  passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1',$retval);  
  if($retval==0)  
70   {   {
71   if($op=="calc")   // element 0 is always 0
72   {   if ($i=="0") continue;
  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);  
  echo '<pre>';  
  echo '<table border="0">';  
  if (array_key_exists("0", $out))  
  {  
  foreach( $out as $i)  
  {  
  $item=explode(",",$i);  
  $pcat=$item[0];  
  $pname=$item[1];  
  $opver=$item[2];  
  $npver=$item[3];  
   
  echo '<tr><td>';  
  echo '<font color=green>'.$pcat.'/'.$pname.'</font>';  
  echo '<td>';  
  echo '<font color=blue> [ '.$opver.' -> '.$npver.' ] </font>';  
  echo '</td>';  
  echo '</td></tr>';  
  }  
  }  
  else echo 'No updates for client '.$client.' available.';  
  echo '</table>';  
  echo '</pre>';  
  }  
  elseif($op=="update")  
  {  
  echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>');  
  echo '<br>';  
  echo '<pre><div align=left class=left>';  
  // hotfix copy a fixed mage.rc  
  system('scp '.$magerc.' root@'.$ip.':/etc/mage.rc');  
  // hotfix2 and a config.rc  
  system('scp '.$configrc.' root@'.$ip.':/etc/alxconfig-ng/config.rc');  
  editvar("VERBOSE","off","/etc/mage.rc");  
   
  // 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');  
  echo $rsync;  
  editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc");  
  editvar("RSYNC",$rsync,"/etc/mage.rc");  
   
  // update repository server location  
  $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');  
  editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc");  
  editvar("MIRRORS",$repository,"/etc/mage.rc");  
   
  // update samba update host  
  $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');  
  editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc");  
   
  // 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");  
  system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage update"');  
73    
74   echo '</div></pre>';   $row=explode("\n", $i);
75   echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>';   foreach( $row as $x)
  }  
  elseif($op=="upgrade")  
76   {   {
77   echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>');   //ignore empty rows
78   echo '<br>';   //(the last one may empty)
79   echo '<pre><div align=left class=left>';   if ($x=="") continue;
80   #echo 'forcing verbose=off <br>';  
81   // hotfix copy a fixed mage.rc   $item=explode(",",trim($x));
82   system('scp '.$magerc.' root@'.$ip.':/etc/mage.rc');   $pcat=$item[0];
83   // hotfix2 and a config.rc   $pname=$item[1];
84   system('scp '.$configrc.' root@'.$ip.':/etc/alxconfig-ng/config.rc');   $pver=$item[2];
85   editvar("VERBOSE","off","/etc/mage.rc");   $pbuild=$item[3];
86    
87   // update rsync server location   echo '<tr><td>';
88   $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 '<font color=green>'.$pcat.'/'.$pname.'</font>';
89   editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc");   echo '<td>';
90   editvar("RSYNC",$rsync,"/etc/mage.rc");   echo '<font color=blue> => [ '.$pver.'-'.$pbuild.' ] </font>';
91     echo '</td>';
92   // update repository server location   echo '</td></tr>';
  $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');  
  editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc");  
  editvar("MIRRORS",$repository,"/etc/mage.rc");  
   
  // update samba update host  
  $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');  
  editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc");  
   
  // 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.' '.$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.' '.$ip.' "NOCOLORS=true /sbin/mage install mage-alx"');  
  system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage install alxconfig-ng-alx"');  
  }  
  //system($sshcmd.' '.$ip.' "NOCOLORS=true /usr/sbin/update-alx"');  
  exec($sshcmd.' '.$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>';  
93   }   }
  else echo 'unkown operation';  
94   }   }
   
  else echo '<img src="pics/offline.gif" align=top> '.strtoupper('Client not online, try again later...<br>');  
95   }   }
96   echo '</td></tr></table>';   else echo 'No updates for client '.$client.' available.';
97     echo '</table>';
98     echo '</pre>';
99    }
100    elseif($op=="update")
101    {
102     echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>');
103     echo '<br>';
104     echo '<pre><div align=left class=left>';
105    
106     sshdo('NOCOLORS=true /sbin/mage update', $ip);
107    
108     echo '</div></pre>';
109     echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>';
110    }
111    elseif($op=="upgrade")
112    {
113     echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>');
114     echo '<br>';
115     echo '<pre><div align=left class=left>';
116    
117     # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first
118     $err = sshdo('[ -x /usr/sbin/update-alx ]', $ip);
119     if($err[0]!=0)
120     {
121     echo '"update-alx" missing on client "'.$client.'". Updating mage and alxconfig-ng first ...<br>';
122     sshdo('NOCOLORS=true mage install mage', $ip);
123     sshdo('NOCOLORS=true mage install alxconfig-ng', $ip);
124     }
125     $err = sshdo('NOCOLORS=true /usr/sbin/update-alx', $ip);
126     if ($err[0]!=0) echo '<script language="JavaScript">alert(\'Upgrade *failed* on client #'.$client.' .\')</script>';
127     else echo '<script language="JavaScript">alert(\'Upgrade successfully installed on client #'.$client.' .\')</script>';
128     echo '</div></pre>';
129    }
130    else echo 'unkown operation';
131    echo '</td></tr></table>';
132    
133  ?>  ?>

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