Subversion Repositories vnag

Rev

Rev 4 | Blame | Last modification | View Log | RSS feed

  1. <?php /* <ViaThinkSoftSignature>
  2. M5s14jZt1LxgtSqICA+mTNwD5gyp7BoQcIZLnI+/UJKBBOucFhN1ZlsZMEnuTBCkD
  3. 2EiOsnpjFqE9AzQA2UyVikHkI+ORmA6NDFEIalPk3hVe2oIC16AFsUPJaJgNix3WG
  4. /P8uTsuYrdfmMnrcHJufyIhrA9CZproNE/3FdWrRCaRVDGRPmvV4H1Ge0p79oLgAP
  5. G/9ExglsCV0aBdn/43H3ckhAoovBHfTyepXk45K2++mEF+DIyZhtOa1F3bWRRmVQL
  6. pT19P96zNcsQSU6IivybRc+dHOwYA6tvGBJftRtBbgkCN/W33FF/YDRAdIRPNIKES
  7. QOE5XkovdNtpJ+N+SgejYDQGpo9cGD5LVPRWZezXqcj/5DCGh69iYJ3iZrAMYz/v/
  8. i/f41m6fl+Bv/A9KKKgz5OtjPfiFEIbgBEp1DdnrBHBt6aeF0OLR8Mi97jiV+Q7JN
  9. QzKyEHTU9T28ie1rE+DVMzukzNPXEULPeGqz0QGpOBFQ7KVu3HbQ5nve9cXUhqKH2
  10. K7pBrmj6t1Owl+oaX3rIZ0JQHBtZEGbdt+0KxGIqcHh0eYggZiYm8ZMTB8jydjKpv
  11. lhvAwRlgWDaQ/i/4wNLJDRNgd7O6TPItNTROw6XKxL9GOzP5wKK6ZNEcStp1rUdI1
  12. rYiqoKhybsiyzmmsoF1AuSt4ya6IYQkV0aOCadpEX33LfzjbeOyM22SNf7FC50QM1
  13. mo/O7MA5rR5n2bkXe24fhJ9T40jhLvrO8KCDXeLK5v6W/4hfnx6ICx+g9+bHO4d2Y
  14. 0Ij9Ck13oaHmmVNkvbFV24DbIYicyCXJZoXSQSGAs2h7Z8TLKpWHMPtzWNTS0ZuDy
  15. Erd9kdkpxX0Yr6tkGmSWMX18qV3gVn3DfXTUrG2Lrzq9eGkAqViVXPmCLpbn9EG/7
  16. Sl0T3XEApLOsJIFCQgIFz1ZqfvkVcyxCX/P8yTa77rz2okroypAw2AHFasw1kYbpb
  17. yt3TmSDp/H90watdIAs6cvzaQZSPT8sBYr2K85n89vzoznU4YdTc2SawEv8/3lPvw
  18. WyoDr+A3myYPG0eSwDZLPqzOylaXCu41Rs9Rm8waYplX87HiNz1dw+vJyfkEqW9hh
  19. kBoMYkBICZuCZ13edXvgutALbJgY6ddmzPqLD50ReBO8ORhWlnq/wrbLJM4WN9h9y
  20. sBN73TLRlfmfmTF1WKpQu54KnFhj8Vu0SgNk5LCP59lT4a83VVRMMr37sbsBRH+Ye
  21. E3nQm/+5lQh9U0M2hpUQqkt1IgImfN/ZTN5MYFCvVMsOJ6H0NRAdBmY3Pl1fwy2Xg
  22. bMvmHc+olwQxf8Ep6bh/yi/+f+X8wLsPvpUbLhCWXeJOOrzOYQwrY9idSuUk6Xsav
  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 2018-07-15
  33.  */
  34.  
  35. declare(ticks=1);
  36.  
  37. class RoundcubeVersionCheck 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_roundcube_version');
  46.                 $this->getHelpManager()->setVersion('1.0');
  47.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local Roundcube Webmail 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, 'roundcubePath', 'The local directory where your Roundcube installation is located.'));
  54.         }
  55.  
  56.         protected function get_roundcube_version($path) {
  57.                 $path = realpath($path) === false ? $path : realpath($path);
  58.  
  59.                 $cont = @file_get_contents("$path/program/lib/Roundcube/bootstrap.php");
  60.                 if (!preg_match("@define\('RCUBE_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 cbRun($optional_args=array()) {
  68.                 $system_dir = $this->argSystemDir->getValue();
  69.                 if (empty($system_dir)) {
  70.                         throw new Exception("Please specify the directory of the Roundcube installation.");
  71.                 }
  72.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  73.  
  74.                 if (!is_dir($system_dir)) {
  75.                         throw new Exception('Directory "'.$system_dir.'" not found.');
  76.                 }
  77.  
  78.                 $version = $this->get_roundcube_version($system_dir);
  79.  
  80.                 $cont = @file_get_contents('https://roundcube.net/download/');
  81.                 if (!preg_match_all('@https://github.com/roundcube/roundcubemail/releases/download/([^/]+)/@ismU', $cont, $m)) {
  82.                         throw new Exception('Cannot parse version from Roundcube website. The plugin probably needs to be updated.');
  83.                 }
  84.  
  85.                 $latest_version = $m[1][0];
  86.  
  87.                 if (in_array($version, $m[1])) {
  88.                         if ($version === $latest_version) {
  89.                                 $this->setStatus(VNag::STATUS_OK);
  90.                                 $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
  91.                         } else {
  92.                                 $this->setStatus(VNag::STATUS_OK);
  93.                                 $this->setHeadline("Version $version (Old Stable / LTS version; latest version is $latest_version) at $system_dir", true);
  94.                         }
  95.                 } else {
  96.                         $this->setStatus(VNag::STATUS_WARNING);
  97.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  98.                 }
  99.         }
  100. }
  101.  
  102.