Subversion Repositories vnag

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php /* <ViaThinkSoftSignature>OJBtqRvIU6hU8LTzanZKhpd9dpHHiBOX4pwyUGXYgEltRcNKKASFsv71lmshrkuxmgCp2q4aa9jB03T0RPOPXtAulRlFpLvsmD7eXHRqt82AC8H2PMw8uoCMk/bqgfAMqf1y0sP9qs5s9faijFgdKlQkJH3nLGDQ3YsN1dYLMwtUQsKtnVobLizdd5tIlyW1OcY5h32Yd2z24CjcgBUbknqBD+I6dBx7TBQWXqX4CwC7N2jDXyn7TBN2CHWtYlY1BldUndt6PXEaaoYOtqcQw/cSc7NvOenQFGQt++Kwur1f31+6HiGbLFGLfrA0sXJWUdYWLHGkNHKmzmPoDZFWweQIadB5QQGtnLWUpPtIsShIg4/G0+Lt6V/janYr0D/IGVnRyXUikh59qNkx942oGF/ozuu39OYyAhyUTbpCT8/PeDwjS2qPbvsZEq2tUDGHHBxq1XW8DmsmLkRCertcVGsG+WLBmxCJLRjI/5UE0zB9XCXwIPOI8+ImtvBgGhEPu63xbORECr6R0L8FWZ8cjCvnrNEFZOSliTQWwUzpcgJTAFSJPlHEF/X4PbqbhsJLU6Z75Q/jIfKWzxzREzkyPKQGDAitKnGwiNZo04tJSxBryd8Vqm0sASmTkSm1TU60C7MOzWCekIekea+lOpoxPwdXuphxwahGTxXkp+FCQ7/K1e/jYOkCgq/Xz7uZRVXK7/bL0QlrwMQtJbbiJHon4pE7aar6yP3mAE6zqXdPzxCRr28ochhY2dFU6RKXK9mMgkAdvalsyksLR4ivEOcGrRW3ZasY8RhLu1UiZKGpVrlanK7E8AqL6moXB5xxTmNeBGBPzWmYJaAFjHp+iFNVy11jGTQD9HW4bQ0vqhj71TyCpmXJnsiF0J3Zurj+iB22U192yBVluuOemOCTfygSySdZXsQCb2dARjnalkyb9ee5j0VrgeI7FYeVne9PkarpWRgvVhEQzLbwcCgRHKpQy0w4V41wx5HdmrcncYntEdbIx0iITKeIFy65VaQYQyk4RNL6PG6jY32gyNqIA7OzwnTYrguBlKhf4Fp9ij8g9xPtXp16Jz1AEzxkbxMzIZeSwQXIv14rbZszTuFJ3LsjH77agS2Gc6nqframOvPF4YszPJUG+EpSLiiuM/5SAXcTB8pDPoaRSVXSg9ouoLjH5BcppDUQqBIaXuJzDvqpfXQzAEBeyZg0jQw/3ylLAIlp4oNmuU+UlmIO4GYlGWVo6eAqH/v/g3cffTVce/OvpjUR0+3bTgmlf8/QC9s/rqtYEJ9jB953TfnSkP1RXP2y0ZlfuumRB2u2mDuJEZrWbZwXdobkfwwLrxPGeucLqPeY+it+yD6tNguvu2c0/BMuPA==</ViaThinkSoftSignature> */ ?>
2
<?php
3
 
4
/*
5
 * VNag - Nagios Framework for PHP
6
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
7
 * Licensed under the terms of the Apache 2.0 license
8
 *
9
 * Revision 2018-07-15
10
 */
11
 
12
declare(ticks=1);
13
 
14
class WordPressVersionCheck extends VNag {
15
        protected $argSystemDir = null;
16
 
17
        public function __construct() {
18
                parent::__construct();
19
 
20
                $this->registerExpectedStandardArguments('Vht');
21
 
22
                $this->getHelpManager()->setPluginName('check_wordpress_version');
23
                $this->getHelpManager()->setVersion('1.0');
24
                $this->getHelpManager()->setShortDescription('This plugin checks if a local WordPress Webmail system has the latest version installed.');
25
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
26
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
27
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
28
 
29
                // Individual (non-standard) arguments:
30
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'wordpressPath', 'The local directory where WordPress installation is located.'));
31
        }
32
 
33
        protected function get_wordpress_version($path) {
34
                $path = realpath($path) === false ? $path : realpath($path);
35
 
36
                $cont = @file_get_contents("$path/wp-includes/version.php");
37
 
38
                if (!preg_match('@\$wp_version = \'(.+)\';@ismU', $cont, $m)) {
39
                        throw new Exception("Cannot find version information at $path");
40
                }
41
 
42
                return $m[1];
43
        }
44
 
45
        protected function get_latest_version() {
46
                $cont = @file_get_contents('https://wordpress.org/download/');
47
                if (!$cont) {
48
                        throw new Exception("Cannot access website with latest version");
49
                }
50
 
51
                if (!preg_match('@Download WordPress ([0-9\.]+)@ism', $cont, $m)) {
52
                        throw new Exception("Cannot find version information on the website");
53
                }
54
 
55
                return trim($m[1]);
56
        }
57
 
58
        protected function cbRun($optional_args=array()) {
59
                $system_dir = $this->argSystemDir->getValue();
60
                if (empty($system_dir)) {
61
                        throw new Exception("Please specify the directory of the WordPress installation.");
62
                }
63
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
64
 
65
                if (!is_dir($system_dir)) {
66
                        throw new Exception('Directory "'.$system_dir.'" not found.', false);
67
                }
68
 
69
                $version = $this->get_wordpress_version($system_dir);
70
 
71
                $latest_version = $this->get_latest_version();
72
 
73
                if ($version == $latest_version) {
74
                        $this->setStatus(VNag::STATUS_OK);
75
                        $this->setHeadline("Version $version at $system_dir", true);
76
                } else {
77
                        $this->setStatus(VNag::STATUS_WARNING);
78
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
79
                }
80
        }
81
}