Subversion Repositories vnag

Rev

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
YhhRwJvSCq9ZIMij3FMlw3RoGYWMmIotnzcKX1mPvLuhjGWoOGYHieG8Ob06sUjAY
2
USMXmEZw3BxLtCMYVFw3pNRfut91obKVEaTFxBoaMCPTpOUfsqHIIwwwTfKc5C9Ij
3
duZGeaepTnUTG/iNuXbiO4Ae0TCrsrZrcwsC53XZ6xch+MbLVPmwS7RayUsm4PoEt
3
uLzcD6jaorajF2zyS6qWSauACaw3jPpulkF66pSgETrNWAzaWlVanmll5gD0pE0j/
4
exzZBXDzoxu9Yk0lvX9FUC8UORJCvx9TO98uSxVZREWGQMYFAL/64lqm4i/PxOUWL
4
FTJ7GBD5+3qHz3aF5DPzncqP3l5G8AodOPDHvD15lM1e/nI4JAW0Pgsiot9AOpV0e
5
7cQt6Ue3W9PtjV7liTUSlQlPaMiu3crAHF5MZxGLGkiuk6BsObutf6foZy5f0n2mU
5
UBmi6uYOGgiuiLI3ewpyWY252aJsAhVlvRRHay23pKZkMpcZBQ2eqd4uv68s71iXd
6
d6Ouyq+eev4MNf/StbnpdiNKv+TJtHcUF6naPCArJGcTFkKFQ31UpaTljIdE2+qmo
6
YCpT5ApoRt+pDXHVg1yUvNsz+lIVentvSMXsKMvWfJpThAppoNIDRgbYcKodEn8Gf
7
vb44zqNvcQ+V5xir2/5FK87yvDFtumrn6RC1BV7skDLmxOIHlcCnOLAv5vMnLOqP+
7
0Smk5ldkuhryswCSO4RYHVW7XEF/ZEuQt2ID3Sx1AQBlJl6i+/eZ7fVTyNQtoezEx
8
PhDnLi7iACs4Kpbnuok45lHpmFyjewMZ/IoOo/1qX4Mxh3yIB9SUe9EdLtx0viegY
8
BljGD3rYxPcJ8eIYoHJf26OamG9z/mm64iNBJ5Pf6paNazV2fqLZCPZNcQzbi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JRgJdtYvcOljfyiMK4OPdMsokIM
17
BW1ibsDJxiQktapIkc/yMYlXVveRe1YyGY+oPjoSfEPvFgxJgsDCnuP8bTY3BHDoT
17
09FtFavsOVDhMJjnkr1UlzPC6tXS2b5sgE/xTbNtm0yV6ji6DSJnMjg0nyj0E1/vf
18
Y10ThdjaiL26cQq/Y/mZ/en9L+IewGeLbC9c11U8N41IvywyQxuTLraqHN85qDGVO
18
afqNx8l0Zqojhal8N02LqXMIZVxeESLwxqqS2mZtPQo9gPdz0Bgq+ce3BXnXohsXZ
19
ibIEzToi4HAJXorbHXkemfJrIPS7JrUTEwDUiO+Xrys+L9oOZl5EUHYUc+GebaMm3
19
F81JQYQoMoNCcH3WlaD+YSQnBxsKNb2qerGStGPEVsjLWJQ/1b3gwAvQvMjSvcDLc
20
nzcSkDjxGfC+44WnDvYDOdEMPtGGjH40fhhawlHO1K4+DlHNLbmBMBCoE5KaHkanN
20
G68YdiuJwf1Ipzo5MVlM6fWzR2JlyG96CXi2j8tqpeZsW42Q09A6liOR3jyY4dhbG
21
jeLh5pvNkMrJWK/1dfr5moDftU/glkHwq2srUs7/8xZU5AqcbBWQSZNztT7p58UwZ
21
0wBsj34RTl+btsXE1xG2P3TwUDaMsZYO8QWfF+m+68piAZ53ZM2vXa9BJeTRl2kHo
22
Kf6hlHOQYdY1dujII1sj2vGqKn1O+57twJpfJ/dEmEzDcii/SFml8zViWZHUG4A7d
22
Zc0uoIndnbFONE3K2Hi0FUMo25brvirV1VVSb2DW0hZbeXj4PDCtgY4tiMMEIo7vc
23
g==
23
g==
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 2018-07-15
32
 * Revision 2022-09-12
33
 */
33
 */
34
 
34
 
35
declare(ticks=1);
35
declare(ticks=1);
36
 
36
 
37
class NoccVersionCheck extends VNag {
37
class NoccVersionCheck 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_nocc_version');
45
                $this->getHelpManager()->setPluginName('check_nocc_version');
46
                $this->getHelpManager()->setVersion('1.0');
46
                $this->getHelpManager()->setVersion('1.0');
47
                $this->getHelpManager()->setShortDescription('This plugin checks if a local NOCC Webmail system has the latest version installed.');
47
                $this->getHelpManager()->setShortDescription('This plugin checks if a local NOCC Webmail 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, 'noccPath', 'The local directory where your NOCC installation is located.'));
53
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'noccPath', 'The local directory where your NOCC installation is located.'));
54
        }
54
        }
55
 
55
 
56
        protected function get_nocc_version($path) {
56
        protected function get_nocc_version($path) {
57
                $path = realpath($path) === false ? $path : realpath($path);
57
                $path = realpath($path) === false ? $path : realpath($path);
58
 
58
 
59
                $cont = @file_get_contents("$path/common.php");
59
                $cont = @file_get_contents("$path/common.php");
60
 
60
 
61
                if (!preg_match('@\$conf\->nocc_version = \'(.+)\';@ismU', $cont, $m)) {
61
                if (!preg_match('@\$conf\->nocc_version = \'(.+)\';@ismU', $cont, $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('http://nocc.sourceforge.net/download/?lang=en');
69
                $cont = @file_get_contents('http://nocc.sourceforge.net/download/?lang=en');
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('@Download the current NOCC version <strong>(.+)</strong>@ismU', $cont, $m)) {
74
                if (!preg_match('@Download the current NOCC version <strong>(.+)</strong>@ismU', $cont, $m)) {
75
                        if (!preg_match('@/nocc\-(.+)\.tar\.gz"@ismU', $cont, $m)) {
75
                        if (!preg_match('@/nocc\-(.+)\.tar\.gz"@ismU', $cont, $m)) {
76
                                throw new Exception("Cannot find version information on the website");
76
                                throw new Exception("Cannot find version information on the website");
77
                        }
77
                        }
78
                }
78
                }
79
 
79
 
80
                return trim($m[1]);
80
                return trim($m[1]);
81
        }
81
        }
82
 
82
 
83
        protected function cbRun($optional_args=array()) {
83
        protected function cbRun($optional_args=array()) {
84
                $system_dir = $this->argSystemDir->getValue();
84
                $system_dir = $this->argSystemDir->getValue();
85
                if (empty($system_dir)) {
85
                if (empty($system_dir)) {
86
                        throw new Exception("Please specify the directory of the NOCC installation.");
86
                        throw new Exception("Please specify the directory of the NOCC installation.");
87
                }
87
                }
88
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
88
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
89
 
89
 
90
                if (!is_dir($system_dir)) {
90
                if (!is_dir($system_dir)) {
91
                        throw new Exception('Directory "'.$system_dir.'" not found.');
91
                        throw new Exception('Directory "'.$system_dir.'" not found.');
92
                }
92
                }
93
 
93
 
94
                $version = $this->get_nocc_version($system_dir);
94
                $version = $this->get_nocc_version($system_dir);
95
 
95
 
96
                $latest_version = $this->get_latest_version();
96
                $latest_version = $this->get_latest_version();
97
 
97
 
98
                if ($version == $latest_version) {
98
                if (version_compare($version,$latest_version) >= 0) {
99
                        $this->setStatus(VNag::STATUS_OK);
99
                        $this->setStatus(VNag::STATUS_OK);
100
                        $this->setHeadline("Version $version at $system_dir", true);
100
                        $this->setHeadline("Version $version at $system_dir", true);
101
                } else {
101
                } else {
102
                        $this->setStatus(VNag::STATUS_WARNING);
102
                        $this->setStatus(VNag::STATUS_WARNING);
103
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
103
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
104
                }
104
                }
105
        }
105
        }
106
}
106
}
107
 
107