Remote port detection can now use the X-Remote-Port header if set

This commit is contained in:
Luc Didry
2014-04-30 00:54:06 +02:00
parent 6b71bbaf35
commit b0af4ccd75
3 changed files with 13 additions and 4 deletions
+1
View File
@@ -3,6 +3,7 @@ Revision history for LUTIm
0.3 2014-
- Antiflood protection for the "Download by URL" feature (#29)
- Stats page improved
- Remote port detection can now use the X-Remote-Port header if set
0.2 2014-03-07
- Server-side encryption available
+8 -1
View File
@@ -74,14 +74,19 @@ sub startup {
$self->helper(
ip => sub {
my $c = shift;
my $ip_only = shift || 0;
my $proxy = '';
my @x_forward = $c->req->headers->header('X-Forwarded-For');
for my $x (@x_forward) {
$proxy .= join(', ', @$x);
}
my $ip = ($proxy) ? $proxy : $c->tx->remote_address;
return $ip.' Remote port: '.$c->tx->remote_port;
my $remote_port = (defined($c->req->headers->header('X-Remote-Port'))) ? $c->req->headers->header('X-Remote-Port') : $c->tx->remote_port;
return ($ip_only) ? $ip : "$ip remote port:$remote_port";
}
);
@@ -243,6 +248,8 @@ sub startup {
before_dispatch => sub {
my $c = shift;
$c->stop_upload();
# API allowed domains
if (defined($c->config->{allowed_domains})) {
if ($c->config->{allowed_domains}->[0] eq '*') {
$c->res->headers->header('Access-Control-Allow-Origin' => '*');
+4 -3
View File
@@ -55,7 +55,8 @@ sub add {
if (defined($file_url) && $file_url) {
if (is_http_uri($file_url) || is_https_uri($file_url)) {
# Anti-flood protection
while (defined($c->app->{wait_for_it}->{$c->ip}) && (time - $c->app->{wait_for_it}->{$c->ip}) <= $c->config->{anti_flood_delay} ) {
my $ip = $c->ip(1);
while (defined($c->app->{wait_for_it}->{$ip}) && (time - $c->app->{wait_for_it}->{$ip}) <= $c->config->{anti_flood_delay} ) {
sleep($c->config->{anti_flood_delay});
}
my $ua = Mojo::UserAgent->new;
@@ -70,7 +71,7 @@ sub add {
asset => $res->content->asset,
filename => $filename
);
$c->app->{wait_for_it}->{$c->ip} = time;
$c->app->{wait_for_it}->{$ip} = time;
} elsif ($tx->res->is_limit_exceeded) {
my $msg = $c->l('file_too_big', $tx->res->max_message_size);
if (defined($c->param('format')) && $c->param('format') eq 'json') {
@@ -186,7 +187,7 @@ sub add {
);
# Log image creation
$c->app->log->info('[CREATION] '.$c->ip.' pushed '.$filename.' (path: '.$path.')');
$c->app->log->info('[CREATION] '.$ip.' pushed '.$filename.' (path: '.$path.')');
# Give url to user
$short = $records[0]->short;