Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>muCA1BNAx3t4UMIIzqCeb9w0THNUjzz6c/qmRy6zLtsiwU3WE0nJFpHwi6R1B3jhrivN4x+RGN9wo2YCpenFDreN0+k4oHsxsqz68eiaiH2+1Z5bKXMayUNG97mFdbWxIxAt1VWBRG4GSXnAbkX3ubNhQw1e2WptqpT4SufS5KcGaaI/MxwRrBdjheyENnNahSFnjM4LHw6R2On+P5RCML9aReiYLECYhZPi/WlqOI7aj46Qfu5g29s6qxfKEc3HWGoXkJi706o9G4j/nffo16EBrgpjLMQxO7z7nhsbbaucABnMuDu50ViFmJRMi6j0ys5SYwrLuoa3VqGL73Gxy7agJgF/4+35Q4LArCyhIIg7xmtOmC+vKIDlJD9cmUpIBT3th9Sxqzl5uMkoqZRpBzOtTIKFX/p4I6VbJSjroHVcCO5rUbwzXZDshdLdbULXTOR8/dJs3aqOPpPbMasblpVc6oRfePS1Wy1agYBl5kbZErJeYr2ZerhsAdwvkoXjM14Sk6Ol9evRdSbdGDVK3x1zJSvoW4yE+tImN7zCnlqCc4AD2u8EWjDXCGfhkaAzbbqf8Geo6TSJQm3YUJWfZFP0y7SYfyzeYt7ZVHyLcUNxowRsAfYndXn2700HqJP1pDtmWEVcnJpbie9BwDkasWbgCXypXcRAItnHDndYIyxxCTYfXamZIrhmQ40aJow1WYEpDzj1TI9vmFTXh0ciY9/rvMATofiUOCgyn6k2BukNFND3oFr9M/FsPx6UFnmjprphQdQSvcIu+VnrnQRRRCwvJRHqjvbZVjN8/aluTPWib5+ITMW0PdrfzXPgZbzLjpBFLg1nHtC7dxFQ/8OyCibCe0+SY0nLyq/TFBbSBjaK96kXjOT8xp5aVyGiSrXm8wPh1WtlOaJhrj5cNP0si/rd7vmLzyxC/eplqddVyfbKVNZRyjbcyyg1D5Wsg9uhp+sgnMSPad1O6yw44rfbtnyT+imUWXoqU4h3B+h21BYIFnYqvJtA/UfloimomfvNxjqiwX0oHuYII3Dv/b14JGXGaps/PaxRvQjxEHOvVZhU5Eus9piYihgQxhq6/B5A6d1Om7iZsyIkOvX+F45WuazvoEc3gs3c6F8EmGY1i4vdSJ6ws9VueJSyyE0hPePGV7vJQ92EduP/j2Yna6cOcNP0W26gNlTcQO2G0K4zm5ZBI5RhocRsTKHxm9XQIA2+KgjvpEupb5R+Sqt7NKPDfMtFiTSoPkCaB1Qgc5JDdJqXlpOm4dlT9OCryAqMvcBJSDchNM+/u7gbk/P5zBZHGpn0BcCkX409jH7Z1l5rMKTwOkInPxD1XkUnXO55HMR2/m+TDlk3BnA6fgIau2eajQ==</ViaThinkSoftSignature> */ ?>
  2. <?php
  3.  
  4. /*
  5.  * VNag - Nagios Framework for PHP
  6.  * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
  7.  * Licensed under the terms of the Apache 2.0 license
  8.  *
  9.  * Revision 2018-07-15
  10.  */
  11.  
  12. declare(ticks=1);
  13.  
  14. class FourImagesVersionCheck extends VNag {
  15.         protected $argSystemDir = null;
  16.  
  17.         public function __construct() {
  18.                 parent::__construct();
  19.  
  20.                 $this->registerExpectedStandardArguments('Vht');
  21.  
  22.                 $this->getHelpManager()->setPluginName('check_4images_version');
  23.                 $this->getHelpManager()->setVersion('1.0');
  24.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local 4images system has the latest version installed.');
  25.                 $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
  26.                 $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
  27.                 $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
  28.  
  29.                 // Individual (non-standard) arguments:
  30.                 $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, '4imagesPath', 'The local directory where your 4images installation is located.'));
  31.         }
  32.  
  33.         protected function get_4images_version($path) {
  34.                 $path = realpath($path) === false ? $path : realpath($path);
  35.  
  36.                 $cont = @file_get_contents("$path/includes/constants.php");
  37.                 if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) {
  38.                         throw new Exception("Cannot find version information at $path");
  39.                 }
  40.  
  41.                 return $m[1];
  42.         }
  43.  
  44.         protected function get_latest_version() {
  45.                 $cont = @file_get_contents('https://www.4homepages.de/download-4images');
  46.                 if (!$cont) {
  47.                         throw new Exception("Cannot access website with latest version");
  48.                 }
  49.  
  50.                 if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) {
  51.                         if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) {
  52.                                 throw new Exception("Cannot find version information on the website");
  53.                         }
  54.                 }
  55.  
  56.                 return trim($m[1]);
  57.         }
  58.  
  59.         protected function cbRun($optional_args=array()) {
  60.                 $system_dir = $this->argSystemDir->getValue();
  61.                 if (empty($system_dir)) {
  62.                         throw new Exception("Please specify the directory of the 4images installation.");
  63.                 }
  64.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  65.  
  66.                 if (!is_dir($system_dir)) {
  67.                         throw new Exception('Directory "'.$system_dir.'" not found.', false);
  68.                 }
  69.  
  70.                 $version = $this->get_4images_version($system_dir);
  71.  
  72.                 $latest_version = $this->get_latest_version();
  73.  
  74.                 if ($version == $latest_version) {
  75.                         $this->setStatus(VNag::STATUS_OK);
  76.                         $this->setHeadline("Version $version at $system_dir", true);
  77.                 } else {
  78.                         $this->setStatus(VNag::STATUS_WARNING);
  79.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  80.                 }
  81.         }
  82. }
  83.  
  84.