stop using REMOTE_ADDR
authorJoey Hess <joey@kitenet.net>
Wed, 23 Jun 2010 20:32:20 +0000 (16:32 -0400)
committerJoey Hess <joey@kitenet.net>
Wed, 23 Jun 2010 20:35:51 +0000 (16:35 -0400)
Everywhere that REMOTE_ADDR was used, a session object is available, so
instead use its remote_addr method.

In IkiWiki::Receive, stop setting a dummy REMOTE_ADDR.

Note that it's possible for a session cookie to be obtained using one IP
address, and then used from another IP. In this case, the first IP will now
be used. I think that should be ok.

12 files changed:
IkiWiki/CGI.pm
IkiWiki/Plugin/attachment.pm
IkiWiki/Plugin/blogspam.pm
IkiWiki/Plugin/comments.pm
IkiWiki/Plugin/editpage.pm
IkiWiki/Plugin/lockedit.pm
IkiWiki/Plugin/moderatedcomments.pm
IkiWiki/Plugin/passwordauth.pm
IkiWiki/Plugin/poll.pm
IkiWiki/Plugin/remove.pm
IkiWiki/Plugin/rename.pm
IkiWiki/Receive.pm

index 28020b500c830bafc52cf49c3ba75bc5dfca1ce4..f2a32a9581077553d5b542fde40f428c15a5e41a 100644 (file)
@@ -283,7 +283,7 @@ sub check_banned ($$) {
 
        foreach my $b (@{$config{banned_users}}) {
                if (pagespec_match("", $b,
-                       ip => $ENV{REMOTE_ADDR},
+                       ip => $session->remote_addr(),
                        name => defined $name ? $name : "",
                )) {
                        $banned=1;
index ce688ca40df0f8c13f9f09206e54a871438a2f10..216e00b3d2117bafc75aaefb66bde815c36cc949 100644 (file)
@@ -58,7 +58,7 @@ sub check_canattach ($$;$) {
                        $config{allowed_attachments},
                        file => $file,
                        user => $session->param("name"),
-                       ip => $ENV{REMOTE_ADDR},
+                       ip => $session->remote_addr(),
                );
        }
 
@@ -185,7 +185,8 @@ sub formbuilder (@) {
                        IkiWiki::disable_commit_hook();
                        IkiWiki::rcs_commit($filename, gettext("attachment upload"),
                                IkiWiki::rcs_prepedit($filename),
-                               $session->param("name"), $ENV{REMOTE_ADDR});
+                               $session->param("name"),
+                               $session->remote_addr());
                        IkiWiki::enable_commit_hook();
                        IkiWiki::rcs_update();
                }
index c4e5cf390cb397a994414bf718c135b4bf498c22..8db3780e8888ee9c9188881e80ae26b6715436ff 100644 (file)
@@ -58,6 +58,7 @@ sub checkconfig () {
 
 sub checkcontent (@) {
        my %params=@_;
+       my $session=$params{session};
        
        if (exists $config{blogspam_pagespec}) {
                return undef
@@ -88,7 +89,7 @@ sub checkcontent (@) {
        push @options, "exclude=stopwords";
 
        my %req=(
-               ip => $ENV{REMOTE_ADDR},
+               ip => $session->remote_addr(),
                comment => defined $params{diff} ? $params{diff} : $params{content},
                subject => defined $params{subject} ? $params{subject} : "",
                name => defined $params{author} ? $params{author} : "",
index d1558001aeff7b177a907d5be34f958df30692a1..4770209c9d556d1bc819c8d32e5c77776f1bbe42 100644 (file)
@@ -402,8 +402,8 @@ sub editcomment ($$) {
                $username =~ s/"/&quot;/g;
                $content .= " username=\"$username\"\n";
        }
-       elsif (defined $ENV{REMOTE_ADDR}) {
-               my $ip = $ENV{REMOTE_ADDR};
+       elsif (defined $session->remote_addr()) {
+               my $ip = $session->remote_addr();
                if ($ip =~ m/^([.0-9]+)$/) {
                        $content .= " ip=\"$1\"\n";
                }
@@ -514,7 +514,8 @@ sub editcomment ($$) {
                        IkiWiki::rcs_add($file);
                        IkiWiki::disable_commit_hook();
                        $conflict = IkiWiki::rcs_commit_staged($message,
-                               $session->param('name'), $ENV{REMOTE_ADDR});
+                               $session->param('name'),
+                               $session->remote_addr());
                        IkiWiki::enable_commit_hook();
                        IkiWiki::rcs_update();
                }
@@ -603,7 +604,8 @@ sub commentmoderation ($$) {
                                my $message = gettext("Comment moderation");
                                IkiWiki::disable_commit_hook();
                                $conflict=IkiWiki::rcs_commit_staged($message,
-                                       $session->param('name'), $ENV{REMOTE_ADDR});
+                                       $session->param('name'),
+                                       $session->remote_addr());
                                IkiWiki::enable_commit_hook();
                                IkiWiki::rcs_update();
                        }
index 3ba6c519e9bafeb304faca37eea975e00c53a486..a8e75121fd672d6ee19557305433c95360582f19 100644 (file)
@@ -403,7 +403,8 @@ sub cgi_editpage ($$) {
                        disable_commit_hook();
                        $conflict=rcs_commit($file, $message,
                                $form->field("rcsinfo"),
-                               $session->param("name"), $ENV{REMOTE_ADDR});
+                               $session->param("name"),
+                               $session->remote_addr());
                        enable_commit_hook();
                        rcs_update();
                }
index 1466e8337f5f16c74c6f809f7af7a62bfadfb56e..5b50fd11509c07cf301b6f9a500331bff4392f93 100644 (file)
@@ -38,7 +38,7 @@ sub canedit ($$) {
        if (defined $config{locked_pages} && length $config{locked_pages} &&
            pagespec_match($page, $config{locked_pages},
                    user => $session->param("name"),
-                   ip => $ENV{REMOTE_ADDR},
+                   ip => $session->remote_addr(),
            )) {
                if ((! defined $user ||
                    ! IkiWiki::userinfo_get($session->param("name"), "regdate")) &&
index ff2c2b160a0bded7228384470b2be27f302d9cdd..5957833fc2de44dc20484f616f8813ff0306400b 100644 (file)
@@ -48,11 +48,11 @@ sub checkcontent (@) {
        }
 
        my $session=$params{session};
-       my $user=$session->param("name") if $session;
+       my $user=$session->param("name");
        if (pagespec_match($params{page}, $config{moderate_pagespec},
                        location => $params{page},
                        (defined $user ? (user => $user) : ()),
-                       (defined $ENV{REMOTE_ADDR} ? (ip => $ENV{REMOTE_ADDR}) : ()),
+                       (defined $session->remote_addr() ? (ip => $session->remote_addr()) : ()),
        )) {
                return gettext("comment needs moderation");
        }
index baddca0939031d883a564e2440a7c63f45722900..35ebd961f53e8da8e2a012d970f8d309d135a307 100644 (file)
@@ -297,7 +297,7 @@ sub formbuilder (@) {
                                        ),
                                        wikiurl => $config{url},
                                        wikiname => $config{wikiname},
-                                       REMOTE_ADDR => $ENV{REMOTE_ADDR},
+                                       remote_addr => $session->remote_addr(),
                                );
                                
                                eval q{use Mail::Sendmail};
index 6bc4579c2547a34691b0274bdeec7b054336a651..e50efa5e093c5764a6156c636b23948db809e7cb 100644 (file)
@@ -136,7 +136,8 @@ sub sessioncgi ($$) {
                        IkiWiki::disable_commit_hook();
                        IkiWiki::rcs_commit($pagesources{$page}, "poll vote ($choice)",
                                IkiWiki::rcs_prepedit($pagesources{$page}),
-                               $session->param("name"), $ENV{REMOTE_ADDR});
+                               $session->param("name"),
+                               $session->remote_addr());
                        IkiWiki::enable_commit_hook();
                        IkiWiki::rcs_update();
                }
index d23b2cc1016851ac537303f9a3438df7446f40bd..b664cbf744a14c10b279f0892f0a0a89041328b8 100644 (file)
@@ -214,7 +214,8 @@ sub sessioncgi ($$) {
                                        IkiWiki::rcs_remove($file);
                                }
                                IkiWiki::rcs_commit_staged(gettext("removed"),
-                                       $session->param("name"), $ENV{REMOTE_ADDR});
+                                       $session->param("name"),
+                                       $session->remote_addr());
                                IkiWiki::enable_commit_hook();
                                IkiWiki::rcs_update();
                        }
index 0da90a538cb15b1e8f7b2b6a162a8f170ecb61bc..977c09e67f18ff033638514f6563840cda265314 100644 (file)
@@ -350,7 +350,9 @@ sub sessioncgi ($$) {
                        }
                        IkiWiki::rcs_commit_staged(
                                sprintf(gettext("rename %s to %s"), $srcfile, $destfile),
-                               $session->param("name"), $ENV{REMOTE_ADDR}) if $config{rcs};
+                               $session->param("name"),
+                               $session->remote_addr(),
+                       ) if $config{rcs};
 
                        # Then link fixups.
                        foreach my $rename (@torename) {
@@ -575,8 +577,8 @@ sub fixlinks ($$$) {
                                        $file,
                                        sprintf(gettext("update for rename of %s to %s"), $rename->{srcfile}, $rename->{destfile}),
                                        $token,
-                                       $session->param("name"), 
-                                       $ENV{REMOTE_ADDR}
+                                       $session->param("name"),
+                                       $session->remote_addr(),
                                );
                                push @fixedlinks, $page if ! defined $conflict;
                        }
index ae1bd8bef44c8b6918f2d2ced55c2074d8bbca13..fdd463025457f918458168a2671f7c97dd2a37ab 100644 (file)
@@ -57,7 +57,6 @@ sub test () {
        eval q{use CGI};
        error($@) if $@;
        my $cgi=CGI->new;
-       $ENV{REMOTE_ADDR}='unknown' unless exists $ENV{REMOTE_ADDR};
 
        # And dummy up a session object.
        require IkiWiki::CGI;