Rev 76 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
32 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature> |
77 | daniel-mar | 2 | kh8uYUEmpc8WCbykBWys6Nxe0uUtfTgDrmwLakX6M0m3Nn4Ck4F2a6Z4n8IVcVrFt |
3 | kTw2Tk6x9jBe4YKiiIHp9M3XijivZ/tzmSgnQGrz9UWmnzUu2P+P/ospsRilxR3cJ |
||
4 | hL5BwqSzBcIWYf09BNuNxgeGi00hzbgZOtR/nQ1JToXMw9ATzPDHxx7sMmibUugdm |
||
5 | 9BTAAHMH+3b3DUYmEQD7ZOqmfFYp0NvnbGMsUKsdS2EJUc9dqVKApfZ/Rjr38/5RA |
||
6 | JgPFRQ+8xFD0UP0Ifg89tvts2x2C+K+uaUG+vV5yxmpA+QWNu+9YoXvUP+txnxv76 |
||
7 | 2KQeejsLvQXjegjYQv4qfvHvpVm2PKfwlnDvHvBObUXgqpyguWZkEhy/XeEbbKZ0Z |
||
8 | drbaYM5UDVpVFKsGXU3k3K+lwDDRj035PGrVwvG7WIIqNc3yB0uHEKjLeA4wr6t+s |
||
9 | JI2LcoeaFAHvSCoePNkr/2+Ksw6hg4PQaofwgaAHZTbFiP0LnuxicdHJPfNmrcADY |
||
10 | 1CbkqQBXS7pFsZYPK2cPw9yE0h4cpl8wuTHC58J4FxZDYi/ZsH+1C+eK0z8PpFihM |
||
11 | JOguZWxtkjiHp5OMhAXi1rv6G/JBZlrLr8rz/UBYVenP4JrZ7qZiMmiJZISfRsDRc |
||
12 | oviI0zxJ1bXJxoNPV7wNFxMP9FJvcUcgovTiHrQa5NJjXEROhQz8MlFwtSl2v/CZg |
||
13 | At8th0JKwWOsyz7kl/CPJwK+adt7h68tBkjCI0pG0fYGxwiMICF/mrlFpj6ZImuWv |
||
14 | cQH4hOS6Nca/f6pudH5WFbPyzqqximhbg+ZUZExlegvl9llLlltFiM+41oLERCQ9b |
||
15 | BxI+k6YP75wGF1wWEjY+j3b51kF42mQrT5jGt5VpY0UdEwdPtnWyUGHNJAcAdvwQ2 |
||
16 | RA3+7lq3iyL4K0FOgNrIbmvTNRE0y/3KnCcXq6eqAvkL0MtjLdrgRfRcDdJ/WfRNR |
||
17 | lprNXKPYHheCe/gVPeMwyVGd4kqb2R3KFvLPhyBJe+HIgDfkgCI5jqSpxFWQmPP12 |
||
18 | Y13kO7iD3rEs+bTHmUaepcgdX6+11HLG7BLwntWj2oc3WhN4QtzA9GtkZGQTUmGec |
||
19 | HMOXqiMeMyTnIA30UPqmV+6/OzTabVc2kT+uV4JKN4lxA+erdO9pKM4YQ0zJxdAS9 |
||
20 | nM8h5N6II7CNriKbb61eqV+3v51l8nxmOZyeezS7zPE4kClem7wWTDoX1MIWzDRxV |
||
21 | FX83Qih9jLq3vuDyMvqmfd9VBsRdRp/RjDXheyijDvbllnVWirDrb9cKxiLs/oRDd |
||
22 | NuKj/vvLwR66i82xvWbmHyrYsSOxj89NJZGO2nvQiri4lke1WC9lnIB41RtYkPvv3 |
||
23 | A== |
||
32 | daniel-mar | 24 | </ViaThinkSoftSignature> */ ?> |
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 |
32 | daniel-mar | 33 | */ |
34 | |||
35 | declare(ticks=1); |
||
36 | |||
37 | class OwnCloudVersionCheck extends VNag { |
||
38 | protected $argSystemDir = null; |
||
39 | |||
40 | public function __construct() { |
||
41 | parent::__construct(); |
||
42 | |||
43 | $this->registerExpectedStandardArguments('Vvht'); |
||
44 | |||
45 | $this->getHelpManager()->setPluginName('check_owncloud_version'); |
||
46 | $this->getHelpManager()->setVersion('1.0'); |
||
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local ownCloud 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, 'ownCloudPath', 'The local directory where your ownCloud installation is located.')); |
||
54 | } |
||
55 | |||
76 | daniel-mar | 56 | protected function get_versions($local_path) { |
32 | daniel-mar | 57 | $local_path = realpath($local_path) === false ? $local_path : realpath($local_path); |
58 | |||
59 | if (!file_exists($local_path . '/version.php')) { |
||
77 | daniel-mar | 60 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'".'); |
32 | daniel-mar | 61 | } |
62 | |||
33 | daniel-mar | 63 | // We don't include version.php because it would be a security vulnerability |
64 | // code injection if somebody controls version.php |
||
77 | daniel-mar | 65 | $cont = @file_get_contents($local_path . '/version.php'); |
66 | if ($cont === false) { |
||
67 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". Missing version.php file.'); |
||
68 | } |
||
33 | daniel-mar | 69 | if (preg_match('@\\$(OC_Version)\\s*=\\s*array\\(\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*\\)\\s*;@ismU', $cont, $m)) { |
70 | $OC_Version = array($m[2],$m[3],$m[4],$m[5]); |
||
71 | } else { |
||
77 | daniel-mar | 72 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Version".'); |
32 | daniel-mar | 73 | } |
33 | daniel-mar | 74 | if (preg_match('@\\$(OC_VersionString)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
75 | $OC_VersionString = $m[3]; |
||
76 | } else { |
||
77 | daniel-mar | 77 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_VersionString".'); |
33 | daniel-mar | 78 | } |
79 | if (preg_match('@\\$(OC_Edition)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
80 | $OC_Edition = $m[3]; |
||
81 | } else { |
||
77 | daniel-mar | 82 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Edition".'); |
33 | daniel-mar | 83 | } |
84 | if (preg_match('@\\$(OC_Channel)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
85 | $OC_Channel = $m[3]; |
||
86 | } else { |
||
77 | daniel-mar | 87 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Channel".'); |
33 | daniel-mar | 88 | } |
89 | if (preg_match('@\\$(OC_Build)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
90 | $OC_Build = $m[3]; |
||
91 | } else { |
||
77 | daniel-mar | 92 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Build".'); |
33 | daniel-mar | 93 | } |
94 | if (preg_match('@\\$(vendor)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
95 | $vendor = $m[3]; |
||
96 | if ($vendor != 'owncloud') { |
||
77 | daniel-mar | 97 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". It is "'.$vendor.'".'); |
33 | daniel-mar | 98 | } |
99 | } else { |
||
77 | daniel-mar | 100 | throw new VNagException('This is not a valid ownCloud installation in "'.$local_path.'". Missing "vendor".'); |
33 | daniel-mar | 101 | } |
32 | daniel-mar | 102 | |
103 | // Owncloud\Updater\Utils\Fetcher::DEFAULT_BASE_URL |
||
104 | $baseUrl = 'https://updates.owncloud.com/server/'; |
||
105 | |||
106 | $update_url = $baseUrl . '?version='. |
||
107 | implode('x', $OC_Version).'x'. |
||
108 | 'installedatx'. |
||
109 | 'lastupdatedatx'. |
||
110 | $OC_Channel.'x'. |
||
111 | $OC_Edition.'x'. |
||
112 | urlencode($OC_Build); |
||
113 | |||
76 | daniel-mar | 114 | $cont = $this->url_get_contents($update_url); |
32 | daniel-mar | 115 | if ($cont === false) { |
77 | daniel-mar | 116 | throw new VNagException('Could not determinate current ownCloud version in "'.$local_path.'". (Cannot access '.$update_url.')'); |
32 | daniel-mar | 117 | } |
118 | |||
119 | if ($cont === '') { |
||
120 | return array($OC_VersionString, $OC_VersionString, $OC_Channel); |
||
121 | } else { |
||
122 | $xml = simplexml_load_string($cont); |
||
76 | daniel-mar | 123 | if ($xml === false) { |
77 | daniel-mar | 124 | throw new VNagException('Could not determinate current ownCloud version in "'.$local_path.'". (Invalid XML downloaded from update-server)'); |
76 | daniel-mar | 125 | } |
32 | daniel-mar | 126 | $new_ver = (string)$xml->version; |
127 | return array($OC_VersionString, $new_ver, $OC_Channel); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | protected function cbRun($optional_args=array()) { |
||
132 | $system_dir = $this->argSystemDir->getValue(); |
||
133 | if (empty($system_dir)) { |
||
77 | daniel-mar | 134 | throw new VNagException("Please specify the directory of the ownCloud installation."); |
32 | daniel-mar | 135 | } |
136 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
137 | |||
138 | if (!is_dir($system_dir)) { |
||
77 | daniel-mar | 139 | throw new VNagException('Directory "'.$system_dir.'" not found.'); |
32 | daniel-mar | 140 | } |
141 | |||
76 | daniel-mar | 142 | list($cur_ver, $new_ver, $channel) = $this->get_versions($system_dir); |
32 | daniel-mar | 143 | |
57 | daniel-mar | 144 | if (version_compare($cur_ver,$new_ver) >= 0) { |
32 | daniel-mar | 145 | $this->setStatus(VNag::STATUS_OK); |
146 | $this->setHeadline("ownCloud version $cur_ver [$channel] is the latest available version for your ownCloud installation at $system_dir", true); |
||
147 | } else { |
||
148 | $this->setStatus(VNag::STATUS_WARNING); |
||
149 | $this->setHeadline("ownCloud version $cur_ver [$channel] is outdated. Newer version is $new_ver [$channel] for installation at $system_dir", true); |
||
150 | } |
||
151 | } |
||
152 | } |