Rev 7 | 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> |
29 | daniel-mar | 2 | lExJowQmx58MVA6MsmRUWBXI3PT7vScRq6WfY82k/2gX71+VIIIoAP7CR+RC2F9t1 |
3 | gSxNUoNAtbwtJry6OSlnKl9Eg/RLmGUFFTuw9J7flX5zBnZwejquWSfvQM3AhkFLe |
||
4 | 0zNLNhaD56gceVrquJzaXqIPdfCSfpPZU0Mo+FvrvbpfTUlMsbabb2Aesxy+Xr0JL |
||
5 | e2a97WXlUdeBKVZQANbjNzArtUgtvkkrIzZOenZ0LLmVvyYQ5oJ6Vlj/dymRyMCzI |
||
6 | tSJFr3e9XdCAyoNOwbjbOTaylYCZYR7lz6pU1gyUyrFrLaVsfMolZouX8t2HzJp1K |
||
7 | ew4GnJ52106GjjXynkMsvry4195S4XrWoWchbbK5FGKKCJXoJK5Mmn/b9IlUBTrQf |
||
8 | osJ9CWjI6K9iEVVNWr6UxyABOqfQokzbqTCf7Az/3kJcLqwk9oB2Y67NiwQgM0eek |
||
9 | nTZdO4KKzLvD3IYrKfhnzXJN4hUz+KE3AsMGXpmSy8ovDYNZtY/Rbs49K8ZlJGqSZ |
||
10 | P/WErF3laGosOnLAmosT8mdUM8pF54sH1Ve57lN4HdDH0Ro1qOWljAB9LridDxj/B |
||
11 | qp5ZTJ89sz/RC6XIVYBJ0rNfg41BhXIEQ3OcVQ2UddgySXUri0J/K/acgpwLa2DB1 |
||
12 | 8l+L7hxox97647hOybj2QWAtbg6l7CffU5sIdw/8fRnuorlmNdnKcqguFynpt3d2c |
||
13 | zKSRmjJdqXEQFMxnz5Toc6BBNRMjl1RLIjyImfiagdP15eDIRnH7ARn6KEmJSDWsR |
||
14 | nsAFXFavn4kc4mkIyf+hef9Dn86wGYP5lJITuFwwz3V5i5PDXwBgkB5Z29qXA1jkg |
||
15 | Bu3GwWKrASpaN6+VxNrZlvLot+BLFPbpDdpGl0hGYcUm2VhDmtE7ZJqILuLkTqc2t |
||
16 | bGOhtF6kDyyhKU5jaiMOUtq4x8lPhDCMXdLd5Jyf6pIUTJbKt5nnsG/R0avpVgacc |
||
17 | KpB3lrpLOF4lI3PyMxMuekoAhXmeRIUcH6fw/k25dfb71FSFiqXpDajYbZGbkSo1I |
||
18 | KKV2VbiAxzE0v6gKDvFNlSNbFwCVshxPHk0jx332qkNecgLKUGOgoXtL/3urjqbv1 |
||
19 | M/40Ci+G+2Wb4uvQ6x8SJZ7f69OxyHr4h7Hrx+MthqoEPDuQKsixw63LjwPbzCXOb |
||
20 | ePysuJrIiy0IqxsUbLSiIBSW7AQkdwcHdmj39vuW+t/Swek5XK7CAu3+lY3LeMC20 |
||
21 | BzgDvUlWohWq7EPTpY2hhjrGvs66sLRPIgbquXB3yo8dfzjHrfwYd3qhjLAUPvepW |
||
22 | PcL+UXgnr+ViOyRjfukNsfruULKvWWs0kaiGbWj5hU+IJoGo3tqK8xtf7ed8VZacu |
||
23 | w== |
||
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 | * |
||
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)) { |
||
29 | daniel-mar | 80 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
2 | daniel-mar | 81 | } |
82 | |||
83 | $version = $this->get_net2ftp_version($system_dir); |
||
84 | |||
7 | daniel-mar | 85 | $cont = @file_get_contents('https://www.net2ftp.com/version.js'); |
2 | daniel-mar | 86 | if (!$cont) { |
29 | daniel-mar | 87 | throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.'); |
2 | daniel-mar | 88 | } |
89 | |||
7 | daniel-mar | 90 | if (!preg_match("@var latest_stable_version\s*=\s*'(.+)';@ismU", $cont, $m)) { |
29 | daniel-mar | 91 | throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.'); |
2 | daniel-mar | 92 | } else { |
7 | daniel-mar | 93 | $latest_stable = $m[1]; |
2 | daniel-mar | 94 | } |
95 | |||
7 | daniel-mar | 96 | if (!preg_match("@var latest_beta_version\s*=\s*'(.+)';@ismU", $cont, $m)) { |
29 | daniel-mar | 97 | throw new Exception('Cannot parse version from net2ftp website. The plugin probably needs to be updated.'); |
2 | daniel-mar | 98 | } else { |
7 | daniel-mar | 99 | $latest_beta = $m[1]; |
2 | daniel-mar | 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 | } |