Verified Commit fdbbd40c authored by Luc Didry's avatar Luc Didry

Improve safebrowsingcheck CLI

- allow to specify URLs to check
- allow to check URLs created <argument> seconds ago
parent e635c2c3
Pipeline #75406 passed with stages
in 7 minutes and 24 seconds
Revision history for Perl application Lstu
0.20-0 2018-??-??
- Improve safebrowsingcheck CLI (displays creators' IP addresses + other URLs from thoses IPs)
- Improve safebrowsingcheck CLI:
- displays creators' IP addresses + other URLs from thoses IPs
- allow to specify URLs to check
- allow to check URLs created <argument> seconds ago
0.19-3 2018-09-08
- Update translations
......
......@@ -4,6 +4,8 @@ use Mojo::Base 'Mojolicious::Command';
use FindBin qw($Bin);
use File::Spec qw(catfile);
use Term::ProgressBar::Quiet;
use Mojo::Util qw(getopt);
use Mojo::Collection 'c';
has description => 'Checks all URLs in database against Google Safe Browsing database (local copy)';
has usage => sub { shift->extract_usage };
......@@ -52,8 +54,24 @@ sub run {
$c->app->plugin('Lstu::Plugin::Helpers');
getopt \@args,
'u|url=s{1,}' => \my @urls_to_check,
's|seconds=i' => \my $delay;
if ($c->app->gsb) {
my $urls = Lstu::DB::URL->new(app => $c->app)->get_all_urls;
my $urls;
if (@urls_to_check) {
$urls = c(get_shorts($c, @urls_to_check));
} elsif ($delay) {
$urls = Lstu::DB::URL->new(app => $c->app)->get_all_urls_created_ago($delay);
} else {
$urls = Lstu::DB::URL->new(app => $c->app)->get_all_urls;
}
unless ($urls->size) {
say 'No URLs to check.';
exit;
}
my $progress = Term::ProgressBar::Quiet->new(
{ name => 'Scanning '.$urls->size.' URLs', count => $urls->size, ETA => 'linear' }
......@@ -92,6 +110,23 @@ sub run {
}
}
sub get_shorts {
my $c = shift;
my @shorts = @_;
my @results;
for my $short (@shorts) {
my $u = Lstu::DB::URL->new(app => $c->app, short => $short);
if ($u->url) {
push @results, $u->to_hash;
} else {
say sprintf('Sorry, unable to find an URL with short = %s', $short);
}
}
return @results;
}
=encoding utf8
=head1 NAME
......
......@@ -406,6 +406,29 @@ sub get_all_urls {
$c->app->dbi->db->select('lstu', undef, { url => { '!=', undef } })->hashes;
}
=head2 get_all_urls_created_ago
=over 1
=item B<Usage> : C<$c-E<gt>get_all_urls_created_ago($seconds)>
=item B<Arguments> : integer, number of seconds
=item B<Purpose> : return all non-empty records created less than $seconds agog
=item B<Returns> : a Mojo::Collection containing hashes of matching records
=back
=cut
sub get_all_urls_created_ago {
my $c = shift;
my $delay = shift;
$c->app->dbi->db->select('lstu', undef, { url => { '!=', undef }, timestamp => { '>=', time - $delay } })->hashes;
}
=head2 _slurp
=over 1
......
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