Subversion Repositories vnag

Rev

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

Rev Author Line No. Line
4 daniel-mar 1
<?php /* <ViaThinkSoftSignature>
58 daniel-mar 2
kaYU5Ej07R4JWIYY77+1u7d9Z/suFEbhvcni+GKz0Y7j5W4RUkmYNGW72dwGJODn3
3
4cbFalcSOJ1X+6RSelabpkRbEAT7xJDYIsZKq4n28PrYYmVoHLgAlQpTC36iFRxqG
4
NsZuDj8iAOaBiaUlB30denRyvP6YYIdFa0hlHY4nK3eqptbS9F5PTxtjB1reHwTOK
5
F4kEhznuZY5POdGnrRNAlB4s5wc70Qqn6JiRtZHtKU1reX//Jdq3FP2HAc82P4izE
6
AZsmJbY5dQwa7YMWe4n9AcWHyXr08zbHqYCzCTgEmLgPv0Z4RsBXSMq9JfseHl19i
7
R8mCQF91/N1vMpnSRhmBEj5p331jHcCwe3w7eQHFJriT8zNosRkeBTYGEowNI3EcO
8
nYRgWfxdpBujU/Q1ES2P/te8efclnVdCGfhlOK21Y6qj9P45mZdnqS1C2YT498N3s
9
AYrl5q793aujZyZ+tZ6SzVTsb7EYYGXkjMmkqFsz1sLNe4Mwmku1gVo1dZKqF/j+8
10
tSl8RgHA5NUzu2m+Rhu14CnBQ36904vN1I/dpbAYnk+9tbCNywuPlPaJtpTpmPQtb
11
TyhZTdL+0SK90O4IhFcEugFBsw+b7LnaqOPw7GwOHXBHWM9xePZ6r0K49/0rwvMyH
12
1j0096b+EAw/hCOf3ic9cZh/rpO9IcOcOJI0zsR0Mta1dzujnzjY66VPt0TCYjWPu
13
chqcU2Re8YuSmIsmkHWOuEJRVDYE/h/2yHNdcdo2ev90DYIjP95UHi9ZxCKoJDEG2
14
aac0WcNMrxEFgmYM8p8v4Bg96x0o+Y16xxMc2T3NeT6E4HrZAx8Sq1hkl4+D0RRid
15
ibXuzxERmDu+DFeA1d+WRLCv0vIFaQHVVx79HiA/U1TdMqbvSv6TPMEX3etjwo9gv
16
4hZ4Io9npHprocFcLLPzgfCBmOGBinvmUGwnw+iVTTK08SVOTPPkT4sOdwiBgRysw
17
F3Bj2O2qwOOkH+1lscTogldQQMvLYQaL6K3RvUHNede2yxnjowjfZBFLdZQVZvvhH
18
cc1QuCqsrU9cmsUPSGd/hkvAlS1a2dk2TLPJTkchxb0Q/hEcl+zwYnW5ZMj8Uvbkj
19
TFnI0XV6upG4WTF53ewPR4dZMfdBzboMFglDFGg7MJY6tkZzwrxTAFmVQSGCUgcVn
20
rzL0NWyivR24OA8cQ2CRe3X4bmJQ4bHuZZf6dLLbbyJJV3x3QwFw1BQCUiJE1mBQH
21
ZfOqsdqwmvVH76R6DStD1BakkjqfB/Q4A2ghRxTqsESMj/KcC1Rj0YL/RbWQGKWb0
22
b+OYXtEHghPQPLH9nUU6wH0pi4zG80rFG1nrOQTYEf4PfyqkdSAa5jK0HTxLIASpV
23
g==
4 daniel-mar 24
</ViaThinkSoftSignature> */ ?>
2 daniel-mar 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
 *
58 daniel-mar 32
 * Revision 2022-12-18
2 daniel-mar 33
 */
34
 
35
declare(ticks=1);
36
 
37
class Net2FtpVersionCheck extends VNag {
38
        protected $argSystemDir = null;
39
 
40
        public function __construct() {
41
                parent::__construct();
42
 
43
                $this->registerExpectedStandardArguments('Vht');
44
 
45
                $this->getHelpManager()->setPluginName('check_net2ftp_version');
46
                $this->getHelpManager()->setVersion('1.0');
47
                $this->getHelpManager()->setShortDescription('This plugin checks if a local net2ftp 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, 'net2ftpPath', 'The local directory where your net2ftp installation is located.'));
54
        }
55
 
58 daniel-mar 56
        protected function get_local_version($path) {
2 daniel-mar 57
                $path = realpath($path) === false ? $path : realpath($path);
58
 
59
                if (!file_exists("$path/settings.inc.php")) {
60
                        throw new Exception("Cannot find net2ftp settings file at $path");
61
                }
62
 
63
                $cont = @file_get_contents("$path/settings.inc.php");
64
 
58 daniel-mar 65
                if (!preg_match('@\\$net2ftp_settings\\["application_version"\\]\\s*=\\s*"([^"]+)";@ismU', $cont, $m)) {
2 daniel-mar 66
                        throw new Exception("Cannot determine version for system $path");
67
                }
68
 
69
                return $m[1];
70
        }
71
 
58 daniel-mar 72
        protected function get_latest_version() {
7 daniel-mar 73
                $cont = @file_get_contents('https://www.net2ftp.com/version.js');
2 daniel-mar 74
                if (!$cont) {
29 daniel-mar 75
                        throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 76
                }
77
 
7 daniel-mar 78
                if (!preg_match("@var latest_stable_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
29 daniel-mar 79
                        throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 80
                } else {
7 daniel-mar 81
                        $latest_stable = $m[1];
2 daniel-mar 82
                }
83
 
7 daniel-mar 84
                if (!preg_match("@var latest_beta_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
29 daniel-mar 85
                        throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 86
                } else {
7 daniel-mar 87
                        $latest_beta = $m[1];
2 daniel-mar 88
                }
89
 
58 daniel-mar 90
                return array($latest_stable, $latest_beta);
91
        }
92
 
93
        protected function cbRun($optional_args=array()) {
94
                $system_dir = $this->argSystemDir->getValue();
95
                if (empty($system_dir)) {
96
                        throw new Exception("Please specify the directory of the net2ftp installation.");
97
                }
98
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
99
 
100
                if (!is_dir($system_dir)) {
101
                        throw new Exception('Directory "'.$system_dir.'" not found.');
102
                }
103
 
104
                $version = $this->get_local_version($system_dir);
105
 
106
                list($latest_stable, $latest_beta) = $this->get_latest_version();
107
 
2 daniel-mar 108
                if ($version == $latest_stable) {
109
                        $this->setStatus(VNag::STATUS_OK);
110
                        $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
111
                } else if ($version == $latest_beta) {
112
                        $this->setStatus(VNag::STATUS_OK);
113
                        $this->setHeadline("Version $version (Latest Beta version) at $system_dir", true);
114
                } else {
115
                        $this->setStatus(VNag::STATUS_WARNING);
116
                        if ($latest_stable != $latest_beta) {
117
                                $this->setHeadline("Version $version is outdated (Latest versions are: $latest_stable Stable or $latest_beta Beta) at $system_dir", true);
118
                        } else {
119
                                $this->setHeadline("Version $version is outdated (Latest version is $latest_stable) at $system_dir", true);
120
                        }
121
                }
122
        }
123
}