Rev 29 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 29 | Rev 57 | ||
---|---|---|---|
1 | <?php /* <ViaThinkSoftSignature> |
1 | <?php /* <ViaThinkSoftSignature> |
2 | INj8GHKi/MYGHSHlhnJTyKdQEKnHl1bdkvxhTv3oLplJtJije4a7tidEPZqawrFw0 |
2 | Jwv2QTTUkaqqNzdKRCyG3W5V7ue0Kdy89/G/x4LhQxUQUZP0Erf3P2EI8rxUdQ2uA |
3 | /wniyLDaIptRhe+x+OStEKG7OckSocxRuxK9PQciJOs+/aE4srSrxKW/mZP8v7gAm |
3 | 0OjWHGS0+1D6yEB8M/HEFCTRzHnMsl8zzo4Uiemi+ZzJytqtYi93HrR6SOWNzzblN |
4 | iuvgRXnoo4VfnNTfAQFLiVcUSRE+Gku4zmPGSHKTKzIWz/IYGeJqc5E6oG47Ult37 |
4 | iFhmDvZs6+4cmH17wvwXutfabzKhUaVFNMavBdkko6sH62dgy3+U5o/qhqAFoAccR |
5 | 0FirA6ZTpxEYfD+oc156jqcbF1TmJjQsZewR+n8YFrCLoTq4XpwUtVtfGlHgAimQI |
5 | FTvD3fMG9CSNnEGMVFcFjpKMIUWQjQj7bB0PA8EMawJlE7R9ydNJBLET0KMnMG6zD |
6 | UFgPphkdI6QvrhpNw4lyT1VoHuutzaK6o/q6PdbUfluzwuL0oTll4Sex/AjTmWs4q |
6 | LNF72ENl9mQ4tfLp1e9qYVJ68Lf2WGu0u4E1Vb2fDgT4c+d31WlmyrcgmqIfKM8hK |
7 | zns+n2/fL6X1L60dqKqYp8oQW2WDw1TEtKdMoPaedjA1TOxvF750SOA22ggv8w3zB |
7 | U5ht/SvmM5OT9OOR6cjZBHVN+ulsibzCYq1szcpKUSlLHiLh0B5keoSpJduGxxz98 |
8 | TyCcAhxag0ZmwIqVYBukASoUNa+YNG8HPaT2kTmRgdqkMUiHZGfaPuvJmGHooVoae |
8 | 7ECTN/s0VWYo4AzwvqSlEl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z/I5TsFoMwKKPZUu3ot7LhYasYN |
16 | aVzu43FzP3vXBKPsOm0n2cY+fDy56G/MX7hGQAIvriw9ajADxx43QjiLNOKS+N1HK |
17 | 568Z0OSc/ryiriboW4vmQrbQBr7zv7mZZXN0ZcdJLtWNCS9smf9ahKiE1VB7YqqiZ |
17 | MNDzW12Ridr0Gnt5NGP8cA/hYZRlpy4kAPJFttA8TTbIdQZHhZaaQCBSfX45jSbPs |
18 | qF0v4arH3ShdKwHK7SircPyAc4XE6bBNjd2Lt54G52lfbuTejgPNdk00RxsjwX1i4 |
18 | Mh9mJmjBvP3bXU4za3XrCxcK/aELxNvczp/UlmL5KDYMalA7arHhaIahLgN2sYNGh |
19 | 5iL+gnZ1YH/C7cnXNjPRseGQIwEz55VDexhIO8KZ/GsjPtCSSwPZZ1XLwWV7T6WVo |
19 | 2tzJywxNGVdWcRQJoFNRCbqRMcroP6ro/VAO4gELfq1RE7C3ZJqjcfwAno6XABi3I |
20 | zIZYOl0Y8nogn9tOw9KyzZJDe993J2of/jP6uICMsT4UgjMPu/D4M/1mIpjbwZzPt |
20 | PuR+LzADuh9yM+1xdYrpAmYfrMEYgBzyx05vn33GDRsaryHYtvkjNRrjBAujnYY0n |
21 | mqUKk5wea4a4JKVActG5/UmdoUw5RNlbXOmnWzRTg5isex4E1ORzHQrcjEQDgwia4 |
21 | Obus4i/hVah6yUgURhprwARav1gPn4IaZbjV0C93CpIWvodwruNW1eTEMoPOw3Fl6 |
22 | r0k0p2pHueH7bFbIJpBvDLlR/a1zeb26jQk73y27edYh/beQI2WYZWiQarkaR7f/D |
22 | x4N1r5Q1uQpHkfJoOnEOSzUxVLa6kMYamF6fE9ckM55RkzJCX+ff4tUPzDGXhS6/x |
23 | A== |
23 | w== |
24 | </ViaThinkSoftSignature> */ ?> |
24 | </ViaThinkSoftSignature> */ ?> |
25 | <?php |
25 | <?php |
26 | 26 | ||
27 | /* |
27 | /* |
28 | * VNag - Nagios Framework for PHP |
28 | * VNag - Nagios Framework for PHP |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
29 | * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com> |
30 | * Licensed under the terms of the Apache 2.0 license |
30 | * Licensed under the terms of the Apache 2.0 license |
31 | * |
31 | * |
32 | * Revision 2021-05-13 |
32 | * Revision 2022-09-12 |
33 | */ |
33 | */ |
34 | 34 | ||
35 | declare(ticks=1); |
35 | declare(ticks=1); |
36 | 36 | ||
37 | class PhpMyAdminVersionCheck extends VNag { |
37 | class PhpMyAdminVersionCheck extends VNag { |
38 | protected $argSystemDir = null; |
38 | protected $argSystemDir = null; |
39 | 39 | ||
40 | public function __construct() { |
40 | public function __construct() { |
41 | parent::__construct(); |
41 | parent::__construct(); |
42 | 42 | ||
43 | $this->registerExpectedStandardArguments('Vht'); |
43 | $this->registerExpectedStandardArguments('Vht'); |
44 | 44 | ||
45 | $this->getHelpManager()->setPluginName('check_phpmyadmin_version'); |
45 | $this->getHelpManager()->setPluginName('check_phpmyadmin_version'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
46 | $this->getHelpManager()->setVersion('1.0'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local phpMyAdmin system has the latest version installed.'); |
47 | $this->getHelpManager()->setShortDescription('This plugin checks if a local phpMyAdmin system has the latest version installed.'); |
48 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
48 | $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
49 | $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-d <directory>]'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
50 | $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com'); |
51 | 51 | ||
52 | // Individual (non-standard) arguments: |
52 | // Individual (non-standard) arguments: |
53 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'phpmyadminPath', 'The local directory where your phpMyAdmin installation is located.')); |
53 | $this->addExpectedArgument($this->argSystemDir = new VNagArgument('d', 'directory', VNagArgument::VALUE_REQUIRED, 'phpmyadminPath', 'The local directory where your phpMyAdmin installation is located.')); |
54 | } |
54 | } |
55 | 55 | ||
56 | protected function get_phpmyadmin_version($path) { |
56 | protected function get_phpmyadmin_version($path) { |
57 | $path = realpath($path) === false ? $path : realpath($path); |
57 | $path = realpath($path) === false ? $path : realpath($path); |
58 | 58 | ||
59 | if (file_exists($file = "$path/libraries/classes/Version.php")) { // Variant 3 (5.1.0+) |
59 | if (file_exists($file = "$path/libraries/classes/Version.php")) { // Variant 3 (5.1.0+) |
60 | $regex = '@VERSION = \'(.*)\'@ismU'; |
60 | $regex = '@VERSION = \'(.*)\'@ismU'; |
61 | } else if (file_exists($file = "$path/libraries/classes/Config.php")) { // Variant 2 (5.0.x) |
61 | } else if (file_exists($file = "$path/libraries/classes/Config.php")) { // Variant 2 (5.0.x) |
62 | $regex = '@\$this->set\(\'PMA_VERSION\', \'(.*)\'\);@ismU'; |
62 | $regex = '@\$this->set\(\'PMA_VERSION\', \'(.*)\'\);@ismU'; |
63 | } else if (file_exists($file = "$path/libraries/Config.class.php")) { // Variant 1 (very old) |
63 | } else if (file_exists($file = "$path/libraries/Config.class.php")) { // Variant 1 (very old) |
64 | $regex = '@\$this->set\(\'PMA_VERSION\', \'(.*)\'\);@ismU'; |
64 | $regex = '@\$this->set\(\'PMA_VERSION\', \'(.*)\'\);@ismU'; |
65 | } else { |
65 | } else { |
66 | throw new Exception("Cannot find the phpMyAdmin version information at $path"); |
66 | throw new Exception("Cannot find the phpMyAdmin version information at $path"); |
67 | } |
67 | } |
68 | 68 | ||
69 | $cont = file_get_contents($file); |
69 | $cont = file_get_contents($file); |
70 | if (!preg_match($regex, $cont, $m)) { |
70 | if (!preg_match($regex, $cont, $m)) { |
71 | throw new Exception("Cannot parse the phpMyAdmin version information at $path"); |
71 | throw new Exception("Cannot parse the phpMyAdmin version information at $path"); |
72 | } |
72 | } |
73 | 73 | ||
74 | return $m[1]; |
74 | return $m[1]; |
75 | } |
75 | } |
76 | 76 | ||
77 | protected function cbRun($optional_args=array()) { |
77 | protected function cbRun($optional_args=array()) { |
78 | $system_dir = $this->argSystemDir->getValue(); |
78 | $system_dir = $this->argSystemDir->getValue(); |
79 | if (empty($system_dir)) { |
79 | if (empty($system_dir)) { |
80 | throw new Exception("Please specify the directory of the phpMyAdmin installation."); |
80 | throw new Exception("Please specify the directory of the phpMyAdmin installation."); |
81 | } |
81 | } |
82 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
82 | $system_dir = realpath($system_dir) === false ? $system_dir : realpath($system_dir); |
83 | 83 | ||
84 | if (!is_dir($system_dir)) { |
84 | if (!is_dir($system_dir)) { |
85 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
85 | throw new Exception('Directory "'.$system_dir.'" not found.'); |
86 | } |
86 | } |
87 | 87 | ||
88 | $version = $this->get_phpmyadmin_version($system_dir); |
88 | $version = $this->get_phpmyadmin_version($system_dir); |
89 | 89 | ||
90 | $cont = @file_get_contents('https://www.phpmyadmin.net/home_page/version.json'); // alternatively version.php |
90 | $cont = @file_get_contents('https://www.phpmyadmin.net/home_page/version.json'); // alternatively version.php |
91 | if (!$cont) { |
91 | if (!$cont) { |
92 | throw new Exception('Cannot parse version from phpMyAdmin website. The plugin probably needs to be updated.'); |
92 | throw new Exception('Cannot parse version from phpMyAdmin website. The plugin probably needs to be updated.'); |
93 | } |
93 | } |
94 | 94 | ||
95 | $json = json_decode($cont, true); |
95 | $json = json_decode($cont, true); |
96 | $latest_version = $json['version']; |
96 | $latest_version = $json['version']; |
97 | 97 | ||
98 | if ($version == $latest_version) { |
98 | if (version_compare($version,$latest_version) >= 0) { |
99 | $this->setStatus(VNag::STATUS_OK); |
99 | $this->setStatus(VNag::STATUS_OK); |
- | 100 | if ($version == $latest_version) { |
|
100 | $this->setHeadline("Version $version (Latest version) at $system_dir", true); |
101 | $this->setHeadline("Version $version (Latest version) at $system_dir", true); |
101 | } else { |
102 | } else { |
- | 103 | $this->setHeadline("Version $version (Latest version $latest_version) at $system_dir", true); |
|
- | 104 | } |
|
- | 105 | } else { |
|
102 | $this->setStatus(VNag::STATUS_WARNING); |
106 | $this->setStatus(VNag::STATUS_WARNING); |
103 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
107 | $this->setHeadline("Version $version is outdated (Latest version is $latest_version) at $system_dir", true); |
104 | } |
108 | } |
105 | } |
109 | } |
106 | } |
110 | } |
107 | 111 |