Rev 2 | 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> |
2 | b9H+o+uc69uskKoarZ6sudOUcbQewFqoqOw7j2C41tLdtnY5lifSSr4xHIOsORG8z |
||
3 | uE4sWz00lp+ySbp/5Cn1wZVLpkusQSkVQZNfaYXqcyhxbpxA04qB4oUFfsecJ4lGP |
||
4 | 8cGHxT1BTxg5P81CelT56Kook+U/npTQzOXwCNL+5E/QipYUcKyh72B3+Or4lS+HP |
||
5 | yP+WHC45XkTyvkItnCXDbsZxQR/oO5JKhv9R8t3oSHoUMX3AjCws5ZzFJ6QlHVl3z |
||
6 | Q4u2o7MXIvYzHiojLFx/ycQ4W3AZ8xsfDRtdisIluwQ37rnQ65gxBe0YMzTjOtKWg |
||
7 | Njr/Minaz8Tx3iSEpqCDmtoTM2lKiyf8I73wrFFiDM9BTHy9AO1Gg6lHUQGdG7URu |
||
8 | sohNh0mLanV/S69UF8EPMzbuJzfeRBd6/eYagge5yIImCLmN/YQdudfM7+ZAlQWXW |
||
9 | jaXIRpMIJZcl8cO002xw9MlMfJRXdAJ8yUduLW1ds8b8SkxdDmWlSnNakoIRbGbuo |
||
10 | BamN3e6od2Xdy9XIOj4GQakS5cqxxEbMOUGiTIuhKmplJD6xzHCYzIsxFe2n9gCkp |
||
11 | GPkNuUwzb6pjS+WSIsltcsBPWu6WaWXp5D7kqspbgm7UrAprZuNojcdn8ymfBo0J+ |
||
12 | UcpYCWZhnwsjSGjIRJ8zmfedi46eYevSbVWrkZbywdNRv+UdEpTNd/20QQUGzvHbP |
||
13 | zsIZMgwL3rDR7j5oJ2nLTygBQhylnzBhzOVdnVJyfaWwJFZgnZUBsL+U+FWF+YHeW |
||
14 | ZGLkrIPnUzIEcyb3uiYT7VWHl+B7HVDyVdMiT9CyjrYRfdP02KShkLgMl/RQcLBfn |
||
15 | xPasSNd1PKWn7G9WoZKvy+d8cE8BrNHnnx4+NoTelV3FSG4gFlX5GlBX4/zxrK5/V |
||
16 | PIsfxpDfrH+SqoEgefwnrM35J3hgJmDJsX/L2xwutWA4FuXHQOphEZOWKZAMM5avw |
||
17 | ZS5Zaig2C1hEbocp+NayTFgXNqjzpLbaZB6iKp4aY9Hm2ZqpY9gPTufdi6cv7vu15 |
||
18 | QYiIYcr4GmWqciDUZB9IuN8180OZGP1HtCCqzsgZZR38kO4fqx5DTzQEn6mdat9h4 |
||
19 | 72K+nF0rrGBRvMKq0yGIX5LhDyn+sXsFuNZOyNJWiuanDDJdTxFWyTA+0X3gzD1N5 |
||
20 | lHD1haPOp3Zv7eM/ppkGGFY69b1/mxcH8Lcre1TCxOSpG+yM+CaZy4jQSStHmXDm8 |
||
21 | z3ZJbe+DgawW9TUJg0r6Mrqer56sDgRVw2GuLkWfxCoDx1n3EoelggDhV10tTttGF |
||
22 | EIQ2m/ruXQ4Ji/S8/gL6oaiBaIsX3PUomLFTvCSfB9TqHKX3yyCsGlXTzwSIoi+FB |
||
23 | Q== |
||
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 | * |
||
32 | * Revision 2018-07-15 |
||
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 | |||
56 | protected function get_net2ftp_version($path) { |
||
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 | |||
65 | if (!preg_match('@\$net2ftp_settings\["application_version"\]\s*=\s*"([^"]+)";@ismU', $cont, $m)) { |
||
66 | throw new Exception("Cannot determine version for system $path"); |
||
67 | } |
||
68 | |||
69 | return $m[1]; |
||
70 | } |
||
71 | |||
72 | protected function cbRun($optional_args=array()) { |
||
73 | $system_dir = $this->argSystemDir->getValue(); |
||
74 | if (empty($system_dir)) { |
||
75 | throw new Exception("Please specify the directory of the net2ftp installation."); |
||
76 | } |
||
77 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
78 | |||
79 | if (!is_dir($system_dir)) { |
||
80 | throw new Exception('Directory "'.$system_dir.'" not found.', false); |
||
81 | } |
||
82 | |||
83 | $version = $this->get_net2ftp_version($system_dir); |
||
84 | |||
85 | $cont = @file_get_contents('https://www.net2ftp.com/version.js'); |
||
86 | if (!$cont) { |
||
87 | throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.', false); |
||
88 | } |
||
89 | |||
90 | if (!preg_match("@var latest_stable_version\s*=\s*'(.+)';@ismU", $cont, $m)) { |
||
91 | throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.', false); |
||
92 | } else { |
||
93 | $latest_stable = $m[1]; |
||
94 | } |
||
95 | |||
96 | if (!preg_match("@var latest_beta_version\s*=\s*'(.+)';@ismU", $cont, $m)) { |
||
97 | throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.', false); |
||
98 | } else { |
||
99 | $latest_beta = $m[1]; |
||
100 | } |
||
101 | |||
102 | if ($version == $latest_stable) { |
||
103 | $this->setStatus(VNag::STATUS_OK); |
||
104 | $this->setHeadline("Version $version (Latest Stable version) at $system_dir", true); |
||
105 | } else if ($version == $latest_beta) { |
||
106 | $this->setStatus(VNag::STATUS_OK); |
||
107 | $this->setHeadline("Version $version (Latest Beta version) at $system_dir", true); |
||
108 | } else { |
||
109 | $this->setStatus(VNag::STATUS_WARNING); |
||
110 | if ($latest_stable != $latest_beta) { |
||
111 | $this->setHeadline("Version $version is outdated (Latest versions are: $latest_stable Stable or $latest_beta Beta) at $system_dir", true); |
||
112 | } else { |
||
113 | $this->setHeadline("Version $version is outdated (Latest version is $latest_stable) at $system_dir", true); |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | } |