From 60644ea2bcfb53c6f279837bd4aa753fd626d526 Mon Sep 17 00:00:00 2001 From: florian Date: Sat, 4 Jan 2014 14:01:54 +0000 Subject: [PATCH] implemented notify.patch from issue #26 thanks to Wim for contributing --- neighborhoodwatch.conf-sample | 8 ++++++++ run.d/cakephp | 1 + run.d/drupal | 12 +++++++++--- run.d/mediawiki | 9 +++++++++ run.d/menaltogallery | 1 + run.d/phpmyadmin | 1 + run.d/toolkit.php | 13 +++++++++++++ run.d/wordpress | 1 + 8 files changed, 43 insertions(+), 3 deletions(-) diff --git a/neighborhoodwatch.conf-sample b/neighborhoodwatch.conf-sample index 5acb9fd..565383e 100644 --- a/neighborhoodwatch.conf-sample +++ b/neighborhoodwatch.conf-sample @@ -19,3 +19,11 @@ export TMP_PATH="${SCRIPT_PATH}/tmp" # Options export VERBOSE="1" +# Command to execute for every outdated installation. This will be called with the following parameters: +# - package +# - expected version +# - found version +# - path +# Example: /usr/local/bin/notify-outdated.sh wordpress 3.7.1 3.6.0 localhost:/home/user/public_html/ +#export NOTIFY_SCRIPT="/usr/local/bin/notify-outdated.sh" + diff --git a/run.d/cakephp b/run.d/cakephp index a344363..20e1efd 100644 --- a/run.d/cakephp +++ b/run.d/cakephp @@ -31,6 +31,7 @@ function checkHost($host, $cake_current) { $version = $parts[1]; if($version < $cake_current) { verbose("WARNING: Outdated CakePHP $version at $hostidentifier$location", 0); + notifyScript("CakePHP", $cake_current, $version, "$hostidentifier$location"); } else { verbose("Recent CakePHP $version at $hostidentifier$location", 2); } diff --git a/run.d/drupal b/run.d/drupal index 3d08ecf..30f4926 100755 --- a/run.d/drupal +++ b/run.d/drupal @@ -48,7 +48,12 @@ function checkHost($host, $dr_current) { $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) echo "WARNING: Outdated Drupal $version at $hostidentifier$location\n"; + 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); @@ -66,9 +71,10 @@ function checkHost($host, $dr_current) { 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); + 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); + verbose("Recent Drupal $version at $host$location", 2); } } } diff --git a/run.d/mediawiki b/run.d/mediawiki index ff9c236..a6ca0e3 100755 --- a/run.d/mediawiki +++ b/run.d/mediawiki @@ -42,6 +42,15 @@ function checkHost($host, $mw_current) { $version_major = $version_parts[0] . "." . $version_parts[1]; if( !array_key_exists($version_major, $mw_current) || $version < $mw_current[$version_major] ) { verbose("WARNING: Outdated MediaWiki $version at $hostidentifier$location", 0); + if( array_key_exists($version_major, $mw_current) ) { + notifyScript("MediaWiki", $mw_current[$version_major], $version, "$hostidentifier$location"); + }else { + $maxVersion = "0.0"; + foreach( array_keys($mw_current) as $mw_version ) { + if( $maxVersion < $mw_version ) $maxVersion = $mw_version; + } + notifyScript("MediaWiki", $maxVersion, $version, "$hostidentifier$location"); + } }else { verbose("Recent MediaWiki $version at $hostidentifier$location", 2); } diff --git a/run.d/menaltogallery b/run.d/menaltogallery index ceb8612..de0dc05 100755 --- a/run.d/menaltogallery +++ b/run.d/menaltogallery @@ -42,6 +42,7 @@ function checkHost($host, $mg_current) { if( !array_key_exists($version_major, $mg_current) || $version < $mg_current[$version_major] ) { verbose("WARNING: Outdated Menalto Gallery $version at $hostidentifier$location", 0); + notifyScript("Menalto Gallery", $mg_current, $version, "$hostidentifier$location"); }else { verbose("Recent Menalto Gallery $version at $hostidentifier$location", 2); } diff --git a/run.d/phpmyadmin b/run.d/phpmyadmin index e6fd5f1..970169a 100755 --- a/run.d/phpmyadmin +++ b/run.d/phpmyadmin @@ -32,6 +32,7 @@ function checkHost($host, $pma_current) { $version = $matches[1]; if($version < $pma_current) { verbose("WARNING: Outdated PHPMyAdmin $version at $hostidentifier$location", 0); + notifyScript("PHPMyAdmin", $pma_current, $version, "$hostidentifier$location"); } else { verbose("Recent PHPMyAdmin $version at $hostidentifier$location", 2); } diff --git a/run.d/toolkit.php b/run.d/toolkit.php index 7f83c05..43b2a61 100644 --- a/run.d/toolkit.php +++ b/run.d/toolkit.php @@ -23,4 +23,17 @@ function verbose($msg, $loglevel=0) { if($loglevel <= $verbose) echo $msg."\n"; } +// Notify script +// +function notifyScript($tool, $expectedVersion, $foundVersion, $path) { + if( getenv('NOTIFY_SCRIPT') != null ) { + $cmd = getenv('NOTIFY_SCRIPT') . " " . + escapeshellarg($tool) . " " . + escapeshellarg($expectedVersion) . " " . + escapeshellarg($foundVersion) . " " . + escapeshellarg($path); + exec($cmd); + } +} + ?> diff --git a/run.d/wordpress b/run.d/wordpress index dd2f11b..1a137da 100755 --- a/run.d/wordpress +++ b/run.d/wordpress @@ -34,6 +34,7 @@ function checkHost($host, $wp_current) { $version = $matches[1]; if($version < $wp_current) { verbose("WARNING: Outdated Wordpress $version at $hostidentifier$location", 0); + notifyScript("Wordpress", $wp_current, $version, "$hostidentifier$location"); } else { verbose("Recent Wordpress $version at $hostidentifier$location", 2); }