Files
neighborhoodwatch/run.d/wordpress

46 lines
1.2 KiB
PHP
Executable File

#!/usr/bin/php -q
<?
// Fetch the host list to check
//
if( getenv('CHK_HOSTS') == null ) {
$hosts = null;
}else {
$hosts = explode(' ', getenv('CHK_HOSTS'));
if (implode($hosts)=='') die("No hosts to check.\n");
}
// Retrieve current Wordpress version from 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'];
checkHost(null, $wp_current);
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);
foreach($results as $instance) {
$parts = explode(':', $instance);
$location = substr($parts[0], 0, strlen($parts[0])-23);
preg_match("/wp_version = '([0-9]+\.[0-9]+(\.[0-9]+)?)';/", $parts[1], $matches);
$version = $matches[1];
if($version < $wp_current) {
echo "WARNING: Outdated Wordpress $version at $hostidentifier$location\n";
}
}
unset($results);
}
?>