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.
master
Joey Hess 2010-06-23 16:32:20 -04:00
parent b4a43406f6
commit 4292802ee5
12 changed files with 27 additions and 19 deletions

View File

@ -283,7 +283,7 @@ sub check_banned ($$) {
foreach my $b (@{$config{banned_users}}) { foreach my $b (@{$config{banned_users}}) {
if (pagespec_match("", $b, if (pagespec_match("", $b,
ip => $ENV{REMOTE_ADDR}, ip => $session->remote_addr(),
name => defined $name ? $name : "", name => defined $name ? $name : "",
)) { )) {
$banned=1; $banned=1;

View File

@ -58,7 +58,7 @@ sub check_canattach ($$;$) {
$config{allowed_attachments}, $config{allowed_attachments},
file => $file, file => $file,
user => $session->param("name"), user => $session->param("name"),
ip => $ENV{REMOTE_ADDR}, ip => $session->remote_addr(),
); );
} }
@ -185,7 +185,8 @@ sub formbuilder (@) {
IkiWiki::disable_commit_hook(); IkiWiki::disable_commit_hook();
IkiWiki::rcs_commit($filename, gettext("attachment upload"), IkiWiki::rcs_commit($filename, gettext("attachment upload"),
IkiWiki::rcs_prepedit($filename), IkiWiki::rcs_prepedit($filename),
$session->param("name"), $ENV{REMOTE_ADDR}); $session->param("name"),
$session->remote_addr());
IkiWiki::enable_commit_hook(); IkiWiki::enable_commit_hook();
IkiWiki::rcs_update(); IkiWiki::rcs_update();
} }

View File

@ -58,6 +58,7 @@ sub checkconfig () {
sub checkcontent (@) { sub checkcontent (@) {
my %params=@_; my %params=@_;
my $session=$params{session};
if (exists $config{blogspam_pagespec}) { if (exists $config{blogspam_pagespec}) {
return undef return undef
@ -88,7 +89,7 @@ sub checkcontent (@) {
push @options, "exclude=stopwords"; push @options, "exclude=stopwords";
my %req=( my %req=(
ip => $ENV{REMOTE_ADDR}, ip => $session->remote_addr(),
comment => defined $params{diff} ? $params{diff} : $params{content}, comment => defined $params{diff} ? $params{diff} : $params{content},
subject => defined $params{subject} ? $params{subject} : "", subject => defined $params{subject} ? $params{subject} : "",
name => defined $params{author} ? $params{author} : "", name => defined $params{author} ? $params{author} : "",

View File

@ -402,8 +402,8 @@ sub editcomment ($$) {
$username =~ s/"/"/g; $username =~ s/"/"/g;
$content .= " username=\"$username\"\n"; $content .= " username=\"$username\"\n";
} }
elsif (defined $ENV{REMOTE_ADDR}) { elsif (defined $session->remote_addr()) {
my $ip = $ENV{REMOTE_ADDR}; my $ip = $session->remote_addr();
if ($ip =~ m/^([.0-9]+)$/) { if ($ip =~ m/^([.0-9]+)$/) {
$content .= " ip=\"$1\"\n"; $content .= " ip=\"$1\"\n";
} }
@ -514,7 +514,8 @@ sub editcomment ($$) {
IkiWiki::rcs_add($file); IkiWiki::rcs_add($file);
IkiWiki::disable_commit_hook(); IkiWiki::disable_commit_hook();
$conflict = IkiWiki::rcs_commit_staged($message, $conflict = IkiWiki::rcs_commit_staged($message,
$session->param('name'), $ENV{REMOTE_ADDR}); $session->param('name'),
$session->remote_addr());
IkiWiki::enable_commit_hook(); IkiWiki::enable_commit_hook();
IkiWiki::rcs_update(); IkiWiki::rcs_update();
} }
@ -603,7 +604,8 @@ sub commentmoderation ($$) {
my $message = gettext("Comment moderation"); my $message = gettext("Comment moderation");
IkiWiki::disable_commit_hook(); IkiWiki::disable_commit_hook();
$conflict=IkiWiki::rcs_commit_staged($message, $conflict=IkiWiki::rcs_commit_staged($message,
$session->param('name'), $ENV{REMOTE_ADDR}); $session->param('name'),
$session->remote_addr());
IkiWiki::enable_commit_hook(); IkiWiki::enable_commit_hook();
IkiWiki::rcs_update(); IkiWiki::rcs_update();
} }

View File

@ -403,7 +403,8 @@ sub cgi_editpage ($$) {
disable_commit_hook(); disable_commit_hook();
$conflict=rcs_commit($file, $message, $conflict=rcs_commit($file, $message,
$form->field("rcsinfo"), $form->field("rcsinfo"),
$session->param("name"), $ENV{REMOTE_ADDR}); $session->param("name"),
$session->remote_addr());
enable_commit_hook(); enable_commit_hook();
rcs_update(); rcs_update();
} }

View File

@ -38,7 +38,7 @@ sub canedit ($$) {
if (defined $config{locked_pages} && length $config{locked_pages} && if (defined $config{locked_pages} && length $config{locked_pages} &&
pagespec_match($page, $config{locked_pages}, pagespec_match($page, $config{locked_pages},
user => $session->param("name"), user => $session->param("name"),
ip => $ENV{REMOTE_ADDR}, ip => $session->remote_addr(),
)) { )) {
if ((! defined $user || if ((! defined $user ||
! IkiWiki::userinfo_get($session->param("name"), "regdate")) && ! IkiWiki::userinfo_get($session->param("name"), "regdate")) &&

View File

@ -48,11 +48,11 @@ sub checkcontent (@) {
} }
my $session=$params{session}; my $session=$params{session};
my $user=$session->param("name") if $session; my $user=$session->param("name");
if (pagespec_match($params{page}, $config{moderate_pagespec}, if (pagespec_match($params{page}, $config{moderate_pagespec},
location => $params{page}, location => $params{page},
(defined $user ? (user => $user) : ()), (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"); return gettext("comment needs moderation");
} }

View File

@ -297,7 +297,7 @@ sub formbuilder (@) {
), ),
wikiurl => $config{url}, wikiurl => $config{url},
wikiname => $config{wikiname}, wikiname => $config{wikiname},
REMOTE_ADDR => $ENV{REMOTE_ADDR}, remote_addr => $session->remote_addr(),
); );
eval q{use Mail::Sendmail}; eval q{use Mail::Sendmail};

View File

@ -136,7 +136,8 @@ sub sessioncgi ($$) {
IkiWiki::disable_commit_hook(); IkiWiki::disable_commit_hook();
IkiWiki::rcs_commit($pagesources{$page}, "poll vote ($choice)", IkiWiki::rcs_commit($pagesources{$page}, "poll vote ($choice)",
IkiWiki::rcs_prepedit($pagesources{$page}), IkiWiki::rcs_prepedit($pagesources{$page}),
$session->param("name"), $ENV{REMOTE_ADDR}); $session->param("name"),
$session->remote_addr());
IkiWiki::enable_commit_hook(); IkiWiki::enable_commit_hook();
IkiWiki::rcs_update(); IkiWiki::rcs_update();
} }

View File

@ -214,7 +214,8 @@ sub sessioncgi ($$) {
IkiWiki::rcs_remove($file); IkiWiki::rcs_remove($file);
} }
IkiWiki::rcs_commit_staged(gettext("removed"), IkiWiki::rcs_commit_staged(gettext("removed"),
$session->param("name"), $ENV{REMOTE_ADDR}); $session->param("name"),
$session->remote_addr());
IkiWiki::enable_commit_hook(); IkiWiki::enable_commit_hook();
IkiWiki::rcs_update(); IkiWiki::rcs_update();
} }

View File

@ -350,7 +350,9 @@ sub sessioncgi ($$) {
} }
IkiWiki::rcs_commit_staged( IkiWiki::rcs_commit_staged(
sprintf(gettext("rename %s to %s"), $srcfile, $destfile), 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. # Then link fixups.
foreach my $rename (@torename) { foreach my $rename (@torename) {
@ -576,7 +578,7 @@ sub fixlinks ($$$) {
sprintf(gettext("update for rename of %s to %s"), $rename->{srcfile}, $rename->{destfile}), sprintf(gettext("update for rename of %s to %s"), $rename->{srcfile}, $rename->{destfile}),
$token, $token,
$session->param("name"), $session->param("name"),
$ENV{REMOTE_ADDR} $session->remote_addr(),
); );
push @fixedlinks, $page if ! defined $conflict; push @fixedlinks, $page if ! defined $conflict;
} }

View File

@ -57,7 +57,6 @@ sub test () {
eval q{use CGI}; eval q{use CGI};
error($@) if $@; error($@) if $@;
my $cgi=CGI->new; my $cgi=CGI->new;
$ENV{REMOTE_ADDR}='unknown' unless exists $ENV{REMOTE_ADDR};
# And dummy up a session object. # And dummy up a session object.
require IkiWiki::CGI; require IkiWiki::CGI;