Subversion Repositories vnag

Rev

Rev 57 | 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>
76 daniel-mar 2
bHBXiUbQ+0PJcOOwAjToPOSaMw/KmBJUBDG1ycVbkSZMrjz6WzZ8OLcdBd9EyaUKC
3
tXQoz0Os3/V8G2T6osN16+DLj7jUwBFdYCbCYt9j95eZ1eSKNNyZtAHtOEVKCdtBC
4
rOwsFHdiRrHe3tvz2SmFkHFrGT53RxbwpztVfXsdsf+Xz7zBvchiQvzNi7phFTBcv
5
WUgNsGG8FbSEAHatnJNeUr3VVkEkeWdTjvP8S6x8Wmh9KREPtIBUeOWPfOl46j1lR
6
VaYVRulJVp8hTxIpciRYyHvgm6MqZuDq+iAEkD4axNhtqbkd9TXQ0jmSnFxHGWhup
7
7mNMT0DPruaeb/yMKVJwVxq6Whdz2+i+N2lSfyZ1FX+4XL0PzWaMM7aQqtLqhSTBr
8
U7vVxX6HOjPVrnyckxPZv4rBcd+9fnZFGIbUIybirMymkBPznmG/hmtzPoepztSf2
9
eGehncIopPfhLUI0MQhzA+7aF6EJYwyv/3FrmbQf9HUKs+f+0vvxQBR+k1hAD3/Qe
10
zQ2BK/or4iNm2wF+eancLYOKQm8VsBrsNtnQKDXIQ3iDChs0nJghQDbrMjbVtZKEu
11
TFKqmQ7v8zPeVmwsiRAYUQ8COASUYLt4sQUlPRG6C3TGFwRdk1Pgq9Slb+uYhs/IK
12
ot9sI46O7XUDGM5AjvNW3zHWX/ySxSClRwN50JwL1TG+5VBwY5UaoNbFz3cLrRhEC
13
M3pNHtMVPZ011d6kUwttGzK4LF3Jopj46uw2lNB9TS82bsQBAbgy5If7IVZx1jsX2
14
S/5zl+JRGCDQbEphfK2PuS0cowbv9apcpEgdK2nWN2mEewx7k3y8/EGFxuiqqqgWE
15
5OvKpXr1uuAOhrrVHDQW5cs+jdhHDHYNixAV58Ut5qCjGPWKagLJsEYqlwkel1rIY
16
yE2lB9+bmqMdBJXcPOuA5067J2DhTBIPUvrRAt9B4EfwV+PYL73CgUVnpnXVEyKqe
17
zM5SlHnb/6W++xRCF3ySn7qr4StonzI5PBraQAT27zUKuTcLEUV4SUB+h9gGWaP7c
18
Ho2wJMgjZ7eG9twks/X60t/cdhCPJqbnmnAiYsDYuMNBz+LEH7uJw/qJh4B1qZfUB
19
TPRlpGSvoPjZyGiMXlpTgpTN/PP7zQBGM9P6HOwPlIRhhHaS1zoms7P+OsdPj1Fxv
20
4fpQ5MX7b8zHuqj+Wn+FGAqZWK4hJ82ry10k26t+pqzevjZTIpb5vfpHbAX+rBzr3
21
UBwdciatgG/DF1TWmCFMaebGfi7gwRSPJY9WMcUujF7DbL48P109SKtuHFGItj98M
22
PPOShotaIAcbEuSQjRvuJ78XctuCwqsi3dimAzRXaN/91YhTSP6+hy00OHdkpRZPc
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
 *
76 daniel-mar 32
 * Revision 2023-10-13
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
 
76 daniel-mar 56
        protected function get_local_version($path) {
18 daniel-mar 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() {
76 daniel-mar 69
                $cont = $this->url_get_contents('https://www.pmwiki.org/wiki/PmWiki/Download');
70
                if ($cont === false) {
18 daniel-mar 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
 
76 daniel-mar 92
                $version = $this->get_local_version($system_dir);
18 daniel-mar 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
}