summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Bugzilla/CGI/Mojo.pm13
-rw-r--r--Bugzilla/Util.pm31
-rwxr-xr-xnew.psgi17
3 files changed, 46 insertions, 15 deletions
diff --git a/Bugzilla/CGI/Mojo.pm b/Bugzilla/CGI/Mojo.pm
index 0ae12f976..e3adf1133 100644
--- a/Bugzilla/CGI/Mojo.pm
+++ b/Bugzilla/CGI/Mojo.pm
@@ -20,10 +20,21 @@ sub script_name {
return $self->controller->req->env->{SCRIPT_NAME};
}
+sub http {
+ my ($self, $header) = @_;
+ return $self->controller->req->headers->header($header);
+}
+
+sub redirect {
+ my ($self, $location) = @_;
+
+ $self->controller->redirect_to($location);
+}
+
sub Vars {
my ($self) = @_;
return $self->controller->req->query_params->to_hash;
}
-1; \ No newline at end of file
+1;
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index a1316c7ef..206c0aa3f 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -321,21 +321,26 @@ sub do_ssl_redirect_if_required {
# Returns the real remote address of the client,
sub remote_ip {
- my $remote_ip = $ENV{'REMOTE_ADDR'} || '127.0.0.1';
- my @proxies = split(/[\s,]+/, Bugzilla->localconfig->{inbound_proxies});
- my @x_forwarded_for = split(/[\s,]+/, $ENV{HTTP_X_FORWARDED_FOR} // '');
-
- return $remote_ip unless @x_forwarded_for;
- return $x_forwarded_for[0] if @proxies && $proxies[0] eq '*';
- return $remote_ip if none { $_ eq $remote_ip } @proxies;
-
- foreach my $ip (reverse @x_forwarded_for) {
- if (none { $_ eq $ip } @proxies) {
- # Keep the original IP address if the remote IP is invalid.
- return validate_ip($ip) || $remote_ip;
+ if (Bugzilla->usage_mode == USAGE_MODE_MOJO) {
+ return Bugzilla->cgi->controller->tx->remote_address;
+ }
+ else {
+ my $remote_ip = $ENV{'REMOTE_ADDR'} || '127.0.0.1';
+ my @proxies = split(/[\s,]+/, Bugzilla->localconfig->{inbound_proxies});
+ my @x_forwarded_for = split(/[\s,]+/, $ENV{HTTP_X_FORWARDED_FOR} // '');
+
+ return $remote_ip unless @x_forwarded_for;
+ return $x_forwarded_for[0] if @proxies && $proxies[0] eq '*';
+ return $remote_ip if none { $_ eq $remote_ip } @proxies;
+
+ foreach my $ip (reverse @x_forwarded_for) {
+ if (none { $_ eq $ip } @proxies) {
+ # Keep the original IP address if the remote IP is invalid.
+ return validate_ip($ip) || $remote_ip;
+ }
}
+ return $remote_ip;
}
- return $remote_ip;
}
sub validate_ip {
diff --git a/new.psgi b/new.psgi
index 8f1484d91..7685a7392 100755
--- a/new.psgi
+++ b/new.psgi
@@ -1,4 +1,17 @@
#!/usr/bin/env perl
+use 5.10.1;
+use strict;
+use warnings;
+
+use File::Basename qw(basename dirname);
+use File::Spec::Functions qw(catdir rel2abs);
+
+BEGIN {
+ require lib;
+ my $dir = rel2abs( dirname(__FILE__) );
+ lib->import( $dir, catdir( $dir, 'lib' ), catdir( $dir, qw(local lib perl5) ) );
+}
+
use Mojolicious::Lite;
use Bugzilla::Constants;
use Bugzilla::CGI::Mojo;
@@ -6,7 +19,6 @@ use Try::Tiny;
plugin 'PODRenderer';
-
app->hook(
around_dispatch => sub {
my ($next, $c) = @_;
@@ -33,9 +45,12 @@ __DATA__
@@ index.html.ep
% layout 'default';
% title 'Welcome';
+% use Bugzilla::Util qw(remote_ip);
<p>Hello, <%= $user->name %> &lt;<%= $user->email %>&gt;
</p>
+<p>Your ip is <%= remote_ip() %>
+</p>
@@ layouts/default.html.ep
<!DOCTYPE html>