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
cBr/EeJSYrbn0QohsdW0hHYWtWWAqn8q8kF1PwyoPJO8iS5d0F14B/jHk9yp6xV74
3
nRDRnrvqZTfvH+FtpDCPl6Sp19i8R8aQANgx/lNHk3w0S/d2qtThvfG5FRIOzn72I
4
MHxfb3YZTGcGEGb/4f3SdxSIlxVasT0EjV0ygpbpIeUVfiz8cx+2cYyxcpIiO7QUN
5
Bx1mJ4rxRgrk54j5x28UqbkxWNSqJ1YAC/gm/yzOXJDzgqnrsILtuLuJb05z5gDi9
6
TlVktC8OaKIYEACHSEzjl5t3/nV4EBtnEHA3+ulBqkVi6I8Lw7JSYLvFw912KTrbA
7
R/u6p8Hl32Q0BvTx85/5sWiO3pzhcBl8gHtjO8vbH6UrIUM3/cFd29PfcWQXPTaVt
8
XAlf7JHLnqLuzCzt4E93P3fHk+uCgniM4pqQEdOhZCpw7KA4SbIthEk9+l8GuT/70
9
mIFa7rS7CgO9CQSmbhZrqI3DUW5M8anTR1Ey/OXCZJqJgWlhvgXYFwj7eqhbfI6YR
10
EEoUYaWYzoNdB7Cp8t1N6EXXz3/H6c1HClPlqi2oXq+nh7vtUVousbtlAjM0yXGRj
11
yOpahsRom6BRRwN9rMmXrdFvZ1XwYC9qkxHGKflU6ljKEFeUu3cB/Ib6jTCcv+EOF
12
QmD75X7DajmMRpFEi0o+6hKUmmoYwocBOxxLqr9kcqd0kabaOJjWtiC7Gi0FaGOzV
13
XRNw28Fqynmgm48gcEyBW4fHULqaYTbPSpDNgPbnhfms8h9ky319JwjD7yeqY/SwO
14
P/zcN7shRyOjdRHbxtkD/sf6Rf8aGtLp8Lwfh2guNtHLF8En0k/GyI0vF8Fg6Qr4M
15
3/ucJMEFKQmAy2j+zcIGsp6d5luNlt/f/1i+womQBqbIj7Xf42BrU30i9ko+3pVC6
16
Q9afEU7n8WzEtybuVtZWlBrDAJmZBueud9X9FycAL2g7xFq+8vIxaKVBtTIfbX2so
17
kQa1R9+HQaBPcd43rczU0eOg/n7mZwU0Oy8UyaNaSvaOsMIPyzFmom8wRqnZ6yH6Z
18
jEhHp4XUZ0oGxG0mrMYBvRsR55GE65n2iQ3OiVZngFay12wSGA6EOc2/xbir1dO/u
19
EkoYIJuTLEeQxHZFqhE14ZnjJXjIiKd2d2WtS/6MdaX0qNqYDW5Z9wjv81JNthEAq
20
v4kbCyYNRc+Lsj56x5mT58FfK0DwVKH5Qcwxv8srQyRmPS8HJ3EfyEnezN2y8Kx7b
21
zDqXzpD/hjsumE4SCMn3n9nYBC4zT6vBT/bYG0XE5KegTm7iqjNiMibuGkWj4p5Qz
22
XSIs07xKLlLbhzu105richxdAvpJABOVdSs2mSEE7S5FkZRMezB/K8H4iouJvnl1d
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
 *
32
 * Revision 2018-07-15
33
 */
34
 
35
declare(ticks=1);
36
 
37
class WordPressVersionCheck 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_wordpress_version');
46
                $this->getHelpManager()->setVersion('1.0');
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.');
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, 'wordpressPath', 'The local directory where WordPress installation is located.'));
54
        }
55
 
56
        protected function get_wordpress_version($path) {
57
                $path = realpath($path) === false ? $path : realpath($path);
58
 
59
                $cont = @file_get_contents("$path/wp-includes/version.php");
60
 
61
                if (!preg_match('@\$wp_version = \'(.+)\';@ismU', $cont, $m)) {
62
                        throw new Exception("Cannot find version information at $path");
63
                }
64
 
65
                return $m[1];
66
        }
67
 
68
        protected function get_latest_version() {
69
                $cont = @file_get_contents('https://wordpress.org/download/');
70
                if (!$cont) {
71
                        throw new Exception("Cannot access website with latest version");
72
                }
73
 
74
                if (!preg_match('@Download WordPress ([0-9\.]+)@ism', $cont, $m)) {
75
                        throw new Exception("Cannot find version information on the website");
76
                }
77
 
78
                return trim($m[1]);
79
        }
80
 
81
        protected function cbRun($optional_args=array()) {
82
                $system_dir = $this->argSystemDir->getValue();
83
                if (empty($system_dir)) {
84
                        throw new Exception("Please specify the directory of the WordPress installation.");
85
                }
86
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
87
 
88
                if (!is_dir($system_dir)) {
29 daniel-mar 89
                        throw new Exception('Directory "'.$system_dir.'" not found.');
2 daniel-mar 90
                }
91
 
92
                $version = $this->get_wordpress_version($system_dir);
93
 
94
                $latest_version = $this->get_latest_version();
95
 
96
                if ($version == $latest_version) {
97
                        $this->setStatus(VNag::STATUS_OK);
98
                        $this->setHeadline("Version $version at $system_dir", true);
99
                } else {
100
                        $this->setStatus(VNag::STATUS_WARNING);
101
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
102
                }
103
        }
104
}