Subversion Repositories vnag

Rev

Rev 76 | 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>
77 daniel-mar 2
j/l/RmkPw7emOo36KLIAYvPpYBHeZjxONYqQqMjVBa3TF1IIqILKtQEzvk7ocvzdL
3
xwJbBQo2FjoEicScuJiew6T8RAH9pu1MrkBrqI9tkhrR6SRW/BvbsL7jS0ypXmu4K
4
OqIlbRS0YERM35lUPfOeHiMLI2hN746kpIVwlPgn5ilZ4T+ac9FkFjXkM898KHzhd
5
fQIKnPQ4ADYezQd0QXJ48SqYVO3Yen/VDc3I5Fej9wgocmZachsKQDDvJFyfQegez
6
ms971SY87VpFO6OUuL23z11Cm8svpPP9ug2ApMb4CEC/RGEZ+ODGEVs5PsSWVN/1V
7
L8ucXSlY/fsZc0t3yBsrB9XA2S8gV2NAq6EvXuiyPxuKGa/2xCLsaxgimZNHPCJJu
8
f1aCvoiD7LcqfqVrNAFIaptaYGMwqWAWuy8qk5VR2P3fHiwXdjwD0KMKyyR8r2zJh
9
gAIVVIFRMOwQ/EIwgvqp7AtdlAIw/VuT+Q0OUVeb02SdNYY/pRpYTwd79jVq24nq4
10
rzkVa6KfSb5gtbPTiNz8Z5efWIOxKXYqmZFxywg3tdGJXSVYAElPkituhbXy+vw/2
11
ANj3beLDMujZ8FxBpjEk6NWo1sd94b1mp6fbhY2PrrK82L+/DSBt8yPx7trZNGz1s
12
KG9EVl2zl2YyHjxZAWFQGTD+Nt/duHLiVa5qTddovnT/v+NuHRsERHVp3vRwoMpFO
13
bv7wU4R56Gl2okiPw5xT0YuUdveld63w77oL3d8PrKLzmBgkCIBhEy5yfJQ/OMxFM
14
2726VrAYZ3EEC8goFtm4VHT4+nk7bv7KeOaVzNGikDBsO+LCtcyyawabxzRR4R4rD
15
QzLGAsPQ+GswGqUSKhvAfx5QA1J1OiYH+/C5eJj4I5eOmVvawWEJt+VlnknOPafCa
16
oVksJ1C9wVcLcYTNPaX8MPruM9bZq7C7Nu38zGQgQbDgD8CFkIjP98VNS1KtFnHfc
17
RN3sSPQE4eyinzrP2ySQLMfZXl6Y6IELJJxcw1F2PeomM94ffM6oWqmPrBc8iK35u
18
7FwbnIf03hPnNnLtZzGCdlv6+CQsHf7f68ebqH4C4N/16tMJYI/ENX+aeUm9JDD1s
19
EbYqJ5pflNYyrIBYGtA0UCHqWVbRiabtc2b3IQhm/jjQ4qArxjf/x8OBlyvjULZXo
20
CvxzmBYGtpm+XDWKAw1SoN/3pNncaSioy0lMasqFQGoYVyqxvB5DPvhp/cnzp1XUt
21
21zUPBObtuxSsYkbh7HLDUg6J660/wRX4ff5ARdIr5fUzKDYLFcbtnVTuw0aXG2ZA
22
DOdiJsm6/mUdRpraftXyH1JshyX9OpsPoIIyuA/oVDx5Mjn+N6ITvvr2TjYHvXfiU
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
 *
76 daniel-mar 32
 * Revision 2023-10-13
2 daniel-mar 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
 
76 daniel-mar 56
        protected function get_local_version($path) {
2 daniel-mar 57
                $path = realpath($path) === false ? $path : realpath($path);
58
 
59
                $cont = @file_get_contents("$path/wp-includes/version.php");
77 daniel-mar 60
                if ($cont === false) {
61
                        throw new VNagException("Cannot find version information at $path (cannot read version.php)");
62
                }
2 daniel-mar 63
                if (!preg_match('@\$wp_version = \'(.+)\';@ismU', $cont, $m)) {
77 daniel-mar 64
                        throw new VNagException("Cannot find version information at $path (cannot find version string)");
2 daniel-mar 65
                }
66
 
67
                return $m[1];
68
        }
69
 
70
        protected function get_latest_version() {
76 daniel-mar 71
                $cont = $this->url_get_contents('https://wordpress.org/download/');
72
                if ($cont === false) {
77 daniel-mar 73
                        throw new VNagException("Cannot access website with latest version");
2 daniel-mar 74
                }
75
 
76
                if (!preg_match('@Download WordPress ([0-9\.]+)@ism', $cont, $m)) {
77 daniel-mar 77
                        throw new VNagException("Cannot find version information on the website");
2 daniel-mar 78
                }
79
 
80
                return trim($m[1]);
81
        }
82
 
83
        protected function cbRun($optional_args=array()) {
84
                $system_dir = $this->argSystemDir->getValue();
85
                if (empty($system_dir)) {
77 daniel-mar 86
                        throw new VNagException("Please specify the directory of the WordPress installation.");
2 daniel-mar 87
                }
88
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
89
 
90
                if (!is_dir($system_dir)) {
77 daniel-mar 91
                        throw new VNagException('Directory "'.$system_dir.'" not found.');
2 daniel-mar 92
                }
93
 
76 daniel-mar 94
                $version = $this->get_local_version($system_dir);
2 daniel-mar 95
 
96
                $latest_version = $this->get_latest_version();
97
 
57 daniel-mar 98
                if (version_compare($version,$latest_version) >= 0) {
2 daniel-mar 99
                        $this->setStatus(VNag::STATUS_OK);
100
                        $this->setHeadline("Version $version at $system_dir", true);
101
                } else {
102
                        $this->setStatus(VNag::STATUS_WARNING);
103
                        $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true);
104
                }
105
        }
106
}