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mf73idFqQfIJL8NEgvAoosOIZr6W+C9nRy+RN0CVguOyREwM |
S9EQ0TTzDl8GJOHkNqFRFW5EFunwMQCoAzv93BslQ5wPGdv5HVccXu9d7hnuwwcF0 |
M7IMEOUchns6+4GvzK8N8zKhiIMwAEWvFk0KA0u1zlMCjG8wQIFdogho34KuMvUXU |
XEAaK+mL5LPW/+cdO9ZDT4FoCl6KjW210neRizzoiYJVN4mx4N7aS15OPWiMLO6f0 |
n/FkWXLSFHGLxWKkvRmwyNAlDjddFOs8vpGgdsaaY3xQqKWg68mBD/qGkPjYt6M61 |
FNXtEsWOYErBCrCXDxtgBEzGy1GK6LTwavMto8ln7h5r1VP9JVSJyoZXFQwChKCGU |
g== |
</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 2021-06-28 |
*/ |
|
declare(ticks=1); |
|
class GitLabVersionCheck extends VNag { |
protected $argSystemDir = null; |
|
public function __construct() { |
parent::__construct(); |
|
$this->registerExpectedStandardArguments('Vvht'); |
|
$this->getHelpManager()->setPluginName('check_gitlab_version'); |
$this->getHelpManager()->setVersion('1.0'); |
$this->getHelpManager()->setShortDescription('This plugin checks if a local GitLab 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, 'gitLabPath', 'The local directory where your GitLab installation (version-manifest.txt) is located.')); |
} |
|
protected function getInstalledVersion($dir) { |
$version_manifest = $dir.'/version-manifest.json'; |
|
if (!file_exists($version_manifest)) { |
throw new Exception('This is not a valid GitLab installation in "'.$dir.'" (version-manifest.json is missing).'); |
} |
|
$json = json_decode(file_get_contents($version_manifest),true); |
return $json['build_version']; |
} |
|
protected function getServerResponse($version) { |
$opts = array( |
'http'=>array( |
'method'=>"GET", |
'header'=>"Referer: http://example.org/\r\n" // Important |
) |
); |
$context = stream_context_create($opts); |
$url = "https://version.gitlab.com/check.svg?gitlab_info=". |
urlencode(base64_encode('{"version":"'.$version.'"}')); |
$file = file_get_contents($url, false, $context); |
|
if (!$file) { |
throw new Exception('Cannot query version.gitlab.com for version check (Version '.$version.')'); |
} |
|
if (!preg_match('@>([^<]+)</text>@ismU', $file, $m)) { |
throw new Exception('Server version.gitlab.com sent an unexpected reply (Version '.$version.')'); |
} |
|
return $m[1]; |
} |
|
protected function cbRun($optional_args=array()) { |
$system_dir = $this->argSystemDir->getValue(); |
if (empty($system_dir)) { |
throw new Exception("Please specify the directory of the GitLab installation."); |
} |
$system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
|
if (!is_dir($system_dir)) { |
throw new Exception('Directory "'.$system_dir.'" not found.'); |
} |
|
$cur_ver = $this->getInstalledVersion($system_dir); |
$status = $this->getServerResponse($cur_ver); |
|
if ($status == 'up-to-date') { |
$this->setStatus(VNag::STATUS_OK); |
} else if ($status == 'update available') { |
$this->setStatus(VNag::STATUS_WARNING); |
} else { |
$this->setStatus(VNag::STATUS_UNKNOWN); |
} |
$this->setHeadline("GitLab version $cur_ver [$status] at $system_dir", true); |
} |
} |