Subversion Repositories vnag

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php /* <ViaThinkSoftSignature>Pk9vVzhiMUsINHj3unermWodlsIIRX8gfqCE9mxoch3WXBd3FqQdASPFk8CNjqMB1bPBUTqhkSkn1gKP8qG7e1kcr8pciOd4RYZmd5HuuqNFdJFK4l8cDYSl71LgqQBKQMMLt9bygoUPVyAgN6b8B87qM6XmTsJHDK74u1OtQOaffQNIBMXvbWH8tDFrcDpKvTvQlgkNYqil/gvZ/KMSjghhh0+OTFmBFeaChK34O0vMv7PbWw2Kt/rT1jxs6sfWzGal1cLAP/wAb1/fwKP8+OsmOuRwcNjEk09/k6mc93SxGAxYvRatgNoE3QhMyJMra9iF22/ZZ2/xkubn4T83rDI+AJXzvsvqpTFezxmTeHG8Y02ufSPOl4lFT9Ds6FtRymHaLtSMrXet3r/RRO0vM8V86kpQ8iEQSPEpXNletRZ9XoE6m2fsZ+laMin+WiHibBrSgr173K/fGuk0Vw1k0oZ10DrottkQ84WBizZXNgMqmQCuXoLKbVJj+75LCGp3z6YwU2XiEXRZbcjyp2FU8LG6NLBZJq3BjnoiFppoFRG2QCqCBAbUCCKNXhCqPyxUmXTRmcusxWEwpTZPMgucGixaRgo56ta7Mp8R6SG3c1k6kvOyueIfWoiyw2DGgMTnX/WvVgbH2TEeYn1RNv5YbEdMAYrcKfFDU9gSzKwr5+KJMSuXR6MhCPRPd0x+U8wg8Spf6Ys426ZMSd1a5MuFCoVt9CgvJcdzMLnQ0bLDBtACMfldEjqM8Qg/BdfS4Fsq9glaaaN5B9/RU50qh2fY12V5kxZK+q/3Nr+Lb9Ks+x7RwivwgBNfO+D1CyDY9JsyvOlc5NMOax2tyAkd4VL5eFPqGh4YwYuY1vxd+oBN1ED72Ozva85BzSi+gJcPF8APZNgGaGTRa/Qxkf0nIEQw4XPOrxysQtVjxzfAqsyzLBqad1ZBm/ed0tzbqPVju17YCa6cKWHGiVZlPHgkcKP8CDSJN1CEG1gp7D5luov777Y3PS1jLOiCD2ZV+ZSy1fWBA8aH8M2taKyRJl2mFYqIAk657nKQa/QaIMmPDaTzGMKJGlXSyLySmkTxpkKNcl4OMDIc8NkYxhk/EJW95rXP+J8X/PNBD05wplBx0d3W0ujUSyT2zeFbTGb4M7ph0SgMEFgwP0ivfSjTh2+ChFvdU0BFz9WbBLr0lU20FYnunsQEdlmU1aMgC23+rG3KYnXwsK7xl+ZK7wcavgNYIjrpdSy5V0errT23OWv/XSjyBEIp8KN2yYpz59/p8Z90E7P67DqIO4XWKfkotiLkRxhblpbJpXynVP/rjreWXN0pNtpA6EeO6pPInpekv3/UAKyrRpI151znpA9qYqSXxV15sA==</ViaThinkSoftSignature> */ ?>
2
<?php
3
 
4
/*
5
 * VNag - Nagios Framework for PHP
6
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
7
 * Licensed under the terms of the Apache 2.0 license
8
 *
9
 * Revision 2018-07-15
10
 */
11
 
12
declare(ticks=1);
13
 
14
class NoccVersionCheck extends VNag {
15
        protected $argSystemDir = null;
16
 
17
        public function __construct() {
18
                parent::__construct();
19
 
20
                $this->registerExpectedStandardArguments('Vht');
21
 
22
                $this->getHelpManager()->setPluginName('check_nocc_version');
23
                $this->getHelpManager()->setVersion('1.0');
24
                $this->getHelpManager()->setShortDescription('This plugin checks if a local NOCC Webmail system has the latest version installed.');
25
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
26
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
27
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
28
 
29
                // Individual (non-standard) arguments:
30
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'noccPath', 'The local directory where your NOCC installation is located.'));
31
        }
32
 
33
        protected function get_nocc_version($path) {
34
                $path = realpath($path) === false ? $path : realpath($path);
35
 
36
                $cont = @file_get_contents("$path/common.php");
37
 
38
                if (!preg_match('@\$conf\->nocc_version = \'(.+)\';@ismU', $cont, $m)) {
39
                        throw new Exception("Cannot find version information at $path");
40
                }
41
 
42
                return $m[1];
43
        }
44
 
45
        protected function get_latest_version() {
46
                $cont = @file_get_contents('http://nocc.sourceforge.net/download/?lang=en');
47
                if (!$cont) {
48
                        throw new Exception("Cannot access website with latest version");
49
                }
50
 
51
                if (!preg_match('@Download the current NOCC version <strong>(.+)</strong>@ismU', $cont, $m)) {
52
                        if (!preg_match('@/nocc\-(.+)\.tar\.gz"@ismU', $cont, $m)) {
53
                                throw new Exception("Cannot find version information on the website");
54
                        }
55
                }
56
 
57
                return trim($m[1]);
58
        }
59
 
60
        protected function cbRun($optional_args=array()) {
61
                $system_dir = $this->argSystemDir->getValue();
62
                if (empty($system_dir)) {
63
                        throw new Exception("Please specify the directory of the NOCC installation.");
64
                }
65
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
66
 
67
                if (!is_dir($system_dir)) {
68
                        throw new Exception('Directory "'.$system_dir.'" not found.', false);
69
                }
70
 
71
                $version = $this->get_nocc_version($system_dir);
72
 
73
                $latest_version = $this->get_latest_version();
74
 
75
                if ($version == $latest_version) {
76
                        $this->setStatus(VNag::STATUS_OK);
77
                        $this->setHeadline("Version $version at $system_dir", true);
78
                } else {
79
                        $this->setStatus(VNag::STATUS_WARNING);
80
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
81
                }
82
        }
83
}