From b39835331ccddd3290b65b8fb3c9463eee2b2d7f Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Fri, 31 Jul 2015 09:35:51 +0200 Subject: [PATCH] Replace GetRemoteHost with $q->remote_addr() --- modules/admin.pl | 6 +++--- modules/ban-quick-editors.pl | 2 +- modules/drafts.pl | 4 ++-- modules/logbannedcontent.pl | 2 +- modules/open-proxy.pl | 6 +++--- modules/recaptcha.pl | 2 +- modules/static-hybrid.pl | 2 +- wiki.pl | 16 ++++++---------- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/modules/admin.pl b/modules/admin.pl index 8b6bdbe3..38ed804a 100644 --- a/modules/admin.pl +++ b/modules/admin.pl @@ -39,7 +39,7 @@ sub AdminPowerDelete { } else { print $q->p(GetPageLink($id) . ' ' . T('deleted')); WriteRcLog($id, Ts('Deleted %s', $id), 0, $Page{revision}, - GetParam('username', ''), GetRemoteHost(), $Page{languages}, + GetParam('username', ''), $q->remote_addr(), $Page{languages}, GetCluster($Page{text})); } # Regenerate index on next request @@ -88,10 +88,10 @@ sub AdminPowerRename { # RecentChanges OpenPage($new); WriteRcLog($id, Ts('Renamed to %s', $new), 0, $Page{revision}, - GetParam('username', ''), GetRemoteHost(), $Page{languages}, + GetParam('username', ''), $q->remote_addr(), $Page{languages}, GetCluster($Page{text})); WriteRcLog($new, Ts('Renamed from %s', $id), 0, $Page{revision}, - GetParam('username', ''), GetRemoteHost(), $Page{languages}, + GetParam('username', ''), $q->remote_addr(), $Page{languages}, GetCluster($Page{text})); print $q->p(Tss('Renamed %1 to %2.', GetPageLink($id), GetPageLink($new))); ReleaseLock(); diff --git a/modules/ban-quick-editors.pl b/modules/ban-quick-editors.pl index 989fa107..d429c1ee 100644 --- a/modules/ban-quick-editors.pl +++ b/modules/ban-quick-editors.pl @@ -29,7 +29,7 @@ sub BanQuickNewUserIsBanned { if (not $rule and $SurgeProtection # need surge protection and GetParam('title')) { - my $name = GetParam('username', GetRemoteHost()); + my $name = GetParam('username', $q->remote_addr()); my @entries = @{$RecentVisitors{$name}}; # $entry[0] is $Now after AddRecentVisitor my $ts = $entries[1]; diff --git a/modules/drafts.pl b/modules/drafts.pl index 3ef6c0b1..c68d3b0e 100644 --- a/modules/drafts.pl +++ b/modules/drafts.pl @@ -28,7 +28,7 @@ push(@MyInitVariables, \&DraftInit); sub DraftInit { if (GetParam('Draft', '')) { SetParam('action', 'draft') ; # Draft button used - } elsif (-f "$DraftDir/" . GetParam('username', GetRemoteHost()) # draft exists + } elsif (-f "$DraftDir/" . GetParam('username', $q->remote_addr()) # draft exists and $FooterNote !~ /action=draft/) { # take care of mod_perl persistence $FooterNote = $q->p(ScriptLink('action=draft', T('Recover Draft'))) . $FooterNote; } @@ -38,7 +38,7 @@ $Action{draft} = \&DoDraft; sub DoDraft { my $id = shift; - my $draft = $DraftDir . '/' . GetParam('username', GetRemoteHost()); + my $draft = $DraftDir . '/' . GetParam('username', $q->remote_addr()); if ($id) { my $text = GetParam('text', ''); ReportError(T('No text to save'), '400 BAD REQUEST') unless $text; diff --git a/modules/logbannedcontent.pl b/modules/logbannedcontent.pl index 83df4838..31efa3bc 100644 --- a/modules/logbannedcontent.pl +++ b/modules/logbannedcontent.pl @@ -47,6 +47,6 @@ sub LogWrite { my $rule = shift; my $id = $OpenPageName || GetId(); AppendStringToFile($BannedFile, - join("\t", TimeToW3($Now), GetRemoteHost(), $id, $rule) + join("\t", TimeToW3($Now), $q->remote_addr(), $id, $rule) . "\n"); } diff --git a/modules/open-proxy.pl b/modules/open-proxy.pl index 6e993e37..c2052529 100644 --- a/modules/open-proxy.pl +++ b/modules/open-proxy.pl @@ -36,10 +36,10 @@ $Action{$SelfBan} = \&DoSelfBan; sub DoSelfBan { my $date = &TimeToText($Now); - my $str = '^' . quotemeta(GetRemoteHost()); + my $str = '^' . quotemeta($q->remote_addr()); OpenPage($BannedHosts); Save ($BannedHosts, $Page{text} . "\n\nself-ban on $date\n $str", - Ts("Self-ban by %s", GetRemoteHost()), 1); # minor edit + Ts("Self-ban by %s", $q->remote_addr()), 1); # minor edit ReportError(T("You have banned your own IP.")); } @@ -55,7 +55,7 @@ sub OpenProxyNewDoEdit { sub BanOpenProxy { my ($force) = @_; - my $ip = GetRemoteHost(); + my $ip = $q->remote_addr(); my $limit = 60*60*24*30; # rescan after 30 days # Only check each IP address once a month my %proxy = split(/\s+/, ReadFile($OpenProxies)); diff --git a/modules/recaptcha.pl b/modules/recaptcha.pl index 06c93f35..1d575118 100644 --- a/modules/recaptcha.pl +++ b/modules/recaptcha.pl @@ -252,7 +252,7 @@ sub ReCaptchaCheckAnswer { eval "use Captcha::reCAPTCHA"; my $result = Captcha::reCAPTCHA->new()->check_answer( $ReCaptchaPrivateKey, - GetRemoteHost(), + $q->remote_addr(), GetParam('recaptcha_challenge_field'), GetParam('recaptcha_response_field') ); diff --git a/modules/static-hybrid.pl b/modules/static-hybrid.pl index 9a64990c..ee18c8b9 100644 --- a/modules/static-hybrid.pl +++ b/modules/static-hybrid.pl @@ -425,7 +425,7 @@ sub StaticNewDoRollback { } elsif (!UserCanEdit($id, 1)) { print Ts('Editing not allowed for %s.', $id), $q->br(); } else { - Save($id, $text, Ts('Rollback to %s', TimeToText($to)), $minor, ($Page{host} ne GetRemoteHost())); + Save($id, $text, Ts('Rollback to %s', TimeToText($to)), $minor, ($Page{host} ne $q->remote_addr())); StaticDeleteFile($id); print Ts('%s rolled back', GetPageLink($id)), ($ts ? ' ' . Ts('to %s', TimeToText($to)) : ''), $q->br(); } diff --git a/wiki.pl b/wiki.pl index 40e6585c..053dfc75 100755 --- a/wiki.pl +++ b/wiki.pl @@ -2087,7 +2087,7 @@ sub DoRollback { } elsif (not UserIsEditor() and my $rule = BannedContent($text)) { print Ts('Rollback of %s would restore banned content.', $id), $rule, $q->br(); } else { - Save($id, $text, Ts('Rollback to %s', TimeToText($to)), $minor, ($Page{host} ne GetRemoteHost())); + Save($id, $text, Ts('Rollback to %s', TimeToText($to)), $minor, ($Page{host} ne $q->remote_addr())); print Ts('%s rolled back', GetPageLink($id)), ($ts ? ' ' . Ts('to %s', TimeToText($to)) : ''), $q->br(); } } @@ -2180,10 +2180,6 @@ sub ScriptLinkDiff { return ScriptLink($action, $text, 'diff'); } -sub GetRemoteHost { - return $ENV{REMOTE_ADDR}; -} - sub GetAuthor { my ($host, $username) = @_; return $username . ' ' . Ts('from %s', $host) if $username and $host; @@ -3199,7 +3195,7 @@ sub UserCanEdit { sub UserIsBanned { return 0 if GetParam('action', '') eq 'password'; # login is always ok - my $host = GetRemoteHost(); + my $host = $q->remote_addr(); foreach (split(/\n/, GetPageContent($BannedHosts))) { if (/^\s*([^#]\S+)/) { # all lines except empty lines and comments, trim whitespace my $regexp = $1; @@ -3563,7 +3559,7 @@ sub Replace { }; if (s/$from/$replacement->()/gei) { # allows use of backreferences push (@result, $id); - Save($id, $_, $from . ' → ' . $to, 1, ($Page{host} ne GetRemoteHost())); + Save($id, $_, $from . ' → ' . $to, 1, ($Page{host} ne $q->remote_addr())); } } ReleaseLock(); @@ -3642,7 +3638,7 @@ sub DoPost { if ($oldrev) { # the first author (no old revision) is not considered to be "new" # prefer usernames for potential new author detection $newAuthor = 1 if not $Page{username} or $Page{username} ne GetParam('username', ''); - $newAuthor = 1 if not GetRemoteHost() or not $Page{host} or GetRemoteHost() ne $Page{host}; + $newAuthor = 1 if not $q->remote_addr() or not $Page{host} or $q->remote_addr() ne $Page{host}; } my $oldtime = $Page{ts}; my $myoldtime = GetParam('oldtime', ''); # maybe empty! @@ -3716,7 +3712,7 @@ sub AddComment { sub Save { # call within lock, with opened page my ($id, $new, $summary, $minor, $upload) = @_; my $user = GetParam('username', ''); - my $host = GetRemoteHost(); + my $host = $q->remote_addr(); my $revision = $Page{revision} + 1; my $old = $Page{text}; my $olddiff = $Page{'diff-major'} == '1' ? $Page{'diff-minor'} : $Page{'diff-major'}; @@ -3944,7 +3940,7 @@ sub DoDebug { sub DoSurgeProtection { return unless $SurgeProtection; - my $name = GetParam('username', GetRemoteHost()); + my $name = GetParam('username', $q->remote_addr()); return unless $name; ReadRecentVisitors(); AddRecentVisitor($name);