Verified Commit 3bfa3f6b authored by Luc Didry's avatar Luc Didry
Browse files

[command][url] Allow to search several IP addresses at once

parent 907bc634
......@@ -5,6 +5,7 @@ Revision history for Perl application Lstu
deleted shortened URL)
- Slugify custom URLs and add a suffix (-2, -3…) if the custom URL is
already taken
- Allow to search several IP addresses at once
0.21-4 2018-12-17
- Add a lockfile to GSB database update to prevent concurrent updates
......
......@@ -15,10 +15,10 @@ sub run {
my @args = @_;
getopt \@args,
'info=s{1,}' => \my @info,
'info=s{1,}' => \my @info,
'r|remove=s{1,}' => \my @remove,
's|search=s' => \my $search,
'ip=s' => \my $ip,
'ip=s{1,}' => \my @ips,
'y|yes' => \my $yes;
if (scalar @info) {
......@@ -31,13 +31,13 @@ sub run {
);
}
if (scalar @remove) {
my @ips;
my @r_ips;
c(@remove)->each(
sub {
my ($e, $num) = @_;
my $u = get_short($c, $e);
if ($u) {
push @ips, $u->created_by if $u->created_by;
push @r_ips, $u->created_by if $u->created_by;
print_infos($u->to_hash);
my $confirm = ($yes) ? 'yes' : undef;
unless (defined $confirm) {
......@@ -57,34 +57,40 @@ sub run {
}
}
);
say sprintf("If you want to ban the uploaders' IPs, please do:\n carton exec script/lstu ban --ban %s", join(' ', @ips)) if @ips;
say sprintf("If you want to ban the uploaders' IPs, please do:\n carton exec script/lstu ban --ban %s", join(' ', @r_ips)) if @r_ips;
}
if ($search) {
my $u = Lstu::DB::URL->new(app => $c->app)->search_url($search);
my @shorts;
my @ips;
my @s_ips;
$u->each(sub {
my ($e, $num) = @_;
push @shorts, $e->{short};
push @ips, $e->{created_by} if $e->{created_by};
push @s_ips, $e->{created_by} if $e->{created_by};
print_infos($e);
});
say sprintf('%d matching URLs', $u->size);
say sprintf("If you want to delete those URLs, please do:\n carton exec script/lstu url --remove %s", join(' ', @shorts)) if @shorts;
say sprintf("If you want to ban those IPs, please do:\n carton exec script/lstu ban --ban %s", join(' ', @ips)) if @ips;
say sprintf("If you want to delete those URLs, please do:\n carton exec script/lstu url --yes --remove %s", join(' ', @shorts)) if @shorts;
say sprintf("If you want to ban those IPs, please do:\n carton exec script/lstu ban --ban %s", join(' ', @s_ips)) if @s_ips;
}
if ($ip) {
my $u = Lstu::DB::URL->new(app => $c->app)->search_creator($ip);
my @shorts;
my @ips;
$u->each(sub {
my ($e, $num) = @_;
push @shorts, $e->{short};
push @ips, $e->{created_by} if $e->{created_by};
print_infos($e);
if (scalar(@ips)) {
my @recap;
c(@ips)->each(sub {
my ($ip, $num) = @_;
my $u = Lstu::DB::URL->new(app => $c->app)->search_creator($ip);
my @shorts;
$u->each(sub {
my ($e, $num) = @_;
push @shorts, $e->{short};
print_infos($e);
});
say sprintf('[%s] %d matching URLs', $ip, $u->size);
if (@shorts) {
say sprintf("[%s] If you want to delete those URLs, please do:\n carton exec script/lstu url --yes --remove %s", $ip, join(' ', @shorts));
push @recap, @shorts;
}
});
say sprintf('%d matching URLs', $u->size);
say sprintf("If you want to delete those URLs, please do:\n carton exec script/lstu url --remove %s", join(' ', @shorts)) if @shorts;
say sprintf("If you want to delete all those URLs, please do:\n carton exec script/lstu url --yes --remove %s", join(' ', @recap)) if @recap;
say sprintf("If you want to ban those IPs, please do:\n carton exec script/lstu ban --ban %s", join(' ', @ips)) if @ips;
}
}
......@@ -137,7 +143,7 @@ Lstu::Command::url - Manage URL in Lstu's database
carton exec script/lstu url --remove <short> <short> [--yes] Remove the space-separated URLs (ask for confirmation unless --yes is given)
Will print infos about URL before confirmation
carton exec script/lstu url --search <url> Search URLs by its true URL (LIKE match)
carton exec script/lstu url --ip <ip address> Search URLs by the IP address of its creator (exact match)
carton exec script/lstu url --ip <ip address> <ip address> Search URLs by the IP address of its creator (exact match)
=cut
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment