--- alx-src/branches/alx-web-050/mageupgrade.php 2010/12/02 19:56:40 1600 +++ alx-src/branches/alx-web-060/mageupgrade.php 2011/05/09 16:31:38 2017 @@ -1,140 +1,156 @@ -'; -?> - -'; - system($str); - } - - $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.''); - while ($row = mysql_fetch_row ($pubkey)) - { - # schreiben der .ssh/known_hosts file mit dem public rsa key des client, - # 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) - { - if($op=="calc") - { - echo ' '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...
'); - exec($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' /sbin/mageupgrade --calc-bash',$out,$err); - echo '
';
-				echo '';
-				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 '';
-						echo '';
-					}
-				}
-				else echo 'No updates for client '.$client.' available.';			
-				echo '
'; - echo ''.$pcat.'/'.$pname.''; - echo ''; - echo ' [ '.$opver.' -> '.$npver.' ] '; - echo '
'; - echo '
'; - } - elseif($op=="update") - { - echo ' '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...
'); - echo '
'; - echo '
'; - // hotfix copy a fixed mage.rc - system('scp /var/www/localhost/htdocs/alx/he/mage.rc root@'.$ip.':/etc/mage.rc'); - // hotfix2 and a config.rc - system('scp /var/www/localhost/htdocs/alx/he/config.rc 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"); - - system($sshcmd.' -l root -o ConnectTimeout=5 '.$ip.' "NOCOLORS=true /sbin/mage update"'); - echo '
'; - echo ''; - } - elseif($op=="upgrade") - { - echo ' '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...
'); - echo '
'; - echo '
'; - #echo 'forcing verbose=off
'; - // hotfix copy a fixed mage.rc - system('scp /var/www/localhost/htdocs/alx/he/mage.rc root@'.$ip.':/etc/mage.rc'); - // hotfix2 and a config.rc - system('scp /var/www/localhost/htdocs/alx/he/config.rc 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'); - 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"); - - - # 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 ...
'; - 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 '
'; - if ($err!=0) echo ''; - else echo ''; - } - else echo 'unkown operation'; - } - - else echo ' '.strtoupper('Client not online, try again later...
'); - } - echo ''; -?> +'; +?> + +'; + system($str); + } + + $pubkey = mysql_query('select public_key from ssh_auth_clients where serial='.$client.''); + while ($row = mysql_fetch_row ($pubkey)) + { + # schreiben der .ssh/known_hosts file mit dem public rsa key des client, + # 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) + { + if($op=="calc") + { + echo ' '.strtoupper('Fetching list of packages to upgrade on client #'.$client.' ('.$ip.')...
'); + exec($sshcmd.' '.$ip.' /sbin/mageupgrade --calc-bash',$out,$err); + echo '
';
+				echo '';
+				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 '';
+						echo '';
+					}
+				}
+				else echo 'No updates for client '.$client.' available.';			
+				echo '
'; + echo ''.$pcat.'/'.$pname.''; + echo ''; + echo ' [ '.$opver.' -> '.$npver.' ] '; + echo '
'; + echo '
'; + } + elseif($op=="update") + { + echo ' '.strtoupper('Fetching new mage database for client #'.$client.' ('.$ip.')...
'); + echo '
'; + echo '
'; + // 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"'); + + echo '
'; + echo ''; + } + elseif($op=="upgrade") + { + echo ' '.strtoupper('Running update-alx on client #'.$client.' ('.$ip.')...
'); + echo '
'; + echo '
'; + #echo 'forcing verbose=off
'; + // 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'); + 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"); + + + # 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 ...
'; + 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 '
'; + if ($err!=0) echo ''; + else echo ''; + } + else echo 'unkown operation'; + } + + else echo ' '.strtoupper('Client not online, try again later...
'); + } + echo ''; +?>