From 4292802ee5f93f7ec7644c5d0a30f7ffeb95e566 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 23 Jun 2010 16:32:20 -0400 Subject: [PATCH] stop using REMOTE_ADDR 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. --- IkiWiki/CGI.pm | 2 +- IkiWiki/Plugin/attachment.pm | 5 +++-- IkiWiki/Plugin/blogspam.pm | 3 ++- IkiWiki/Plugin/comments.pm | 10 ++++++---- IkiWiki/Plugin/editpage.pm | 3 ++- IkiWiki/Plugin/lockedit.pm | 2 +- IkiWiki/Plugin/moderatedcomments.pm | 4 ++-- IkiWiki/Plugin/passwordauth.pm | 2 +- IkiWiki/Plugin/poll.pm | 3 ++- IkiWiki/Plugin/remove.pm | 3 ++- IkiWiki/Plugin/rename.pm | 8 +++++--- IkiWiki/Receive.pm | 1 - 12 files changed, 27 insertions(+), 19 deletions(-) diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm index 28020b500..f2a32a958 100644 --- a/IkiWiki/CGI.pm +++ b/IkiWiki/CGI.pm @@ -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; diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index ce688ca40..216e00b3d 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -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(); } diff --git a/IkiWiki/Plugin/blogspam.pm b/IkiWiki/Plugin/blogspam.pm index c4e5cf390..8db3780e8 100644 --- a/IkiWiki/Plugin/blogspam.pm +++ b/IkiWiki/Plugin/blogspam.pm @@ -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} : "", diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index d1558001a..4770209c9 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -402,8 +402,8 @@ sub editcomment ($$) { $username =~ s/"/"/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(); } diff --git a/IkiWiki/Plugin/editpage.pm b/IkiWiki/Plugin/editpage.pm index 3ba6c519e..a8e75121f 100644 --- a/IkiWiki/Plugin/editpage.pm +++ b/IkiWiki/Plugin/editpage.pm @@ -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(); } diff --git a/IkiWiki/Plugin/lockedit.pm b/IkiWiki/Plugin/lockedit.pm index 1466e8337..5b50fd115 100644 --- a/IkiWiki/Plugin/lockedit.pm +++ b/IkiWiki/Plugin/lockedit.pm @@ -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")) && diff --git a/IkiWiki/Plugin/moderatedcomments.pm b/IkiWiki/Plugin/moderatedcomments.pm index ff2c2b160..5957833fc 100644 --- a/IkiWiki/Plugin/moderatedcomments.pm +++ b/IkiWiki/Plugin/moderatedcomments.pm @@ -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"); } diff --git a/IkiWiki/Plugin/passwordauth.pm b/IkiWiki/Plugin/passwordauth.pm index baddca093..35ebd961f 100644 --- a/IkiWiki/Plugin/passwordauth.pm +++ b/IkiWiki/Plugin/passwordauth.pm @@ -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}; diff --git a/IkiWiki/Plugin/poll.pm b/IkiWiki/Plugin/poll.pm index 6bc4579c2..e50efa5e0 100644 --- a/IkiWiki/Plugin/poll.pm +++ b/IkiWiki/Plugin/poll.pm @@ -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(); } diff --git a/IkiWiki/Plugin/remove.pm b/IkiWiki/Plugin/remove.pm index d23b2cc10..b664cbf74 100644 --- a/IkiWiki/Plugin/remove.pm +++ b/IkiWiki/Plugin/remove.pm @@ -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(); } diff --git a/IkiWiki/Plugin/rename.pm b/IkiWiki/Plugin/rename.pm index 0da90a538..977c09e67 100644 --- a/IkiWiki/Plugin/rename.pm +++ b/IkiWiki/Plugin/rename.pm @@ -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; } diff --git a/IkiWiki/Receive.pm b/IkiWiki/Receive.pm index ae1bd8bef..fdd463025 100644 --- a/IkiWiki/Receive.pm +++ b/IkiWiki/Receive.pm @@ -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; -- 2.26.2