<?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 2023-10-13
*/
declare(ticks=1);
class Net2FtpVersionCheck extends VNag {
protected $argSystemDir = null;
public function __construct() {
parent::__construct();
$this->registerExpectedStandardArguments('Vht');
$this->getHelpManager()->setPluginName('check_net2ftp_version');
$this->getHelpManager()->setVersion('2023-10-13');
$this->getHelpManager()->setShortDescription('This plugin checks if a local net2ftp 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, 'net2ftpPath', 'The local directory where your net2ftp installation is located.'));
}
protected function get_local_version($path) {
throw new VNagException("Cannot find net2ftp settings file at $path");
}
if ($cont === false) {
throw new VNagException("Cannot determine version for system $path (settings.inc.php not found)");
}
if (!preg_match('@\\$net2ftp_settings\\["application_version"\\]\\s*=\\s*"([^"]+)";@ismU', $cont, $m)) {
throw new VNagException("Cannot determine version for system $path (application_version setting not found)");
}
return $m[1];
}
protected function get_latest_version() {
$cont = $this->url_get_contents('https://www.net2ftp.com/version.js');
if ($cont === false) {
throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
}
if (!preg_match("@var latest_stable_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
} else {
$latest_stable = $m[1];
}
if (!preg_match("@var latest_beta_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
} else {
$latest_beta = $m[1];
}
return array($latest_stable, $latest_beta);
}
protected function cbRun
($optional_args=array()) {
$system_dir = $this->argSystemDir->getValue();
if (empty($system_dir)) {
throw new VNagException("Please specify the directory of the net2ftp installation.");
}
$system_dir = realpath($system_dir) === false ?
$system_dir : realpath($system_dir);
throw new VNagException('Directory "'.$system_dir.'" not found.');
}
$version = $this->get_local_version($system_dir);
list($latest_stable, $latest_beta) = $this->get_latest_version();
if ($version == $latest_stable) {
$this->setStatus(VNag::STATUS_OK);
$this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
} else if ($version == $latest_beta) {
$this->setStatus(VNag::STATUS_OK);
$this->setHeadline("Version $version (Latest Beta version) at $system_dir", true);
} else {
$this->setStatus(VNag::STATUS_WARNING);
if ($latest_stable != $latest_beta) {
$this->setHeadline("Version $version is outdated (Latest versions are: $latest_stable Stable or $latest_beta Beta) at $system_dir", true);
} else {
$this->setHeadline("Version $version is outdated (Latest version is $latest_stable) at $system_dir", true);
}
}
}
}