diff --git a/Changes b/Changes index 04ea321..7d2821c 100644 --- a/Changes +++ b/Changes @@ -4,6 +4,8 @@ Revision history for LUTIm - Antiflood protection for the "Download by URL" feature (#29) - Stats page improved - Remote port detection can now use the X-Remote-Port header if set + - LUTIm now uses the X-Forwarded-Proto header to set the scheme to https if needed + The "https" option in configuration file is deprecated and will be removed in 0.4 0.2 2014-03-07 - Server-side encryption available diff --git a/README.md b/README.md index 316e39c..8c6a2fc 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ 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 (default is 0) ; +* https: 1 if you want to provide secure images URLs (default is 0) DEPRECATED, PASS A `X-Forwarded-Proto` HEADER TO LUTIM FROM YOUR REVERSE PROXY INSTEAD ; * 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) ; * broadcast\_message: put some string (not HTML) here and this message will be displayed on all LUTIm pages (not in JSON responses) ; diff --git a/lib/Lutim.pm b/lib/Lutim.pm index 5530db9..093c852 100644 --- a/lib/Lutim.pm +++ b/lib/Lutim.pm @@ -262,6 +262,11 @@ sub startup { } } } + + # Scheme detection + if ((defined($c->req->headers->header('X-Forwarded-Proto')) && $c->req->headers->header('X-Forwarded-Proto') eq 'https') || (defined($c->config->{https}) && $c->config->{https})) { + $c->req->url->base->scheme('https'); + } } ); diff --git a/lutim.conf.template b/lutim.conf.template index 38514f5..2e9f919 100644 --- a/lutim.conf.template +++ b/lutim.conf.template @@ -64,8 +64,9 @@ # optional, no default #hosted_by => 'My super hoster Hoster logo', + # DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED + # LUTIm now checks if the X-Forwarded-Proto header is present and equal to https. # set to 1 if you use Lutim behind a secure web server - # secure connection detection will be improved in the future # optional, default is 0 #https => 0, diff --git a/templates/about.html.ep b/templates/about.html.ep index d3fdbfd..a9e7325 100644 --- a/templates/about.html.ep +++ b/templates/about.html.ep @@ -1,6 +1,5 @@ % # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab: -% my $scheme = (defined(config('https')) && config('https')) ? 'https' : 'http'; diff --git a/templates/index.html.ep b/templates/index.html.ep index d532262..41509c3 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -1,5 +1,4 @@ % # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab: -% my $scheme = (defined(config('https')) && config('https')) ? 'https' : 'http';
% if (config('always_encrypt')) {

<%=l 'always_encrypt' %>

@@ -12,9 +11,9 @@
<%= stash('filename') %>
@@ -135,7 +134,7 @@ if (dl !== '') { url = url+'?'+dl; } - return '<%== url_for('index')->base->scheme($scheme)->to_abs() %>/'+url+''; + return '<%== url_for('index')->to_abs() %>'+url+''; } function message(success, msg) { if(success) { diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index e92bf0b..4e37738 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -1,8 +1,7 @@ % # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab: % use Mojo::Util qw(url_escape); % my $twitter_url = 'https://twitter.com/share'; -% my $scheme = (defined(config('https')) && config('https')) ? 'https' : 'http'; -% my $url = url_for('/')->base->scheme($scheme)->to_abs().'/'; +% my $url = url_for('/')->to_abs(); % $twitter_url .= '?url='.url_escape("$url") % .'&via=framasky' % .'&text=Check out this %23LUTIm instance! '; @@ -108,7 +107,7 @@