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
FiyjR9oqgAeei220CERRBiLHuRAHb0/kx6b9OY4Ltv2b0fJO25aP3K18k/KQntpXh
3
28Yw3g1W/w807lr4xgRILQhhA3/JejkqNlKMb5bTZMcaNbTxBD44K/AHHXE62HesA
4
YgtFyG0j8qRn+MpTEBktuwxUmMqU1HT+SHQYq9Ytj0jVX4o0hbZ29yv23waZUYI7q
5
5as5ROs4veCrjPDSlVRty/jjviFe9ercdIta/ihXGfTR4MNymXCLKO3c3Y52yVBcI
6
N0xd0D3YvWZb1eyjMT1akpnFWfg+2RSqkwtNJUGHmiTF9m54dE3OfQGLEQhx062oY
7
WkbB7/Mc1sSs/U7eBdN553UycFI6j+M5yXhKmcAFTb3RMdiNRL5RsWYkx6u/tvJxO
8
CmJZ8Ln41pqdJiXSjE52psHLNcVlOAwzKdjqsC8l4kpYBQJhVMaIkfAiJ8t5lKkYj
9
T73QpaJl2db2Z95Skk8Utp+apI2jK/1x6IGE+PXUAIP7luQLPBrSaOrcCRRr1gXzX
10
WJJNpDuWMVIfsFqaLblSMcRwEKz8fRHM3Z/fiRKHW4Zo5eBmoq5kqafSHmZnA3jVy
11
QkIuqYa7nrwLpmsVT1rHqKWYbj7NduStIm0MNwdkui2AWZsA0G/NsXx08IrZlJ8Cd
12
3U0pZ1QGbGrOSfyWzLZh6oGCHnbHFgAIz5x6uWrwLpxXhuTDVws+oiSA02YdC8Flb
13
ew71AQKkqVsV0U6hQYFsHsL+pvu04TcqP05xfwBZl3UWtRPuSg5pio5vOdtGIVFa3
14
m3D01fQ9F4iRSZJCCMLcndD5F94CSCimd3zUyjNU9fMYaZ1Z9NE7HEt4tzhM7M0wD
15
/ea3HhG1cjNfulUFvy+04x0YuS7cIT/zCiDFkAB4T+hWwgbPBIJHumVCVbVhQr8gl
16
c+RGWMIrQ1BfHIsxOdnGxrW/jxMpcqzjO9nNB0QDsMSNaAuXQ8EVOMnDmiH8daaQM
17
QH2QBKXtgcKPVPJpqSbvPT2WGEAgdlfDphFhOC/L18dt5Ja8KGbBtQ2dhL6FLoPmc
18
WPY9jFrxv+eSICvUi5Wc6okClao/ml2xPis+O+kRbve1r6PkfKFhnG3hCQ+jxyO1M
19
RM4D+oEOAP/Xbl4/Uc+u5Ot1sbFGs4VoiKibPeiggIizzfp05R+tMgMIz7hUmAM6Y
20
FkZzxzKThl8V3s4yXLGv/drBJpSa1fG4lZmmOXfCvsAf15J660ObOxn7AiJN8fT4E
21
fLjHgoTZiCFYU2UMFwXpfKedm7u6+0gLyFk6ni4C6DAlUKKEVK5Cm+p/Ql3cNr70m
22
UhimfsrB26EYkwFWcfQGWhkUs1F5fmglVC1TSn9MflBEO0hUH2e/ivQIdNssN7Ni1
23
w==
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
// TODO: Also check extensions
36
 
37
declare(ticks=1);
38
 
39
class JoomlaVersionCheck extends VNag {
40
        protected $argSystemDir = null;
41
 
42
        public function __construct() {
43
                parent::__construct();
44
 
45
                $this->registerExpectedStandardArguments('Vht');
46
 
47
                $this->getHelpManager()->setPluginName('check_joomla_version');
48
                $this->getHelpManager()->setVersion('1.0');
49
                $this->getHelpManager()->setShortDescription('This plugin checks if a local Joomla system has the latest version installed.');
50
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
51
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
52
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
53
 
54
                // Individual (non-standard) arguments:
55
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'joomlaPath', 'The local directory where your Joomla installation is located.'));
56
        }
57
 
58
        protected function check_joomla_system($path) {
59
                $path = realpath($path) === false ? $path : realpath($path);
60
 
61
                $manifest_file = $path.'/administrator/manifests/files/joomla.xml';
62
 
63
                if (!file_exists($manifest_file)) {
64
                        throw new Exception("Manifest file $manifest_file not found");
65
                }
66
 
67
                $cont = file_get_contents($manifest_file);
68
                $manifest = new SimpleXMLElement($cont);
69
 
70
                $version = (string)$manifest->version;
71
 
72
                $count = 0;
73
                foreach ($manifest->updateservers->server as $updateserver) {
74
                        $cont = @file_get_contents($updateserver);
75
                        if ($cont) {
76
                                $extensions = new SimpleXMLElement($cont);
77
                                foreach ($extensions as $candidate) {
78
                                        $count++;
79
                                        if ($version == (string)$candidate['version']) {
80
                                                $detailsurl = (string)$candidate['detailsurl'];
81
                                                if ($detailsurl == 'https://update.joomla.org/core/extension.xml') $type = 1;
82
                                                else if ($detailsurl == 'https://update.joomla.org/core/sts/extension_sts.xml') $type = 2;
83
                                                else $type == 0;
84
                                                return array($type, $version);
85
                                        }
86
                                }
87
                        }
88
                }
89
 
90
                if ($count == 0) {
91
                        throw new Exception("Error checking update servers");
92
                }
93
 
94
                return array(-1, $version);
95
        }
96
 
97
        protected function cbRun($optional_args=array()) {
98
                $system_dir = $this->argSystemDir->getValue();
99
                if (empty($system_dir)) {
100
                        throw new Exception("Please specify the directory of the Joomla installation.");
101
                }
102
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
103
 
104
                if (!is_dir($system_dir)) {
105
                        throw new Exception('Directory "'.$system_dir.'" not found.', false);
106
                }
107
 
108
                list($type, $version) = $this->check_joomla_system($system_dir);
109
 
110
                if ($type == 1) {
111
                        $this->setStatus(VNag::STATUS_OK);
112
                        $this->setHeadline("Version $version (Long-Term-Support) found at $system_dir", true);
113
                } else if ($type == 2) {
114
                        $this->setStatus(VNag::STATUS_OK);
115
                        $this->setHeadline("Version $version (Short-Term-Support) found at $system_dir", true);
116
                } else if ($type == 0) {
117
                        // This should not happen
118
                        $this->setStatus(VNag::STATUS_OK);
119
                        $this->setHeadline("Version $version (supported) found at $system_dir", true);
120
                } else if ($type == -1) {
121
                        $this->setStatus(VNag::STATUS_WARNING);
122
                        $this->setHeadline("Version $version is outdated at $system_dir", true);
123
                } else {
124
                        assert(false);
125
                }
126
        }
127
}
128