diff --git a/lib/Lutim.pm b/lib/Lutim.pm index 3dac847..6b2eada 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -3,6 +3,7 @@ package Lutim; use Mojo::Base 'Mojolicious'; use Mojo::IOLoop; use Lutim::DB::Image; +use Lutim::DefaultConfig qw($default_config); use vars qw($im_loaded); BEGIN { @@ -28,39 +29,7 @@ sub startup { $self->plugin('DebugDumperHelper'); my $config = $self->plugin('Config', { - default => { - provisioning => 100, - provis_step => 5, - length => 8, - always_encrypt => 0, - anti_flood_delay => 5, - max_file_size => 10*1024*1024, - https => 0, - proposed_delays => '0,1,7,30,365', - default_delay => 0, - max_delay => 0, - token_length => 24, - crypto_key_length => 8, - thumbnail_size => 100, - theme => 'default', - dbtype => 'sqlite', - db_path => 'lutim.db', - max_files_in_zip => 15, - prefix => '/', - minion => { - enabled => 0, - dbtype => 'sqlite', - db_path => 'minion.db' - }, - session_duration => 3600, - cache_max_size => 0, - memcached_servers => [], - quiet_logs => 0, - disable_img_stats => 0, - x_frame_options => 'DENY', - x_content_type_options => 'nosniff', - x_xss_protection => '1; mode=block', - } + default => $default_config }); if (scalar(@{$config->{memcached_servers}})) { diff --git a/lib/Lutim/Command/cron/cleanbdd.pm b/lib/Lutim/Command/cron/cleanbdd.pm index b65589b..e5e2958 100644 --- a/lib/Lutim/Command/cron/cleanbdd.pm +++ b/lib/Lutim/Command/cron/cleanbdd.pm @@ -3,6 +3,7 @@ package Lutim::Command::cron::cleanbdd; use Mojo::Base 'Mojolicious::Command'; use Mojo::File; use Lutim::DB::Image; +use Lutim::DefaultConfig qw($default_config); use FindBin qw($Bin); use File::Spec qw(catfile); @@ -21,10 +22,7 @@ sub run { } my $config = $c->app->plugin('Config', { file => $cfile, - default => { - keep_ip_during => 365, - dbtype => 'sqlite', - } + default => $default_config }); my $separation = time() - $config->{keep_ip_during} * 86400; diff --git a/lib/Lutim/Command/cron/cleanfiles.pm b/lib/Lutim/Command/cron/cleanfiles.pm index 1293213..4d6f0f7 100644 --- a/lib/Lutim/Command/cron/cleanfiles.pm +++ b/lib/Lutim/Command/cron/cleanfiles.pm @@ -3,6 +3,7 @@ package Lutim::Command::cron::cleanfiles; use Mojo::Base 'Mojolicious::Command'; use Mojo::File; use Lutim::DB::Image; +use Lutim::DefaultConfig qw($default_config); use Lutim; use FindBin qw($Bin); use File::Spec qw(catfile); @@ -22,9 +23,7 @@ sub run { } my $config = $c->app->plugin('Config', { file => $cfile, - default => { - dbtype => 'sqlite', - } + default => $default_config }); my $l = Lutim->new; diff --git a/lib/Lutim/Command/cron/stats.pm b/lib/Lutim/Command/cron/stats.pm index 6c9a1db..cde9f3e 100644 --- a/lib/Lutim/Command/cron/stats.pm +++ b/lib/Lutim/Command/cron/stats.pm @@ -6,6 +6,7 @@ use Mojo::Util qw(encode); use Mojo::File; use Mojo::JSON qw(encode_json); use Lutim::DB::Image; +use Lutim::DefaultConfig qw($default_config); use DateTime; use FindBin qw($Bin); use File::Spec qw(catfile); @@ -26,11 +27,7 @@ sub run { } my $config = $c->app->plugin('Config', { file => $cfile, - default => { - theme => 'default', - stats_day_num => 365, - dbtype => 'sqlite' - } + default => $default_config }); my $template = 'themes/'.$config->{theme}.'/templates/data.html.ep.template'; diff --git a/lib/Lutim/Command/cron/watch.pm b/lib/Lutim/Command/cron/watch.pm index 31eda39..8b8b7e3 100644 --- a/lib/Lutim/Command/cron/watch.pm +++ b/lib/Lutim/Command/cron/watch.pm @@ -3,6 +3,7 @@ package Lutim::Command::cron::watch; use Mojo::Base 'Mojolicious::Command'; use Filesys::DiskUsage qw/du/; use Lutim::DB::Image; +use Lutim::DefaultConfig qw($default_config); use Lutim; use Mojo::File; use Switch; @@ -24,10 +25,7 @@ sub run { } my $config = $c->app->plugin('Config', { file => $cfile, - default => { - policy_when_full => 'warn', - dbtype => 'sqlite', - } + default => $default_config }); if (defined($config->{max_total_size})) { diff --git a/lib/Lutim/Command/image.pm b/lib/Lutim/Command/image.pm index d98e13c..b4ad261 100644 --- a/lib/Lutim/Command/image.pm +++ b/lib/Lutim/Command/image.pm @@ -4,6 +4,7 @@ use Mojo::Base 'Mojolicious::Command'; use Mojo::Util qw(getopt); use Mojo::Collection 'c'; use Lutim::DB::Image; +use Lutim::DefaultConfig qw($default_config); use FindBin qw($Bin); use File::Spec qw(catfile); @@ -25,38 +26,7 @@ sub run { } my $config = $c->app->plugin('Config', { file => $cfile, - default => { - provisioning => 100, - provis_step => 5, - length => 8, - always_encrypt => 0, - anti_flood_delay => 5, - max_file_size => 10*1024*1024, - https => 0, - proposed_delays => '0,1,7,30,365', - default_delay => 0, - max_delay => 0, - token_length => 24, - crypto_key_length => 8, - thumbnail_size => 100, - theme => 'default', - dbtype => 'sqlite', - db_path => 'lutim.db', - max_files_in_zip => 15, - prefix => '/', - minion => { - enabled => 0, - dbtype => 'sqlite', - db_path => 'minion.db' - }, - cache_max_size => 0, - memcached_servers => [], - quiet_logs => 0, - disable_img_stats => 0, - x_frame_options => 'DENY', - x_content_type_options => 'nosniff', - x_xss_protection => '1; mode=block', - } + default => $default_config }); if (scalar(@{$config->{memcached_servers}})) { diff --git a/lib/Lutim/DefaultConfig.pm b/lib/Lutim/DefaultConfig.pm new file mode 100644 index 0000000..025fa57 --- /dev/null +++ b/lib/Lutim/DefaultConfig.pm @@ -0,0 +1,43 @@ +# vim:set sw=4 ts=4 sts=4 ft=perl expandtab: +package Lutim::DefaultConfig; +require Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw($default_config); +our $default_config = { + provisioning => 100, + provis_step => 5, + length => 8, + always_encrypt => 0, + anti_flood_delay => 5, + max_file_size => 10*1024*1024, + https => 0, + proposed_delays => '0,1,7,30,365', + default_delay => 0, + max_delay => 0, + token_length => 24, + crypto_key_length => 8, + thumbnail_size => 100, + theme => 'default', + dbtype => 'sqlite', + db_path => 'lutim.db', + max_files_in_zip => 15, + prefix => '/', + minion => { + enabled => 0, + dbtype => 'sqlite', + db_path => 'minion.db' + }, + session_duration => 3600, + cache_max_size => 0, + memcached_servers => [], + quiet_logs => 0, + disable_img_stats => 0, + x_frame_options => 'DENY', + x_content_type_options => 'nosniff', + x_xss_protection => '1; mode=block', + stats_day_num => 365, + keep_ip_during => 365, + policy_when_full => 'warn', +}; + +1; diff --git a/lib/Mounter.pm b/lib/Mounter.pm index 3355446..2680ab6 100644 --- a/lib/Mounter.pm +++ b/lib/Mounter.pm @@ -4,6 +4,7 @@ use Mojo::Base 'Mojolicious'; use Mojo::File; use FindBin qw($Bin); use File::Spec qw(catfile); +use Lutim::DefaultConfig qw($default_config); # This method will run once at server start sub startup { @@ -18,43 +19,10 @@ sub startup { $cfile = Mojo::File->new($Bin, '..', $ENV{MOJO_CONFIG}); } } - my $config = $self->plugin('Config' => - { - file => $cfile, - default => { - provisioning => 100, - provis_step => 5, - length => 8, - always_encrypt => 0, - anti_flood_delay => 5, - max_file_size => 10*1024*1024, - https => 0, - proposed_delays => '0,1,7,30,365', - default_delay => 0, - max_delay => 0, - token_length => 24, - crypto_key_length => 8, - thumbnail_size => 100, - theme => 'default', - dbtype => 'sqlite', - db_path => 'lutim.db', - max_files_in_zip => 15, - prefix => '/', - minion => { - enabled => 0, - dbtype => 'sqlite', - db_path => 'minion.db' - }, - cache_max_size => 0, - memcached_servers => [], - quiet_logs => 0, - disable_img_stats => 0, - x_frame_options => 'DENY', - x_content_type_options => 'nosniff', - x_xss_protection => '1; mode=block', - } - } - ); + my $config = $self->plugin('Config', { + file => $cfile, + default => $default_config + }); $config->{prefix} = $config->{url_sub_dir} if (defined($config->{url_sub_dir}) && $config->{prefix} eq '/'); diff --git a/themes/default/lib/Lutim/I18N/lutim.pot b/themes/default/lib/Lutim/I18N/lutim.pot index 67b45b0..ec75317 100644 --- a/themes/default/lib/Lutim/I18N/lutim.pot +++ b/themes/default/lib/Lutim/I18N/lutim.pot @@ -19,7 +19,7 @@ msgstr "" #. (30) #. ($delay) #. (config('max_delay') -#: lib/Lutim/Command/cron/stats.pm:159 lib/Lutim/Command/cron/stats.pm:160 lib/Lutim/Command/cron/stats.pm:173 lib/Lutim/Command/cron/stats.pm:174 lib/Lutim/Command/cron/stats.pm:190 lib/Lutim/Command/cron/stats.pm:191 themes/default/templates/myfiles.html.ep:24 themes/default/templates/myfiles.html.ep:33 themes/default/templates/myfiles.html.ep:34 themes/default/templates/partial/for_my_delay.html.ep:13 themes/default/templates/partial/for_my_delay.html.ep:14 themes/default/templates/partial/for_my_delay.html.ep:4 themes/default/templates/partial/lutim.js.ep:140 themes/default/templates/partial/lutim.js.ep:149 themes/default/templates/partial/lutim.js.ep:150 themes/default/templates/partial/raw.js.ep:23 themes/default/templates/partial/raw.js.ep:24 themes/default/templates/partial/raw.js.ep:6 themes/default/templates/partial/raw.js.ep:7 themes/default/templates/raw.html.ep:8 themes/default/templates/raw.html.ep:9 +#: lib/Lutim/Command/cron/stats.pm:156 lib/Lutim/Command/cron/stats.pm:157 lib/Lutim/Command/cron/stats.pm:170 lib/Lutim/Command/cron/stats.pm:171 lib/Lutim/Command/cron/stats.pm:187 lib/Lutim/Command/cron/stats.pm:188 themes/default/templates/myfiles.html.ep:24 themes/default/templates/myfiles.html.ep:33 themes/default/templates/myfiles.html.ep:34 themes/default/templates/partial/for_my_delay.html.ep:13 themes/default/templates/partial/for_my_delay.html.ep:14 themes/default/templates/partial/for_my_delay.html.ep:4 themes/default/templates/partial/lutim.js.ep:140 themes/default/templates/partial/lutim.js.ep:149 themes/default/templates/partial/lutim.js.ep:150 themes/default/templates/partial/raw.js.ep:23 themes/default/templates/partial/raw.js.ep:24 themes/default/templates/partial/raw.js.ep:6 themes/default/templates/partial/raw.js.ep:7 themes/default/templates/raw.html.ep:8 themes/default/templates/raw.html.ep:9 msgid "%1 days" msgstr "" @@ -32,11 +32,11 @@ msgstr "" msgid "-or-" msgstr "" -#: lib/Lutim.pm:350 lib/Lutim/Command/cron/stats.pm:161 lib/Lutim/Command/cron/stats.pm:175 lib/Lutim/Command/cron/stats.pm:192 themes/default/templates/index.html.ep:5 themes/default/templates/myfiles.html.ep:5 themes/default/templates/partial/raw.js.ep:25 themes/default/templates/partial/raw.js.ep:8 themes/default/templates/raw.html.ep:10 +#: lib/Lutim.pm:319 lib/Lutim/Command/cron/stats.pm:158 lib/Lutim/Command/cron/stats.pm:172 lib/Lutim/Command/cron/stats.pm:189 themes/default/templates/index.html.ep:5 themes/default/templates/myfiles.html.ep:5 themes/default/templates/partial/raw.js.ep:25 themes/default/templates/partial/raw.js.ep:8 themes/default/templates/raw.html.ep:10 msgid "1 year" msgstr "" -#: lib/Lutim.pm:349 lib/Lutim/Command/cron/stats.pm:158 lib/Lutim/Command/cron/stats.pm:172 lib/Lutim/Command/cron/stats.pm:189 themes/default/templates/index.html.ep:4 themes/default/templates/myfiles.html.ep:33 themes/default/templates/myfiles.html.ep:4 themes/default/templates/partial/for_my_delay.html.ep:13 themes/default/templates/partial/lutim.js.ep:149 themes/default/templates/partial/raw.js.ep:22 themes/default/templates/partial/raw.js.ep:5 themes/default/templates/raw.html.ep:7 +#: lib/Lutim.pm:318 lib/Lutim/Command/cron/stats.pm:155 lib/Lutim/Command/cron/stats.pm:169 lib/Lutim/Command/cron/stats.pm:186 themes/default/templates/index.html.ep:4 themes/default/templates/myfiles.html.ep:33 themes/default/templates/myfiles.html.ep:4 themes/default/templates/partial/for_my_delay.html.ep:13 themes/default/templates/partial/lutim.js.ep:149 themes/default/templates/partial/raw.js.ep:22 themes/default/templates/partial/raw.js.ep:5 themes/default/templates/raw.html.ep:7 msgid "24 hours" msgstr "" @@ -48,7 +48,7 @@ msgstr "" msgid "About" msgstr "" -#: lib/Lutim/Command/cron/stats.pm:154 themes/default/templates/raw.html.ep:3 +#: lib/Lutim/Command/cron/stats.pm:151 themes/default/templates/raw.html.ep:3 msgid "Active images" msgstr "" @@ -108,11 +108,11 @@ msgstr "" msgid "Delete at first view?" msgstr "" -#: lib/Lutim/Command/cron/stats.pm:155 themes/default/templates/raw.html.ep:4 +#: lib/Lutim/Command/cron/stats.pm:152 themes/default/templates/raw.html.ep:4 msgid "Deleted images" msgstr "" -#: lib/Lutim/Command/cron/stats.pm:156 themes/default/templates/raw.html.ep:5 +#: lib/Lutim/Command/cron/stats.pm:153 themes/default/templates/raw.html.ep:5 msgid "Deleted images in 30 days" msgstr "" @@ -204,7 +204,7 @@ msgstr "" msgid "Image URL" msgstr "" -#: lib/Lutim/Command/cron/stats.pm:153 themes/default/templates/raw.html.ep:2 +#: lib/Lutim/Command/cron/stats.pm:150 themes/default/templates/raw.html.ep:2 msgid "Image delay" msgstr "" @@ -445,7 +445,7 @@ msgstr "" msgid "Toggle navigation" msgstr "" -#: lib/Lutim/Command/cron/stats.pm:162 themes/default/templates/raw.html.ep:11 +#: lib/Lutim/Command/cron/stats.pm:159 themes/default/templates/raw.html.ep:11 msgid "Total" msgstr "" @@ -547,7 +547,7 @@ msgstr "" msgid "core developer" msgstr "" -#: lib/Lutim.pm:348 lib/Lutim/Command/cron/stats.pm:157 lib/Lutim/Command/cron/stats.pm:171 lib/Lutim/Command/cron/stats.pm:188 themes/default/templates/index.html.ep:3 themes/default/templates/myfiles.html.ep:3 themes/default/templates/partial/raw.js.ep:21 themes/default/templates/partial/raw.js.ep:4 themes/default/templates/raw.html.ep:6 +#: lib/Lutim.pm:317 lib/Lutim/Command/cron/stats.pm:154 lib/Lutim/Command/cron/stats.pm:168 lib/Lutim/Command/cron/stats.pm:185 themes/default/templates/index.html.ep:3 themes/default/templates/myfiles.html.ep:3 themes/default/templates/partial/raw.js.ep:21 themes/default/templates/partial/raw.js.ep:4 themes/default/templates/raw.html.ep:6 msgid "no time limit" msgstr ""