Forum OpenACS Development: Re: ad_conn peeraddr

Collapse
10: Re: ad_conn peeraddr (response to 1)
Posted by Jay Dubanik on

Thanks Gustaf,

It worked perfectly, we get correct IPs stored in database now.

Just one correction for those who plan on adding this patch.

  1. There is no peer_addr only peeraddr should be used.
  2. The adconn -set peeraddr should be set in adproc -private rp_filter
ad_proc -private rp_filter { why } {

  This is the first filter that runs for non-resource URLs. It sets up ad_conn and handles
  session security.

} {

    #####
    #
    # Initialize the environment: reset ad_conn, and populate it with
    # a few things.
    #
    #####

    ad_conn -reset
    ad_conn -set request [nsv_incr rp_properties request_count]
    ad_conn -set user_id 0
    ad_conn -set start_clicks [clock clicks -milliseconds]

# Start of patch ReversedProxyMode
    ad_conn -set peeraddr [ns_conn peeraddr]
if { [ns_config -bool ns/parameters ReverseProxyMode 0] } {
  set addr [lindex [ns_set iget [ns_conn headers] x-forwarded-for] end]
    if {[string length $addr] > 0} {
        ad_conn -set peeraddr $addr
   }
}
# End of ReversedProxyMode

    ds_collect_connection_info