Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | daniel-mar | 1 | <?php /* <ViaThinkSoftSignature>q6gx+eKOBlrjudngDLewBu36ohNJSKufLoPCxcLlswvaRLCe6fNoEPFIkS4FW748JC+3c7H3HZx4oyqEztzYqaG53xpaM4jFKsRs4hYPsxLmOtXyiXUhk5bTeZzyGYQpTHIquBkUBcworlVKxaTTdipcytlq0e9bTWMNd1vivtttYdpJd+UkiaQL/Mb/AwvU62Qy27URiKSiLx356H9XQbZl7NvSxnrvDwcV/1+tAp/XpFh3F+BK88+y6hs7oNsN9D9Hc2dw3sSPH1b75HQTyDD8yyBxqGqxAEDYUNBEQPHnxYk2uLagolfiLXiyrUkJr8NewattBAECBmfFjXjOvhVz4ggPYKVjOL5i1cKviwsiHo5BFH7H5QECqUbGyHNm+Ce6IJ5o5wveQG+JCzNjH1BifZZ/dNM26PbyVyOLiFok8dc/fkdLmbj1x5hYY4nvhL92QUT83XBDzXV/2QIiiQTnwi89V3iOv4bfLEc9OcEDM0m+dKKrista+btJLw8u7NV4PXYE1U/UBpH+NjJ6uJ9nitVfOYN8LgwerGhFN/WYxjiBgRdhbux2/YQvH2V0yX0+sNn5tRLi45LRLM5VoCg56r6vhNaYRoYTeluSJ57FwMVong1JLv/kW07/wHQ0PBRs3tDEPfJnatiJxYhhJKd04QdEfYuQj5o+51u3OIDMLNh/3IQtxM1La6I7dBA4vpq/o3+Tg5xE5HouzDPelo8OTzB/7sVsFHIFah1BI3PoIcbNBKNuMz34KU3ZQAs8LnYDutTKLtEXFOOhROidGochYXUG71guCH8byMo+tJ8ISzzNQCslvcbL2Xc3jlQwlsKtxB3bLJxs0pWbJ73MY4w2lDUBtXPmF3Qdw1n4CoWs09EJAxYU1ZvtwftTtfIEOV3YODIC5QzZ1zH6yDDvjPJ2WTLbIIXrsC00a0KM8aek8lHog9a/ypZKFZ+QEw5kWSVkp7hALM3jwxrSNF6gnf0Rnmw6V6MltZI+MhfSYsb0YyINvhQaiI0hyeeIEMSyZZfMRhDCKmg09ee/pkUD/d5lOQ0/Nb0fhdL4MCsR4X8YoG+OFgZ3D47Mvw9qpOw2m5SQonMVDJQFLH+qNgSqlcoJbqy0ElBK1eUHP9aHUyMVugxR8v383ernTsUhBja76w2lJ1d4Cd9Gfh0ASKO8ApnxCH4//R34u0DX5VIZHHQRZa3BoyjdsS+2FnEEcjZXYmT+O89+m0bjNqnMvkR82YKssUPI1DW+OwoE06TQX0jyOkFmGEFnkJEOa6ScnjiCRLc4T65ABbK2xKTo65ylS5zMY6/QmbNCoteoq9f9RelLyK6Ra3io8pjQemdyLBiHq+NySUK75dO7YxUuZJJswQ==</ViaThinkSoftSignature> */ ?> |
2 | <?php |
||
3 | |||
4 | /* |
||
5 | * VNag - Nagios Framework for PHP |
||
6 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
||
7 | * Licensed under the terms of the Apache 2.0 license |
||
8 | * |
||
9 | * Revision 2018-07-15 |
||
10 | */ |
||
11 | |||
12 | declare(ticks=1); |
||
13 | |||
14 | class PhpMyAdminVersionCheck extends VNag { |
||
15 | protected $argSystemDir = null; |
||
16 | |||
17 | public function __construct() { |
||
18 | parent::__construct(); |
||
19 | |||
20 | $this->registerExpectedStandardArguments('Vht'); |
||
21 | |||
22 | $this->getHelpManager()->setPluginName('check_phpmyadmin_version'); |
||
23 | $this->getHelpManager()->setVersion('1.0'); |
||
24 | $this->getHelpManager()->setShortDescription('This plugin checks if a local phpMyAdmin system has the latest version installed.'); |
||
25 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
||
26 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
||
27 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
||
28 | |||
29 | // Individual (non-standard) arguments: |
||
30 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'phpmyadminPath', 'The local directory where your phpMyAdmin installation is located.')); |
||
31 | } |
||
32 | |||
33 | protected function get_phpmyadmin_version($path) { |
||
34 | $path = realpath($path) === false ? $path : realpath($path); |
||
35 | |||
36 | if (file_exists($file = "$path/libraries/classes/Config.php")) { |
||
37 | $cont = file_get_contents($file); |
||
38 | } else if (file_exists($file = "$path/libraries/Config.class.php")) { // older phpMyAdmin versions |
||
39 | $cont = file_get_contents($file); |
||
40 | } else { |
||
41 | throw new Exception("Cannot find the phpMyAdmin version information at $path"); |
||
42 | } |
||
43 | |||
44 | if (!preg_match('@\$this->set\(\'PMA_VERSION\', \'(.*)\'\);@ismU', $cont, $m)) { |
||
45 | throw new Exception("Cannot parse the phpMyAdmin version information at $path"); |
||
46 | } |
||
47 | |||
48 | return $m[1]; |
||
49 | } |
||
50 | |||
51 | protected function cbRun($optional_args=array()) { |
||
52 | $system_dir = $this->argSystemDir->getValue(); |
||
53 | if (empty($system_dir)) { |
||
54 | throw new Exception("Please specify the directory of the phpMyAdmin installation."); |
||
55 | } |
||
56 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
||
57 | |||
58 | if (!is_dir($system_dir)) { |
||
59 | throw new Exception('Directory "'.$system_dir.'" not found.', false); |
||
60 | } |
||
61 | |||
62 | $version = $this->get_phpmyadmin_version($system_dir); |
||
63 | |||
64 | $cont = @file_get_contents('https://www.phpmyadmin.net/home_page/version.json'); // alternatively version.php |
||
65 | if (!$cont) { |
||
66 | throw new Exception('Cannot parse version from phpMyAdmin website. The plugin probably needs to be updated.', false); |
||
67 | } |
||
68 | |||
69 | $json = json_decode($cont, true); |
||
70 | $latest_version = $json['version']; |
||
71 | |||
72 | if ($version == $latest_version) { |
||
73 | $this->setStatus(VNag::STATUS_OK); |
||
74 | $this->setHeadline("Version $version (Latest version) at $system_dir", true); |
||
75 | } else { |
||
76 | $this->setStatus(VNag::STATUS_WARNING); |
||
77 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
||
78 | } |
||
79 | } |
||
80 | } |