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 | f+K8EPao6vhPVpCTEtyIMftupx9RqcfHho7MxGqkqIaCyInQOh8dw6sYdbjqtCgK9 |
3 | LqCpcOcsDge+TbOu5JBnT1cFUkDISNGUbWv/pjPy+iCm7D3vRxtjIgmXQuf+rmP9D |
||
4 | gJ/z9Z5UwetA1vooQ/8Y+8Qf0vsHA668BeN12L/tUtVNiQI6ePAyt1NGHnILyLZMF |
||
5 | JKxrGghLToBuNc3yIJgtxUN0YgTiE4ZTrjan5+tWzevUhEh+F/S8PftADd+cgmSAp |
||
6 | a3uRdhT+SUQrs0TPCFHOC0cAgyK2+pm8Ln/wJKv3hgIQU6RbUwwH8INQU7uBvX9Rb |
||
7 | kDPIvptPVZLr96+04lnPTxjsN34fLzUlSYKmiP0Agy3sRjcx2tLlrXe+EdCYi271u |
||
8 | Ar2TStJwScyE9DUY0W19eLbU8YXJdbiZwtd1D6DOMvQq4UPdj7faDjcHWcm5kOnS0 |
||
9 | 4cecP3HaN/liz0EjSy+ZG5qgqBkPlNtBjtlLtbL559fWtc6UD8QTHla6I0OexNEPu |
||
10 | 0DcYE2WS2tkIwA0RClMBaFzkwr4d8fuuaRKfJ8DsjfU1UdRiwedDu/x/PqXAdEZ2u |
||
11 | e2sww7APpbAzvFcFiuRtCSeJttguhtgZbSQDNl1tTENMYEFF4+Zxhjyg+gytim2H/ |
||
12 | zAKO+Q63OedRSfxKniiDvpz3jPyZor+hE0beT1rDf76nnjBA7dcnc/zAVUPl5Iw/Z |
||
13 | m8veB3wwCUUQZB1xHHMc3YoG6zw5vW8ozIIWIbJVpjn6L8LdaC0uLeNcYuaGSDxm2 |
||
14 | Bzzl3hVdamULy7kSB8Ry8mYUba4DTnOqCjGhkLhrWfChcSCeevYZwadqPWNvaVzkw |
||
15 | LGV3jzXuyXmJ6V1e8c0tpZxebRi1V8Aep/NFrgMSV3dc8JHWiYJ4SBOVhhdaOEwBZ |
||
16 | wwI7dxAQHT6pXHtI9ZeZEL1+BLEMqyswWlPMgXgPbrRhHcTQE9AhMaxxGt3pT1+c2 |
||
17 | k8Da1MWBLyr2D5U+Mc2Vnrh2+VJRyeZZEGVqiZV9ruOcFajmCv9r6wceFZhVOJAUv |
||
18 | o5cmsnPL9C4QaNLCqFnP9SlD47n+JLxODi6js4MLTqxBqs/HoG8IPkWfRmUuVhfNa |
||
19 | O4P9xA3uI5GjJbyvU+xgQj3oy7WUZZmfhVRSC4eNGjbsUT9vV9d9YKQ8/pnWJSTOC |
||
20 | VOxx/RxQnWYwjEXTliuCHxgFocGU5ySczR5627fK7/KOxTAZoLWg8nnve1kzbogxM |
||
21 | se6hHR6OKxWTZNsSWQHjK5F6IiBOw2fGYGPvGlSWDNXv4yr8JpL33Vpw7yJglsZpW |
||
22 | 70ZDY2iGa0BCt7Gi6BMNmUwZ+nxKtMDVwtyYNj2sVMWJfo+VBl6wmXiPuVQ6zxsEL |
||
76 | daniel-mar | 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 | * |
||
76 | daniel-mar | 32 | * Revision 2023-10-13 |
2 | daniel-mar | 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 | |||
76 | daniel-mar | 58 | protected function get_versions($path) { |
2 | daniel-mar | 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)) { |
||
77 | daniel-mar | 64 | throw new VNagException("Manifest file $manifest_file not found"); |
2 | daniel-mar | 65 | } |
66 | |||
77 | daniel-mar | 67 | $cont = @file_get_contents($manifest_file); |
68 | if ($cont === false) { |
||
69 | throw new VNagException("Cannot read $manifest_file"); |
||
70 | } |
||
71 | |||
2 | daniel-mar | 72 | $manifest = new SimpleXMLElement($cont); |
73 | |||
74 | $version = (string)$manifest->version; |
||
75 | |||
76 | $count = 0; |
||
77 | foreach ($manifest->updateservers->server as $updateserver) { |
||
76 | daniel-mar | 78 | $cont = $this->url_get_contents($updateserver); |
79 | if ($cont !== false) { |
||
2 | daniel-mar | 80 | $extensions = new SimpleXMLElement($cont); |
81 | foreach ($extensions as $candidate) { |
||
82 | $count++; |
||
83 | if ($version == (string)$candidate['version']) { |
||
84 | $detailsurl = (string)$candidate['detailsurl']; |
||
85 | if ($detailsurl == 'https://update.joomla.org/core/extension.xml') $type = 1; |
||
86 | else if ($detailsurl == 'https://update.joomla.org/core/sts/extension_sts.xml') $type = 2; |
||
28 | daniel-mar | 87 | else $type = 0; |
2 | daniel-mar | 88 | return array($type, $version); |
89 | } |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | |||
94 | if ($count == 0) { |
||
77 | daniel-mar | 95 | throw new VNagException("Error checking update servers"); |
2 | daniel-mar | 96 | } |
97 | |||
98 | return array(-1, $version); |
||
99 | } |
||
100 | |||
101 | protected function cbRun($optional_args=array()) { |
||
102 | $system_dir = $this->argSystemDir->getValue(); |
||
103 | if (empty($system_dir)) { |
||
77 | daniel-mar | 104 | throw new VNagException("Please specify the directory of the Joomla installation."); |
2 | daniel-mar | 105 | } |
106 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
107 | |||
108 | if (!is_dir($system_dir)) { |
||
77 | daniel-mar | 109 | throw new VNagException('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 110 | } |
111 | |||
76 | daniel-mar | 112 | list($type, $version) = $this->get_versions($system_dir); |
2 | daniel-mar | 113 | |
114 | if ($type == 1) { |
||
115 | $this->setStatus(VNag::STATUS_OK); |
||
116 | $this->setHeadline("Version $version (Long-Term-Support) found at $system_dir", true); |
||
117 | } else if ($type == 2) { |
||
118 | $this->setStatus(VNag::STATUS_OK); |
||
119 | $this->setHeadline("Version $version (Short-Term-Support) found at $system_dir", true); |
||
120 | } else if ($type == 0) { |
||
121 | // This should not happen |
||
122 | $this->setStatus(VNag::STATUS_OK); |
||
123 | $this->setHeadline("Version $version (supported) found at $system_dir", true); |
||
124 | } else if ($type == -1) { |
||
125 | $this->setStatus(VNag::STATUS_WARNING); |
||
126 | $this->setHeadline("Version $version is outdated at $system_dir", true); |
||
127 | } else { |
||
128 | assert(false); |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 |