Create DefaultConfig module — DRY
This commit is contained in:
parent
549c230055
commit
b57ed7605f
26
lib/Lufi.pm
26
lib/Lufi.pm
|
@ -6,6 +6,7 @@ use Apache::Htpasswd;
|
|||
use Mojolicious::Sessions;
|
||||
use Email::Valid;
|
||||
use Data::Validate::URI qw(is_web_uri);
|
||||
use Lufi::DefaultConfig qw($default_config);
|
||||
|
||||
$ENV{MOJO_MAX_WEBSOCKET_SIZE} = 100485760; # 10 * 1024 * 1024 = 10MiB
|
||||
|
||||
|
@ -14,30 +15,7 @@ sub startup {
|
|||
my $self = shift;
|
||||
|
||||
my $config = $self->plugin('Config' => {
|
||||
default => {
|
||||
prefix => '/',
|
||||
provisioning => 100,
|
||||
provis_step => 5,
|
||||
length => 10,
|
||||
token_length => 32,
|
||||
secrets => ['hfudsifdsih'],
|
||||
default_delay => 0,
|
||||
max_delay => 0,
|
||||
mail => {
|
||||
how => 'sendmail'
|
||||
},
|
||||
mail_sender => 'no-reply@lufi.io',
|
||||
theme => 'default',
|
||||
upload_dir => 'files',
|
||||
session_duration => 3600,
|
||||
allow_pwd_on_files => 0,
|
||||
dbtype => 'sqlite',
|
||||
db_path => 'lufi.db',
|
||||
force_burn_after_reading => 0,
|
||||
x_frame_options => 'DENY',
|
||||
x_content_type_options => 'nosniff',
|
||||
x_xss_protection => '1; mode=block',
|
||||
}
|
||||
default => $default_config
|
||||
});
|
||||
|
||||
die 'You need to provide a contact information in lufi.conf!' unless (defined($self->config('contact')));
|
||||
|
|
|
@ -3,6 +3,7 @@ package Lufi::Command::cron::cleanbdd;
|
|||
use Mojo::Base 'Mojolicious::Command';
|
||||
use Lufi::DB::File;
|
||||
use FindBin qw($Bin);
|
||||
use Lufi::DefaultConfig qw($default_config);
|
||||
|
||||
has description => 'Delete IP addresses from database after configured delay.';
|
||||
has usage => sub { shift->extract_usage };
|
||||
|
@ -19,30 +20,7 @@ sub run {
|
|||
}
|
||||
my $config = $c->app->plugin('Config', {
|
||||
file => $cfile,
|
||||
default => {
|
||||
prefix => '/',
|
||||
provisioning => 100,
|
||||
provis_step => 5,
|
||||
length => 10,
|
||||
token_length => 32,
|
||||
secrets => ['hfudsifdsih'],
|
||||
default_delay => 0,
|
||||
max_delay => 0,
|
||||
mail => {
|
||||
how => 'sendmail'
|
||||
},
|
||||
mail_sender => 'no-reply@lufi.io',
|
||||
theme => 'default',
|
||||
upload_dir => 'files',
|
||||
session_duration => 3600,
|
||||
allow_pwd_on_files => 0,
|
||||
dbtype => 'sqlite',
|
||||
db_path => 'lufi.db',
|
||||
force_burn_after_reading => 0,
|
||||
x_frame_options => 'DENY',
|
||||
x_content_type_options => 'nosniff',
|
||||
x_xss_protection => '1; mode=block',
|
||||
}
|
||||
default => $default_config
|
||||
});
|
||||
|
||||
my $separation = time() - $config->{keep_ip_during} * 86400;
|
||||
|
|
|
@ -3,6 +3,7 @@ package Lufi::Command::cron::cleanfiles;
|
|||
use Mojo::Base 'Mojolicious::Command';
|
||||
use Lufi::DB::File;
|
||||
use FindBin qw($Bin);
|
||||
use Lufi::DefaultConfig qw($default_config);
|
||||
|
||||
has description => 'Delete expired files.';
|
||||
has usage => sub { shift->extract_usage };
|
||||
|
@ -19,30 +20,7 @@ sub run {
|
|||
}
|
||||
my $config = $c->app->plugin('Config', {
|
||||
file => $cfile,
|
||||
default => {
|
||||
prefix => '/',
|
||||
provisioning => 100,
|
||||
provis_step => 5,
|
||||
length => 10,
|
||||
token_length => 32,
|
||||
secrets => ['hfudsifdsih'],
|
||||
default_delay => 0,
|
||||
max_delay => 0,
|
||||
mail => {
|
||||
how => 'sendmail'
|
||||
},
|
||||
mail_sender => 'no-reply@lufi.io',
|
||||
theme => 'default',
|
||||
upload_dir => 'files',
|
||||
session_duration => 3600,
|
||||
allow_pwd_on_files => 0,
|
||||
dbtype => 'sqlite',
|
||||
db_path => 'lufi.db',
|
||||
force_burn_after_reading => 0,
|
||||
x_frame_options => 'DENY',
|
||||
x_content_type_options => 'nosniff',
|
||||
x_xss_protection => '1; mode=block',
|
||||
}
|
||||
default => $default_config
|
||||
});
|
||||
|
||||
my $time = time();
|
||||
|
|
|
@ -4,6 +4,7 @@ use Filesys::DiskUsage qw/du/;
|
|||
use Lufi::DB::File;
|
||||
use Switch;
|
||||
use FindBin qw($Bin);
|
||||
use Lufi::DefaultConfig qw($default_config);
|
||||
|
||||
has description => 'Watch the files directory and take action when over quota';
|
||||
has usage => sub { shift->extract_usage };
|
||||
|
@ -20,30 +21,7 @@ sub run {
|
|||
}
|
||||
my $config = $c->app->plugin('Config', {
|
||||
file => $cfile,
|
||||
default => {
|
||||
prefix => '/',
|
||||
provisioning => 100,
|
||||
provis_step => 5,
|
||||
length => 10,
|
||||
token_length => 32,
|
||||
secrets => ['hfudsifdsih'],
|
||||
default_delay => 0,
|
||||
max_delay => 0,
|
||||
mail => {
|
||||
how => 'sendmail'
|
||||
},
|
||||
mail_sender => 'no-reply@lufi.io',
|
||||
theme => 'default',
|
||||
upload_dir => 'files',
|
||||
session_duration => 3600,
|
||||
allow_pwd_on_files => 0,
|
||||
dbtype => 'sqlite',
|
||||
db_path => 'lufi.db',
|
||||
force_burn_after_reading => 0,
|
||||
x_frame_options => 'DENY',
|
||||
x_content_type_options => 'nosniff',
|
||||
x_xss_protection => '1; mode=block',
|
||||
}
|
||||
default => $default_config
|
||||
});
|
||||
|
||||
if (defined($config->{max_total_size})) {
|
||||
|
|
|
@ -5,6 +5,7 @@ use Lufi::DB::Slice;
|
|||
use Mojo::SQLite;
|
||||
use FindBin qw($Bin);
|
||||
use Term::ProgressBar;
|
||||
use Lufi::DefaultConfig qw($default_config);
|
||||
|
||||
has description => 'Migrate the records from a SQLite db to the currently configured database';
|
||||
has usage => sub { shift->extract_usage };
|
||||
|
@ -21,30 +22,7 @@ sub run {
|
|||
}
|
||||
my $config = $c->app->plugin('Config', {
|
||||
file => $cfile,
|
||||
default => {
|
||||
prefix => '/',
|
||||
provisioning => 100,
|
||||
provis_step => 5,
|
||||
length => 10,
|
||||
token_length => 32,
|
||||
secrets => ['hfudsifdsih'],
|
||||
default_delay => 0,
|
||||
max_delay => 0,
|
||||
mail => {
|
||||
how => 'sendmail'
|
||||
},
|
||||
mail_sender => 'no-reply@lufi.io',
|
||||
theme => 'default',
|
||||
upload_dir => 'files',
|
||||
session_duration => 3600,
|
||||
allow_pwd_on_files => 0,
|
||||
dbtype => 'sqlite',
|
||||
db_path => 'lufi.db',
|
||||
force_burn_after_reading => 0,
|
||||
x_frame_options => 'DENY',
|
||||
x_content_type_options => 'nosniff',
|
||||
x_xss_protection => '1; mode=block',
|
||||
}
|
||||
default => $default_config
|
||||
});
|
||||
|
||||
if ($config->{dbtype} eq 'sqlite') {
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
|
||||
package Lufi::DefaultConfig;
|
||||
require Exporter;
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT_OK = qw($default_config);
|
||||
our $default_config = {
|
||||
prefix => '/',
|
||||
provisioning => 100,
|
||||
provis_step => 5,
|
||||
length => 10,
|
||||
token_length => 32,
|
||||
secrets => ['hfudsifdsih'],
|
||||
default_delay => 0,
|
||||
max_delay => 0,
|
||||
mail => {
|
||||
how => 'sendmail'
|
||||
},
|
||||
mail_sender => 'no-reply@lufi.io',
|
||||
theme => 'default',
|
||||
upload_dir => 'files',
|
||||
session_duration => 3600,
|
||||
allow_pwd_on_files => 0,
|
||||
dbtype => 'sqlite',
|
||||
db_path => 'lufi.db',
|
||||
force_burn_after_reading => 0,
|
||||
x_frame_options => 'DENY',
|
||||
x_content_type_options => 'nosniff',
|
||||
x_xss_protection => '1; mode=block',
|
||||
};
|
||||
|
||||
1;
|
|
@ -2,6 +2,7 @@ package Mounter;
|
|||
use Mojo::Base 'Mojolicious';
|
||||
use FindBin qw($Bin);
|
||||
use File::Spec qw(catfile);
|
||||
use Lufi::DefaultConfig qw($default_config);
|
||||
|
||||
# This method will run once at server start
|
||||
sub startup {
|
||||
|
@ -19,33 +20,7 @@ sub startup {
|
|||
my $config = $self->plugin('Config' =>
|
||||
{
|
||||
file => $cfile,
|
||||
default => {
|
||||
prefix => '/',
|
||||
theme => 'default',
|
||||
dbtype => 'sqlite',
|
||||
prefix => '/',
|
||||
provisioning => 100,
|
||||
provis_step => 5,
|
||||
length => 10,
|
||||
token_length => 32,
|
||||
secrets => ['hfudsifdsih'],
|
||||
default_delay => 0,
|
||||
max_delay => 0,
|
||||
mail => {
|
||||
how => 'sendmail'
|
||||
},
|
||||
mail_sender => 'no-reply@lufi.io',
|
||||
theme => 'default',
|
||||
upload_dir => 'files',
|
||||
session_duration => 3600,
|
||||
allow_pwd_on_files => 0,
|
||||
dbtype => 'sqlite',
|
||||
db_path => 'lufi.db',
|
||||
force_burn_after_reading => 0,
|
||||
x_frame_options => 'DENY',
|
||||
x_content_type_options => 'nosniff',
|
||||
x_xss_protection => '1; mode=block',
|
||||
}
|
||||
default => $default_config
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue