modified code so that local machine is checked. CHECK_HOSTS can now be empty (only local check)
This commit is contained in:
		| @@ -4,6 +4,7 @@ | |||||||
| # | # | ||||||
|  |  | ||||||
| # Hosts that need to be checked (these need to be an ssh login with keys, not passwords, hosts space separated) | # Hosts that need to be checked (these need to be an ssh login with keys, not passwords, hosts space separated) | ||||||
|  | # If the list is empty, the local machine will be checked. | ||||||
| # | # | ||||||
| export CHK_HOSTS="host1 host2 host3" | export CHK_HOSTS="host1 host2 host3" | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,9 +32,8 @@ if($feed && $feed instanceof SimpleXMLElement) { | |||||||
|  |  | ||||||
| // Start checking hosts | // Start checking hosts | ||||||
| // | // | ||||||
| if( $hosts == null ) { | checkHost(null, $dr_current); | ||||||
|   checkHost(null, $dr_current); | if( $hosts != null ) { | ||||||
| } else { |  | ||||||
|   foreach($hosts as $host) { |   foreach($hosts as $host) { | ||||||
|     checkHost($host, $dr_current); |     checkHost($host, $dr_current); | ||||||
|   } |   } | ||||||
| @@ -43,7 +42,7 @@ if( $hosts == null ) { | |||||||
| function checkHost($host, $dr_current) { | function checkHost($host, $dr_current) { | ||||||
|   // For Drupal 4.x - 6.x |   // For Drupal 4.x - 6.x | ||||||
|   $cmd = "locate modules/system/system.module | xargs grep -H 'VERSION'"; |   $cmd = "locate modules/system/system.module | xargs grep -H 'VERSION'"; | ||||||
|   $hostidentifier = ""; |   $hostidentifier = "localhost:"; | ||||||
|   if( $host != null ) { |   if( $host != null ) { | ||||||
|  	$cmd = "ssh $host \"" . $cmd . "\""; |  	$cmd = "ssh $host \"" . $cmd . "\""; | ||||||
| 	$hostidentifier = $host . ":"; | 	$hostidentifier = $host . ":"; | ||||||
|   | |||||||
| @@ -14,14 +14,29 @@ if( getenv('CHK_HOSTS') == null ) { | |||||||
| $wp_api = unserialize(file_get_contents("http://api.wordpress.org/core/version-check/1.6/")); | $wp_api = unserialize(file_get_contents("http://api.wordpress.org/core/version-check/1.6/")); | ||||||
| $wp_current = $wp_api['offers'][0]['current']; | $wp_current = $wp_api['offers'][0]['current']; | ||||||
|  |  | ||||||
| foreach($hosts as $host) { | checkHost(null, $wp_current); | ||||||
|   $cmd = "ssh $host \"locate wp-includes/version.php | xargs grep -H 'wp_version ='\""; | if( $hosts != null ) { | ||||||
|  |   foreach($hosts as $host) { | ||||||
|  |     checkHost($host, $wp_current); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function checkHost($host, $wp_current) { | ||||||
|  |   $cmd = "locate wp-includes/version.php | xargs grep -H 'wp_version ='"; | ||||||
|  |   $hostidentifier = "localhost:"; | ||||||
|  |   if( $host != null ) { | ||||||
|  |     $cmd = "ssh $host \"" . $cmd . "\""; | ||||||
|  |     $hostidentifier = $host . ":"; | ||||||
|  |   } | ||||||
|   exec($cmd, $results); |   exec($cmd, $results); | ||||||
|   foreach($results as $instance) { |   foreach($results as $instance) { | ||||||
|     $parts = explode(':', $instance); |     $parts = explode(':', $instance); | ||||||
|     $location = substr($parts[0], 0, strlen($parts[0])-23); |     $location = substr($parts[0], 0, strlen($parts[0])-23); | ||||||
|     $version = substr($parts[1], 15, 5); |     preg_match("/wp_version = '([0-9]+\.[0-9]+(\.[0-9]+)?)';/", $parts[1], $matches); | ||||||
|     if($version < $wp_current) echo "WARNING: Outdated Wordpress $version at $host:$location\n"; |     $version = $matches[1]; | ||||||
|  |     if($version < $wp_current) { | ||||||
|  | 	echo "WARNING: Outdated Wordpress $version at $hostidentifier$location\n"; | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|   unset($results); |   unset($results); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user