Subversion Repositories vnag

Rev

Rev 29 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>
  2. lAkMAIwL5Eb71IHJLCJVhuS1bw1OUs8gYlJMpZhoPHf6dARxLpWHATIIiIzdP9qsX
  3. LYl24sYg3jpuSUCwTyJlJp3BZn9D3pJPQrU7AI02eBd/9h5Mz7nXxExIfOUKamtYC
  4. RS82nKHZhKO8j24sVfQclA0I6zWEOzBMmpRoL3r2RkTNJl9EtbgGS85UnRVFOkx68
  5. V0P5mCGIoqbrvdQgGKxsk4b8T3+x9M7L7NZTNimQQgSQ3KfehELyVPxAPJUs+LGBn
  6. +hTdAZWG7I++aiBGpzB6kWZ4WRdYn8Sd4OhIiiS3hRxKOUhxJWGLjbtBRLVR0GFUw
  7. UihDbY4jnts6vx+wFzd4/DGi1jlIyJZIKENgPsOnoz3mizSlFJOxKYTBzL5CFTes+
  8. AdpF4jbh+i+r3elB6llvUfTUxji7VxFPUNlgr3A+OfNU07SNh532Hxw1TLA29zUaL
  9. n2ng2h23TW06qlVW+D+7x7yU+7UieBvpt+m8kX3a9Y8O44ZOenpxYthw/6htw2RqJ
  10. 0yhzLDfklZSs4cDgY58PqTmxRYxpuzN9A94ef+Gw3D5subQY8VXmNouPPsYAopJLQ
  11. KA66wCvI0ceg3qbID6dIFZ32XlLLcIV6vAtc5hFhJh+uWbuP0r3t3IBfxmCDCbqVT
  12. rX8aCG4KoDujMXdDNdgL3LWcWdbyiiADo/CNIOtYlNv8ePhVmX6dpGToOfhEoGVCO
  13. MzuaQGt3jQ6W3lDyaMqxQuPSREdhGFWLiolTfxECayaLWcy8hQ8AQxMA55d9V3x6K
  14. FZUycEjLe1HoASe7dXPVsMCg+iuw8/A1BDZQXSulNq86NVOrnQrXmJFUrBd+Wy7mk
  15. MeFl8Leckma3kSh2IYgcuhUn67vE1bXaLHEs1PYvn91LPoROKodDYhyYSuHDHTgMe
  16. /B4nCqwkL3oUGlNsMcvXchwTFy6PWEMuw2+O87MIPlbNRdS6PVwIvRu5+SXDMYxgi
  17. X+QyexhefP8HIcDzHdtK8Q9ATLfrhsSNhyYHnFG2Q1E2a8eR0Gg9IUYgUjaCnp0WP
  18. o1tvBqQoNxuM8FwtJEaDLLJYGI8SM7pRj1bNtekOoNrC2EWmATpXpawSEhVD/4FGh
  19. tsfXhp3uGM/7mtnQgBS6N2rBN1zJ0qTcT1RxTmU9CcY2odrmAcI7cRIoBphdkaE8N
  20. v5IA5ODOpT9F/ZMmo38FPrKLSNGbcVWIjhBht3tq8EVK3+sO0CjUgnBX46vVkQtzZ
  21. 3coIm9KhY6VPW8//Wugby2nG3hOFqMEPYVfCfUNj+7Fsw0gWTnhvpZITKjW+hjccC
  22. 64d8LOmGGCYpRSn89mItof6I0EDvXR99Sd6eMEuQGLyijFcBbWQePuiwda1sDNf9U
  23. w==
  24. </ViaThinkSoftSignature> */ ?>
  25. <?php
  26.  
  27. /*
  28.  * VNag - Nagios Framework for PHP
  29.  * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
  30.  * Licensed under the terms of the Apache 2.0 license
  31.  *
  32.  * Revision 2022-09-12
  33.  */
  34.  
  35. declare(ticks=1);
  36.  
  37. class FourImagesVersionCheck extends VNag {
  38.         protected $argSystemDir = null;
  39.  
  40.         public function __construct() {
  41.                 parent::__construct();
  42.  
  43.                 $this->registerExpectedStandardArguments('Vht');
  44.  
  45.                 $this->getHelpManager()->setPluginName('check_4images_version');
  46.                 $this->getHelpManager()->setVersion('1.0');
  47.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local 4images system has the latest version installed.');
  48.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  49.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
  50.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  51.  
  52.                 // Individual (non-standard) arguments:
  53.                 $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, '4imagesPath', 'The local directory where your 4images installation is located.'));
  54.         }
  55.  
  56.         protected function get_4images_version($path) {
  57.                 $path = realpath($path) === false ? $path : realpath($path);
  58.  
  59.                 $cont = @file_get_contents("$path/includes/constants.php");
  60.                 if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) {
  61.                         throw new Exception("Cannot find version information at $path");
  62.                 }
  63.  
  64.                 return $m[1];
  65.         }
  66.  
  67.         protected function get_latest_version() {
  68.                 $cont = @file_get_contents('https://www.4homepages.de/download-4images');
  69.                 if (!$cont) {
  70.                         throw new Exception("Cannot access website with latest version");
  71.                 }
  72.  
  73.                 if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) {
  74.                         if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) {
  75.                                 throw new Exception("Cannot find version information on the website");
  76.                         }
  77.                 }
  78.  
  79.                 return trim($m[1]);
  80.         }
  81.  
  82.         protected function cbRun($optional_args=array()) {
  83.                 $system_dir = $this->argSystemDir->getValue();
  84.                 if (empty($system_dir)) {
  85.                         throw new Exception("Please specify the directory of the 4images installation.");
  86.                 }
  87.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  88.  
  89.                 if (!is_dir($system_dir)) {
  90.                         throw new Exception('Directory "'.$system_dir.'" not found.');
  91.                 }
  92.  
  93.                 $version = $this->get_4images_version($system_dir);
  94.  
  95.                 $latest_version = $this->get_latest_version();
  96.  
  97.                 if (version_compare($version,$latest_version) >= 0) {
  98.                         $this->setStatus(VNag::STATUS_OK);
  99.                         $this->setHeadline("Version $version at $system_dir", true);
  100.                 } else {
  101.                         $this->setStatus(VNag::STATUS_WARNING);
  102.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  103.                 }
  104.         }
  105. }
  106.  
  107.