Subversion Repositories vnag

Rev

Rev 29 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 daniel-mar 1
<?php /* <ViaThinkSoftSignature>
57 daniel-mar 2
USMXmEZw3BxLtCMYVFw3pNRfut91obKVEaTFxBoaMCPTpOUfsqHIIwwwTfKc5C9Ij
3
uLzcD6jaorajF2zyS6qWSauACaw3jPpulkF66pSgETrNWAzaWlVanmll5gD0pE0j/
4
FTJ7GBD5+3qHz3aF5DPzncqP3l5G8AodOPDHvD15lM1e/nI4JAW0Pgsiot9AOpV0e
5
UBmi6uYOGgiuiLI3ewpyWY252aJsAhVlvRRHay23pKZkMpcZBQ2eqd4uv68s71iXd
6
YCpT5ApoRt+pDXHVg1yUvNsz+lIVentvSMXsKMvWfJpThAppoNIDRgbYcKodEn8Gf
7
0Smk5ldkuhryswCSO4RYHVW7XEF/ZEuQt2ID3Sx1AQBlJl6i+/eZ7fVTyNQtoezEx
8
BljGD3rYxPcJ8eIYoHJf26OamG9z/mm64iNBJ5Pf6paNazV2fqLZCPZNcQzbiYlzE
9
cNJPmC7nCib59enEopIQkdLnu6HFhTjVru+yCWT8V5b2zHE/u5kEclTVpdXwHeBvN
10
cDGrTe32lCA3nuN/5FFv/C1WH000p0oy2nxZoLNg9nAkCvJ/KWj6PKA4sW+zAPleB
11
mPOK+F413X37Poh7eRS17cqYegQYkezpegXIASLiKNo0Oj1C0nSzhHnBhLjDCnG6R
12
E3JAiP24H+WPxJsiW8W1qVtESwYER8A9NVYGHNWdHPaV9tyBwap9qLfUHXjfkTuJE
13
od0Z4ZSmxHIVAN53Sd5r0MceGJmI3Uk1L4FGdyIJd/peWNaWHroVsFtporI+XsjSV
14
Gk6KORxLERNtIAi4q0BVcBCjSeY/CP+o7UwkMzp1m3v+3xqP1YBO1gg/i5FGZRh5d
15
r7MRbXoVgsTWA9zYeSDFwdkFpUuc9GwdZN6lIFTWAYl8VAhG5UiUs7WAN5dj+Xfrx
16
DrXLXxFY5/BYd2ggm6G+LiVQenvsiMtdR5sQNsJRgJdtYvcOljfyiMK4OPdMsokIM
17
09FtFavsOVDhMJjnkr1UlzPC6tXS2b5sgE/xTbNtm0yV6ji6DSJnMjg0nyj0E1/vf
18
afqNx8l0Zqojhal8N02LqXMIZVxeESLwxqqS2mZtPQo9gPdz0Bgq+ce3BXnXohsXZ
19
F81JQYQoMoNCcH3WlaD+YSQnBxsKNb2qerGStGPEVsjLWJQ/1b3gwAvQvMjSvcDLc
20
G68YdiuJwf1Ipzo5MVlM6fWzR2JlyG96CXi2j8tqpeZsW42Q09A6liOR3jyY4dhbG
21
0wBsj34RTl+btsXE1xG2P3TwUDaMsZYO8QWfF+m+68piAZ53ZM2vXa9BJeTRl2kHo
22
Zc0uoIndnbFONE3K2Hi0FUMo25brvirV1VVSb2DW0hZbeXj4PDCtgY4tiMMEIo7vc
29 daniel-mar 23
g==
4 daniel-mar 24
</ViaThinkSoftSignature> */ ?>
2 daniel-mar 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
2 daniel-mar 33
 */
34
 
35
declare(ticks=1);
36
 
37
class NoccVersionCheck 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_nocc_version');
46
                $this->getHelpManager()->setVersion('1.0');
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.');
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, 'noccPath', 'The local directory where your NOCC installation is located.'));
54
        }
55
 
56
        protected function get_nocc_version($path) {
57
                $path = realpath($path) === false ? $path : realpath($path);
58
 
59
                $cont = @file_get_contents("$path/common.php");
60
 
61
                if (!preg_match('@\$conf\->nocc_version = \'(.+)\';@ismU', $cont, $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('http://nocc.sourceforge.net/download/?lang=en');
70
                if (!$cont) {
71
                        throw new Exception("Cannot access website with latest version");
72
                }
73
 
74
                if (!preg_match('@Download the current NOCC version <strong>(.+)</strong>@ismU', $cont, $m)) {
75
                        if (!preg_match('@/nocc\-(.+)\.tar\.gz"@ismU', $cont, $m)) {
76
                                throw new Exception("Cannot find version information on the website");
77
                        }
78
                }
79
 
80
                return trim($m[1]);
81
        }
82
 
83
        protected function cbRun($optional_args=array()) {
84
                $system_dir = $this->argSystemDir->getValue();
85
                if (empty($system_dir)) {
86
                        throw new Exception("Please specify the directory of the NOCC installation.");
87
                }
88
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
89
 
90
                if (!is_dir($system_dir)) {
29 daniel-mar 91
                        throw new Exception('Directory "'.$system_dir.'" not found.');
2 daniel-mar 92
                }
93
 
94
                $version = $this->get_nocc_version($system_dir);
95
 
96
                $latest_version = $this->get_latest_version();
97
 
57 daniel-mar 98
                if (version_compare($version,$latest_version) >= 0) {
2 daniel-mar 99
                        $this->setStatus(VNag::STATUS_OK);
100
                        $this->setHeadline("Version $version at $system_dir", true);
101
                } else {
102
                        $this->setStatus(VNag::STATUS_WARNING);
103
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
104
                }
105
        }
106
}