diff --git a/README.md b/README.md index 156fc80..3bc811f 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,9 @@ vi lutim.conf * hosted\_by: if someone hosts your LUTIm instance, you can add some HTML (a logo for example) to make it appear on index page ; * tweet\_card\_via: a twitter account which will appear on twitter cards ; * max\_file\_size: well, this is explicit (default is 10Mio = 10485760 octets) ; -* https: 1 if you want to provide secure images URLs. +* https: 1 if you want to provide secure images URLs (default is 0) ; +* stats\_day\_num: when you generate statistics with `script/lutim cron stats`, you will have stats for the last `stats_day_num` days (default is 365) ; +* keep\_ip\_during: when you delete IP addresses of image's senders with `script/lutim cron cleanbdd`, the IP addresses of images older than `keep_ip_during` days will be deleted (default is 365) ; ##Usage ``` @@ -81,6 +83,27 @@ sub vcl_recv { } ``` +##Cron jobs +LUTIm have commands which can be used in cron jobs. + +To see what commands are available: +```shell +carton exec script/lutim cron +``` + +###Statistics +To generate statistics which can be viewed at the address `/stats`: +```shell +carton exec script/lutim cron stats +``` + +###Delete IP adresses from database +To automatically delete the IP addresses of image's senders after a configurable delay: +```shell +carton exec script/lutim cron cleanbdd +``` + + ##Shutter integration See where Shutter () keeps its plugins on your computer. On my computer, it's in `/usr/share/shutter/resources/system/upload_plugins/upload`. diff --git a/lib/Mojolicious/Command/cron/cleanbdd.pm b/lib/Mojolicious/Command/cron/cleanbdd.pm new file mode 100644 index 0000000..4532110 --- /dev/null +++ b/lib/Mojolicious/Command/cron/cleanbdd.pm @@ -0,0 +1,38 @@ +package Mojolicious::Command::cron::cleanbdd; +use Mojo::Base 'Mojolicious::Command'; +use LutimModel; +use Mojo::Util qw(slurp decode); +use Mojolicious::Plugin::Config; + +has description => 'Delete IP addresses from database after configured delay.'; +has usage => sub { shift->extract_usage }; + +sub run { + my $c = shift; + + my $config = Mojolicious::Plugin::Config->parse(decode('UTF-8', slurp 'lutim.conf'), 'lutim.conf'); + + $config->{keep_ip_during} = (defined($config->{keep_ip_during})) ? $config->{keep_ip_during} : 365; + + my $separation = time() - $config->{keep_ip_during} * 86400; + + LutimModel->do( + 'UPDATE lutim SET created_by = "" WHERE path IS NOT NULL AND created_at < ?', + {}, + $separation + ); +} + +=encoding utf8 + +=head1 NAME + +Mojolicious::Command::cron::cleanbdd - Delete IP addresses from database after configured delay + +=head1 SYNOPSIS + + Usage: script/lutim cron cleanbdd + +=cut + +1; diff --git a/lutim.conf.template b/lutim.conf.template index 1d33e89..9bf6388 100644 --- a/lutim.conf.template +++ b/lutim.conf.template @@ -16,5 +16,6 @@ max_file_size => 10485760, # optional, size in octets, you can write it 10*1024*1024 #hosted_by => 'My super hoster Hoster logo', # optional #https => 0, # optional, set to 1 if you use Lutim behind a secure web server - #stats_day_num => 365, # optional, number of days shown in /stats page + #stats_day_num => 365, # optional, number of days shown in /stats page (used with script/lutim cron stats) + #keep_ip_during => 365, # optional, number of days, after that delay, the IP addresses of image creators will be deleted (used with script/lutim cron cleanbdd) };