Subversion Repositories vnag

Rev

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

  1. <?php /* <ViaThinkSoftSignature>
  2. FWd3PzwACGUUNwFj2FZtdCx2ipXSNX3x1uyBFYgzLzp0K55oOdnhaEN+27cirbkFQ
  3. V7tzbYBjLSBjEJHuxvJ9O0z3Pe4UfpBssdGK8olMawnYpucXTWu5V/LXpHR8+/6Ky
  4. DSnF9zrZWOQVCopAhoxQIr3qrZOVduC5/fVuJ3G4KMQpnPRee39bfjYOw9uZWLYeb
  5. Ad65OvGt4FWinnFF2nWmtwzjJizewBgHGOANcLcGfku9jPWW7yPv4h/AkM0Djoef5
  6. a9KAjruBIl59Ff0f8XwIqHVobn1e8r7C5OxAj+k8MJFEKIuc+p0cTs6jvNlqIPmqq
  7. j3v+HCcLJO3F/EQ5B5RvjJdzSoYWz9SAO+qZj5w+NFnhAOl3wU3tvxPOqqdJbHh9m
  8. 8odOGvxQynUPyD5gm6VvRKT9XqaFEWrW4fZsjZBqAQ4OPmr9OZojvI6DgcCKawxeY
  9. Je2QWUTAD8LugXi4+K9SNWAReIUF5JjUAAM52CwlybgYj2JLZGjUiXdIiZ64wn/sW
  10. WKOiHk6kKiNIG2hoSFapWF7kzuqAKLISDzMKFQ6SpnGy72It8btxwpnrdfociZzJ+
  11. 8rPoIa4Xbo2Kz3Gel42wHnokXZdqWaTkMGY9kRON+MdXMVNoZFtUxegniDMtwK/48
  12. 4E0FrL3LBLdhveKvKbf8D0jpns/tByOELsw3p2m+frCAfUfmjoqeuC+jpkRYF3JxI
  13. jSZdJozWJTwNVpvhT3Q16/0O4gLm6Uqwxz0oLpsoA/c1P/yGOqf8eFdWklu46PvZY
  14. KuB4Uv8TANYvk3HMGNbz2OSWnbKAFuhm7pztZdtztszbYU7VB8/UQ2FLLLoYtkXBf
  15. R2AB2qyvy7hbNp4Qq+NyJFuM13WOHI6EcJHAMdkpNZ3E5D9Oz9QWOELAwpcgUUOGr
  16. uDoK1DYVx80+Ark8BOEQ2EroNSBYhepKltUHoa7hU8168E/9RQPU5j1FPAVxzohp3
  17. T5ZpJlxRG6P0AvwfVXKJq0gYwpdsmY3ICi+B0FCGv9d10lpxiGg7AouUQ4MBQbgzS
  18. 5Exe2dkmaQG5JgPwstUCr46aAVTOIKgfgHZKgWKkKdryhLNpRY10Cg6V3YYpKK2IM
  19. 83CsIu9sCMGRj6cmruPVU0V03UUazz1msJRYtxZU7kcpEYSbWWpY4vVaRDzNwvhIa
  20. v58j4TUKubiiAUBLlMF/JI5WmdIpAgbNxDmH/th7Oji2cJUMicnyPWXo9ldUUt0PA
  21. JGGODkYUXPzQ3hj4ncI742VXxbhTe6MCkZKPu/D3y54KHyc9Q67tc533Qu7+KEX3A
  22. rO9FDJKPnreXD57NC9hx7CWYkh8XobtlbqKgBW2wHufEy7rtyElus0+j7PFBKjgCD
  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 2023-10-13
  33.  */
  34.  
  35. declare(ticks=1);
  36.  
  37. class PmWikiVersionCheck 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_pmwiki_version');
  46.                 $this->getHelpManager()->setVersion('1.0');
  47.                 $this->getHelpManager()->setShortDescription('This plugin checks if a local PmWiki 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, 'pmWikiPath', 'The local directory where PmWiki 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/scripts/version.php");
  60.                 if ($cont === false) {
  61.                         throw new VNagException("Cannot find version information at $path (cannot read version.php)");
  62.                 }
  63.  
  64.                 if (!preg_match('@\\$Version="pmwiki-(.+)";@is', $cont, $m)) {
  65.                         throw new VNagException("Cannot find version information at $path (cannot find version string)");
  66.                 }
  67.  
  68.                 return $m[1];
  69.         }
  70.  
  71.         protected function get_latest_version() {
  72.                 $cont = $this->url_get_contents('https://www.pmwiki.org/wiki/PmWiki/Download');
  73.                 if ($cont === false) {
  74.                         throw new VNagException("Cannot access website with latest version");
  75.                 }
  76.  
  77.                 if (!preg_match('@Latest <em>stable</em> release \(pmwiki-(.+)<@ismU', $cont, $m)) {
  78.                         throw new VNagException("Cannot find version information on the website");
  79.                 }
  80.  
  81.                 return $m[1];
  82.         }
  83.  
  84.         protected function cbRun($optional_args=array()) {
  85.                 $system_dir = $this->argSystemDir->getValue();
  86.                 if (empty($system_dir)) {
  87.                         throw new VNagException("Please specify the directory of the PmWiki installation.");
  88.                 }
  89.                 $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
  90.  
  91.                 if (!is_dir($system_dir)) {
  92.                         throw new VNagException('Directory "'.$system_dir.'" not found.');
  93.                 }
  94.  
  95.                 $version = $this->get_local_version($system_dir);
  96.  
  97.                 $latest_version = $this->get_latest_version();
  98.  
  99.                 if (version_compare($version,$latest_version) >= 0) {
  100.                         $this->setStatus(VNag::STATUS_OK);
  101.                         $this->setHeadline("Version $version at $system_dir", true);
  102.                 } else {
  103.                         $this->setStatus(VNag::STATUS_WARNING);
  104.                         $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
  105.                 }
  106.         }
  107. }
  108.