Files
neighborhoodwatch/run.d/drupal
florian 60644ea2bc implemented notify.patch from issue #26
thanks to Wim for contributing
2014-01-04 14:01:54 +00:00

86 lines
2.5 KiB
PHP
Executable File

#!/usr/bin/php -q
<?php
require_once("toolkit.php");
// Retrieve current Drupal version as documented at http://www.goldcoastmedia.co.uk/blog/drupal-versions-with-php
//
$latest = NULL;
$url = 'http://updates.drupal.org/release-history/drupal/7.x';
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'timeout' => 10,
),
));
$data = file_get_contents($url, FALSE, $context);
if($data)
$feed = simplexml_load_string($data);
if($feed && $feed instanceof SimpleXMLElement && isset($feed->releases->release[0]->version)) {
$dr_current = $feed->releases->release[0]->version;
verbose("Current Drupal version: $dr_current", 1);
} else {
die("Unable to determine current Drupal version, exiting\n");
}
verbose("Current Drupal version: $dr_current", 1);
// Start checking hosts
//
checkHost(null, $dr_current);
if( $hosts != null ) {
foreach($hosts as $host) {
checkHost($host, $dr_current);
}
}
function checkHost($host, $dr_current) {
// For Drupal 4.x - 6.x
$cmd = "locate modules/system/system.module | xargs grep -H '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])-28);
if(substr($parts[1], 0, 16) == "define('VERSION'") {
$version = substr($parts[1], 19, strpos($parts[1], "'", 19)-19);
if($version < $dr_current) {
verbose("WARNING: Outdated Drupal $version at $hostidentifier$location", 0);
notifyScript("Drupal", $dr_current, $version, "$hostidentifier$location");
}else {
verbose("Recent Drupal $version at $host$location", 2);
}
}
}
unset($results);
// For Drupal 7.x
$cmd = "locate includes/bootstrap.inc | xargs grep -H 'VERSION'";
if( $host != null ) {
$cmd = "ssh $host \"" . $cmd . "\"";
}
exec($cmd, $results);
foreach($results as $instance) {
$parts = explode(':', $instance);
$location = substr($parts[0], 0, strlen($parts[0])-23);
if(substr($parts[1], 0, 16) == "define('VERSION'") {
$version = substr($parts[1], 19, strpos($parts[1], "'", 19)-19);
if($version < $dr_current) {
verbose("WARNING: Outdated Drupal $version at $host$location", 0);
notifyScript("Drupal", $dr_current, $version, "$hostidentifier$location");
} else {
verbose("Recent Drupal $version at $host$location", 2);
}
}
}
unset($results);
}
?>