]> git.joonet.de Git - adminer.git/commitdiff
Add AdminerLoginIp
authorJakub Vrana <jakub@vrana.cz>
Fri, 19 Jul 2019 12:35:20 +0000 (14:35 +0200)
committerJakub Vrana <jakub@vrana.cz>
Fri, 19 Jul 2019 12:36:42 +0000 (14:36 +0200)
plugins/login-ip.php [new file with mode: 0644]

diff --git a/plugins/login-ip.php b/plugins/login-ip.php
new file mode 100644 (file)
index 0000000..f8363ea
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+/** Check IP address and allow empty password
+* @link https://www.adminer.org/plugins/#use
+* @author Jakub Vrana, https://www.vrana.cz/
+* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
+* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
+*/
+class AdminerLoginIp {
+       /** @access protected */
+       var $ips;
+       /** @access protected */
+       var $forwarded_for;
+       
+       /** Set allowed IP addresses
+       * @param array IP address prefixes
+       * @param array X-Forwarded-For prefixes if IP address matches, empty array means anything
+       */
+       function __construct($ips, $forwarded_for = array()) {
+               $this->ips = $ips;
+               $this->forwarded_for= $forwarded_for;
+       }
+
+       function login($login, $password) {
+               foreach ($this->ips as $ip) {
+                       if (strncasecmp($_SERVER["REMOTE_ADDR"], $ip, strlen($ip))) {
+                               if (!$this->forwarded_for) {
+                                       return true;
+                               }
+                               if ($_SERVER["HTTP_X_FORWARDED_FOR"]) {
+                                       foreach ($this->forwarded_for as $forwarded_for) {
+                                               if (strncasecmp(preg_replace('~.*, *~', '', $_SERVER["HTTP_X_FORWARDED_FOR"]), $forwarded_for, strlen($forwarded_for))) {
+                                                       return true;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return false;
+       }
+
+}