Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 355 - (hide annotations) (download)
Mon Oct 10 19:42:06 2005 UTC (18 years, 7 months ago) by niro
File size: 3991 byte(s)
cvs import: alx-web for alxconfig-ng
 - code clean up and
 - reorganized the whole structure

1 niro 355 <?
2     # echo '<body onload="window.setTimeout(\'window.close()\', 1750)">';
3     echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>';
4     include('include/dbconn.php');
5    
6     # $client = '1';
7     # $ip = '192.168.0.159';
8     # $op = 'calcdsfs';
9    
10     $home = '/home/www-data';
11     # $update_alx_cmd = 'NOCOLORS=true
12     # /usr/sbin/update-alx
13     # --user tjoke
14     # --pass strunz
15     # --server-share //192.168.0.2/magetmp
16     # --min-space 50000
17     # --mirrors http://192.168.0.2/magellan-050
18     # --rsync rsync://192.168.0.2/mage-cvs-alx
19     # --profile alx-050';
20     # --proxy
21     # --ftp-proxy
22     # --http-proxy
23     # --no-proxy';
24    
25    
26     ?>
27     <style type="text/css">
28     div.left { margin-left:20%; }
29     </style>
30     <?
31    
32     $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.'');
33     while ($row = mysql_fetch_row ($pubkey))
34     {
35     # schreiben der .ssh/known_hosts file mit dem public rsa key des client,
36     # um die "yes" abfrage zu vermeiden
37     $hostfile = fopen ($home."/.ssh/known_hosts","w");
38     fwrite($hostfile,$ip." ".$row[0],strlen($row[0])+strlen($ip)+1);
39     fclose($hostfile);
40    
41     # reboot des clients
42     passthru('/usr/sbin/fping -c 1 -t 50 -q '.$ip.' &> /dev/null && exit 0 || exit 1',$retval);
43     if($retval==0)
44     {
45     if($op=="calc")
46     {
47     echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...<br>');
48     exec('/usr/bin/ssh -l root '.$ip.' /sbin/mageupgrade --calc-bash',$out,$err);
49     echo '<pre>';
50     echo '<table border="0">';
51     if (array_key_exists("0", $out))
52     {
53     foreach( $out as $i)
54     {
55     $item=explode(",",$i);
56     $pcat=$item[0];
57     $pname=$item[1];
58     $opver=$item[2];
59     $npver=$item[3];
60    
61     echo '<tr><td>';
62     echo '<font color=green>'.$pcat.'/'.$pname.'</font>';
63     echo '<td>';
64     echo '<font color=blue> [ '.$opver.' -> '.$npver.' ] </font>';
65     echo '</td>';
66     echo '</td></tr>';
67     }
68     }
69     else echo 'No updates for client '.$client.' available.';
70     echo '</table>';
71     echo '</pre>';
72     }
73     elseif($op=="update")
74     {
75     echo '<img src="pics/online.gif" align=top> '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...<br>');
76     echo '<br>';
77     echo '<pre><div align=left class=left>';
78     system('/usr/bin/ssh -l root '.$ip.' "NOCOLORS=true /sbin/mage update"');
79     echo '</div></pre>';
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     system('/usr/bin/ssh -l root '.$ip.' \'sed -i -e "s:^\\(VERBOSE=\\).*:\\1\\"off\\":" /etc/mage.rc\'');
88     # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first
89     exec('/usr/bin/ssh -l root '.$ip.' "[ -x /usr/sbin/update-alx ] && exit 0 || exit 1"',$outarr,$err);
90     if($err!=0)
91     {
92     echo '"/usr/sbin/update-alx" missing on client "'.$client.'". Updating mage-alx and alxconfig-ng-alx first ...<br>';
93     system('/usr/bin/ssh -l root '.$ip.' "NOCOLORS=true /sbin/mage install mage-alx"');
94     #system('/usr/bin/scp /var/www/localhost/htdocs/alx/he/update-alx root@'.$ip.':/usr/sbin');
95     system('/usr/bin/ssh -l root '.$ip.' "NOCOLORS=true /sbin/mage install alxconfig-ng-alx"');
96     }
97     #system('/usr/bin/ssh -l root '.$ip.' "NOCOLORS=true /usr/sbin/update-alx --user tjoke --pass strunz --server-share //192.168.0.2/magetmp --min-space 50000 --mirrors http://192.168.0.2/alx-050 --rsync rsync://192.168.0.2/mage-cvs-alx --profile alx-050"');
98     system('/usr/bin/ssh -l root '.$ip.' "NOCOLORS=true /usr/sbin/update-alx"');
99     echo '</div></pre>';
100     }
101     else echo 'unkown operation';
102     }
103    
104     else echo '<img src="pics/offline.gif" align=top> '.strtoupper('Client not online, try again later...<br>');
105     }
106     echo '</td></tr></table>';
107     ?>