Subversion Repositories vnag

Rev

Rev 77 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
/*
4
 * VNag - Nagios Framework for PHP
5
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
6
 * Licensed under the terms of the Apache 2.0 license
7
 *
76 daniel-mar 8
 * Revision 2023-10-13
2 daniel-mar 9
 */
10
 
11
declare(ticks=1);
12
 
13
class Net2FtpVersionCheck extends VNag {
14
        protected $argSystemDir = null;
15
 
16
        public function __construct() {
17
                parent::__construct();
18
 
19
                $this->registerExpectedStandardArguments('Vht');
20
 
21
                $this->getHelpManager()->setPluginName('check_net2ftp_version');
79 daniel-mar 22
                $this->getHelpManager()->setVersion('2023-10-13');
2 daniel-mar 23
                $this->getHelpManager()->setShortDescription('This plugin checks if a local net2ftp system has the latest version installed.');
24
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
25
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]');
26
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
27
 
28
                // Individual (non-standard) arguments:
29
                $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'net2ftpPath', 'The local directory where your net2ftp installation is located.'));
30
        }
31
 
58 daniel-mar 32
        protected function get_local_version($path) {
2 daniel-mar 33
                $path = realpath($path) === false ? $path : realpath($path);
34
 
35
                if (!file_exists("$path/settings.inc.php")) {
77 daniel-mar 36
                        throw new VNagException("Cannot find net2ftp settings file at $path");
2 daniel-mar 37
                }
38
 
39
                $cont = @file_get_contents("$path/settings.inc.php");
77 daniel-mar 40
                if ($cont === false) {
41
                        throw new VNagException("Cannot determine version for system $path (settings.inc.php not found)");
42
                }
58 daniel-mar 43
                if (!preg_match('@\\$net2ftp_settings\\["application_version"\\]\\s*=\\s*"([^"]+)";@ismU', $cont, $m)) {
77 daniel-mar 44
                        throw new VNagException("Cannot determine version for system $path (application_version setting not found)");
2 daniel-mar 45
                }
46
 
47
                return $m[1];
48
        }
49
 
58 daniel-mar 50
        protected function get_latest_version() {
76 daniel-mar 51
                $cont = $this->url_get_contents('https://www.net2ftp.com/version.js');
52
                if ($cont === false) {
77 daniel-mar 53
                        throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 54
                }
55
 
7 daniel-mar 56
                if (!preg_match("@var latest_stable_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
77 daniel-mar 57
                        throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 58
                } else {
7 daniel-mar 59
                        $latest_stable = $m[1];
2 daniel-mar 60
                }
61
 
7 daniel-mar 62
                if (!preg_match("@var latest_beta_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
77 daniel-mar 63
                        throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 64
                } else {
7 daniel-mar 65
                        $latest_beta = $m[1];
2 daniel-mar 66
                }
67
 
58 daniel-mar 68
                return array($latest_stable, $latest_beta);
69
        }
70
 
71
        protected function cbRun($optional_args=array()) {
72
                $system_dir = $this->argSystemDir->getValue();
73
                if (empty($system_dir)) {
77 daniel-mar 74
                        throw new VNagException("Please specify the directory of the net2ftp installation.");
58 daniel-mar 75
                }
76
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
77
 
78
                if (!is_dir($system_dir)) {
77 daniel-mar 79
                        throw new VNagException('Directory "'.$system_dir.'" not found.');
58 daniel-mar 80
                }
81
 
82
                $version = $this->get_local_version($system_dir);
83
 
84
                list($latest_stable, $latest_beta) = $this->get_latest_version();
85
 
2 daniel-mar 86
                if ($version == $latest_stable) {
87
                        $this->setStatus(VNag::STATUS_OK);
88
                        $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
89
                } else if ($version == $latest_beta) {
90
                        $this->setStatus(VNag::STATUS_OK);
91
                        $this->setHeadline("Version $version (Latest Beta version) at $system_dir", true);
92
                } else {
93
                        $this->setStatus(VNag::STATUS_WARNING);
94
                        if ($latest_stable != $latest_beta) {
95
                                $this->setHeadline("Version $version is outdated (Latest versions are: $latest_stable Stable or $latest_beta Beta) at $system_dir", true);
96
                        } else {
97
                                $this->setHeadline("Version $version is outdated (Latest version is $latest_stable) at $system_dir", true);
98
                        }
99
                }
100
        }
101
}