Rev 33 | 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> |
57 | daniel-mar | 2 | x8VDWLNVIBuTV+Bwn57lv0/eS256StHnC4d4Jdcpmn2mhOKU9INdgEdQWaRVsqPdL |
3 | v7ML2ZSeGQTO7E3rHtXvlhbFikllomsC8MiR1Ja+LogZR8VHpnAE29g6l+llwQYBq |
||
4 | F5UoDQQUHkxVf6fA2wcGfvzt3CjS4Ab1wcGerspjywQVDWHNFuTXYB7VzziAchJBv |
||
5 | dgTbzsW0LuNK9M09ve8szm8mYdQ3DbUo9kOOudmrP7jVm3FPowFcFQyI+XVooNwxq |
||
6 | 0bt5HWWdn3iklgCdbK4I0PfFom7IIRmWLQcn+O9Xb6hsJNNMwzBtFRt6KqjrOJnFm |
||
7 | ENr0cMMDMt4rZlSLVP7MQL9X20/L8Sx6x9lSLe3L0kjRsQk5OtlzeP15ntjd4wYak |
||
8 | rDIj/nUQ/Fejkv210s6DJTtPFLCiVN6UlMfooL1Kp439HYfSko0QFTK3Szc7shsDg |
||
9 | QOWcEnheheJ4pUm0GsvSvikKz+MVMyygp0FLxe4j7/Dt8hR6y2sbC9X3RffRh+OHK |
||
10 | 916LMzW0zowM8lc5+Orw5iZHpk5hFj19p2TN9cAzWWleGLWWBWFZgqIZVPbLgV5pM |
||
11 | tVRHHGTitZ68yU6U0fcDbafd4Fs4BIACMuAo3aR27PZJMKYWphLhwbhfH1jUQ+a4p |
||
12 | sxGCViiUSy+Fi2rl9T2glCKxwQmzZk3LQwbX37Cf+bCUV4u+x/vFrHPdKbbipP9XU |
||
13 | gjzXnWk/rytrXtiVJgk0R/nWq6KuzvMeivvQuPcJvtjbNWeSa/CCI33oBGfBWqOWf |
||
14 | tHYZ2ygQ/gkyD6Sjls5+3G1M6m5a3evgib4hSqXWIo5rmDtilSZ3pUOFpcsGZ9O1j |
||
15 | cMgVq78ErkEVJonNwoz1L2de6ArqF5IflG6vqDCwmm/iJNazwth1mem4S/O8HFMVZ |
||
16 | PVCslXsikJSFiN7EthHA4iGrMvZnVpT0OBaHSXcIRWiB6goIiKC7GgqiRx5Ho+rC+ |
||
17 | h4DiSJ1lI6AbwWI+ATkGlLzLvjVb3ESmDXSisBVE1cMrh3TK/MJQ8XRRRfwNxzYT0 |
||
18 | EOC1nZ/RSgjrilOqJbRlmXAqIv0vTSbIFpyYolOZjMVDZ9IluWy6sCErfuR/XHXYa |
||
19 | 3oSEAlmpCzMkberpuVWCRcbLDMI+jjtx1J5SKn/IVMsNyB4ygi5YCuvqKxRge8rdq |
||
20 | GByaLxhO2ziDQGAK08+PHCLD19n9APbtyplEiX6wA5Mv2F2rEenuSbIAyXCxC4WnD |
||
21 | dyHau/7F2y4uyt6F0eD8PmtFYDtjH0RIGFtwqnmh61JChfxymXogN7Ee7bMqWJFe3 |
||
22 | Ksd0egFhulWY9ox4KdDpUXDETfM3pIYnHKI7FWe2/4zqdUgA7sT/14ZuCdqXQJmsP |
||
32 | daniel-mar | 23 | w== |
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 | * |
||
57 | daniel-mar | 32 | * Revision 2022-09-12 |
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 | |||
56 | protected function get_owncloud_version($local_path) { |
||
57 | $local_path = realpath($local_path) === false ? $local_path : realpath($local_path); |
||
58 | |||
59 | if (!file_exists($local_path . '/version.php')) { |
||
60 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'".'); |
||
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 |
||
65 | $cont = file_get_contents($local_path . '/version.php'); |
||
66 | if (preg_match('@\\$(OC_Version)\\s*=\\s*array\\(\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*\\)\\s*;@ismU', $cont, $m)) { |
||
67 | $OC_Version = array($m[2],$m[3],$m[4],$m[5]); |
||
68 | } else { |
||
69 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Version".'); |
||
32 | daniel-mar | 70 | } |
33 | daniel-mar | 71 | if (preg_match('@\\$(OC_VersionString)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
72 | $OC_VersionString = $m[3]; |
||
73 | } else { |
||
74 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_VersionString".'); |
||
75 | } |
||
76 | if (preg_match('@\\$(OC_Edition)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
77 | $OC_Edition = $m[3]; |
||
78 | } else { |
||
79 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Edition".'); |
||
80 | } |
||
81 | if (preg_match('@\\$(OC_Channel)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
82 | $OC_Channel = $m[3]; |
||
83 | } else { |
||
84 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Channel".'); |
||
85 | } |
||
86 | if (preg_match('@\\$(OC_Build)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
87 | $OC_Build = $m[3]; |
||
88 | } else { |
||
89 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Build".'); |
||
90 | } |
||
91 | if (preg_match('@\\$(vendor)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) { |
||
92 | $vendor = $m[3]; |
||
93 | if ($vendor != 'owncloud') { |
||
94 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". It is "'.$vendor.'".'); |
||
95 | } |
||
96 | } else { |
||
97 | throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "vendor".'); |
||
98 | } |
||
32 | daniel-mar | 99 | |
100 | // Owncloud\Updater\Utils\Fetcher::DEFAULT_BASE_URL |
||
101 | $baseUrl = 'https://updates.owncloud.com/server/'; |
||
102 | |||
103 | $update_url = $baseUrl . '?version='. |
||
104 | implode('x', $OC_Version).'x'. |
||
105 | 'installedatx'. |
||
106 | 'lastupdatedatx'. |
||
107 | $OC_Channel.'x'. |
||
108 | $OC_Edition.'x'. |
||
109 | urlencode($OC_Build); |
||
110 | |||
111 | $cont = file_get_contents($update_url); |
||
112 | if ($cont === false) { |
||
113 | throw new Exception('Could not determinate current ownCloud version in "'.$local_path.'".'); |
||
114 | } |
||
115 | |||
116 | if ($cont === '') { |
||
117 | return array($OC_VersionString, $OC_VersionString, $OC_Channel); |
||
118 | } else { |
||
119 | $xml = simplexml_load_string($cont); |
||
120 | $new_ver = (string)$xml->version; |
||
121 | return array($OC_VersionString, $new_ver, $OC_Channel); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | protected function cbRun($optional_args=array()) { |
||
126 | $system_dir = $this->argSystemDir->getValue(); |
||
127 | if (empty($system_dir)) { |
||
128 | throw new Exception("Please specify the directory of the ownCloud installation."); |
||
129 | } |
||
130 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
131 | |||
132 | if (!is_dir($system_dir)) { |
||
133 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
||
134 | } |
||
135 | |||
136 | list($cur_ver, $new_ver, $channel) = $this->get_owncloud_version($system_dir); |
||
137 | |||
57 | daniel-mar | 138 | if (version_compare($cur_ver,$new_ver) >= 0) { |
32 | daniel-mar | 139 | $this->setStatus(VNag::STATUS_OK); |
140 | $this->setHeadline("ownCloud version $cur_ver [$channel] is the latest available version for your ownCloud installation at $system_dir", true); |
||
141 | } else { |
||
142 | $this->setStatus(VNag::STATUS_WARNING); |
||
143 | $this->setHeadline("ownCloud version $cur_ver [$channel] is outdated. Newer version is $new_ver [$channel] for installation at $system_dir", true); |
||
144 | } |
||
145 | } |
||
146 | } |