Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
18 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
2 | eqUk8Qv5K8hX8WxJgxbENCqVzJJoy0A0HTqnXHFhek/uPLrsQ46mh2QnL/42GCX6W |
||
3 | VdQVhaNjrzwxA7xM6zsLDktr6tadog/ayNq60usmt0BUXNxLeAa9x3D5FcUSHgnk0 |
||
4 | MnyyqwXJGLUyIBJVoGLYV4EQoQleJXZVV61qReSjgWqKm7Dy+Uzsqfz/FT6LMjgjw |
||
5 | qAhr02Geht+Ya6WIV7eVNYl99CNM6yit0XCYPS+ategNlwRFvpNZOTV8DWhtTx1AP |
||
6 | khaJq2bqdPIIrdR39dv8uZ4BbMqlk0ShZ1xM9cTVPeOVtQKwocdsP/ANavzCUTvIR |
||
7 | 9pWud+qGTE31Im5ZV1b9YU4KNv/3wOj4vOLLVA7FerrcL5UBAPTUZOOVGExW6FpoY |
||
8 | qnVMyNOJR3zx9yN9bWaSjbbbCNYnREA8L2UY6g8VIhPugVY6UmhHD1H9s7S2N7vtC |
||
9 | AIsKeWGWKEh755CRpadkqX64LpvYuEm2HeQmvFxtpcAN3mw5P6mqloPBtmHlDvJW2 |
||
10 | S3CbXkxkJaYf/UuFFobug2zTv8m0a6+0SPlt9EpFNh8PCXXW4vkiDVUwSbG+D3/Pt |
||
11 | fZBI2MYhMTG0Lt8HwXKxhFsYySZ3gGq4Go22nM++Ywffyl0WY2R2Rr2LQehdRzyTL |
||
12 | aNUoWbmeaYEghpRBbTzXi+w3c1z8qd9hicP8sTWxWGfymlLm2x74NerKqgzMnvElV |
||
13 | n6vO2rR9SyI5pxJIPY6wMCBquNZh93edwn5qo2SGqZlsB4ADdg0FdRV4vTeoUQbPq |
||
14 | N4RrweV2LF65cO+IZzrXN/srhzWTtN9j7uXCAmDEsb0uWOIoawbSXSZeiNUI8vDCY |
||
15 | Q7ErXb7382yC2Lrjy7NVeL7fyQA1qRBDtuAbj8/uyqUXsdzPrbS2jFWZj5gewVTob |
||
16 | 5f8z3k5pYS2EQKwFfc1K/wM4oo/ti+4pdtR9/vNba7KDoDe9gb0LjqeYERCwqMIU4 |
||
17 | HCJID5vDXrA37MPT93u51Uy++rVpN8qxDYVCi7sZHZlMmkuowYEVsDWIf1gtFEA3p |
||
18 | wpJuCV/hkY5tjl3bFXOS9Ds9rQcTcuvN2DFCsMdjIfhgrFnP+Ikow32JUms1Ys2ZR |
||
19 | N+Jzlld4e8hkoljkCU2J5OEzdb6gHc/wWBr0myonkfKMCN9J6x/WnZFRVmYbQnt7w |
||
20 | HpfIC0kNm1HvGzryHtCaTI1cADPwpNN9Aq1AqDkXht+RRzOFYlM9kF/hVR3TMGoOW |
||
21 | Kda3sUa1oJ+hasSD1g3a7DeqZ71E3JqCOpgivU0sHOkcQ1GwCsNyyaINXo3DXDa3+ |
||
22 | l9LUhOFixOuOYgTfMWiSVTt8x3m7M5EUtR6Jek6JVdkclyaPyeQOGN13LtMDzyqc1 |
||
23 | Q== |
||
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 2020-03-12 |
||
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)) { |
||
89 | throw new Exception('Directory "'.$system_dir.'" not found.', false); |
||
90 | } |
||
91 | |||
92 | $version = $this->get_pmwiki_version($system_dir); |
||
93 | |||
94 | $latest_version = $this->get_latest_version(); |
||
95 | |||
96 | // TODO: We should probably use version_compare() instead of string comparison |
||
97 | if ($version == $latest_version) { |
||
98 | $this->setStatus(VNag::STATUS_OK); |
||
99 | $this->setHeadline("Version $version at $system_dir", true); |
||
100 | } else { |
||
101 | $this->setStatus(VNag::STATUS_WARNING); |
||
102 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
103 | } |
||
104 | } |
||
105 | } |