Rev 37 | 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> |
76 | daniel-mar | 2 | hKnF6Hd5bzvvU4SQOXMtp89OAgeryMb2Ob8UKCrzfHkJ5uAchpNs6JBzm8YFh3mW6 |
3 | Y2Q5dME2QNcDxmEQoWfq6++2/5ln/6a1o43BxWKUZVW2QGg+8TKgJU7NVcEDP/L9/ |
||
4 | cO9dP5aYSp97qXgm6WO7a65s8FmSQN7LYJZquQRR7FFKALvzpOlGLlzbspEORbJdm |
||
5 | 6+3cVC9iCZOTYkho8ISqAxvf4pIFJ5onDHgwjyQXZ2wU1CVzVcwM3t70wZ79dbvIX |
||
6 | oHKmrFBNLHZIDnRtjo6wMctjxFrofXNXreTxzS3Dum2aUfQJSceLusF1VFvZ1iBra |
||
7 | gZRKjFlvj2J1VIKE/2tpQ2odYzmTq/jUHZdZCmtT9vFx9pH8elsTC0wyiMehyy69m |
||
8 | tGChnZW9wjGQtKrVuk+47UQsjbuZJsTIQxw/D6+fbMxPr0J9HwtmNqFc5VRfs3Cd4 |
||
9 | biSdnAUV0TkZzQ5ISxfDHX3ywDKWxd/BqlB5zUkIU5/rZM/rD/Q1bb/uKOVFtRavi |
||
10 | ZDLbtPfXU3NMhf3kbfiEzR7tHWBYL+Z7JWiSVGdHhFvfLzqQh6hHDG5XIOUf+TuWh |
||
11 | On48GsqQVwO/qmyOUOjxwBXAWfGhIVnp/coiu2YYJfYcSuLzVzxLIys4VqCk0/zTD |
||
12 | PhjP7jui3q/abeFfsWOddcGOaFik/V29OUhGK1nNGOZRIC+NSTOYTmR5B3DCRKQi+ |
||
13 | kZaOTJVUpwaOZybp9Lln2zlbX53ulu9eXhkldtVGqm/pEDVVPVa7uRSgBTPvtpLFf |
||
14 | BWSh0tAuKAEI/9Qpu+BIJSdCdGxiZpbVt2unMo0vrQV3Vy4+rXvtWuJjyFX55nEQf |
||
15 | 5wBp/unxyBmNm8cRvGmzmy1J0t0mB3nkiAj1UAEKRFYnN8Owb47mB0q/gvE4HtDof |
||
16 | LS/IT5ECgJyVxNpWESR5Dx3fGKVr7G4ihvzqC3jkCj7FldaVLyMZqTiU5fRkOnvnA |
||
17 | 0joAJvJx3rPryvcfez1iXrUVRBH6y8MFVs9GeLlcNkdtWC5XlY0j8VozMJ/lrgXGB |
||
18 | N9wjXvLgZK1W7Db07N84Qo2gBcut9HjK3g04au3IcPGpkT4HEe1R9l2khYITemAWQ |
||
19 | o+vMnuxxpwqbs1g7xlKIkglUsplQrbEub1huzWyEY4H4UAEKibFLGF/NjNmJDceV6 |
||
20 | ornstaiXrBUlc9lCO4RmAwOpF5JhCDe/XYjON7biT/9Yp08IAHT7CWgtqEeod6vzJ |
||
21 | Fj+qUgptMRfgwoslF+jA66bOzSDs5A0LMynv99yFvQ7IWjkL28zNXnsfP9y06ZyyN |
||
22 | VMv1/pNRYq2/T7H5cVzotED8BXkvR1N3NpGxCYziJBGD3tlcjzFPdPyMhsQ8DFewC |
||
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)) { |
||
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) { |
||
76 | daniel-mar | 74 | $cont = $this->url_get_contents($updateserver); |
75 | if ($cont !== false) { |
||
2 | daniel-mar | 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; |
||
28 | daniel-mar | 83 | else $type = 0; |
2 | daniel-mar | 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)) { |
||
29 | daniel-mar | 105 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 106 | } |
107 | |||
76 | daniel-mar | 108 | list($type, $version) = $this->get_versions($system_dir); |
2 | daniel-mar | 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 |