Subversion Repositories vnag

Rev

Rev 76 | 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>
77 daniel-mar 2
FJRVnIdhB1D3LlEHa+sUsf8GetU/KYLo8RBGo0FxQ1JKQmjSNbvmLswrjaPoGodu+
3
5tylc9Oh0UGXodM+I4tEgInSIA7tCESSvMdRS3+I1rgX9xDdlMRoHuZwIFpMRxfcJ
4
hzDzGPf0NPpCfupiaxlHK8ZWkDshwNKbUalNQrONKddv1JjGV6e1tp9qJZH+kDopo
5
qJvZFkVcvbFNDYX7/GvgD8qZW77bJA4wPmLjTsqUIllnHdxso3byAPtwpLuDW3139
6
aFD8SUKHZV2J4clj/NmdJ7Fl1h1u435c/5IQbShKBFDXh68QHsPfxqStOjHUwWMx3
7
vwKH6yyBXidC2e5O5Vc4MNjayYbffXtGg8GEnQUEqHyDhR5mgxTEprx5KphfgNDxb
8
/Ba7hPa34ZacAkX6LNNjcCreE34Cz06g45hq4lPZm2ierAsljJOAAAU165mw5nUxR
9
aOcFLge8TIN4lzCmY4sVLCRm3cNZxUlU7GIcojgRIf5MbsYeFFGO+B1vMX0cWlwYR
10
3BK1EC4996Yw5av4UanvOOA7CAyQSY3Ype3yPeJuohjdJDmlt5498RtlLCEzt0+G6
11
246P6olAOXRMPrK2ul82d5/VeA+vPsiiQrPRFHdfkviQtDJcOXpGPf+Mry4UMevjn
12
jMLM+tPg1wFxqhdOIKuJDQfm9CLnAQqbq9nyXd8nNmZ++0yV9zQhW6WxPBWHebueh
13
5HliPdexsFU0PjC885qlQldZvwUHZUqDrSY6G7UnwCNUZeGIHlItxxAb2yyqeaSCK
14
xSrBlX29Pj0OSgG52+ceDAEMS718lLc9ujIibg3YmHmpQRHALINw5Ie/OlyN3R/qq
15
9Eg5NXyGgPXo425xJerxNdrzKsHNLd3zdYrSA7jIFaOp59G7aN9oBf+f1St+9MxZy
16
no6fNBQJRX54x36E3PyeyENjV2yY2Os97agvZADbpjpsdheoTYjEZT5FG+gdg722W
17
zNffSrbAR6VnldTHUK7LlevS6n+vc9mEZB+rRGXy+njqh0VmR+oJti4InshgDGrJF
18
RwxfdFxSYu6msy/TqO9h70Ixs5C/ALeC5jEEJmScRN1CLLiuwNMdyBEMnmDmU1I6a
19
Sg6hgIvBRCyDTOwokFSApy0Zq+25OhmD9p5bY3eyxKaACscuLuwpv1G/4zIGbSJWv
20
DU6/M5UBiKUl6ceDFKMs2Dtizi6ZnvbwYWi2t7fB6HaTPEtXSef52hFXpPgB/VNLw
21
zF/9mATFKWWhpFtaenVQP3UvAhj+Gvp8ZbNIGyBl48Ww8BYpJY5Lu+AJeMj4SFDX0
22
LoJ8f4BCol5mabN46lQZgupmMhxs1vQDWxRQtpXAabY/v/04DwOL2rXUmC8yMa8PS
76 daniel-mar 23
Q==
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
 *
76 daniel-mar 32
 * Revision 2023-10-13
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")) {
77 daniel-mar 60
                        throw new VNagException("Cannot find net2ftp settings file at $path");
2 daniel-mar 61
                }
62
 
63
                $cont = @file_get_contents("$path/settings.inc.php");
77 daniel-mar 64
                if ($cont === false) {
65
                        throw new VNagException("Cannot determine version for system $path (settings.inc.php not found)");
66
                }
58 daniel-mar 67
                if (!preg_match('@\\$net2ftp_settings\\["application_version"\\]\\s*=\\s*"([^"]+)";@ismU', $cont, $m)) {
77 daniel-mar 68
                        throw new VNagException("Cannot determine version for system $path (application_version setting not found)");
2 daniel-mar 69
                }
70
 
71
                return $m[1];
72
        }
73
 
58 daniel-mar 74
        protected function get_latest_version() {
76 daniel-mar 75
                $cont = $this->url_get_contents('https://www.net2ftp.com/version.js');
76
                if ($cont === false) {
77 daniel-mar 77
                        throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 78
                }
79
 
7 daniel-mar 80
                if (!preg_match("@var latest_stable_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
77 daniel-mar 81
                        throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 82
                } else {
7 daniel-mar 83
                        $latest_stable = $m[1];
2 daniel-mar 84
                }
85
 
7 daniel-mar 86
                if (!preg_match("@var latest_beta_version\s*=\s*'(.+)';@ismU", $cont, $m)) {
77 daniel-mar 87
                        throw new VNagException('Cannot parse version from net2ftp website. The plugin probably needs to be updated.');
2 daniel-mar 88
                } else {
7 daniel-mar 89
                        $latest_beta = $m[1];
2 daniel-mar 90
                }
91
 
58 daniel-mar 92
                return array($latest_stable, $latest_beta);
93
        }
94
 
95
        protected function cbRun($optional_args=array()) {
96
                $system_dir = $this->argSystemDir->getValue();
97
                if (empty($system_dir)) {
77 daniel-mar 98
                        throw new VNagException("Please specify the directory of the net2ftp installation.");
58 daniel-mar 99
                }
100
                $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir);
101
 
102
                if (!is_dir($system_dir)) {
77 daniel-mar 103
                        throw new VNagException('Directory "'.$system_dir.'" not found.');
58 daniel-mar 104
                }
105
 
106
                $version = $this->get_local_version($system_dir);
107
 
108
                list($latest_stable, $latest_beta) = $this->get_latest_version();
109
 
2 daniel-mar 110
                if ($version == $latest_stable) {
111
                        $this->setStatus(VNag::STATUS_OK);
112
                        $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true);
113
                } else if ($version == $latest_beta) {
114
                        $this->setStatus(VNag::STATUS_OK);
115
                        $this->setHeadline("Version $version (Latest Beta version) at $system_dir", true);
116
                } else {
117
                        $this->setStatus(VNag::STATUS_WARNING);
118
                        if ($latest_stable != $latest_beta) {
119
                                $this->setHeadline("Version $version is outdated (Latest versions are: $latest_stable Stable or $latest_beta Beta) at $system_dir", true);
120
                        } else {
121
                                $this->setHeadline("Version $version is outdated (Latest version is $latest_stable) at $system_dir", true);
122
                        }
123
                }
124
        }
125
}