Contents of /alx-src/branches/alx-web-050/mageupgrade.php
Parent Directory | Revision Log
Revision 1633 -
(show annotations)
(download)
Thu Dec 9 22:31:39 2010 UTC (13 years, 9 months ago) by niro
File size: 7636 byte(s)
Thu Dec 9 22:31:39 2010 UTC (13 years, 9 months ago) by niro
File size: 7636 byte(s)
-variable config|mage.rc
1 | <? |
2 | include('include/dbconn.php'); |
3 | include('include/basesql.php'); |
4 | |
5 | echo '<table width=100% height=100% style="border:solid black 1px; background-color:#d5e5ff"><tr><td valign=middle align=center>'; |
6 | ?> |
7 | <style type="text/css"> |
8 | div.left { margin-left:20%; } |
9 | </style> |
10 | <? |
11 | function editvar($var, $value, $file) |
12 | { |
13 | global $ip; |
14 | global $sshcmd; |
15 | |
16 | // sed cmd: ssh -l root 10.11.12.13 'sed -i -e "s|^\(VAR=\).*|\1\"VALUE\"| FILE' |
17 | $str = $sshcmd.' '.$ip.' \'sed -i -e "s|^\\('.$var.'=\\).*|\\1\\"'.$value.'\\"|" '.$file.'\''; |
18 | //echo $str.'<br>'; |
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.' '.$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 '.$magerc.' root@'.$ip.':/etc/mage.rc'); |
70 | // hotfix2 and a config.rc |
71 | system('scp '.$configrc.' root@'.$ip.':/etc/alxconfig-ng/config.rc'); |
72 | editvar("VERBOSE","off","/etc/mage.rc"); |
73 | |
74 | // update rsync server location |
75 | $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 | echo $rsync; |
77 | editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc"); |
78 | editvar("RSYNC",$rsync,"/etc/mage.rc"); |
79 | |
80 | // update repository server location |
81 | $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 | editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc"); |
83 | editvar("MIRRORS",$repository,"/etc/mage.rc"); |
84 | |
85 | // 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 | editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc"); |
88 | |
89 | // update samba update user |
90 | $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 | editvar("SMB_UPDATE_USER",$smbusername,"/etc/alxconfig-ng/config.rc"); |
92 | |
93 | // update samba update password |
94 | $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("SMB_UPDATE_PASS",$smbpassword,"/etc/alxconfig-ng/config.rc"); |
96 | system($sshcmd.' '.$ip.' "NOCOLORS=true /sbin/mage update"'); |
97 | |
98 | echo '</div></pre>'; |
99 | echo '<script language="JavaScript">alert(\'Database-update successfully completed on client #'.$client.' .\')</script>'; |
100 | } |
101 | elseif($op=="upgrade") |
102 | { |
103 | echo '<img src="pics/online.gif" align=top> '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...<br>'); |
104 | echo '<br>'; |
105 | echo '<pre><div align=left class=left>'; |
106 | #echo 'forcing verbose=off <br>'; |
107 | // hotfix copy a fixed mage.rc |
108 | system('scp '.$magerc.' root@'.$ip.':/etc/mage.rc'); |
109 | // hotfix2 and a config.rc |
110 | system('scp '.$configrc.' root@'.$ip.':/etc/alxconfig-ng/config.rc'); |
111 | editvar("VERBOSE","off","/etc/mage.rc"); |
112 | |
113 | // 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 | editvar("MAGE_RSYNC",$rsync,"/etc/alxconfig-ng/config.rc"); |
116 | editvar("RSYNC",$rsync,"/etc/mage.rc"); |
117 | |
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 | editvar("MAGE_MIRRORS",$repository,"/etc/alxconfig-ng/config.rc"); |
121 | editvar("MIRRORS",$repository,"/etc/mage.rc"); |
122 | |
123 | // update samba update host |
124 | $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 | editvar("SMB_UPDATE_HOST",$updateserver,"/etc/alxconfig-ng/config.rc"); |
126 | |
127 | // update samba update user |
128 | $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 | editvar("SMB_UPDATE_USER",$smbusername,"/etc/alxconfig-ng/config.rc"); |
130 | |
131 | // update samba update password |
132 | $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 | |
135 | |
136 | # check if /usr/sbin/update-alx exists, if not update mage-alx and alxconfig-alx first |
137 | exec($sshcmd.' '.$ip.' "[ -x /usr/sbin/update-alx ] && exit 0 || exit 1"',$outarr,$err); |
138 | if($err!=0) |
139 | { |
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 | ?> |
Properties
Name | Value |
---|---|
svn:executable | * |