Subversion Repositories vnag

Rev

Rev 57 | 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>
76 daniel-mar 2
UzghgdkH2mWbh17KeuX+tCGeGd4f9DmMtoRV1S0L+qpVQ+3khc8X9mMqxd1pNwzG/
3
+FnU1vAhHRT2sOcWVGsWThIBZtSIbdy+/HoAhqB94nAqwMIzwrOCwOnB+2EbbkWPv
4
TQImz8/wxd+Bh3sKpefgxZa1soa5fsLib/Ag2xDL4swEJ3HZRwPqB/su+I7zbMmVH
5
Aks5P0MnfZY1Jtj1yXaFilaTkUDDqaN8AOEjbA9qa7mxa79zhLq1weDLTeprYUMWq
6
R3jO6ohiNgIEddRhmvCC3n5HMiIfyUtJHwpS/+4VLBqejpMmEP9cTeCabS8HZO1SD
7
AJvmIa6rhPdA6gYw0eSI4LzkMKohgykrO6/i1o4+6Uo4INpe7foJClnRNboPLHdr8
8
TniS7Xz7Y8/EK+RRQx9dy1AQEzJ3zE30y3Hj3SvAPzlVs2SjTz5+tmVlsqAp092lQ
9
isZsjCJK4YKno39MhP3CiNEcN7Yx98KCYwDmEWSlTbYgTCMuo96CEAdObLCOtrdip
10
GnttI5xLfLip6xE5w9C6oXtBx5mEqa1+k1VIVDljQ6ft2ug35w5n8T4qmDvphgtYD
11
FxlzMRpLKTWzUEh/BxWYJDDhvDcpz9aOS7MX5NRx0Nsh9TAiYzT7WgcJmdU92qAJB
12
sYH02IV8X4HK52DkEYWsNn/uvbTLtIrRJPB3QyKgiZr1xDzG2/xM+nmyNCPuc1tuL
13
UvTiE+mHF3EUGItKpWuio7jwisPcSiERaJkzzmlSyEgks7GO0R727G4LN6aU6bfZd
14
NFcUn8wNApIrSpY9QWCZR4SLlbI+KLc8dV98x29WqBZtVfPqHaLb1x0A8tdwzkbzi
15
XlPDTSoq41Vp3Ac/048LTBq7sqRgQfeXOpOykhe9GwbyIa4r245cpO9ecSqhIC+Hk
16
/jvS1DL6X8JDBQfb+jlG0Etolvgm8wXrPqUbBXOjXrZdL6Llh5ds7swIetoWvPMXI
17
Dj+7vk/SYhUA2esmDt5h13MZIlxiyCQ3WimVhqzy4ugNBHFdCkoaXsCm0gCy1rLmO
18
kV8CTAW6zEhBCrgGHhaaGMV0RTc6ygnkVjPyZ3c6p6bxlc3DJgJ7E1dDNOqWH/mzO
19
n61R6pl7ISJ9/Js0FJkL5WcvCbjao2QuJD00gyGsJpOt3WfCCHGjif/VWZo4M9Y/K
20
GDyE+Lwq2690k+K2876Y+rdXoopjhLv6GYXXrjPhUTRMtzXkK5tiVjRzLMN5T2fvC
21
gWLFxi5J1qM4DV4AGLF245144Stsa3j558edqgWEK4CVTsHGT1YiQFF0omFVlG9IT
22
cMeslXPMLRwpyx2Z/UoMBiTsc+7lazwlZ/w9RutNd7pRWA1E3GcIC4AO4NPLQ/1nW
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");
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() {
76 daniel-mar 68
                $cont = $this->url_get_contents('https://www.4homepages.de/download-4images');
69
                if ($cont === false) {
2 daniel-mar 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)) {
29 daniel-mar 90
                        throw new Exception('Directory "'.$system_dir.'" not found.');
2 daniel-mar 91
                }
92
 
76 daniel-mar 93
                $version = $this->get_local_version($system_dir);
2 daniel-mar 94
 
95
                $latest_version = $this->get_latest_version();
96
 
57 daniel-mar 97
                if (version_compare($version,$latest_version) >= 0) {
2 daniel-mar 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