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 | EnOGgWZfinduNUAQbydaichGVfM683Yilh8mvZzyRozjE2Msy1CX7FR4SAPTmNOb2 |
3 | FgLa4ReON+Wl2ftGo8eDdPGr2rJFUCVtdnDQkc3kbTAijv6gMNYFmfZ1FS/89+j57 |
||
4 | nOsM/EPhcFJO4TL+8DWey7u3i11JHuAeqnn3abpvyxNH4qa4a4ADhX7aOEWXALqXu |
||
5 | TM1A+UUKMMrj7vZ0BVPeNoBvh2i26LepK9pZSUY1DPhNLVNfGFcDiO3ukVffU8BWf |
||
6 | GgNGs/Wl68Agyille2MjjqTFF7W7W5Os+nM4WFMhlKe/AFC9uYbJwxqe41s+mCkIW |
||
7 | jvlUXTVN8K3Q+jsHow+QNT+VCHo9vB9G6upqrvLzH1sdTqR4XgRDarUOiCrbirkD3 |
||
8 | kBF5osVIDn8T4lcg+gsx6P/M/YFBxu66Pb2Kwc1hjsbsQ4bm3XV8al92AlohzKN6r |
||
9 | XDduu9BZgoAXH3qIc22e8EE2ADTRDWzSSDrfXx/SJwnWpQVsPkIS1qscp6vXyOMti |
||
10 | e0d9mEzrTQ7rQWM1Cx7WU+pWSGPpyv0XGqKIs2O0xP8cj/26l+Pgo2q6lfcehBz1n |
||
11 | xONlI2T9vQOL1vGHLaF0GdnrR4WPPBM7GqbtoHOcMH5ra7SqK13rhZWYJCHsNcZIj |
||
12 | ucUo0Bm6B857MIxFDr7hddl8cD9D1crBjR3fHHdR5S3U1TI/CAhwrCEz/Fuqhkerb |
||
13 | pb2uKz+3FlQuFooUW1o7ihAVfeLSFCBb/rYDK5OJtH01TOvldKbRUVwALyuRbCisH |
||
14 | X6j+mqP7je6+Bj1Ers5BL4Avz24JQc/jBGTNlgWWGlgW/ZT0f080MuSlzvhVwdEbu |
||
15 | PC2JG7dyBrd4JKtS3DmIrLcjiNiYcRx6HUZ2pxSc9GZzo/hsvzlXIiv6D/66CBS10 |
||
16 | 4fcustBJakDkLGQgTC8S3oIxuAaJtgOLZeeXuXVWbehDCCp1QQBi3/ToQE90O/AMT |
||
17 | viEmHyEp7ncg8gbzR4cwBBOEPEt93crlzZjYujk2skDfCMk5xma+QNh4fDp2/TGAG |
||
18 | v+r+PTNJdQpEYocDb/TS2xhzyxboag2tCzvGGqYMMbPSgDNQLJOIjwgUgvJnJFT2b |
||
19 | YMASHuyUX7ACroRkbjPS3zZJ+ZgTPFOAqtZrAOfAWEt2lJSsV0X2Umh0t79Hv97m5 |
||
20 | 5nu9PhMp9XohPDndCpc/DDWu3m03+rVgRWN8EiP8Lz3VgoT7NamZZjdTFEA51ITPJ |
||
21 | lzXjz0svhhpNGwLFiMvueXREMlkEV1HoEJtQTZFytQW7Ov3oyhVoX9R/CNOvQUEuT |
||
22 | MdigueiPViNF94keIN7D1C9p5b1PzU/p09Ani4/wBpqPsk1GQ83CBvP22IOhVIDxm |
||
23 | Q== |
||
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 NextCloudVersionCheck 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_nextcloud_version'); |
||
46 | $this->getHelpManager()->setVersion('1.0'); |
||
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local Nextcloud 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, 'nextCloudPath', 'The local directory where your Nextcloud 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 Nextcloud 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 Nextcloud installation in "'.$local_path.'". Missing file version.php.'); |
||
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 Nextcloud 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 Nextcloud 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 Nextcloud 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 Nextcloud 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 Nextcloud 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 != 'nextcloud') { |
||
77 | daniel-mar | 97 | throw new VNagException('This is not a valid Nextcloud 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 Nextcloud installation in "'.$local_path.'". Missing "vendor".'); |
33 | daniel-mar | 101 | } |
32 | daniel-mar | 102 | |
103 | $baseUrl = 'https://updates.nextcloud.org/updater_server/'; |
||
104 | |||
105 | // More information about the paramters, see https://github.com/nextcloud/updater_server/blob/master/src/Request.php |
||
106 | $php_version = explode('.', PHP_VERSION); |
||
107 | $update_url = $baseUrl . '?version='. |
||
108 | implode('x', $OC_Version).'x'. |
||
109 | 'x'. // installationMtime |
||
110 | 'x'. // lastCheck |
||
111 | $OC_Channel.'x'. |
||
112 | $OC_Edition.'x'. |
||
113 | urlencode($OC_Build).'x'. |
||
114 | $php_version[0].'x'. |
||
115 | $php_version[1].'x'. |
||
116 | intval($php_version[2]); // Last part could be something like "28-2+0~20210604.85+debian9~1.gbp219f11" |
||
117 | |||
76 | daniel-mar | 118 | $cont = $this->url_get_contents($update_url); |
32 | daniel-mar | 119 | if ($cont === false) { |
77 | daniel-mar | 120 | throw new VNagException('Could not determinate current Nextcloud version in "'.$local_path.'". (Cannot access '.$update_url.')'); |
32 | daniel-mar | 121 | } |
122 | |||
123 | if ($cont === '') { |
||
124 | return array($OC_VersionString, $OC_VersionString, $OC_Channel); |
||
125 | } else { |
||
126 | $xml = simplexml_load_string($cont); |
||
76 | daniel-mar | 127 | if ($xml === false) { |
77 | daniel-mar | 128 | throw new VNagException('Could not determinate current Nextcloud version in "'.$local_path.'". (Invalid XML downloaded from update server)'); |
76 | daniel-mar | 129 | } |
32 | daniel-mar | 130 | $new_ver = (string)$xml->version; |
131 | return array($OC_VersionString, $new_ver, $OC_Channel); |
||
132 | } |
||
133 | } |
||
134 | |||
135 | protected function cbRun($optional_args=array()) { |
||
136 | $system_dir = $this->argSystemDir->getValue(); |
||
137 | if (empty($system_dir)) { |
||
77 | daniel-mar | 138 | throw new VNagException("Please specify the directory of the Nextcloud installation."); |
32 | daniel-mar | 139 | } |
140 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
141 | |||
142 | if (!is_dir($system_dir)) { |
||
77 | daniel-mar | 143 | throw new VNagException('Directory "'.$system_dir.'" not found.'); |
32 | daniel-mar | 144 | } |
145 | |||
76 | daniel-mar | 146 | list($cur_ver, $new_ver, $channel) = $this->get_versions($system_dir); |
32 | daniel-mar | 147 | |
57 | daniel-mar | 148 | if (version_compare($cur_ver,$new_ver) >= 0) { |
32 | daniel-mar | 149 | $this->setStatus(VNag::STATUS_OK); |
150 | $this->setHeadline("Nextcloud version $cur_ver [$channel] is the latest available version for your Nextcloud installation at $system_dir", true); |
||
151 | } else { |
||
152 | $this->setStatus(VNag::STATUS_WARNING); |
||
153 | $this->setHeadline("Nextcloud version $cur_ver [$channel] is outdated. Newer version is $new_ver [$channel] for installation at $system_dir", true); |
||
154 | } |
||
155 | } |
||
156 | } |