Rev 29 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
18 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
57 | daniel-mar | 2 | rpUdHNdO4FpccwYOBOlXhGElqJIl7T6SKi8+rz7lwKg1w7EpBqrn+bqF4gmmcT8JX |
3 | 49NsMDcPftt9qc//I9CdiK7mGiFiR8ymWt/xCXQaIIAllAq8+8PHJfihot9z9fzLS |
||
4 | xJQ61eJfrU8aeHWl1FaeI193ESmzY2HzjvOt0W883EQDLxVDQ45sGu623SX1XuTFH |
||
5 | L/rkT6EUM5iWOqBfwho+1V2HZATk4sGB7ZMSLWUyGlXIagJOZQIPb1uQHA5G9zcW/ |
||
6 | 6yDVhXrKyHi7rApzDqYHaemEr5b9Qmaw4KJbWIFsqCWpWTeRRsI5hrnRiZwCm1yaE |
||
7 | 9j6wGzCi5m9Yp2Xm36sPmhAG9An6c9wypIIyp3WV44ECFmpuTQqtqaj7MTorxztKs |
||
8 | yTPr7lcLSYzfqYcbsPUb6vLTXmFz71nq+aBRgrqXa6V/coIL84qpIzM4JCdDrUSNN |
||
9 | vVXolPoSu1XL1gA9Y+3X915vdVUfMSVUfLhOWqiZD+tmmlDZTvlFAq9kM2gjkzeRS |
||
10 | Tj7rJeIhkN39e9h17RhTBT50OQvJIpJUwLmAdorV1F/zWMDRK6LtYT00B+EYQ3SIR |
||
11 | FwZRlW7LMjNrbFj2r2ocBJGhkP1YQBrZakj6Qa50iB1dsS+3OZxtQ/jWP/VXFc631 |
||
12 | vosPB4/u+GqryaRR3C/LpxMBypIVDk4J6LRh5EhUDjjNu9L1yIBOu0syHp6Wuojto |
||
13 | zDbD0Y13Ik3wrLBOz/J6Wu1/baN2CN/a2yaUlGKIqoUHijM909J1YVZDNdahssNIK |
||
14 | M9jK/AHfv/I6wB1IGH39+W9aFJNOnLu5lY3JQEAPuheaIxiN4/71fO2AOTiIdsC9h |
||
15 | jjvRukBnI9GAXx56awejGZ8DDhX+k2hJrx6N9G+tKCB7yGx2Wed91ZNGbIRJlWJQk |
||
16 | hFr+8rP60u/ySa2RDBCzwLbG/KUlvL1P5mGfU507t1shIZg0lZIxgZHYARgDRzOm4 |
||
17 | jPCX3G77jxd4VubQ0YU9ip0LjiirAuY6JKpz6aqLnZxRnD5bpuRvyf++X0JOujPwZ |
||
18 | T0bFVHUdXJzIU/7GpO/nYbmdOkmf/z4zZZEGI9/6hMLLoZ1RtCKZ1/h8Z+CUMDNfE |
||
19 | R6e7RwuHeUHSo3q0XHL/OfcVZKlyzQkvp3UD4ftErEBhMolFAQQIG1og5v5h6EMOn |
||
20 | CkQPJ6RzSn0k/f3PiixXE0iH/X62LH0m4U9vg2+S700d/91N+R4Nawu3A/cqyCXZa |
||
21 | A3xQtlTg2E7o6RKFTqqWfHxk2rKZ9AWrft/chy+iVJxn1G8b+TwMPd6NBRnfah+77 |
||
22 | JQiGbHpKHxv8OAJC58VPKVfjBqoOg9llTH5+b0eZ9owzF8d9UohQ/vgoCph7bk8q1 |
||
29 | daniel-mar | 23 | w== |
18 | daniel-mar | 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 | * |
||
57 | daniel-mar | 32 | * Revision 2022-09-12 |
18 | daniel-mar | 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_pmwiki_version($path) { |
||
57 | $path = realpath($path) === false ? $path : realpath($path); |
||
58 | |||
59 | $c = @file_get_contents("$path/scripts/version.php"); |
||
60 | |||
61 | if (!preg_match('@\\$Version="pmwiki-(.+)";@is', $c, $m)) { |
||
62 | throw new Exception("Cannot find version information at $path"); |
||
63 | } |
||
64 | |||
65 | return $m[1]; |
||
66 | } |
||
67 | |||
68 | protected function get_latest_version() { |
||
69 | $cont = @file_get_contents('https://www.pmwiki.org/wiki/PmWiki/Download'); |
||
70 | if (!$cont) { |
||
71 | throw new Exception("Cannot access website with latest version"); |
||
72 | } |
||
73 | |||
74 | if (!preg_match('@Latest <em>stable</em> release \(pmwiki-(.+)<@ismU', $cont, $m)) { |
||
75 | throw new Exception("Cannot find version information on the website"); |
||
76 | } |
||
77 | |||
78 | return $m[1]; |
||
79 | } |
||
80 | |||
81 | protected function cbRun($optional_args=array()) { |
||
82 | $system_dir = $this->argSystemDir->getValue(); |
||
83 | if (empty($system_dir)) { |
||
84 | throw new Exception("Please specify the directory of the PmWiki installation."); |
||
85 | } |
||
86 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
87 | |||
88 | if (!is_dir($system_dir)) { |
||
29 | daniel-mar | 89 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
18 | daniel-mar | 90 | } |
91 | |||
92 | $version = $this->get_pmwiki_version($system_dir); |
||
93 | |||
94 | $latest_version = $this->get_latest_version(); |
||
95 | |||
57 | daniel-mar | 96 | if (version_compare($version,$latest_version) >= 0) { |
18 | daniel-mar | 97 | $this->setStatus(VNag::STATUS_OK); |
98 | $this->setHeadline("Version $version at $system_dir", true); |
||
99 | } else { |
||
100 | $this->setStatus(VNag::STATUS_WARNING); |
||
101 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
102 | } |
||
103 | } |
||
104 | } |