Subversion Repositories vnag

Rev

Rev 58 | 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>
76 daniel-mar 2
Y47HtMofXduSMBqHYs0A2zUutszEFPtnTiplJnrXJJCTA4aIl3/mw1UwycL+xmcvG
3
eeO81pkefEWiXtWhoRqX4MIBUv7zZ7Yp+O9/uUs/l+++WvBHkEue++SyuJXgRlYOS
4
14NGZl2w4LJjLEw6RYFtq7UhHlojVrFfysBXgbzYyvMx+mbkstNLTwJZ34T2wJCAK
5
b3bYzIavozAoSBPiyq1LblDE+EMFbVEdHvRzNTNrcc7fVcDuZt3pzbHkXbJzAbIT+
6
8s5ZCwxrzuy+Q2kq4GCeiTUdpneq8UwWFqrM5pgSpjLP0MM8DZMVJeYcm5KWomOnO
7
HjGhU53upbQkMpadXJOU8eLm0XSD8WwxK6cWiZTGyS0Vg22Hepgv5HDobHWk3Dt7I
8
8ryhwdS2wtfvioWcabm95coxWIayQq/49bW/U0iBZCUlizpkLFVQiqFrPV7BpMN5G
9
tjdJBjR1Hg5E8ALpa19v4B6TCb/ujGTlZkVqQbNBhrTH1VuJ7UNSx9Lnt/Y3Jwss8
10
63HHSs1nG5cnCgpef0ojH20aLk7N7k7DwWMYovOlx/LpfmgK3iYTBo4UlwBVTJByk
11
nMK010KnruouDT5alpeZ/tvSYWzWakgqaOMCd6IaDhDt+v/RZXtXuvSOjV+tfX1nF
12
rATHyku3y4dH09uirH9AHuN1PfFi/mjXiOPlUjHdgdih/nTmKFxDJhi7qX1Cbrch5
13
L0Rq7nPTD9R4B7k8YwmDmMWAY/+XPTg0Y+J+ivCVnNkReqsEDLS/fMGu8VekBhxIh
14
WoivFYr62IdEMfDdK7usvVY3lA1xSS4X/bg9OixwTVyjyiZjYPGpilR4q5rB4LrDb
15
Jn8JuB2jFLFCAABeNbLd76Cz35CVhmNm1VetFhBYlVG7k/a7PZgH79GZDXRpzYCOP
16
mMCYYNgCJ1RDXZeeKsTD+gZ/VjAS/XvUgVCN/Du37EW/IsMPoOQNVKbWOEj3HYbwi
17
7wr4ebqMtjMxfikc1uUu2WIlnooYDF5NusE3y24Vok0sUv3qqZ9nDrI6tOG1wFUSx
18
CYyJVAUV0tgjOeixgzdseR7oi5pT8RjUHg3Y/EOHDMg3ZXPZiJzITQaprkB9Zu3Kg
19
v7ks3PZqxBRxYtCBsMHXmKsWavRBmL7NZP8ETk0SIXmhpK45LHh/LkD/8KktRQ8Gx
20
PRfqK+LWFmAOBfCABUt0ZsN6lA0u5U+ddOMl0sSTsSn7C3mCnTwmFGroGR0gWUQhJ
21
wJ4tagVYOJUxgFOa0TiNTttVrYTx+DPfjm7F6c3yjaTg/MKBf5eOKvNPlD22lnsNh
22
pkWe14wIwYN7nwVGe6+5IR6GpuYCvfQ0tMTg3NEwraHl0U/wtcGbraAgQQZWoTqNg
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")) {
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() {
76 daniel-mar 73
                $cont = $this->url_get_contents('https://www.net2ftp.com/version.js');
74
                if ($cont === false) {
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
}