mirror of
https://framagit.org/fiat-tux/hat-softwares/lutim.git
synced 2026-08-06 08:53:03 +02:00
Fix #29
Configurable antiflood protection for the "Download by URL" feature
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
Revision history for LUTIm
|
||||
|
||||
0.3 2014-
|
||||
- Antiflood protection for the "Download by URL" feature (#29)
|
||||
|
||||
0.2 2014-03-07
|
||||
- Server-side encryption available
|
||||
- Thumbnails of uploaded images in response
|
||||
|
||||
+14
-6
@@ -10,16 +10,19 @@ mkdir($ENV{MOJO_TMPDIR}, 0700) unless (-d $ENV{MOJO_TMPDIR});
|
||||
sub startup {
|
||||
my $self = shift;
|
||||
|
||||
$self->{wait_for_it} = {};
|
||||
|
||||
$self->plugin('I18N');
|
||||
|
||||
my $config = $self->plugin('Config');
|
||||
|
||||
# Default values
|
||||
$config->{provisioning} = 100 unless (defined($config->{provisionning}));
|
||||
$config->{provisioning} = 100 unless (defined($config->{provisioning}));
|
||||
$config->{provis_step} = 5 unless (defined($config->{provis_step}));
|
||||
$config->{length} = 8 unless (defined($config->{length}));
|
||||
$config->{always_encrypt} = 0 unless (defined($config->{always_encrypt}));
|
||||
$config->{provisioning} = 100 unless (defined($config->{provisionning}));
|
||||
$config->{provisioning} = 100 unless (defined($config->{provisioning}));
|
||||
$config->{provis_step} = 5 unless (defined($config->{provis_step}));
|
||||
$config->{length} = 8 unless (defined($config->{length}));
|
||||
$config->{always_encrypt} = 0 unless (defined($config->{always_encrypt}));
|
||||
$config->{anti_flood_delay} = 5 unless (defined($config->{anti_flood_delay}));
|
||||
|
||||
die "You need to provide a contact information in lutim.conf !" unless (defined($config->{contact}));
|
||||
|
||||
@@ -257,7 +260,12 @@ sub startup {
|
||||
|
||||
$self->hook(
|
||||
after_dispatch => sub {
|
||||
shift->provisioning();
|
||||
my $c = shift;
|
||||
$c->provisioning();
|
||||
|
||||
# Purge expired anti-flood protection
|
||||
my $wait_for_it = $c->app->{wait_for_it};
|
||||
delete @{$wait_for_it}{grep { time - $wait_for_it->{$_} > $c->config->{anti_flood_delay} } keys %{$wait_for_it}} if (defined($wait_for_it));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ sub add {
|
||||
if(!defined($c->stash('stop_upload'))) {
|
||||
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} ) {
|
||||
sleep($c->config->{anti_flood_delay});
|
||||
}
|
||||
my $ua = Mojo::UserAgent->new;
|
||||
my $tx = $ua->get($file_url => {DNT => 1});
|
||||
if (my $res = $tx->success) {
|
||||
@@ -66,6 +70,7 @@ sub add {
|
||||
asset => $tx->res->content->asset,
|
||||
filename => $filename
|
||||
);
|
||||
$c->app->{wait_for_it}->{$c->ip} = time;
|
||||
} else {
|
||||
my $msg = $c->l('download_error');
|
||||
if (defined($c->param('format')) && $c->param('format') eq 'json') {
|
||||
|
||||
@@ -39,6 +39,11 @@
|
||||
# optional, default is 100
|
||||
#provisioning => 100,
|
||||
|
||||
# anti-flood protection delay, in seconds
|
||||
# users won't be able to ask LUTIm to download images more than one per anti_flood_delay seconds
|
||||
# optional, default is 5
|
||||
#anti_flood_delay => 5
|
||||
|
||||
# twitter account which will appear on twitter cards
|
||||
# see https://dev.twitter.com/docs/cards/validation/validator to register your LUTIm instance on twitter
|
||||
# optional, default is @framasky
|
||||
|
||||
Reference in New Issue
Block a user