Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>
  2. OpbezgMkPVeK+pfO9zIJJPwMOQ4+s630AKA2J/Ty+RAdDwFg0cUT39SNttpTBpK+a
  3. y9RxTZ11ln3kvaw6NbOHSPswfOZX9+jl8IhgpzQzDE+ha0JA0WFrDv342DgcWgap7
  4. hWCbucAj/9aOpPT3j5tBxsUs8FON297kr5dQwtSmHcsPIauu2tsaAOOUdDouEO8Ua
  5. xPrpdQ6oN5tpiBlWh5RBTn+19N0ra96MUXi02Tk4+6axIQ8xrkeTNb8LLkQM/h3J7
  6. oVndkbnF/xVrtMxjz7pB+0IxiTAREM6cRBfVsrMawyPWp075iqiVuea3XCy2Di1rW
  7. 3hbfWg0QfYX63ft4Ag7HyxANs9NMcNEDU3tdotae+Rs7W8L7c7Gu1+Pc6wTjX1gBV
  8. Y0am+pP0Uceug2sR7nCi6Ew9ff6XQE9DUy7/GkQsxpRhxs/2UpuHHpiygvl1DhUrm
  9. vBbDmfKSN3QTdKaTVJ3ym19MyvU/KAgHPsLX2ekDUGKIwc32vUUBvYVJvMdoavI+P
  10. +1YKEg/oRveZuEaWvpyu/AJIlhFrd9/ZaLenyC5KpiTB+1+x3vvbVkcvOAZydmCOl
  11. jHS0M2ep33yl5qSBjv6gdiwkaX6ABStaZNNcyiPbG7CBhbkdTlePrwSQ6GpV5F6F1
  12. rs1mnAhFHxNK/BC0BtOMEU25xmODEf5o7Fs88sce38CaIEQ60WNX2ntMl4Fj0nDVj
  13. nIb8tAk04h8uXPs+ZMWS5Z18OimkzGUaiig8Fr8cgi5OHdq7653/KrdyLc/y2gu+J
  14. SrLzvQ505M0CtxRkQq1bBOw8gdeDfQfsYebwkz5t/AstIDQBaTNBbT2sgSAjtNz4k
  15. AssiRulBzQW2usaVk2wcJWZgsZAkDCih2l2oVyrEUi1ZyG04L1//pHHEKiZToPQVa
  16. 1AkIH+EAgq9gsdDCqYxHr7otFoEScMkI5I4hsKIB0QA4RssthlKAwsxnVxUhiKn4u
  17. U3Id6tZ9y3Wy0652VSeD4R1PZPnyy8lGKzZ1LfxKyPUWpcZLSQwdHPWRxzd6gp1aw
  18. 98+Iwqt9nezuum+PcAVYNEaU7bJ8UNVLlsviBNevKGcW5Q5WSK97w6BZ03uwFHSmb
  19. HT6n2/lSw8yL1j4eShi0kK/kEhmB0GenuwlZpBnyIpSSvKhDENsQMqUpQc/r1zqp/
  20. V7IQM0V1sU35flp486GhDpEwX2XrIFM7ChCXONQpfv8LXS0Q5UUVimlner5YotdmJ
  21. WnCwWLdyGLDPQGTtsyTQOa0QqVgn6vruU99wjtmKuamiG/VvtRu/iinzQRgOsAYLV
  22. +xFTcloIlYqMBcTYbmE8P31rqnVKmFOH0SjiGDzi5VT21s1H4UKdcf4DX5TUklTTw
  23. A==
  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 2023-10-13
  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_local_version($path) {
  57.                 $path = realpath($path) === false ? $path : realpath($path);
  58.  
  59.                 $cont = @file_get_contents("$path/program/lib/Roundcube/bootstrap.php");
  60.                 if ($cont === false) {
  61.                         throw new VNagException("Cannot find version information at $path (cannot find bootstrap.php)");
  62.                 }
  63.                 if (!preg_match("@define\('RCUBE_VERSION', '(.*)'\);@ismU", $cont, $m)) {
  64.                         throw new VNagException("Cannot find version information at $path (cannot find RCUBE_VERSION)");
  65.                 }
  66.  
  67.                 return $m[1];
  68.         }
  69.  
  70.         protected function get_latest_version() {
  71.                 $cont = $this->url_get_contents('https://api.github.com/repos/roundcube/roundcubemail/releases/latest');
  72.                 if ($cont === false) {
  73.                         throw new VNagException('Cannot parse version from GitHub API. The plugin probably needs to be updated. (Cannot access api.github.com)');
  74.                 }
  75.  
  76.                 $data = @json_decode($cont, true);
  77.                 if ($data === false) {
  78.                         throw new VNagException('Cannot parse version from GitHub API. The plugin probably needs to be updated. (Invalid JSON at api.github.com)');
  79.                 }
  80.  
  81.                 return $data['tag_name']; // e.g. "1.6.3"
  82.         }
  83.  
  84.         protected function get_latest_versions_with_lts() {
  85.                 $cont = $this->url_get_contents('https://roundcube.net/download/');
  86.                 if ($cont === false) {
  87.                         throw new VNagException('Cannot parse version from Roundcube website. The plugin probably needs to be updated. (Cannot access roundcube.net)');
  88.                 }
  89.  
  90.                 if (!preg_match_all('@https://github.com/roundcube/roundcubemail/releases/download/([^/]+)/@ismU', $cont, $m)) {
  91.                         throw new VNagException('Cannot parse version from Roundcube website. The plugin probably needs to be updated. (Regex mismatch at roundcube.net)');
  92.                 }
  93.  
  94.                 return $m[1];
  95.         }
  96.  
  97.         protected function cbRun($optional_args=array()) {
  98.                 $system_dir = $this->argSystemDir->getValue();
  99.                 if (empty($system_dir)) {
  100.                         throw new VNagException("Please specify the directory of the Roundcube installation.");
  101.                 }
  102.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  103.  
  104.                 if (!is_dir($system_dir)) {
  105.                         throw new VNagException('Directory "'.$system_dir.'" not found.');
  106.                 }
  107.  
  108.                 $version = $this->get_local_version($system_dir);
  109.  
  110.                 try {
  111.                         $stable_versions = $this->get_latest_versions_with_lts();
  112.                         $latest_version = $stable_versions[0];
  113.                 } catch (Exception $e) {
  114.                         // roundcube.net blocks HTTPS connections from the ViaThinkSoft server since 13 Oct 2023. WHY?!
  115.                         // Access GitHub instead (but we do not get the LTS information there...)
  116.                         $latest_version = $this->get_latest_version();
  117.                         $stable_versions = [ $latest_version ];
  118.                 }
  119.  
  120.                 if (in_array($version, $stable_versions)) {
  121.                         if ($version === $latest_version) {
  122.                                 $this->setStatus(VNag::STATUS_OK);
  123.                                 $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
  124.                         } else {
  125.                                 $this->setStatus(VNag::STATUS_OK);
  126.                                 $this->setHeadline("Version $version (Old Stable / LTS version; latest version is $latest_version) at $system_dir", true);
  127.                         }
  128.                 } else {
  129.                         $this->setStatus(VNag::STATUS_WARNING);
  130.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  131.                 }
  132.         }
  133. }
  134.  
  135.