mirror of
https://framagit.org/fiat-tux/hat-softwares/lutim.git
synced 2026-07-04 08:51:31 +02:00
Remote port detection can now use the X-Remote-Port header if set
This commit is contained in:
@@ -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
@@ -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' => '*');
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user