#!/usr/bin/perl
#
# mod_perl startup file. 
#
# This file is used for pre-loading perl code for use under 
# Apache::Registry, or for creating mod_perl handlers. See:
#
#       http://perl.apache.org/guide/
#
# for more information.
#

# Automatically fix up the REMOTE_IP environment variable.
use lib '/var/home/slowtwitch/slowtwitch.com/cgi-bin/articles/admin';
use Links::mod_perl;
use Apache2::Connection ();
use Apache2::RequestRec ();
use APR::Table ();

sub My::ProxyRemoteAddr ($) {
# ------------------------------------------------
    my $r = shift;
    my $c = $r->connection();
    my $ip = $c->remote_ip;
    unless ($ip eq '127.0.0.1') {
        return OK;
    }
# Select last value in the chain -- ip from most recent proxy (to prevent fake ip injection)
    if (my ($ip) = $r->headers_in->{'X-Forwarded-For'} =~ /([^,\s]+)$/) {
        $r->connection->remote_ip($ip);
    }
    return OK;
}


# Must return a true value
1;

