Jump to content

mod_authz_dbd Custom DB Query


apacheguy

Recommended Posts

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 in

Require dbd-login
AuthzDBDQuery "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-login
AuthzDBDQuery "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?

Link to comment
Share on other sites

  • 2 months later...


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;
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.