Rev 77 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * VNag - Nagios Framework for PHP |
||
5 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
6 | * Licensed under the terms of the Apache 2.0 license |
||
7 | * |
||
76 | daniel-mar | 8 | * Revision 2023-10-13 |
2 | daniel-mar | 9 | */ |
10 | |||
11 | declare(ticks=1); |
||
12 | |||
13 | class FourImagesVersionCheck extends VNag { |
||
14 | protected $argSystemDir = null; |
||
15 | |||
16 | public function __construct() { |
||
17 | parent::__construct(); |
||
18 | |||
19 | $this->registerExpectedStandardArguments('Vht'); |
||
20 | |||
21 | $this->getHelpManager()->setPluginName('check_4images_version'); |
||
79 | daniel-mar | 22 | $this->getHelpManager()->setVersion('2023-10-13'); |
2 | daniel-mar | 23 | $this->getHelpManager()->setShortDescription('This plugin checks if a local 4images system has the latest version installed.'); |
24 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
25 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
||
26 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
27 | |||
28 | // Individual (non-standard) arguments: |
||
29 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, '4imagesPath', 'The local directory where your 4images installation is located.')); |
||
30 | } |
||
31 | |||
76 | daniel-mar | 32 | protected function get_local_version($path) { |
2 | daniel-mar | 33 | $path = realpath($path) === false ? $path : realpath($path); |
34 | |||
35 | $cont = @file_get_contents("$path/includes/constants.php"); |
||
77 | daniel-mar | 36 | if ($cont === false) { |
37 | throw new VNagException("Cannot find version information at $path (cannot read constants.php)"); |
||
38 | } |
||
2 | daniel-mar | 39 | if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) { |
77 | daniel-mar | 40 | throw new VNagException("Cannot find version information at $path (constant SCRIPT_VERSION not found in constants.php)"); |
2 | daniel-mar | 41 | } |
42 | |||
43 | return $m[1]; |
||
44 | } |
||
45 | |||
46 | protected function get_latest_version() { |
||
76 | daniel-mar | 47 | $cont = $this->url_get_contents('https://www.4homepages.de/download-4images'); |
48 | if ($cont === false) { |
||
77 | daniel-mar | 49 | throw new VNagException("Cannot access website with latest version"); |
2 | daniel-mar | 50 | } |
51 | |||
52 | if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) { |
||
53 | if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) { |
||
77 | daniel-mar | 54 | throw new VNagException("Cannot find version information on the website"); |
2 | daniel-mar | 55 | } |
56 | } |
||
57 | |||
58 | return trim($m[1]); |
||
59 | } |
||
60 | |||
61 | protected function cbRun($optional_args=array()) { |
||
62 | $system_dir = $this->argSystemDir->getValue(); |
||
63 | if (empty($system_dir)) { |
||
77 | daniel-mar | 64 | throw new VNagException("Please specify the directory of the 4images installation."); |
2 | daniel-mar | 65 | } |
66 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
67 | |||
68 | if (!is_dir($system_dir)) { |
||
77 | daniel-mar | 69 | throw new VNagException('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 70 | } |
71 | |||
76 | daniel-mar | 72 | $version = $this->get_local_version($system_dir); |
2 | daniel-mar | 73 | |
74 | $latest_version = $this->get_latest_version(); |
||
75 | |||
57 | daniel-mar | 76 | if (version_compare($version,$latest_version) >= 0) { |
2 | daniel-mar | 77 | $this->setStatus(VNag::STATUS_OK); |
78 | $this->setHeadline("Version $version at $system_dir", true); |
||
79 | } else { |
||
80 | $this->setStatus(VNag::STATUS_WARNING); |
||
81 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 |