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 | SJsIrfinSzsYbyQO+IHwJkShVGvRRbKXBSTuyO+b058nk32JwGIh6fEo7tkWBAtS0 |
3 | 3e9479eHecdKr4IYhYwPF02Z/JUO3xt4E4rhevEtATx9XgJgV+bu4mMxrYZPxShUx |
||
4 | NjEr9DYGYlfJgY+XgK1bwjGjIHyBpO4Eh1QovgJ3I2mWEiYaX3S/vuw+KGsa063uT |
||
5 | tsyBWIMgn+XTN5bJWz6jqgOKGnsKVTSeEpre78uCloLFmI0wXp8MNfBfesSs40zK0 |
||
6 | trqCF8yp3NitzwUtnecwQxbncp8iVGU9bO8EoD3BUy9Ohv8GINCQjtnuuAx9YFVlD |
||
7 | ++wb8yN3p3NsLw8r5nu0DCPbfPxJALC7UiBcZ/z7m6CO4rbsaV1yfSaX5jDrAvCtd |
||
8 | TQPBIcb/V+HcVgikGSbZkBxTv8+R27nyv3csGPIOu5AQMBhtDbNAJphDYhmFXxqVw |
||
9 | Ww91POe3UqBao/cxDbsAZRL7RJ26L1J4d5n8qEd6DJH03uV6SW/EjPieLaGgZ7mhY |
||
10 | 4ifQGqTHjZmQuLs1S1aFL6F4oT7UG/6nmBT7zyd4Lcpa1wRjO1egAC3OxDCrYJ8wB |
||
11 | fJWzqLd9gT5utmvx91I83N65evE4LcqS5uGjED48s0uGZ3g4YDFySwlxqI0mclDGZ |
||
12 | 8Mf4c4vTjzB0tzFgTKiYlzR27PQQ+7g0VTGKl1SKwBt8mXRI3iQwkvk/QUXWhvR71 |
||
13 | y0hoCVxlC4cq91brH8LornfDDHQhyVydrkAvl55uXSv8xq7RhlY+Pp784CkNAemKs |
||
14 | t8HfHWtfXN7aXXiV0wtq3+fNE1wykSnz/onYFNw269JNTZgW4llFZgY8DWpOu/B3Q |
||
15 | m0j5DxatYr571TByTWH+1dLPOga2VaBYhJonAlaVf1FNF9IRhsZoENIDUq/7ej/uw |
||
16 | G5XWbRVX4GZ32CLWo8NTup6VtriZdscUf+Erw0H7Xw5gOJoSCzOy3/8dFmoIWQyx1 |
||
17 | ZsejNS4tLZf52gOg1XuF01ZRUyMX8X2XW8AUPd2b8Fu3cObSuUDpYgNGRK54INMjO |
||
18 | VXSsrOZOpo9ybNQ2h6OrJndA1UJtrThowVxn55DsfSAQ4AaI7ZLztGRMSmWk6c5P3 |
||
19 | iNSa2U9Xy5fV9neN1T5BibyP64aFWkR+gZFC9Xxgdl/YQiPEmorxU98JtDwtsBR5J |
||
20 | FdMfIzsrreiXs9rbrTeX3sw0T4Ag2hOrQuoBuZy5TDoh8Gjc8bebfcALNR88sktN7 |
||
21 | WMEA8T3uxhE13LI3Pu3iM6iWw+6+gNGmBA9kC42jQvN7s5S+7CEA9PyDVI0CiFn5p |
||
22 | uzEa/b8BTISIhb6dQzM0yUs2vk+PXFAa5muIGMGmf+dUbPuC+BXbGRic81xKDdYDU |
||
57 | 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 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 | |||
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/includes/constants.php"); |
||
77 | daniel-mar | 60 | if ($cont === false) { |
61 | throw new VNagException("Cannot find version information at $path (cannot read constants.php)"); |
||
62 | } |
||
2 | daniel-mar | 63 | if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) { |
77 | daniel-mar | 64 | throw new VNagException("Cannot find version information at $path (constant SCRIPT_VERSION not found in constants.php)"); |
2 | daniel-mar | 65 | } |
66 | |||
67 | return $m[1]; |
||
68 | } |
||
69 | |||
70 | protected function get_latest_version() { |
||
76 | daniel-mar | 71 | $cont = $this->url_get_contents('https://www.4homepages.de/download-4images'); |
72 | if ($cont === false) { |
||
77 | daniel-mar | 73 | throw new VNagException("Cannot access website with latest version"); |
2 | daniel-mar | 74 | } |
75 | |||
76 | if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) { |
||
77 | if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) { |
||
77 | daniel-mar | 78 | throw new VNagException("Cannot find version information on the website"); |
2 | daniel-mar | 79 | } |
80 | } |
||
81 | |||
82 | return trim($m[1]); |
||
83 | } |
||
84 | |||
85 | protected function cbRun($optional_args=array()) { |
||
86 | $system_dir = $this->argSystemDir->getValue(); |
||
87 | if (empty($system_dir)) { |
||
77 | daniel-mar | 88 | throw new VNagException("Please specify the directory of the 4images installation."); |
2 | daniel-mar | 89 | } |
90 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
91 | |||
92 | if (!is_dir($system_dir)) { |
||
77 | daniel-mar | 93 | throw new VNagException('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 94 | } |
95 | |||
76 | daniel-mar | 96 | $version = $this->get_local_version($system_dir); |
2 | daniel-mar | 97 | |
98 | $latest_version = $this->get_latest_version(); |
||
99 | |||
57 | daniel-mar | 100 | if (version_compare($version,$latest_version) >= 0) { |
2 | daniel-mar | 101 | $this->setStatus(VNag::STATUS_OK); |
102 | $this->setHeadline("Version $version at $system_dir", true); |
||
103 | } else { |
||
104 | $this->setStatus(VNag::STATUS_WARNING); |
||
105 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 |