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

Fix URL removal in memcached from safebrowsingcheck and url commands

parent 4388fad9
Pipeline #88483 passed with stages
in 10 minutes and 6 seconds
Revision history for Perl application Lstu
0.22-0 ????-??-??
0.21-2 2018-11-19
- Fix URL removal in memcached from safebrowsingcheck and url commands
0.21-1 2018-10-17
- Fix URL removal in memcached from safebrowsingcheck command
......
......@@ -3,6 +3,7 @@ package Lstu;
use Mojo::Base 'Mojolicious';
use Mojo::JSON;
use Lstu::DB::URL;
use Lstu::DefaultConfig qw($default_config);
$ENV{MOJO_REVERSE_PROXY} = 1;
......@@ -11,33 +12,7 @@ sub startup {
my $self = shift;
my $config = $self->plugin('Config' => {
default => {
prefix => '/',
provisioning => 100,
provis_step => 5,
length => 8,
secret => ['hfudsifdsih'],
page_offset => 10,
theme => 'default',
ban_min_strike => 3,
ban_whitelist => [],
ban_blacklist => [],
minion => {
enabled => 0,
db_path => 'minion.db'
},
session_duration => 3600,
dbtype => 'sqlite',
db_path => 'lstu.db',
max_redir => 2,
skip_spamhaus => 0,
safebrowsing_api_key => '',
memcached_servers => [],
x_frame_options => 'DENY',
x_content_type_options => 'nosniff',
x_xss_protection => '1; mode=block',
log_creator_ip => 0,
}
default => $default_config
});
$config->{provisioning} = $config->{provisionning} if (defined($config->{provisionning}));
......
......@@ -13,45 +13,6 @@ sub run {
my $c = shift;
my @args = @_;
my $cfile = Mojo::File->new($Bin, '..' , 'lstu.conf');
if (defined $ENV{MOJO_CONFIG}) {
$cfile = Mojo::File->new($ENV{MOJO_CONFIG});
unless (-e $cfile->to_abs) {
$cfile = Mojo::File->new($Bin, '..', $ENV{MOJO_CONFIG});
}
}
my $config = $c->app->plugin('Config', {
file => $cfile,
default => {
prefix => '/',
provisioning => 100,
provis_step => 5,
length => 8,
secret => ['hfudsifdsih'],
page_offset => 10,
theme => 'default',
ban_min_strike => 3,
ban_whitelist => [],
ban_blacklist => [],
minion => {
enabled => 0,
db_path => 'minion.db'
},
session_duration => 3600,
dbtype => 'sqlite',
db_path => 'lstu.db',
max_redir => 2,
skip_spamhaus => 0,
safebrowsing_api_key => '',
memcached_servers => [],
x_frame_options => 'DENY',
x_content_type_options => 'nosniff',
x_xss_protection => '1; mode=block',
log_creator_ip => 0,
}
});
$c->app->plugin('Lstu::Plugin::Helpers');
getopt \@args,
'b|ban=s{1,}' => \my @ban_ips,
......
......@@ -16,46 +16,6 @@ sub run {
my $c = shift;
my @args = @_;
my $cfile = Mojo::File->new($Bin, '..' , 'lstu.conf');
if (defined $ENV{MOJO_CONFIG}) {
$cfile = Mojo::File->new($ENV{MOJO_CONFIG});
unless (-e $cfile->to_abs) {
$cfile = Mojo::File->new($Bin, '..', $ENV{MOJO_CONFIG});
}
}
my $config = $c->app->plugin('Config', {
file => $cfile,
default => {
prefix => '/',
provisioning => 100,
provis_step => 5,
length => 8,
secret => ['hfudsifdsih'],
page_offset => 10,
theme => 'default',
ban_min_strike => 3,
ban_whitelist => [],
ban_blacklist => [],
minion => {
enabled => 0,
db_path => 'minion.db'
},
session_duration => 3600,
dbtype => 'sqlite',
db_path => 'lstu.db',
max_redir => 2,
skip_spamhaus => 0,
safebrowsing_api_key => '',
memcached_servers => [],
x_frame_options => 'DENY',
x_content_type_options => 'nosniff',
x_xss_protection => '1; mode=block',
log_creator_ip => 0,
}
});
$c->app->plugin('Lstu::Plugin::Helpers');
getopt \@args,
'u|url=s{1,}' => \my @urls_to_check,
's|seconds=i' => \my $delay,
......@@ -97,7 +57,7 @@ sub run {
$deleted += Lstu::DB::URL->new(
app => $c->app,
short => $e->{short}
)->delete if $remove;
)->remove if $remove;
}
});
......@@ -119,7 +79,7 @@ sub run {
$deleted += Lstu::DB::URL->new(
app => $c->app,
short => $e->{short}
)->delete if ($remove && $all);
)->remove if ($remove && $all);
});
}
my @ips = keys %bad_ips;
......
......@@ -14,43 +14,6 @@ sub run {
my $c = shift;
my @args = @_;
my $cfile = Mojo::File->new($Bin, '..' , 'lstu.conf');
if (defined $ENV{MOJO_CONFIG}) {
$cfile = Mojo::File->new($ENV{MOJO_CONFIG});
unless (-e $cfile->to_abs) {
$cfile = Mojo::File->new($Bin, '..', $ENV{MOJO_CONFIG});
}
}
my $config = $c->app->plugin('Config', {
file => $cfile,
default => {
prefix => '/',
provisioning => 100,
provis_step => 5,
length => 8,
secret => ['hfudsifdsih'],
page_offset => 10,
theme => 'default',
ban_min_strike => 3,
ban_whitelist => [],
ban_blacklist => [],
minion => {
enabled => 0,
db_path => 'minion.db'
},
session_duration => 3600,
dbtype => 'sqlite',
db_path => 'lstu.db',
max_redir => 2,
skip_spamhaus => 0,
memcached_servers => [],
x_frame_options => 'DENY',
x_content_type_options => 'nosniff',
x_xss_protection => '1; mode=block',
log_creator_ip => 0,
}
});
getopt \@args,
'info=s{1,}' => \my @info,
'r|remove=s{1,}' => \my @remove,
......@@ -81,7 +44,7 @@ sub run {
chomp $confirm;
}
if ($confirm =~ m/^y(es)?$/i) {
if ($u->delete) {
if ($u->remove) {
say sprintf('Success: %s URL has been removed', $e);
} else {
say sprintf('Failure: %s URL has not been removed', $e);
......
......@@ -62,7 +62,7 @@ sub login {
Lstu::DB::Session->new(
app => $c,
token => $c->session('token')
)->delete;
)->remove;
delete $c->session->{token};
$c->respond_to(
json => sub {
......@@ -119,10 +119,7 @@ sub delete {
short => $short
);
if ($db_url->url) {
my $deleted = $db_url->delete;
if (scalar(@{$c->config('memcached_servers')})) {
$c->chi('lstu_urls_cache')->remove($short);
}
my $deleted = $db_url->remove;
$c->respond_to(
json => { json => { success => Mojo::JSON->true, deleted => $deleted } },
any => sub {
......
......@@ -88,15 +88,15 @@ sub to_hash {
}
}
=head2 delete
=head2 remove
=over 1
=item B<Usage> : C<$c-E<gt>delete>
=item B<Usage> : C<$c-E<gt>remove>
=item B<Arguments> : none
=item B<Purpose> : delete the session record from the database
=item B<Purpose> : remove the session record from the database
=item B<Returns> : the Lstu::DB::Session object
......@@ -104,17 +104,17 @@ sub to_hash {
=cut
sub delete {
sub remove {
my $c = shift;
$c->app->dbi->db->query('DELETE FROM sessions WHERE token = ?', $c->token);
my $h = $c->app->dbi->db->query('SELECT * FROM sessions WHERE token = ?', $c->token)->hashes;
if ($h->size) {
# We found the session, it hasn't been deleted
# We found the session, it hasn't been removed
return 0;
} else {
$c = Lstu::DB::Session->new(app => $c->app);
# We didn't found the session, it has been deleted
# We didn't found the session, it has been removed
return 1;
}
}
......
......@@ -148,15 +148,15 @@ sub write {
return $c;
}
=head2 delete
=head2 remove
=over 1
=item B<Usage> : C<$c-E<gt>delete>
=item B<Usage> : C<$c-E<gt>remove>
=item B<Arguments> : none
=item B<Purpose> : delete the URL record from the database
=item B<Purpose> : remove the URL record from the database
=item B<Returns> : 1 for success, 0 for failure
......@@ -164,13 +164,13 @@ sub write {
=cut
sub delete {
sub remove {
my $c = shift;
$c->app->dbi->db->query('DELETE FROM lstu WHERE short = ?', $c->short);
my $h = $c->app->dbi->db->query('SELECT * FROM lstu WHERE short = ?', $c->short)->hashes;
if ($h->size) {
# We found the URL, it hasn't been deleted
# We found the URL, it hasn't been removed
return 0;
} else {
if (scalar(@{$c->app->config('memcached_servers')})) {
......@@ -178,7 +178,7 @@ sub delete {
}
$c = Lstu::DB::URL->new(app => $c->app);
# We didn't found the URL, it has been deleted
# We didn't found the URL, it has been removed
return 1;
}
}
......
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
package Lstu::DefaultConfig;
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw($default_config);
our $default_config = {
prefix => '/',
provisioning => 100,
provis_step => 5,
length => 8,
secret => ['hfudsifdsih'],
page_offset => 10,
theme => 'default',
ban_min_strike => 3,
ban_whitelist => [],
ban_blacklist => [],
minion => {
enabled => 0,
db_path => 'minion.db'
},
session_duration => 3600,
dbtype => 'sqlite',
db_path => 'lstu.db',
max_redir => 2,
skip_spamhaus => 0,
safebrowsing_api_key => '',
memcached_servers => [],
x_frame_options => 'DENY',
x_content_type_options => 'nosniff',
x_xss_protection => '1; mode=block',
log_creator_ip => 0,
};
1;
......@@ -3,6 +3,7 @@ use Mojo::Base 'Mojolicious';
use Mojo::File;
use FindBin qw($Bin);
use File::Spec qw(catfile);
use Lstu::DefaultConfig qw($default_config);
# This method will run once at server start
sub startup {
......@@ -20,33 +21,7 @@ sub startup {
my $config = $self->plugin('Config' =>
{
file => $cfile,
default => {
prefix => '/',
provisioning => 100,
provis_step => 5,
length => 8,
secret => ['hfudsifdsih'],
page_offset => 10,
theme => 'default',
ban_min_strike => 3,
ban_whitelist => [],
ban_blacklist => [],
minion => {
enabled => 0,
db_path => 'minion.db'
},
session_duration => 3600,
dbtype => 'sqlite',
db_path => 'lstu.db',
max_redir => 2,
skip_spamhaus => 0,
safebrowsing_api_key => '',
memcached_servers => [],
x_frame_options => 'DENY',
x_content_type_options => 'nosniff',
x_xss_protection => '1; mode=block',
log_creator_ip => 0,
}
default => $default_config
}
);
......
......@@ -11,6 +11,7 @@ use Test::Mojo;
use Lstu::DB::URL;
use Lstu::DB::Ban;
use Lstu::DB::Session;
use Lstu::DefaultConfig qw($default_config);
use FindBin qw($Bin);
use File::Spec::Functions;
......@@ -29,11 +30,7 @@ BEGIN {
my $config = $m->plugin('Config' =>
{
file => $cfile->to_abs->to_string,
default => {
dbtype => 'sqlite',
max_redir => 2,
skip_spamhaus => 0,
}
default => $default_config
}
);
$m->plugin('Lstu::Plugin::Helpers');
......
......@@ -231,7 +231,7 @@ msgid "The URL you want to shorten comes from a domain (%1) that is blacklisted
msgstr ""
#. ($c->url_for('/')
#: lib/Lstu/Controller/Admin.pm:134 lib/Lstu/Controller/Stats.pm:184 lib/Lstu/Controller/URL.pm:223
#: lib/Lstu/Controller/Admin.pm:131 lib/Lstu/Controller/Stats.pm:184 lib/Lstu/Controller/URL.pm:223
msgid "The shortened URL %1 doesn't exist."
msgstr ""
......@@ -314,7 +314,7 @@ msgstr ""
msgid "You will have the statistics page with the admin stats if you're succesfully logged in, or your stats and a failure message otherwise"
msgstr ""
#: lib/Lstu/Controller/Admin.pm:145
#: lib/Lstu/Controller/Admin.pm:142
msgid "You're not authenticated as the admin"
msgstr ""
......
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