Rev 29 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 29 | Rev 57 | ||
---|---|---|---|
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | 1nbCL4jEjMIUirsnswcLvLOyfe4r5lC8uW+VWf4gmxQJkjsT6mBL7UJ1qkLyozyix |
2 | lAkMAIwL5Eb71IHJLCJVhuS1bw1OUs8gYlJMpZhoPHf6dARxLpWHATIIiIzdP9qsX |
3 | 7BLkSW+00lytdAut4LORacPuO8vKTgPsbwYktrAON26lo3mTFpcoOriwPATDavd5d |
3 | LYl24sYg3jpuSUCwTyJlJp3BZn9D3pJPQrU7AI02eBd/9h5Mz7nXxExIfOUKamtYC |
4 | F69Ma5FM6vDtucdiOhBM+jRQB+91dOjFCg05lNNzk9ZPazZ6HQR4roZUShRZxjR5N |
4 | RS82nKHZhKO8j24sVfQclA0I6zWEOzBMmpRoL3r2RkTNJl9EtbgGS85UnRVFOkx68 |
5 | 8+C/ZtAxPHspZnKtcLCxKgeBuRxaIbm12XLnB1ol8fuSiVOL208y2a2bV+Ne0+/K1 |
5 | V0P5mCGIoqbrvdQgGKxsk4b8T3+x9M7L7NZTNimQQgSQ3KfehELyVPxAPJUs+LGBn |
6 | B1qguJuZ71OgpHcp62TqtoX7cdzMbwqNvLTzvBzWeanbrs2ULKTbFSI+SvYfY4Z7j |
6 | +hTdAZWG7I++aiBGpzB6kWZ4WRdYn8Sd4OhIiiS3hRxKOUhxJWGLjbtBRLVR0GFUw |
7 | J0MMurcUuiupxGLPElQbW7PwS/Yu5onMm7HpOPp6HdVxlyyWDTyJymVxuY+ouYctd |
7 | UihDbY4jnts6vx+wFzd4/DGi1jlIyJZIKENgPsOnoz3mizSlFJOxKYTBzL5CFTes+ |
8 | QnlAdVlLgkC7melQvF038ANRJt6Z/0IbxOGPp0gyo7VLcG6P2tylAoqn4w8MoqbKj |
8 | AdpF4jbh+i+r3elB6llvUfTUx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inuWyrSD/tIKD |
16 | /B4nCqwkL3oUGlNsMcvXchwTFy6PWEMuw2+O87MIPlbNRdS6PVwIvRu5+SXDMYxgi |
17 | k4FhYR3zvUK7hoeEeZbdHdV68oeakKiDSSUpDtvYMrQar9u1xbcoSpmq8PJM7jjex |
17 | X+QyexhefP8HIcDzHdtK8Q9ATLfrhsSNhyYHnFG2Q1E2a8eR0Gg9IUYgUjaCnp0WP |
18 | i4Mix+Yn63IkY/Nfcj6abeOdVMX+7rkjsB+xe8AQC1PTHig7bqnJElw0jTJEP83A5 |
18 | o1tvBqQoNxuM8FwtJEaDLLJYGI8SM7pRj1bNtekOoNrC2EWmATpXpawSEhVD/4FGh |
19 | OrZt3p7lWDKzAlIPXgDWAsBOWoCjVKx8WWQsxcOdpUzqv1K4VApCsVgKmXoOWeRVb |
19 | tsfXhp3uGM/7mtnQgBS6N2rBN1zJ0qTcT1RxTmU9CcY2odrmAcI7cRIoBphdkaE8N |
20 | 3kwvJHGR9C0qkUKEmYcpCI1cIPo+UmR35Ox9/im48jIXgA0SDs3vegLVECvoz00Fr |
20 | v5IA5ODOpT9F/ZMmo38FPrKLSNGbcVWIjhBht3tq8EVK3+sO0CjUgnBX46vVkQtzZ |
21 | 7zRfkvOq/0mnDZN/nKceGogyCBPmImZ2PU6wyDztvkfxT7EbE12T3dWKiw1sXM9L/ |
21 | 3coIm9KhY6VPW8//Wugby2nG3hOFqMEPYVfCfUNj+7Fsw0gWTnhvpZITKjW+hjccC |
22 | hHR8FZxhV4x3ZxqeyRHjKv0itK+vEBpTvCQX6kUMPn0WUi7A9Mj76LHCqlPAAIi2N |
22 | 64d8LOmGGCYpRSn89mItof6I0EDvXR99Sd6eMEuQGLyijFcBbWQePuiwda1sDNf9U |
23 | Q== |
23 | w== |
24 | </ViaThinkSoftSignature> */ ?> |
24 | </ViaThinkSoftSignature> */ ?> |
25 | <?php |
25 | <?php |
26 | 26 | ||
27 | /* |
27 | /* |
28 | * VNag - Nagios Framework for PHP |
28 | * VNag - Nagios Framework for PHP |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
30 | * Licensed under the terms of the Apache 2.0 license |
30 | * Licensed under the terms of the Apache 2.0 license |
31 | * |
31 | * |
32 | * Revision 2018-07-15 |
32 | * Revision 2022-09-12 |
33 | */ |
33 | */ |
34 | 34 | ||
35 | declare(ticks=1); |
35 | declare(ticks=1); |
36 | 36 | ||
37 | class FourImagesVersionCheck extends VNag { |
37 | class FourImagesVersionCheck extends VNag { |
38 | protected $argSystemDir = null; |
38 | protected $argSystemDir = null; |
39 | 39 | ||
40 | public function __construct() { |
40 | public function __construct() { |
41 | parent::__construct(); |
41 | parent::__construct(); |
42 | 42 | ||
43 | $this->registerExpectedStandardArguments('Vht'); |
43 | $this->registerExpectedStandardArguments('Vht'); |
44 | 44 | ||
45 | $this->getHelpManager()->setPluginName('check_4images_version'); |
45 | $this->getHelpManager()->setPluginName('check_4images_version'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local 4images system has the latest version installed.'); |
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.'); |
48 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
51 | 51 | ||
52 | // Individual (non-standard) arguments: |
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.')); |
53 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, '4imagesPath', 'The local directory where your 4images installation is located.')); |
54 | } |
54 | } |
55 | 55 | ||
56 | protected function get_4images_version($path) { |
56 | protected function get_4images_version($path) { |
57 | $path = realpath($path) === false ? $path : realpath($path); |
57 | $path = realpath($path) === false ? $path : realpath($path); |
58 | 58 | ||
59 | $cont = @file_get_contents("$path/includes/constants.php"); |
59 | $cont = @file_get_contents("$path/includes/constants.php"); |
60 | if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) { |
60 | if (!preg_match("@define\('SCRIPT_VERSION', '(.*)'\);@ismU", $cont, $m)) { |
61 | throw new Exception("Cannot find version information at $path"); |
61 | throw new Exception("Cannot find version information at $path"); |
62 | } |
62 | } |
63 | 63 | ||
64 | return $m[1]; |
64 | return $m[1]; |
65 | } |
65 | } |
66 | 66 | ||
67 | protected function get_latest_version() { |
67 | protected function get_latest_version() { |
68 | $cont = @file_get_contents('https://www.4homepages.de/download-4images'); |
68 | $cont = @file_get_contents('https://www.4homepages.de/download-4images'); |
69 | if (!$cont) { |
69 | if (!$cont) { |
70 | throw new Exception("Cannot access website with latest version"); |
70 | throw new Exception("Cannot access website with latest version"); |
71 | } |
71 | } |
72 | 72 | ||
73 | if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) { |
73 | if (!preg_match('@<h2>Download 4images (.+)</h2>@ismU', $cont, $m)) { |
74 | if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) { |
74 | if (!preg_match('@>Current Version: (.+)</a>@ismU', $cont, $m)) { |
75 | throw new Exception("Cannot find version information on the website"); |
75 | throw new Exception("Cannot find version information on the website"); |
76 | } |
76 | } |
77 | } |
77 | } |
78 | 78 | ||
79 | return trim($m[1]); |
79 | return trim($m[1]); |
80 | } |
80 | } |
81 | 81 | ||
82 | protected function cbRun($optional_args=array()) { |
82 | protected function cbRun($optional_args=array()) { |
83 | $system_dir = $this->argSystemDir->getValue(); |
83 | $system_dir = $this->argSystemDir->getValue(); |
84 | if (empty($system_dir)) { |
84 | if (empty($system_dir)) { |
85 | throw new Exception("Please specify the directory of the 4images installation."); |
85 | throw new Exception("Please specify the directory of the 4images installation."); |
86 | } |
86 | } |
87 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
87 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
88 | 88 | ||
89 | if (!is_dir($system_dir)) { |
89 | if (!is_dir($system_dir)) { |
90 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
90 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
91 | } |
91 | } |
92 | 92 | ||
93 | $version = $this->get_4images_version($system_dir); |
93 | $version = $this->get_4images_version($system_dir); |
94 | 94 | ||
95 | $latest_version = $this->get_latest_version(); |
95 | $latest_version = $this->get_latest_version(); |
96 | 96 | ||
97 | if ($version == $latest_version) { |
97 | if (version_compare($version,$latest_version) >= 0) { |
98 | $this->setStatus(VNag::STATUS_OK); |
98 | $this->setStatus(VNag::STATUS_OK); |
99 | $this->setHeadline("Version $version at $system_dir", true); |
99 | $this->setHeadline("Version $version at $system_dir", true); |
100 | } else { |
100 | } else { |
101 | $this->setStatus(VNag::STATUS_WARNING); |
101 | $this->setStatus(VNag::STATUS_WARNING); |
102 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
102 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
103 | } |
103 | } |
104 | } |
104 | } |
105 | } |
105 | } |
106 | 106 | ||
107 | 107 |