Rev 29 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 29 | Rev 57 | ||
---|---|---|---|
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | NYkLKM16RHNYfXmjgdkPJRDFv60IevURDpDXhislrri20CeCNbL85l/s8qTzwi3B3 |
2 | rpUdHNdO4FpccwYOBOlXhGElqJIl7T6SKi8+rz7lwKg1w7EpBqrn+bqF4gmmcT8JX |
3 | DBka6P0CaPrhOx1eBOTJ1/DgFMP8peQnG/VE+Riq35tzS5m0rX7b8zAt0f14HmuB4 |
3 | 49NsMDcPftt9qc//I9CdiK7mGiFiR8ymWt/xCXQaIIAllAq8+8PHJfihot9z9fzLS |
4 | cpLY91ZtLUEb+KM+rKLu+mn+oXHbUo8+Tti7MAOp+GxR2mBPHJFgW3NgfaFdmBWiY |
4 | xJQ61eJfrU8aeHWl1FaeI193ESmzY2HzjvOt0W883EQDLxVDQ45sGu623SX1XuTFH |
5 | MQiVUcpo4+Jc3iLUkMEHvUpspOJLWwXdl5iznN98AvboiMd30qujSZDcFXvyRgsJv |
5 | L/rkT6EUM5iWOqBfwho+1V2HZATk4sGB7ZMSLWUyGlXIagJOZQIPb1uQHA5G9zcW/ |
6 | BMhw8k/snsHTBvsfsDsaluVNGIK97Vuj70fRUeYxhWgLwuZogHu6T4LL0rpk7sMuN |
6 | 6yDVhXrKyHi7rApzDqYHaemEr5b9Qmaw4KJbWIFsqCWpWTeRRsI5hrnRiZwCm1yaE |
7 | BM3kZJ8/7o9rP0JiKuEsGchn04sr5DmOL6k3W1DN/BwhUEEjqAqfKD1X06fkXlNeb |
7 | 9j6wGzCi5m9Yp2Xm36sPmhAG9An6c9wypIIyp3WV44ECFmpuTQqtqaj7MTorxztKs |
8 | BXOK21kKvjOk3EdUlEAWH+xiMf5eFAYNl4EjKPNwRMZXF4j2oU3VLBqjWWJtUfIfi |
8 | yTPr7lcLSYzfqYcbsPUb6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5CicjJseIegqTdh |
16 | hFr+8rP60u/ySa2RDBCzwLbG/KUlvL1P5mGfU507t1shIZg0lZIxgZHYARgDRzOm4 |
17 | Dfk6LrTfZLlZH7I3bqTbent8ksfY5HUVBhYDHYxe8WuYaH/JjoQR+OetX4Oc4H7TL |
17 | jPCX3G77jxd4VubQ0YU9ip0LjiirAuY6JKpz6aqLnZxRnD5bpuRvyf++X0JOujPwZ |
18 | 02J+8ZlRtbPC/RiJBiCvkrfdIKfEgPuAe7tJcak/qkOX732n9YbG57FGkLN8O1UL5 |
18 | T0bFVHUdXJzIU/7GpO/nYbmdOkmf/z4zZZEGI9/6hMLLoZ1RtCKZ1/h8Z+CUMDNfE |
19 | Zq5JGoraJCPQ7n0DQFVJE6czbagE8qRsIg8vcojkggm3keP1lHLD9d9iCFXxmq3nR |
19 | R6e7RwuHeUHSo3q0XHL/OfcVZKlyzQkvp3UD4ftErEBhMolFAQQIG1og5v5h6EMOn |
20 | t48A0i4MOoviV+9b6flfEBzXc2E8QN0fe+7Y/3zBASpBp7y/93dvPJHXHUqQy/3IA |
20 | CkQPJ6RzSn0k/f3PiixXE0iH/X62LH0m4U9vg2+S700d/91N+R4Nawu3A/cqyCXZa |
21 | YE9Pis9ln8iBIlgXycu0PAeeHZgAOoXwxmZci/etLAiSJ3Uy/lfriyBBg7bR0U554 |
21 | A3xQtlTg2E7o6RKFTqqWfHxk2rKZ9AWrft/chy+iVJxn1G8b+TwMPd6NBRnfah+77 |
22 | OofVYwCyRyh9V46ifqhpYVdsqpFllmyiZGdJgm0CfIcAFiEjXAwljH8i0wU+hEHza |
22 | JQiGbHpKHxv8OAJC58VPKVfjBqoOg9llTH5+b0eZ9owzF8d9UohQ/vgoCph7bk8q1 |
23 | w== |
23 | w== |
24 | </ViaThinkSoftSignature> */ ?> |
24 | </ViaThinkSoftSignature> */ ?> |
25 | <?php |
25 | <?php |
26 | 26 | ||
27 | /* |
27 | /* |
28 | * VNag - Nagios Framework for PHP |
28 | * VNag - Nagios Framework for PHP |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
30 | * Licensed under the terms of the Apache 2.0 license |
30 | * Licensed under the terms of the Apache 2.0 license |
31 | * |
31 | * |
32 | * Revision 2020-03-12 |
32 | * Revision 2022-09-12 |
33 | */ |
33 | */ |
34 | 34 | ||
35 | declare(ticks=1); |
35 | declare(ticks=1); |
36 | 36 | ||
37 | class PmWikiVersionCheck extends VNag { |
37 | class PmWikiVersionCheck extends VNag { |
38 | protected $argSystemDir = null; |
38 | protected $argSystemDir = null; |
39 | 39 | ||
40 | public function __construct() { |
40 | public function __construct() { |
41 | parent::__construct(); |
41 | parent::__construct(); |
42 | 42 | ||
43 | $this->registerExpectedStandardArguments('Vht'); |
43 | $this->registerExpectedStandardArguments('Vht'); |
44 | 44 | ||
45 | $this->getHelpManager()->setPluginName('check_pmwiki_version'); |
45 | $this->getHelpManager()->setPluginName('check_pmwiki_version'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local PmWiki system has the latest version installed.'); |
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.'); |
48 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
51 | 51 | ||
52 | // Individual (non-standard) arguments: |
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.')); |
53 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'pmWikiPath', 'The local directory where PmWiki installation is located.')); |
54 | } |
54 | } |
55 | 55 | ||
56 | protected function get_pmwiki_version($path) { |
56 | protected function get_pmwiki_version($path) { |
57 | $path = realpath($path) === false ? $path : realpath($path); |
57 | $path = realpath($path) === false ? $path : realpath($path); |
58 | 58 | ||
59 | $c = @file_get_contents("$path/scripts/version.php"); |
59 | $c = @file_get_contents("$path/scripts/version.php"); |
60 | 60 | ||
61 | if (!preg_match('@\\$Version="pmwiki-(.+)";@is', $c, $m)) { |
61 | if (!preg_match('@\\$Version="pmwiki-(.+)";@is', $c, $m)) { |
62 | throw new Exception("Cannot find version information at $path"); |
62 | throw new Exception("Cannot find version information at $path"); |
63 | } |
63 | } |
64 | 64 | ||
65 | return $m[1]; |
65 | return $m[1]; |
66 | } |
66 | } |
67 | 67 | ||
68 | protected function get_latest_version() { |
68 | protected function get_latest_version() { |
69 | $cont = @file_get_contents('https://www.pmwiki.org/wiki/PmWiki/Download'); |
69 | $cont = @file_get_contents('https://www.pmwiki.org/wiki/PmWiki/Download'); |
70 | if (!$cont) { |
70 | if (!$cont) { |
71 | throw new Exception("Cannot access website with latest version"); |
71 | throw new Exception("Cannot access website with latest version"); |
72 | } |
72 | } |
73 | 73 | ||
74 | if (!preg_match('@Latest <em>stable</em> release \(pmwiki-(.+)<@ismU', $cont, $m)) { |
74 | if (!preg_match('@Latest <em>stable</em> release \(pmwiki-(.+)<@ismU', $cont, $m)) { |
75 | throw new Exception("Cannot find version information on the website"); |
75 | throw new Exception("Cannot find version information on the website"); |
76 | } |
76 | } |
77 | 77 | ||
78 | return $m[1]; |
78 | return $m[1]; |
79 | } |
79 | } |
80 | 80 | ||
81 | protected function cbRun($optional_args=array()) { |
81 | protected function cbRun($optional_args=array()) { |
82 | $system_dir = $this->argSystemDir->getValue(); |
82 | $system_dir = $this->argSystemDir->getValue(); |
83 | if (empty($system_dir)) { |
83 | if (empty($system_dir)) { |
84 | throw new Exception("Please specify the directory of the PmWiki installation."); |
84 | throw new Exception("Please specify the directory of the PmWiki installation."); |
85 | } |
85 | } |
86 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
86 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
87 | 87 | ||
88 | if (!is_dir($system_dir)) { |
88 | if (!is_dir($system_dir)) { |
89 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
89 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
90 | } |
90 | } |
91 | 91 | ||
92 | $version = $this->get_pmwiki_version($system_dir); |
92 | $version = $this->get_pmwiki_version($system_dir); |
93 | 93 | ||
94 | $latest_version = $this->get_latest_version(); |
94 | $latest_version = $this->get_latest_version(); |
95 | 95 | ||
96 | // TODO: We should probably use version_compare() instead of string comparison |
- | |
97 | if ($version == $latest_version) { |
96 | if (version_compare($version,$latest_version) >= 0) { |
98 | $this->setStatus(VNag::STATUS_OK); |
97 | $this->setStatus(VNag::STATUS_OK); |
99 | $this->setHeadline("Version $version at $system_dir", true); |
98 | $this->setHeadline("Version $version at $system_dir", true); |
100 | } else { |
99 | } else { |
101 | $this->setStatus(VNag::STATUS_WARNING); |
100 | $this->setStatus(VNag::STATUS_WARNING); |
102 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
101 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
103 | } |
102 | } |
104 | } |
103 | } |
105 | } |
104 | } |
106 | 105 |