Subversion Repositories vnag

Rev

Rev 4 | 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>
29 daniel-mar 2
1nbCL4jEjMIUirsnswcLvLOyfe4r5lC8uW+VWf4gmxQJkjsT6mBL7UJ1qkLyozyix
3
7BLkSW+00lytdAut4LORacPuO8vKTgPsbwYktrAON26lo3mTFpcoOriwPATDavd5d
4
F69Ma5FM6vDtucdiOhBM+jRQB+91dOjFCg05lNNzk9ZPazZ6HQR4roZUShRZxjR5N
5
8+C/ZtAxPHspZnKtcLCxKgeBuRxaIbm12XLnB1ol8fuSiVOL208y2a2bV+Ne0+/K1
6
B1qguJuZ71OgpHcp62TqtoX7cdzMbwqNvLTzvBzWeanbrs2ULKTbFSI+SvYfY4Z7j
7
J0MMurcUuiupxGLPElQbW7PwS/Yu5onMm7HpOPp6HdVxlyyWDTyJymVxuY+ouYctd
8
QnlAdVlLgkC7melQvF038ANRJt6Z/0IbxOGPp0gyo7VLcG6P2tylAoqn4w8MoqbKj
9
6024IA+/HILQhpnMjnH37QoSp2z1v6yrzXc2P0HvY8zh0SbvLWvMJqUyYaYkyfvT+
10
XvcXDHspoFAC759RWvRokzXvNhHX87ocTxmr/RZ+nxHHPXXhgpgl/nNPnRT+NRQJ4
11
4MYoQUZOBRrW6QOmKC7851das0OhFiDdGQTHdWTjx49Q1GnBJc2PeXhQ822jfK4g6
12
uamXBhjme+E24saVl970VKdYzcpkzkEv1GHMfs8H0qv9mcTSFidLXxT/5MEfXJh+j
13
BBI6oiCidY7rIygR+OuuYZRZ4/PInSVHyGNyt2lzWON3OGy6tDzEU1/soHU0SvMnE
14
nDBAATL7qxKOsM/FA2y8mn/n9n7bTpbDkIzmOLaxK2zHExx6HJuusKoSrca9DCNwJ
15
ZKqsj1TbX5C9K84f1IJ1XHZ2chYnaK9gUk6x7gWUYn9UtCjwlgHHuXtuYxNQv/6Fa
16
ZA02zyuC9YOn3d2iisanSglVlSbTb9eLobRgZhs/xe6wBdKqQN61inuWyrSD/tIKD
17
k4FhYR3zvUK7hoeEeZbdHdV68oeakKiDSSUpDtvYMrQar9u1xbcoSpmq8PJM7jjex
18
i4Mix+Yn63IkY/Nfcj6abeOdVMX+7rkjsB+xe8AQC1PTHig7bqnJElw0jTJEP83A5
19
OrZt3p7lWDKzAlIPXgDWAsBOWoCjVKx8WWQsxcOdpUzqv1K4VApCsVgKmXoOWeRVb
20
3kwvJHGR9C0qkUKEmYcpCI1cIPo+UmR35Ox9/im48jIXgA0SDs3vegLVECvoz00Fr
21
7zRfkvOq/0mnDZN/nKceGogyCBPmImZ2PU6wyDztvkfxT7EbE12T3dWKiw1sXM9L/
22
hHR8FZxhV4x3ZxqeyRHjKv0itK+vEBpTvCQX6kUMPn0WUi7A9Mj76LHCqlPAAIi2N
4 daniel-mar 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)) {
29 daniel-mar 90
                        throw new Exception('Directory "'.$system_dir.'" not found.');
2 daniel-mar 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