diff --git a/lib/Lufi.pm b/lib/Lufi.pm index aeacf05..57af3b6 100644 --- a/lib/Lufi.pm +++ b/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'))); diff --git a/lib/Lufi/Command/cron/cleanbdd.pm b/lib/Lufi/Command/cron/cleanbdd.pm index 2aaa57a..4ff7fbc 100644 --- a/lib/Lufi/Command/cron/cleanbdd.pm +++ b/lib/Lufi/Command/cron/cleanbdd.pm @@ -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; diff --git a/lib/Lufi/Command/cron/cleanfiles.pm b/lib/Lufi/Command/cron/cleanfiles.pm index fad9d5e..2e3ec34 100644 --- a/lib/Lufi/Command/cron/cleanfiles.pm +++ b/lib/Lufi/Command/cron/cleanfiles.pm @@ -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(); diff --git a/lib/Lufi/Command/cron/watch.pm b/lib/Lufi/Command/cron/watch.pm index 5aa4bb7..6badb2e 100644 --- a/lib/Lufi/Command/cron/watch.pm +++ b/lib/Lufi/Command/cron/watch.pm @@ -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})) { diff --git a/lib/Lufi/Command/sqliteToOtherDB.pm b/lib/Lufi/Command/sqliteToOtherDB.pm index 5bfbb87..20e8561 100644 --- a/lib/Lufi/Command/sqliteToOtherDB.pm +++ b/lib/Lufi/Command/sqliteToOtherDB.pm @@ -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') { diff --git a/lib/Lufi/DefaultConfig.pm b/lib/Lufi/DefaultConfig.pm new file mode 100644 index 0000000..d8d75e4 --- /dev/null +++ b/lib/Lufi/DefaultConfig.pm @@ -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; diff --git a/lib/Mounter.pm b/lib/Mounter.pm index 3d5d455..5408e0b 100644 --- a/lib/Mounter.pm +++ b/lib/Mounter.pm @@ -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 } );