Subversion Repositories vnag

Rev

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
cBr/EeJSYrbn0QohsdW0hHYWtWWAqn8q8kF1PwyoPJO8iS5d0F14B/jHk9yp6xV74
2
a5D298rMx3/qA9ukmfMkxQf4wri7C1GCHanryxaFj+57d4OjKrBALddgP6VyXNkSm
3
nRDRnrvqZTfvH+FtpDCPl6Sp19i8R8aQANgx/lNHk3w0S/d2qtThvfG5FRIOzn72I
3
DI8Y+4Y5Da256sr6AXw+VlL98Z+k8cVCtA4yqRJh+rD17SnkswDvQXeUbJuTzJahw
4
MHxfb3YZTGcGEGb/4f3SdxSIlxVasT0EjV0ygpbpIeUVfiz8cx+2cYyxcpIiO7QUN
4
4BVhjzgmVsIE88FAA66gSzj8saBEfWMAymFrdxHn9CK4HZa+JBADLmLo9Oc8FlrnS
5
Bx1mJ4rxRgrk54j5x28UqbkxWNSqJ1YAC/gm/yzOXJDzgqnrsILtuLuJb05z5gDi9
5
+OVQ9ctEeCRG+CWoF//2j35SfmN3ivnrvM6tuZ0ZiLOM5JRNSOpeiOpmrLqlqWVz0
6
TlVktC8OaKIYEACHSEzjl5t3/nV4EBtnEHA3+ulBqkVi6I8Lw7JSYLvFw912KTrbA
6
LC6yZ28naCLVyeYf4lwhFXIK0W7KhE2YP3EaUr5Ekd/1sGpr9tQK3rQ+bjvheemTt
7
R/u6p8Hl32Q0BvTx85/5sWiO3pzhcBl8gHtjO8vbH6UrIUM3/cFd29PfcWQXPTaVt
7
JFKTorIRqzdQt2BzymnyenkTVc9KV51mXSZvXJyDN3Er8YIge3CnTjbtw0HagZ0QE
8
XAlf7JHLnqLuzCzt4E93P3fHk+uCgniM4pqQEdOhZCpw7KA4SbIthEk9+l8GuT/70
8
4f2FHLYnID3ntwdPGf3kHbSo554CHkgSw2w52ieuCCkf6qNyRohA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/aCFWwQ48haRe1j4jfBqNPKHV2wJfo
17
kQa1R9+HQaBPcd43rczU0eOg/n7mZwU0Oy8UyaNaSvaOsMIPyzFmom8wRqnZ6yH6Z
17
o1oJq4kPPQfQIJrbAMQlTR/l5z4VwLbT0CWKKu59SO1+l2y6gL4Qh2FXhYgnSIPx2
18
jEhHp4XUZ0oGxG0mrMYBvRsR55GE65n2iQ3OiVZngFay12wSGA6EOc2/xbir1dO/u
18
ig7qHr5NAYFLf/Msw0uqsCH6Xevdc030jvqRXr9l+OhdxM1XfnOPCDAudq/+16t7T
19
EkoYIJuTLEeQxHZFqhE14ZnjJXjIiKd2d2WtS/6MdaX0qNqYDW5Z9wjv81JNthEAq
19
JZMF6XwsjQF+D5YUlU/Hz7fmShkiQ+S5fhIy9gfA1n0M4X2s4/bS6GP3edTPFfKpV
20
v4kbCyYNRc+Lsj56x5mT58FfK0DwVKH5Qcwxv8srQyRmPS8HJ3EfyEnezN2y8Kx7b
20
ZE1EKloQB5SwPXd3iGQRmGA6Lj8TPg7G20NVDBpQACKsHrxc3ULhP0MMnw3PdhHcN
21
zDqXzpD/hjsumE4SCMn3n9nYBC4zT6vBT/bYG0XE5KegTm7iqjNiMibuGkWj4p5Qz
21
6mbZkeRiJyJ7dPVwF+XB8Xmd03hZXRR6/xbcy3/3zW373IeFLZ63cU45EHJMM6B4l
22
XSIs07xKLlLbhzu105richxdAvpJABOVdSs2mSEE7S5FkZRMezB/K8H4iouJvnl1d
22
plUjYSAqqVehnWDRpAsBCkqJi3z8Mqr9/88LcEXBZgDk4Pe+csbEQaL919EN+ux5n
23
w==
23
A==
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 WordPressVersionCheck extends VNag {
37
class WordPressVersionCheck 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_wordpress_version');
45
                $this->getHelpManager()->setPluginName('check_wordpress_version');
46
                $this->getHelpManager()->setVersion('1.0');
46
                $this->getHelpManager()->setVersion('1.0');
47
                $this->getHelpManager()->setShortDescription('This plugin checks if a local WordPress Webmail system has the latest version installed.');
47
                $this->getHelpManager()->setShortDescription('This plugin checks if a local WordPress Webmail 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, 'wordpressPath', 'The local directory where WordPress installation is located.'));
53
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'wordpressPath', 'The local directory where WordPress installation is located.'));
54
        }
54
        }
55
 
55
 
56
        protected function get_wordpress_version($path) {
56
        protected function get_wordpress_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/wp-includes/version.php");
59
                $cont = @file_get_contents("$path/wp-includes/version.php");
60
 
60
 
61
                if (!preg_match('@\$wp_version = \'(.+)\';@ismU', $cont, $m)) {
61
                if (!preg_match('@\$wp_version = \'(.+)\';@ismU', $cont, $m)) {
62
                        throw new Exception("Cannot find version information at $path");
62
                        throw new Exception("Cannot find version information at $path");
63
                }
63
                }
64
 
64
 
65
                return $m[1];
65
                return $m[1];
66
        }
66
        }
67
 
67
 
68
        protected function get_latest_version() {
68
        protected function get_latest_version() {
69
                $cont = @file_get_contents('https://wordpress.org/download/');
69
                $cont = @file_get_contents('https://wordpress.org/download/');
70
                if (!$cont) {
70
                if (!$cont) {
71
                        throw new Exception("Cannot access website with latest version");
71
                        throw new Exception("Cannot access website with latest version");
72
                }
72
                }
73
 
73
 
74
                if (!preg_match('@Download WordPress ([0-9\.]+)@ism', $cont, $m)) {
74
                if (!preg_match('@Download WordPress ([0-9\.]+)@ism', $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
                return trim($m[1]);
78
                return trim($m[1]);
79
        }
79
        }
80
 
80
 
81
        protected function cbRun($optional_args=array()) {
81
        protected function cbRun($optional_args=array()) {
82
                $system_dir = $this->argSystemDir->getValue();
82
                $system_dir = $this->argSystemDir->getValue();
83
                if (empty($system_dir)) {
83
                if (empty($system_dir)) {
84
                        throw new Exception("Please specify the directory of the WordPress installation.");
84
                        throw new Exception("Please specify the directory of the WordPress installation.");
85
                }
85
                }
86
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
86
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
87
 
87
 
88
                if (!is_dir($system_dir)) {
88
                if (!is_dir($system_dir)) {
89
                        throw new Exception('Directory "'.$system_dir.'" not found.');
89
                        throw new Exception('Directory "'.$system_dir.'" not found.');
90
                }
90
                }
91
 
91
 
92
                $version = $this->get_wordpress_version($system_dir);
92
                $version = $this->get_wordpress_version($system_dir);
93
 
93
 
94
                $latest_version = $this->get_latest_version();
94
                $latest_version = $this->get_latest_version();
95
 
95
 
96
                if ($version == $latest_version) {
96
                if (version_compare($version,$latest_version) >= 0) {
97
                        $this->setStatus(VNag::STATUS_OK);
97
                        $this->setStatus(VNag::STATUS_OK);
98
                        $this->setHeadline("Version $version at $system_dir", true);
98
                        $this->setHeadline("Version $version at $system_dir", true);
99
                } else {
99
                } else {
100
                        $this->setStatus(VNag::STATUS_WARNING);
100
                        $this->setStatus(VNag::STATUS_WARNING);
101
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
101
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
102
                }
102
                }
103
        }
103
        }
104
}
104
}
105
 
105