apacheguy Posted February 8, 2015 Share Posted February 8, 2015 Hi all, I recently transitioned to Apache 2.4 from 2.2. I'm looking to take advantage of mod_authz_dbd to replace my Basic Auth scheme I had in place before. Per the docs on this module (http://httpd.apache.org/docs/trunk/mod/mod_authz_dbd.html), I can execute a custom statement to log a user in like this: # dbd-login action executes a statement to log user inRequire dbd-loginAuthzDBDQuery "UPDATE authn SET login = 'true' WHERE user = %s" Trouble is, I want it to log the user IP address. Apache supposedly supports calling ENV VARS from with httpd.conf, but for some reason the following code does not work: Require dbd-loginAuthzDBDQuery "INSERT INTO Logins (User, IP) VALUES (%s, '${REMOTE_ADDR}')" It inserts %{REMOTE_ADDR} instead of the actual ip address value. Any idea how I can get this to work? Quote Link to comment https://forums.phpfreaks.com/topic/294447-mod_authz_dbd-custom-db-query/ Share on other sites More sharing options...
jeffreyappel Posted April 9, 2015 Share Posted April 9, 2015 if ($this->validate_ip($ip)) return $ip; } } } if (!empty($_SERVER['HTTP_X_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_X_FORWARDED'])) return $_SERVER['HTTP_X_FORWARDED']; if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']) && $this->validate_ip($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; if (!empty($_SERVER['HTTP_FORWARDED_FOR']) && $this->validate_ip($_SERVER['HTTP_FORWARDED_FOR'])) return $_SERVER['HTTP_FORWARDED_FOR']; if (!empty($_SERVER['HTTP_FORWARDED']) && $this->validate_ip($_SERVER['HTTP_FORWARDED'])) return $_SERVER['HTTP_FORWARDED']; // Return unreliable IP address since all else failed return $_SERVER['REMOTE_ADDR']; } /** * Ensures an IP address is both a valid IP address and does not fall within * a private network range. * * @access public * @param string $ip */ public function validate_ip($ip) { if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) return false; self::$ip = $ip; return true; } Quote Link to comment https://forums.phpfreaks.com/topic/294447-mod_authz_dbd-custom-db-query/#findComment-1508559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.