Rev 76 | 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> |
77 | daniel-mar | 2 | gr/1vRpjKy5z4D+dglj2jnNc9DfOawz0AiEfTwiL0IS9Z7dSQ6oUwrnCCN539UfAQ |
3 | 6a5F8T06WRO6yhFOQQaiJApX5Yt9NTb/X0hZ6pxRQ0/kg22wvpS048sEkNMvmxGjh |
||
4 | vV+53l+YnB5EtyXCVQ/ZRp8RnFeB90L421X2C7iyGNjbye1XmXyODvAj4TW7x2Jnv |
||
5 | x4ZUnecWHrHtn7szS8Z7FlbeB8K3O3lUuxdohv0Mu/e7Lga9YBu3x3cOjz54bNzIg |
||
6 | GVbg++iiwHNYvejK/kDk/BhRpjm4lB5AKnfhI73V/Kd4gam/MYS6JTIlvLUbdHmWU |
||
7 | rzmwnRSh1sTsTBjGuosUeMWKIkqrNroNCgWTmm4sQWP5ae4pB9wN0iRNvH2qtxg69 |
||
8 | OWVAbjvkz+ws5aGgmEq6vsly6XUn96TY7ZCJrFns9nxAZeoGp6IT2aYOvcc8B83TR |
||
9 | Kd7HVg6yuZTJEDz0Coemh3AmqmwPQQjTxfOHbaC7pdA/oktybmJGUi5CwjZWyPZRo |
||
10 | g873PMfjkFhYpumOp8wKCU+3CqAqpxC8VYGdrULGfza6qDkSoeXRNnb+WYsbwwPFm |
||
11 | 82Rcg4Kax1/7cOtTntaT0AGxLHYqUJoUC3cUZDn2SpeWUNI2GLFwA2Jn0XGVc5KLy |
||
12 | u63DACjmQsJF6ANjYW/URZvoR+kyjzWen5CtkUZeuC1feZfe3r4/7d4d3IEYqx+vK |
||
13 | /RYZaREq4TGgidyqwU3tNT9sMW1GU5jyHpSZ4mrqQLgDkmW9Q7x0VA3Ib4wlY9SKs |
||
14 | fBAt1o/Ds6Ik97wIgYnqD0MsZEpAS4MZqdWgFd7ifZ/mRE38oiejClHQWM2HYRxN+ |
||
15 | mdbHCCg9lHGyPdyW9GIrHpwlJMuM+BA5W1l5hMUkBr4pmLzdCto9shoPVztirKyde |
||
16 | LhxID/wsbcOKhDqfSE72gKaELsu+uBBXbdPsnQFnsv5ptkUVzbH8+E6TmR+t3D0E9 |
||
17 | JAiebXJ4HRHZk2nLS71nPjEHPSvm73cHMs+vpD2zLW1NQmQQbBTNx8+T0nwuWB+qC |
||
18 | y2c8O3obKFE5rK/Wz0476WPDs4HH93FF13o1SZuTKI5ZPxDUvTJNaWsQmRJKQefJf |
||
19 | hPlhd20axsMZnkqql3Xko4KjWhhXbU8yDv44unynmh1rL/MskdY9oF6dnjxUc4BZ+ |
||
20 | z2E1Wda7dPQ8h06qJDEPqdzUoOmRH1sHMBMvP8pZeJTCWN9yJwytBTV2OTj22Xs4j |
||
21 | dNtBUlo0fGhIoycI3dwtEN2xUQMRb6dhN5e1Cn2xnkSaHtn7XGqJVB2II7rVqvgXZ |
||
22 | +7+d64dwLF2qk9+zDrnx4q8lFBPmjZkGH6Brj1t8Hc99qKfu/30GHPJai8/QpjO+A |
||
76 | daniel-mar | 23 | w== |
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 | * |
||
76 | daniel-mar | 32 | * Revision 2023-10-13 |
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 | |||
76 | daniel-mar | 56 | protected function get_local_version($path) { |
2 | daniel-mar | 57 | $path = realpath($path) === false ? $path : realpath($path); |
58 | |||
59 | $cont = @file_get_contents("$path/common.php"); |
||
77 | daniel-mar | 60 | if ($cont === false) { |
61 | throw new VNagException("Cannot find version information at $path (common.php not found)"); |
||
62 | } |
||
2 | daniel-mar | 63 | |
64 | if (!preg_match('@\$conf\->nocc_version = \'(.+)\';@ismU', $cont, $m)) { |
||
77 | daniel-mar | 65 | throw new VNagException("Cannot find version information at $path (nocc_version configuration not found)"); |
2 | daniel-mar | 66 | } |
67 | |||
68 | return $m[1]; |
||
69 | } |
||
70 | |||
71 | protected function get_latest_version() { |
||
76 | daniel-mar | 72 | $cont = $this->url_get_contents('http://nocc.sourceforge.net/download/?lang=en'); |
73 | if ($cont === false) { |
||
77 | daniel-mar | 74 | throw new VNagException("Cannot access website with latest version"); |
2 | daniel-mar | 75 | } |
76 | |||
77 | if (!preg_match('@Download the current NOCC version <strong>(.+)</strong>@ismU', $cont, $m)) { |
||
78 | if (!preg_match('@/nocc\-(.+)\.tar\.gz"@ismU', $cont, $m)) { |
||
77 | daniel-mar | 79 | throw new VNagException("Cannot find version information on the website"); |
2 | daniel-mar | 80 | } |
81 | } |
||
82 | |||
83 | return trim($m[1]); |
||
84 | } |
||
85 | |||
86 | protected function cbRun($optional_args=array()) { |
||
87 | $system_dir = $this->argSystemDir->getValue(); |
||
88 | if (empty($system_dir)) { |
||
77 | daniel-mar | 89 | throw new VNagException("Please specify the directory of the NOCC installation."); |
2 | daniel-mar | 90 | } |
91 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
92 | |||
93 | if (!is_dir($system_dir)) { |
||
77 | daniel-mar | 94 | throw new VNagException('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 95 | } |
96 | |||
76 | daniel-mar | 97 | $version = $this->get_local_version($system_dir); |
2 | daniel-mar | 98 | |
99 | $latest_version = $this->get_latest_version(); |
||
100 | |||
57 | daniel-mar | 101 | if (version_compare($version,$latest_version) >= 0) { |
2 | daniel-mar | 102 | $this->setStatus(VNag::STATUS_OK); |
103 | $this->setHeadline("Version $version at $system_dir", true); |
||
104 | } else { |
||
105 | $this->setStatus(VNag::STATUS_WARNING); |
||
106 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
107 | } |
||
108 | } |
||
109 | } |