Magellan Linux

Annotation of /alx-src/trunk/alx-web/mageupgrade.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 425 - (hide annotations) (download)
Wed Jun 4 22:35:14 2008 UTC (15 years, 11 months ago) by niro
File size: 4270 byte(s)
-convert to unix

1 niro 425 <?
2     include('include/config.inc.php');
3     include('include/dbconn.php');
4     include('include/basesql.php');
5    
6     echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>';
7     ?>
8     <style type="text/css">
9     div.left { margin-left:20%; }
10     </style>
11     <?
12     function editvar($var, $value, $file)
13     {
14     global $ip;
15     global $sshcmd;
16    
17     // sed cmd: ssh -l root 10.11.12.13 'sed -i -e "s|^(VAR=).*|\"VALUE\"| FILE'
18     $str = $sshcmd.' -l root '.$ip.' \'sed -i -e "s|^\\('.$var.'=\\).*|\\1\\"'.$value.'\\"|" '.$file.'\'';
19     system($str);
20     }
21    
22     $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.'');
23     while ($row = mysql_fetch_row ($pubkey))
24     {
25     # schreiben der .ssh/known_hosts file mit dem public rsa key des client,
26     # um die "yes" abfrage zu vermeiden
27     $hostfile = fopen ($home."/.ssh/known_hosts","w");
28     fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);
29     fclose($hostfile);
30    
31     # reboot des clients
32     passthru($pingcmd.' '.$ip.' &> /dev/null && exit 0 || exit 1',$retval);
33     if($retval==0)
34     {
35     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>');
38     exec($sshcmd.' -l root '.$ip.' /sbin/mageupgrade --calc-bash',$out,$err);
39     echo '<pre>';
40     echo '<table border="0">';
41     if (array_key_exists("0", $out))
42     {
43     foreach( $out as $i)
44     {
45     $item=explode(",",$i);
46     $pcat=$item[0];
47     $pname=$item[1];
48     $opver=$item[2];
49     $npver=$item[3];
50    
51     echo '<tr><td>';
52     echo '<font color=green>'.$pcat.'/'.$pname.'</font>';
53     echo '<td>';
54     echo '<font color=blue> [ '.$opver.' -> '.$npver.' ] </font>';
55     echo '</td>';
56     echo '</td></tr>';
57     }
58     }
59     else echo 'No updates for client '.$client.' available.';
60     echo '</table>';
61     echo '</pre>';
62     }
63     elseif($op=="update")
64     {
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>';
68     // hotfix copy a fixed mage.rc
69     system('scp /var/www/localhost/htdocs/alx/he/mage.rc root@'.$ip.':/etc/mage.rc');
70     editvar("VERBOSE","off","/etc/mage.rc");
71    
72     // update rsync server location
73     $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');
74     echo $rsync;
75     editvar("RSYNC",$rsync,"/etc/mage.rc");
76    
77     system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /sbin/mage update"');
78     echo '</div></pre>';
79     echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>';
80     }
81     elseif($op=="upgrade")
82     {
83     echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>');
84     echo '<br>';
85     echo '<pre><div align=left class=left>';
86     echo 'forcing verbose=off <br>';
87     editvar("VERBOSE","off","/etc/mage.rc");
88    
89     // update repository server locations
90     $repo = sqlfirst('SELECT repository FROM client_locations WHERE location="HAT"', 'repository');
91     editvar("MIRRORS",$repo,"/etc/mage.rc");
92    
93     # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first
94     exec($sshcmd.' -l root '.$ip.' "[ -x /usr/sbin/update-alx ] && exit 0 || exit 1"',$outarr,$err);
95     if($err!=0)
96     {
97     echo '"/usr/sbin/update-alx" missing on client "'.$client.'". Updating mage-alx and alxconfig-ng-alx first ...<br>';
98     system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /sbin/mage install mage-alx"');
99     system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /sbin/mage install alxconfig-ng-alx"');
100     }
101     system($sshcmd.' -l root '.$ip.' "NOCOLORS=true /usr/sbin/update-alx"');
102     echo '</div></pre>';
103     echo '<script language="JavaScript">alert(\'Upgrade successfully installed on client #'.$client.' .\')</script>';
104     }
105     else echo 'unkown operation';
106     }
107    
108     else echo '<img src="pics/offline.gif" align=top> '.strtoupper('Client not online, try again later...<br>');
109     }
110     echo '</td></tr></table>';
111     ?>