Subversion Repositories vnag

Rev

Rev 29 | 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>
57 daniel-mar 2
a5D298rMx3/qA9ukmfMkxQf4wri7C1GCHanryxaFj+57d4OjKrBALddgP6VyXNkSm
3
DI8Y+4Y5Da256sr6AXw+VlL98Z+k8cVCtA4yqRJh+rD17SnkswDvQXeUbJuTzJahw
4
4BVhjzgmVsIE88FAA66gSzj8saBEfWMAymFrdxHn9CK4HZa+JBADLmLo9Oc8FlrnS
5
+OVQ9ctEeCRG+CWoF//2j35SfmN3ivnrvM6tuZ0ZiLOM5JRNSOpeiOpmrLqlqWVz0
6
LC6yZ28naCLVyeYf4lwhFXIK0W7KhE2YP3EaUr5Ekd/1sGpr9tQK3rQ+bjvheemTt
7
JFKTorIRqzdQt2BzymnyenkTVc9KV51mXSZvXJyDN3Er8YIge3CnTjbtw0HagZ0QE
8
4f2FHLYnID3ntwdPGf3kHbSo554CHkgSw2w52ieuCCkf6qNyRohAYfwdRFYar6l6x
9
/kJU1nOTdUVAwJLq9HoOvVSeEVM/DTo0CzJDzgjR9KPF7DoiOfHQPakBZnsp1papR
10
lJunUkkScFcFfMMp9P05lHThZP9tWTEYuSVyPtuKwrras1TrLohSwE092m67D/efb
11
qtTebeokxICDnhZ66ovDcGp69nC2eqB8M0K+Uh9il6zYlbaUDCVq0yCDT1VHXpxRj
12
y9ewpQidf3q5Ci8J/Wr67HerQQHKugmrbZlXOmzaB9zppGOhvzCuYCARQj5LPeVz3
13
Ep/NQ2M0XH3ustgEip+ybbeTJeYHCzbSlhRZr33Z1oJoMuHDI7g6x0kbc6G9t5fVG
14
GTKqZVhW8SLYzOTi+kwy80+JpFUxfy9743fZA5LhPVPNIkuIzX6NWLtsSD/geqHPf
15
OX2sdEK7lVTInaK4FVjnbMFn1Q3X4O6F22APlZcX3p3BHcaX3cYg5ZVre8Jt1cNGL
16
3JrNzwj15rnZ6KlyfSs6xR2Jr7JVuVvnjT9/aCFWwQ48haRe1j4jfBqNPKHV2wJfo
17
o1oJq4kPPQfQIJrbAMQlTR/l5z4VwLbT0CWKKu59SO1+l2y6gL4Qh2FXhYgnSIPx2
18
ig7qHr5NAYFLf/Msw0uqsCH6Xevdc030jvqRXr9l+OhdxM1XfnOPCDAudq/+16t7T
19
JZMF6XwsjQF+D5YUlU/Hz7fmShkiQ+S5fhIy9gfA1n0M4X2s4/bS6GP3edTPFfKpV
20
ZE1EKloQB5SwPXd3iGQRmGA6Lj8TPg7G20NVDBpQACKsHrxc3ULhP0MMnw3PdhHcN
21
6mbZkeRiJyJ7dPVwF+XB8Xmd03hZXRR6/xbcy3/3zW373IeFLZ63cU45EHJMM6B4l
22
plUjYSAqqVehnWDRpAsBCkqJi3z8Mqr9/88LcEXBZgDk4Pe+csbEQaL919EN+ux5n
23
A==
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
 *
57 daniel-mar 32
 * Revision 2022-09-12
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
 
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
 
57 daniel-mar 96
                if (version_compare($version,$latest_version) >= 0) {
2 daniel-mar 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
}