Rev 2 | 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> |
2 | Pk9vVzhiMUsINHj3unermWodlsIIRX8gfqCE9mxoch3WXBd3FqQdASPFk8CNjqMB1 |
||
3 | bPBUTqhkSkn1gKP8qG7e1kcr8pciOd4RYZmd5HuuqNFdJFK4l8cDYSl71LgqQBKQM |
||
4 | MLt9bygoUPVyAgN6b8B87qM6XmTsJHDK74u1OtQOaffQNIBMXvbWH8tDFrcDpKvTv |
||
5 | QlgkNYqil/gvZ/KMSjghhh0+OTFmBFeaChK34O0vMv7PbWw2Kt/rT1jxs6sfWzGal |
||
6 | 1cLAP/wAb1/fwKP8+OsmOuRwcNjEk09/k6mc93SxGAxYvRatgNoE3QhMyJMra9iF2 |
||
7 | 2/ZZ2/xkubn4T83rDI+AJXzvsvqpTFezxmTeHG8Y02ufSPOl4lFT9Ds6FtRymHaLt |
||
8 | SMrXet3r/RRO0vM8V86kpQ8iEQSPEpXNletRZ9XoE6m2fsZ+laMin+WiHibBrSgr1 |
||
9 | 73K/fGuk0Vw1k0oZ10DrottkQ84WBizZXNgMqmQCuXoLKbVJj+75LCGp3z6YwU2Xi |
||
10 | EXRZbcjyp2FU8LG6NLBZJq3BjnoiFppoFRG2QCqCBAbUCCKNXhCqPyxUmXTRmcusx |
||
11 | WEwpTZPMgucGixaRgo56ta7Mp8R6SG3c1k6kvOyueIfWoiyw2DGgMTnX/WvVgbH2T |
||
12 | EeYn1RNv5YbEdMAYrcKfFDU9gSzKwr5+KJMSuXR6MhCPRPd0x+U8wg8Spf6Ys426Z |
||
13 | MSd1a5MuFCoVt9CgvJcdzMLnQ0bLDBtACMfldEjqM8Qg/BdfS4Fsq9glaaaN5B9/R |
||
14 | U50qh2fY12V5kxZK+q/3Nr+Lb9Ks+x7RwivwgBNfO+D1CyDY9JsyvOlc5NMOax2ty |
||
15 | Akd4VL5eFPqGh4YwYuY1vxd+oBN1ED72Ozva85BzSi+gJcPF8APZNgGaGTRa/Qxkf |
||
16 | 0nIEQw4XPOrxysQtVjxzfAqsyzLBqad1ZBm/ed0tzbqPVju17YCa6cKWHGiVZlPHg |
||
17 | kcKP8CDSJN1CEG1gp7D5luov777Y3PS1jLOiCD2ZV+ZSy1fWBA8aH8M2taKyRJl2m |
||
18 | FYqIAk657nKQa/QaIMmPDaTzGMKJGlXSyLySmkTxpkKNcl4OMDIc8NkYxhk/EJW95 |
||
19 | rXP+J8X/PNBD05wplBx0d3W0ujUSyT2zeFbTGb4M7ph0SgMEFgwP0ivfSjTh2+ChF |
||
20 | vdU0BFz9WbBLr0lU20FYnunsQEdlmU1aMgC23+rG3KYnXwsK7xl+ZK7wcavgNYIjr |
||
21 | pdSy5V0errT23OWv/XSjyBEIp8KN2yYpz59/p8Z90E7P67DqIO4XWKfkotiLkRxhb |
||
22 | lpbJpXynVP/rjreWXN0pNtpA6EeO6pPInpekv3/UAKyrRpI151znpA9qYqSXxV15s |
||
23 | A== |
||
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)) { |
||
91 | throw new Exception('Directory "'.$system_dir.'" not found.', false); |
||
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 | } |