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xzYT0
EOC1nZ/RSgjrilOqJbRlmXAqIv0vTSbIFpyYolOZjMVDZ9IluWy6sCErfuR/XHXYa
3oSEAlmpCzMkberpuVWCRcbLDMI+jjtx1J5SKn/IVMsNyB4ygi5YCuvqKxRge8rdq
GByaLxhO2ziDQGAK08+PHCLD19n9APbtyplEiX6wA5Mv2F2rEenuSbIAyXCxC4WnD
dyHau/7F2y4uyt6F0eD8PmtFYDtjH0RIGFtwqnmh61JChfxymXogN7Ee7bMqWJFe3
Ksd0egFhulWY9ox4KdDpUXDETfM3pIYnHKI7FWe2/4zqdUgA7sT/14ZuCdqXQJmsP
w==
</ViaThinkSoftSignature> */ ?>
<?php
/*
* VNag - Nagios Framework for PHP
* Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
* Licensed under the terms of the Apache 2.0 license
*
* Revision 2022-09-12
*/
declare(ticks=1);
class OwnCloudVersionCheck extends VNag {
protected $argSystemDir = null;
public function __construct() {
parent::__construct();
$this->registerExpectedStandardArguments('Vvht');
$this->getHelpManager()->setPluginName('check_owncloud_version');
$this->getHelpManager()->setVersion('1.0');
$this->getHelpManager()->setShortDescription('This plugin checks if a local ownCloud system has the latest version installed.');
$this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
$this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
$this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
// Individual (non-standard) arguments:
$this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'ownCloudPath', 'The local directory where your ownCloud installation is located.'));
}
protected function get_owncloud_version($local_path) {
$local_path = realpath($local_path) === false ?
$local_path : realpath($local_path);
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'".');
}
// We don't include version.php because it would be a security vulnerability
// code injection if somebody controls version.php
if (preg_match('@\\$(OC_Version)\\s*=\\s*array\\(\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*,\\s*(.+)\\s*\\)\\s*;@ismU', $cont, $m)) {
$OC_Version = array($m[2],$m[3],$m[4],$m[5]);
} else {
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Version".');
}
if (preg_match('@\\$(OC_VersionString)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
$OC_VersionString = $m[3];
} else {
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_VersionString".');
}
if (preg_match('@\\$(OC_Edition)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
$OC_Edition = $m[3];
} else {
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Edition".');
}
if (preg_match('@\\$(OC_Channel)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
$OC_Channel = $m[3];
} else {
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Channel".');
}
if (preg_match('@\\$(OC_Build)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
$OC_Build = $m[3];
} else {
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "OC_Build".');
}
if (preg_match('@\\$(vendor)\\s*=\\s*([\'"])(.*)\\2\\s*;@ismU', $cont, $m)) {
$vendor = $m[3];
if ($vendor != 'owncloud') {
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". It is "'.$vendor.'".');
}
} else {
throw new Exception('This is not a valid ownCloud installation in "'.$local_path.'". Missing "vendor".');
}
// Owncloud\Updater\Utils\Fetcher::DEFAULT_BASE_URL
$baseUrl = 'https://updates.owncloud.com/server/';
$update_url = $baseUrl . '?version='.
'installedatx'.
'lastupdatedatx'.
$OC_Channel.'x'.
$OC_Edition.'x'.
if ($cont === false) {
throw new Exception('Could not determinate current ownCloud version in "'.$local_path.'".');
}
if ($cont === '') {
return array($OC_VersionString, $OC_VersionString, $OC_Channel);
} else {
$new_ver = (string)$xml->version;
return array($OC_VersionString, $new_ver, $OC_Channel);
}
}
protected function cbRun
($optional_args=array()) {
$system_dir = $this->argSystemDir->getValue();
if (empty($system_dir)) {
throw new Exception("Please specify the directory of the ownCloud installation.");
}
$system_dir = realpath($system_dir) === false ?
$system_dir : realpath($system_dir);
throw new Exception('Directory "'.$system_dir.'" not found.');
}
list($cur_ver, $new_ver, $channel) = $this->get_owncloud_version($system_dir);
$this->setStatus(VNag::STATUS_OK);
$this->setHeadline("ownCloud version $cur_ver [$channel] is the latest available version for your ownCloud installation at $system_dir", true);
} else {
$this->setStatus(VNag::STATUS_WARNING);
$this->setHeadline("ownCloud version $cur_ver [$channel] is outdated. Newer version is $new_ver [$channel] for installation at $system_dir", true);
}
}
}