Subversion Repositories vnag

Rev

Rev 2 | 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>
2
OJBtqRvIU6hU8LTzanZKhpd9dpHHiBOX4pwyUGXYgEltRcNKKASFsv71lmshrkuxm
3
gCp2q4aa9jB03T0RPOPXtAulRlFpLvsmD7eXHRqt82AC8H2PMw8uoCMk/bqgfAMqf
4
1y0sP9qs5s9faijFgdKlQkJH3nLGDQ3YsN1dYLMwtUQsKtnVobLizdd5tIlyW1OcY
5
5h32Yd2z24CjcgBUbknqBD+I6dBx7TBQWXqX4CwC7N2jDXyn7TBN2CHWtYlY1BldU
6
ndt6PXEaaoYOtqcQw/cSc7NvOenQFGQt++Kwur1f31+6HiGbLFGLfrA0sXJWUdYWL
7
HGkNHKmzmPoDZFWweQIadB5QQGtnLWUpPtIsShIg4/G0+Lt6V/janYr0D/IGVnRyX
8
Uikh59qNkx942oGF/ozuu39OYyAhyUTbpCT8/PeDwjS2qPbvsZEq2tUDGHHBxq1XW
9
8DmsmLkRCertcVGsG+WLBmxCJLRjI/5UE0zB9XCXwIPOI8+ImtvBgGhEPu63xbORE
10
Cr6R0L8FWZ8cjCvnrNEFZOSliTQWwUzpcgJTAFSJPlHEF/X4PbqbhsJLU6Z75Q/jI
11
fKWzxzREzkyPKQGDAitKnGwiNZo04tJSxBryd8Vqm0sASmTkSm1TU60C7MOzWCekI
12
ekea+lOpoxPwdXuphxwahGTxXkp+FCQ7/K1e/jYOkCgq/Xz7uZRVXK7/bL0QlrwMQ
13
tJbbiJHon4pE7aar6yP3mAE6zqXdPzxCRr28ochhY2dFU6RKXK9mMgkAdvalsyksL
14
R4ivEOcGrRW3ZasY8RhLu1UiZKGpVrlanK7E8AqL6moXB5xxTmNeBGBPzWmYJaAFj
15
Hp+iFNVy11jGTQD9HW4bQ0vqhj71TyCpmXJnsiF0J3Zurj+iB22U192yBVluuOemO
16
CTfygSySdZXsQCb2dARjnalkyb9ee5j0VrgeI7FYeVne9PkarpWRgvVhEQzLbwcCg
17
RHKpQy0w4V41wx5HdmrcncYntEdbIx0iITKeIFy65VaQYQyk4RNL6PG6jY32gyNqI
18
A7OzwnTYrguBlKhf4Fp9ij8g9xPtXp16Jz1AEzxkbxMzIZeSwQXIv14rbZszTuFJ3
19
LsjH77agS2Gc6nqframOvPF4YszPJUG+EpSLiiuM/5SAXcTB8pDPoaRSVXSg9ouoL
20
jH5BcppDUQqBIaXuJzDvqpfXQzAEBeyZg0jQw/3ylLAIlp4oNmuU+UlmIO4GYlGWV
21
o6eAqH/v/g3cffTVce/OvpjUR0+3bTgmlf8/QC9s/rqtYEJ9jB953TfnSkP1RXP2y
22
0ZlfuumRB2u2mDuJEZrWbZwXdobkfwwLrxPGeucLqPeY+it+yD6tNguvu2c0/BMuP
23
A==
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)) {
89
                        throw new Exception('Directory "'.$system_dir.'" not found.', false);
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
}