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 | muCA1BNAx3t4UMIIzqCeb9w0THNUjzz6c/qmRy6zLtsiwU3WE0nJFpHwi6R1B3jhr |
||
3 | ivN4x+RGN9wo2YCpenFDreN0+k4oHsxsqz68eiaiH2+1Z5bKXMayUNG97mFdbWxIx |
||
4 | At1VWBRG4GSXnAbkX3ubNhQw1e2WptqpT4SufS5KcGaaI/MxwRrBdjheyENnNahSF |
||
5 | njM4LHw6R2On+P5RCML9aReiYLECYhZPi/WlqOI7aj46Qfu5g29s6qxfKEc3HWGoX |
||
6 | kJi706o9G4j/nffo16EBrgpjLMQxO7z7nhsbbaucABnMuDu50ViFmJRMi6j0ys5SY |
||
7 | wrLuoa3VqGL73Gxy7agJgF/4+35Q4LArCyhIIg7xmtOmC+vKIDlJD9cmUpIBT3th9 |
||
8 | Sxqzl5uMkoqZRpBzOtTIKFX/p4I6VbJSjroHVcCO5rUbwzXZDshdLdbULXTOR8/dJ |
||
9 | s3aqOPpPbMasblpVc6oRfePS1Wy1agYBl5kbZErJeYr2ZerhsAdwvkoXjM14Sk6Ol |
||
10 | 9evRdSbdGDVK3x1zJSvoW4yE+tImN7zCnlqCc4AD2u8EWjDXCGfhkaAzbbqf8Geo6 |
||
11 | TSJQm3YUJWfZFP0y7SYfyzeYt7ZVHyLcUNxowRsAfYndXn2700HqJP1pDtmWEVcnJ |
||
12 | pbie9BwDkasWbgCXypXcRAItnHDndYIyxxCTYfXamZIrhmQ40aJow1WYEpDzj1TI9 |
||
13 | vmFTXh0ciY9/rvMATofiUOCgyn6k2BukNFND3oFr9M/FsPx6UFnmjprphQdQSvcIu |
||
14 | +VnrnQRRRCwvJRHqjvbZVjN8/aluTPWib5+ITMW0PdrfzXPgZbzLjpBFLg1nHtC7d |
||
15 | xFQ/8OyCibCe0+SY0nLyq/TFBbSBjaK96kXjOT8xp5aVyGiSrXm8wPh1WtlOaJhrj |
||
16 | 5cNP0si/rd7vmLzyxC/eplqddVyfbKVNZRyjbcyyg1D5Wsg9uhp+sgnMSPad1O6yw |
||
17 | 44rfbtnyT+imUWXoqU4h3B+h21BYIFnYqvJtA/UfloimomfvNxjqiwX0oHuYII3Dv |
||
18 | /b14JGXGaps/PaxRvQjxEHOvVZhU5Eus9piYihgQxhq6/B5A6d1Om7iZsyIkOvX+F |
||
19 | 45WuazvoEc3gs3c6F8EmGY1i4vdSJ6ws9VueJSyyE0hPePGV7vJQ92EduP/j2Yna6 |
||
20 | cOcNP0W26gNlTcQO2G0K4zm5ZBI5RhocRsTKHxm9XQIA2+KgjvpEupb5R+Sqt7NKP |
||
21 | DfMtFiTSoPkCaB1Qgc5JDdJqXlpOm4dlT9OCryAqMvcBJSDchNM+/u7gbk/P5zBZH |
||
22 | Gpn0BcCkX409jH7Z1l5rMKTwOkInPxD1XkUnXO55HMR2/m+TDlk3BnA6fgIau2eaj |
||
23 | Q== |
||
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 FourImagesVersionCheck 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_4images_version'); |
||
46 | $this->getHelpManager()->setVersion('1.0'); |
||
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local 4images 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, '4imagesPath', 'The local directory where your 4images installation is located.')); |
||
54 | } |
||
55 | |||
56 | protected function get_4images_version($path) { |
||
57 | $path = realpath($path) === false ? $path : realpath($path); |
||
58 | |||
59 | $cont = @file_get_contents("$path/includes/constants.php"); |
||
60 | if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) { |
||
61 | throw new Exception("Cannot find version information at $path"); |
||
62 | } |
||
63 | |||
64 | return $m[1]; |
||
65 | } |
||
66 | |||
67 | protected function get_latest_version() { |
||
68 | $cont = @file_get_contents('https://www.4homepages.de/download-4images'); |
||
69 | if (!$cont) { |
||
70 | throw new Exception("Cannot access website with latest version"); |
||
71 | } |
||
72 | |||
73 | if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) { |
||
74 | if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) { |
||
75 | throw new Exception("Cannot find version information on the website"); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | return trim($m[1]); |
||
80 | } |
||
81 | |||
82 | protected function cbRun($optional_args=array()) { |
||
83 | $system_dir = $this->argSystemDir->getValue(); |
||
84 | if (empty($system_dir)) { |
||
85 | throw new Exception("Please specify the directory of the 4images installation."); |
||
86 | } |
||
87 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
88 | |||
89 | if (!is_dir($system_dir)) { |
||
90 | throw new Exception('Directory "'.$system_dir.'" not found.', false); |
||
91 | } |
||
92 | |||
93 | $version = $this->get_4images_version($system_dir); |
||
94 | |||
95 | $latest_version = $this->get_latest_version(); |
||
96 | |||
97 | if ($version == $latest_version) { |
||
98 | $this->setStatus(VNag::STATUS_OK); |
||
99 | $this->setHeadline("Version $version at $system_dir", true); |
||
100 | } else { |
||
101 | $this->setStatus(VNag::STATUS_WARNING); |
||
102 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 |