Subversion Repositories vnag

Rev

Rev 4 | 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>
29 daniel-mar 2
YhhRwJvSCq9ZIMij3FMlw3RoGYWMmIotnzcKX1mPvLuhjGWoOGYHieG8Ob06sUjAY
3
duZGeaepTnUTG/iNuXbiO4Ae0TCrsrZrcwsC53XZ6xch+MbLVPmwS7RayUsm4PoEt
4
exzZBXDzoxu9Yk0lvX9FUC8UORJCvx9TO98uSxVZREWGQMYFAL/64lqm4i/PxOUWL
5
7cQt6Ue3W9PtjV7liTUSlQlPaMiu3crAHF5MZxGLGkiuk6BsObutf6foZy5f0n2mU
6
d6Ouyq+eev4MNf/StbnpdiNKv+TJtHcUF6naPCArJGcTFkKFQ31UpaTljIdE2+qmo
7
vb44zqNvcQ+V5xir2/5FK87yvDFtumrn6RC1BV7skDLmxOIHlcCnOLAv5vMnLOqP+
8
PhDnLi7iACs4Kpbnuok45lHpmFyjewMZ/IoOo/1qX4Mxh3yIB9SUe9EdLtx0viegY
9
V+p+154+EAQRoZVt2n2/F11tkqIBRPnFKxZtx8zPjyUtN5pNYOrTaCvAB5YG0gP1J
10
gV+A1QcHxufn8+Dkhe5vqxq1FHvB//YpqPgjhSO13yi+2PaSlrkcfqFHTvIjwhdRU
11
hJ6V8zamyCqkrXej68/vAo05q7oproUOW4C2wLUe+Ew1m+vdsBZNs3gktkRXewFyZ
12
NUd+OZl7yvRKSEDROGDnYjMFj7LDXEaaRK7ZHR3Z2I2BQeh1nf5gKveX1gVvLYgKu
13
KlfrNnFZLgr4HLalxRRcucFkfWLLs97qWoNV+/qiRnSDNXESVGNF1lZA2O9uhiAuD
14
BSMLmWMD1wfBIsscG0LbwZBBk/jvqHN9Z/ZKNNqp0a9EpPKuN5KM6Kae0qy5y9lci
15
4O0Ifu95eA7T1XQvrY+EdqMUJ1U3XM+x3ut/S6LtwBTA9k5SsmuxwGA8rFqIvMABq
16
oNzstw8PX1xsOy8sQEjEe27L4wAQlfkF5QlbT2xgwxxAM3pLCelzbA0MXfRIBRXTg
17
BW1ibsDJxiQktapIkc/yMYlXVveRe1YyGY+oPjoSfEPvFgxJgsDCnuP8bTY3BHDoT
18
Y10ThdjaiL26cQq/Y/mZ/en9L+IewGeLbC9c11U8N41IvywyQxuTLraqHN85qDGVO
19
ibIEzToi4HAJXorbHXkemfJrIPS7JrUTEwDUiO+Xrys+L9oOZl5EUHYUc+GebaMm3
20
nzcSkDjxGfC+44WnDvYDOdEMPtGGjH40fhhawlHO1K4+DlHNLbmBMBCoE5KaHkanN
21
jeLh5pvNkMrJWK/1dfr5moDftU/glkHwq2srUs7/8xZU5AqcbBWQSZNztT7p58UwZ
22
Kf6hlHOQYdY1dujII1sj2vGqKn1O+57twJpfJ/dEmEzDcii/SFml8zViWZHUG4A7d
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
 *
32
 * Revision 2018-07-15
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
 
98
                if ($version == $latest_version) {
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
}