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

Improve GSB object creation and GSB DB update

parent fbfd91e4
Pipeline #73207 passed with stages
in 7 minutes and 33 seconds
Revision history for Perl application Lstu
0.19-2 2018-09-08
- Improve GSB object creation and GSB DB update
0.19-1 2018-09-08
- Update translations
......
......@@ -242,11 +242,12 @@ sub startup {
$self->provisioning();
});
if ($self->stash('gsb')) {
if ($self->config('safebrowsing_api_key')) {
$self->gsb(1);
Mojo::IOLoop->recurring(86400 => sub {
my $loop = shift;
$self->gsb_update();
$self->gsb(1);
});
}
......
......@@ -59,12 +59,13 @@ sub run {
{ name => 'Scanning '.$urls->size.' URLs', count => $urls->size, ETA => 'linear' }
);
my @bad;
my $gsb = $c->app->gsb;
$urls->each(sub {
my ($e, $num) = @_;
$progress->update($num);
my @matches = $c->app->gsb->lookup(url => $e->{url});
my @matches = $gsb->lookup(url => $e->{url});
if (@matches) {
push @bad, $e->{short};
......
......@@ -206,7 +206,8 @@ sub _cleaning {
}
sub _gsb {
my $c = shift;
my $c = shift;
my $check = shift;
# Google safebrowsing (if configured)
if ($c->config('safebrowsing_api_key')) {
......@@ -215,14 +216,18 @@ sub _gsb {
my $force_update = (!-e Mojo::File->new($Bin, '..' , 'safebrowsing_db'));
my $storage = Net::Google::SafeBrowsing4::Storage::File->new(path => Mojo::File->new($Bin, '..' , 'safebrowsing_db'));
state $gsb = Net::Google::SafeBrowsing4->new(
key => $c->config('safebrowsing_api_key'),
storage => $storage,
storage => Net::Google::SafeBrowsing4::Storage::File->new(path => Mojo::File->new($Bin, '..' , 'safebrowsing_db')),
);
$c->gsb_update($force_update);
if ($force_update) {
$gsb->update();
} elsif ($check) {
my $update = Mojo::File->new($Bin, '..' , 'safebrowsing_db')->to_string;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($update);
$gsb->update() if $mtime < time - 86400;
}
return $gsb;
} else {
......@@ -230,15 +235,4 @@ sub _gsb {
}
}
sub _gsb_update {
my $c = shift;
my $force_update = shift;
return $c->gsb->update() if $force_update;
my $update = Mojo::File->new($Bin, '..' , 'safebrowsing_db')->to_string;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($update);
$c->gsb->update() if ($mtime < time - 86400);
}
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