Allow to use lutim under a sub-directory (example.org/lutim)

Fix #46 and #57
This commit is contained in:
Luc Didry
2015-08-02 21:07:50 +02:00
parent a9ea0d35e6
commit 2e8f0eda2a
10 changed files with 54 additions and 62 deletions

View File

@@ -181,9 +181,7 @@ server {
# If you want to log the remote port of the image senders, you'll need that
proxy_set_header X-Remote-Port $remote_port;
# Lutim reads this header and understands that the current session is actually HTTPS.
# Enable it if you run a HTTPS server (in this case, don't forgot to change the listen port above)
#proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Proto $scheme;
# We expect the downsteam servers to redirect to the right hostname, so don't do any rewrites here.
proxy_redirect off;
@@ -191,6 +189,8 @@ server {
}
```
If you use Lutim under a subdirectory like `/lutim/`, change the `prefix` configuration option and prefix the nginx locations with `/lutim` (or whatever you choose).
## Cron jobs
Lutim have commands which can be used in cron jobs.

View File

@@ -65,8 +65,8 @@ sub startup {
$headers->add('Content-Disposition' => $dl.';filename='.$filename);
$c->res->content->headers($headers);
$c->app->log->debug($key);
if ($key) {
$c->app->log->debug($key);
$asset = $c->decrypt($key, $path);
} else {
$asset = Mojo::Asset::File->new(path => $path);
@@ -78,19 +78,6 @@ sub startup {
}
);
$self->helper(
index_url => sub {
my $c = shift;
my $to_abs = shift;
my $url = $c->url_for('index');
$url = $url->to_abs() if (defined($to_abs) && $to_abs);
$url =~ s#([^/])$#$1/#;
return $url;
}
);
$self->helper(
ip => sub {
my $c = shift;

View File

@@ -13,12 +13,16 @@ sub startup {
{
file => File::Spec->catfile($Bin, '..' ,'lutim.conf'),
default => {
url_sub_dir => '/'
prefix => '/'
}
}
);
$self->plugin('Mount' => {$config->{url_sub_dir} => File::Spec->catfile($Bin, '..', 'script', 'application')});
$config->{prefix} = $config->{url_sub_dir} if (defined($config->{url_sub_dir}) && $config->{prefix} eq '/');
$self->app->log->warn('"url_sub_dir" configuration option is deprecated. Use "prefix" instead. "url_sub_dir" will be removed in the future') if (defined($config->{url_sub_dir}));
$self->plugin('Mount' => {$config->{prefix} => File::Spec->catfile($Bin, '..', 'script', 'application')});
}
1;

View File

@@ -99,9 +99,9 @@
# URL sub-directory in which you want Lutim to be accessible
# example: you want to have Lutim under https://example.org/lutim/
# => set url_sub_dir to '/lutim' or to '/lutim/', it doesn't matter
# => set prefix to '/lutim' or to '/lutim/', it doesn't matter
# optional, defaut is /
#url_sub_dir => '/',
#prefix => '/',
##########################
# Lutim cron jobs settings

View File

@@ -7,7 +7,7 @@
<p><%= l('Drag and drop an image in the appropriate area or use the traditional way to send files and Lutim will provide you four URLs. One to view the image, an other to directly download it, one you can use on social networks and a last to delete the image when you want.') %></p>
<p><%= l('You can, optionally, request that the image(s) posted on Lutim to be deleted at first view (or download) or after the delay selected from those proposed.') %></p>
<h4><%= l('Is it really free (as in free beer)?') %></h4>
<p><%== l('Yes, it is! On the other side, if you want to support the developer, you can do it via <a href="https://flattr.com/submit/auto?user_id=_SKy_&amp;url=%1&amp;title=Lutim&amp;category=software">Flattr</a> or with <a href="bitcoin:1JCEtmx9pyzWfitMQj2pKAk8GNgyix7RmA?label=lutim">BitCoin</a>.', url_for('index')->to_abs()) %></p>
<p><%== l('Yes, it is! On the other side, if you want to support the developer, you can do it via <a href="https://flattr.com/submit/auto?user_id=_SKy_&amp;url=%1&amp;title=Lutim&amp;category=software">Flattr</a> or with <a href="bitcoin:1JCEtmx9pyzWfitMQj2pKAk8GNgyix7RmA?label=lutim">BitCoin</a>.', url_for('/')->to_abs()) %></p>
<h4><%= l('Is it really anonymous?') %></h4>
<p><%= l('Yes, it is! On the other side, for legal reasons, your IP address will be stored when you send an image. Don\'t panic, it is normally the case of all sites on which you send files!') %></p>
<p><%= l('The IP address of the image\'s sender is retained for a delay which depends of the administrator\'s choice (for the official instance, which is located in France, it\'s one year).') %></p>
@@ -36,5 +36,5 @@
<li>Laura Arjona Reina (<a href="https://wiki.debian.org/LauraArjona">https://wiki.debian.org/LauraArjona</a>), <%= l('spanish translation') %>
</ul>
<%= link_to url_for('index') => ( class => "btn btn-primary btn-lg" ) => begin %><%= l('Back to homepage') %><% end%>
<%= link_to url_for('/') => ( class => "btn btn-primary btn-lg" ) => begin %><%= l('Back to homepage') %><% end%>
</div>

View File

@@ -15,9 +15,9 @@
% }
<div>
% # Display image informations
% my $url = index_url(1).stash('short');
% my $url = url_for('/'.stash('short'))->to_abs();
<strong><%= stash('filename') %></strong>
&nbsp;&nbsp;&nbsp;<a target="_blank" class="btn btn-default btn-primary btn-xs" href="https://twitter.com/share?url=<%= $url %>?t"><%= l('Tweet it!') %></a>
&nbsp;&nbsp;&nbsp;<a title="<%= l('Tweet it!') %>" target="_blank" href="https://twitter.com/share?url=<%= $url %>?t"><span class="icon icon-twitter"></span></a>
<ul class="list-unstyled">
% my $delete_url = url_for('delete', {short => stash('real_short'), token => stash('token')})->to_abs();
<li><i class="icon icon-eye" title =" <%= l('View link') %>"></i> <%= link_to $url => begin %> <%= $url %> <%= end %></li>
@@ -81,7 +81,7 @@
</div>
<noscript>
<form class="form" role="form" method="POST" action="<%== index_url %>" enctype="multipart/form-data">
<form class="form" role="form" method="POST" action="<%= url_for('/') %>" enctype="multipart/form-data">
<div class="form-group form-inline">
<select name="delete-day" class="form-control">
% for my $delay (qw/0 1 7 30 365/) {
@@ -186,14 +186,14 @@
function link(url, dl, token, modify) {
if (token !== undefined) {
if (modify !== undefined && modify === true) {
return '<%== index_url(1) %>m/'+url+'/'+token;
return '<%== url_for('/m/')->to_abs() %>'+url+'/'+token;
} else {
url = 'd/'+url+'/'+token;
}
} else if (dl !== '') {
url = url+'?'+dl;
}
return '<a href="<%== index_url(1) %>'+url+'"><%== index_url(1) %>'+url+'</a>';
return '<a href="<%== url_for('/')->to_abs() %>'+url+'"><%== url_for('/')->to_abs() %>'+url+'</a>';
}
function share(url) {
console.log(url);
@@ -207,9 +207,9 @@
});
}
function tw_url(url) {
var btn = '&nbsp;&nbsp;&nbsp;<a title="<%= l('Tweet it!') %>" target="_blank" href="https://twitter.com/share?url=<%== url_for('index')->to_abs() %>'+url+'?t"><span class="icon icon-twitter"></span></a>';
var btn = '&nbsp;&nbsp;&nbsp;<a title="<%= l('Tweet it!') %>" target="_blank" href="https://twitter.com/share?url=<%== url_for('/')->to_abs() %>'+url+'?t"><span class="icon icon-twitter"></span></a>';
if (navigator.mozSetMessageHandler !== undefined) {
btn = btn+'&nbsp;&nbsp;&nbsp;<a title="<%= l('Share it!') %>" target="_blank" href="" onclick="share(\'<%== url_for('index')->to_abs() %>'+url+'?t\');return false;"><span class="icon icon-share"></span></a>';
btn = btn+'&nbsp;&nbsp;&nbsp;<a title="<%= l('Share it!') %>" target="_blank" href="" onclick="share(\'<%== url_for('/')->to_abs() %>'+url+'?t\');return false;"><span class="icon icon-share"></span></a>';
}
return btn
}
@@ -218,7 +218,7 @@
url : url,
type : "POST",
data : {
'image_url' : '<%== index_url(1) %>'+short,
'image_url' : '<%== url_for('/')->to_abs() %>'+short,
'format' : 'json',
'first-view' : ($("#first-view-"+short).prop('checked')) ? 1 : 0,
'delete-day' : $("#day-"+short).val()
@@ -284,7 +284,7 @@
}
function bindddz(firstview, deleteday) {
$('#drag-and-drop-zone').dmUploader({
url: '<%== index_url %>',
url: '<%== url_for('/') %>',
dataType: 'json',
allowedTypes: 'image/*',
maxFileSize: <%= $max_file_size %>,
@@ -317,7 +317,7 @@
$(".hidden-spin").css('display', 'block');
console.log(val);
$.ajax({
url : '<%== index_url %>',
url : '<%== url_for('/') %>',
type : "POST",
data : {
'lutim-file-url' : val,
@@ -357,7 +357,7 @@
$(".messages").append('<div id="1-div">'+file.name+'<br><div class="progress"><div id="1"class="progress-bar progress-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"><span id="1-text" class="pull-left" style="padding-left: 10px;"> 0%</span></div></div></div>');
// Ajax Submit
$.ajax({
url: '<%== index_url %>',
url: '<%== url_for('/') %>',
type: 'POST',
dataType: 'json',
data: fd,

View File

@@ -1,7 +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 $url = index_url(1);
% my $url = url_for('/')->to_abs();
% $twitter_url .= '?url='.url_escape("$url")
% .'&via=framasky'
% .'&text=Check out this %23Lutim instance! ';
@@ -14,14 +14,14 @@
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="icon" type="image/png" href="<%= index_url %>img/favicon.png">
<link rel="icon" sizes="128x128" href="<%= index_url %>img/lutim128.png">
<link rel="icon" sizes="196x196" href="<%= index_url %>img/lutim196.png">
<link rel="apple-touch-icon" href="<%= index_url %>img/lutim60.png">
<link rel="apple-touch-icon" sizes="76x76" href="<%= index_url %>img/lutim76.png">
<link rel="apple-touch-icon" sizes="120x120" href="<%= index_url %>img/lutim120.png">
<link rel="apple-touch-icon" sizes="152x152" href="<%= index_url %>img/lutim152.png">
<link rel="apple-touch-icon-precomposed" sizes="128x128" href="<%= index_url %>img/lutim128.png">
<link rel="icon" type="image/png" href="<%= url_for('/img/favicon.png') %>">
<link rel="icon" sizes="128x128" href="<%= url_for('/img/lutim128.png') %>">
<link rel="icon" sizes="196x196" href="<%= url_for('/img/lutim196.png') %>">
<link rel="apple-touch-icon" href="<%= url_for('/img/lutim60.png') %>">
<link rel="apple-touch-icon" sizes="76x76" href="<%= url_for('/img/lutim76.png') %>">
<link rel="apple-touch-icon" sizes="120x120" href="<%= url_for('/img/lutim120.png') %>">
<link rel="apple-touch-icon" sizes="152x152" href="<%= url_for('/img/lutim152.png') %>">
<link rel="apple-touch-icon-precomposed" sizes="128x128" href="<%= url_for('/img/lutim128.png') %>">
% if (current_route 'stats') {
%= asset 'stats.css'
% } elsif (current_route 'about') {
@@ -40,18 +40,18 @@
% }
<div>
<div class="pull-left hidden-xs logo">
<img src="<%= index_url %>img/Lutim_small.png" alt="Lutim logo" width="57" height="75">
<img src="<%= url_for('/img/Lutim_small.png') %>" alt="Lutim logo" width="57" height="75">
</div>
<a class="link_nocol" href="<%= url_for('/') %>" title="<%= l('Homepage') %>"><h1 class="hennypenny">Let's Upload That Image!</h1></a>
<p>
&copy; 2014 <%= link_to 'http://www.fiat-tux.fr' => begin %>Luc Didry<% end %> — 
<%= l('License:') %> <%= link_to 'https://www.gnu.org/licenses/agpl-3.0.html' => begin %>AGPL<% end %> — 
<%= link_to url_for('about') => begin %><%= l('Informations') %><% end %> — 
<%= link_to 'https://github.com/ldidry/lutim' => (title => l('Fork me!')) => begin %><i class="lead icon icon-github-circled"></i><% end %> 
<%= link_to 'https://git.framasoft.org/luc/lutim' => (title => l('Fork me!')) => begin %><i class="lead icon icon-git"></i><% end %> 
<%= link_to $twitter_url => (title => l('Share on Twitter')) => begin %><i class="lead icon icon-twitter"></i><% end %> 
<%= link_to 'https://flattr.com/submit/auto?user_id=_SKy_&url='.$url.'&title=Lutim&category=software' => (title => 'Flattr this') => begin %><i class="lead icon icon-flattr"></i><% end %> 
<%= link_to 'bitcoin:1K3n4MXNRSMHk28oTfXEvDunWFthePvd8v?label=lutim' => (title => 'Give Bitcoins') => begin %><i class="lead icon icon-bitcoin"></i><% end %> 
<a class="btn btn-default btn-xs" href="#" id="install-app"><img src="<%= url_for('/') %>img/rocket.png" alt="mozilla rocket logo"> <%= l('Install webapp') %></a>
<%= link_to 'bitcoin:1JCEtmx9pyzWfitMQj2pKAk8GNgyix7RmA?label=lutim' => (title => 'Give Bitcoins') => begin %><i class="lead icon icon-bitcoin"></i><% end %> 
<a class="btn btn-default btn-xs" href="#" id="install-app"><img src="<%= url_for('/img/rocket.png') %>" alt="mozilla rocket logo"> <%= l('Install webapp') %></a>
</p>
</div>
</div>

View File

@@ -1,7 +1,7 @@
{
"name": "Lutim",
"description": "Let's Upload That Image!\n\nThis is a simple image sharing app which use <%= url_for('index')->to_abs %> for storing the images. Once you have uploaded an image, you'll be provided differents links:\n a view link, which points directly to the image\n a download link, which force the download of the image\n a twitter link, which you can share on twitter : the image will natively appeared in twitter\n a delete link, which allows you to delete the image anytime you want\n\nThe image is stored on <%= url_for('index')->to_abs %> for a delay which you can define.\n\nThe particularity of Lutim is that the image is encrypted and its usage is as most anonymous as possible. See the information page (<%= url_for('about')->to_abs %>) for more details.\nLicense: AGPLv3 (https://www.gnu.org/licenses/agpl-3.0.html)",
"launch_path": "<%= url_for('index') %>",
"description": "Let's Upload That Image!\n\nThis is a simple image sharing app which use <%= url_for('/')->to_abs %> for storing the images. Once you have uploaded an image, you'll be provided differents links:\n a view link, which points directly to the image\n a download link, which force the download of the image\n a twitter link, which you can share on twitter : the image will natively appeared in twitter\n a delete link, which allows you to delete the image anytime you want\n\nThe image is stored on <%= url_for('/')->to_abs %> for a delay which you can define.\n\nThe particularity of Lutim is that the image is encrypted and its usage is as most anonymous as possible. See the information page (<%= url_for('about')->to_abs %>) for more details.\nLicense: AGPLv3 (https://www.gnu.org/licenses/agpl-3.0.html)",
"launch_path": "<%= url_for('/') %>",
"icons": {
"32": "<%= url_for('/img/lutim32.png') %>",
"60": "<%= url_for('/img/lutim60.png') %>",
@@ -17,7 +17,7 @@
"default_locale": "en",
"locales": {
"fr": {
"description": "Envoyons cette image !\n\nCeci est une application de partage simple d'images qui utilise <%= url_for('index')->to_abs %> pour enregistrer les images. Une fois que vous avez envoyé une image, vous obtiendrez différents liens :\n un lien de visualisation, qui pointe directement sur l'image\n un lien de téléchargement, qui force le téléchargement de l'image\n un lien twitter, que vous pouvez partager sur twitter : l'image apparaîtra nativement dans twitter\n un lien de suppression, qui vous permet de supprimer l'image quand vous le souhaitez\n\nL'image est conservée sur <%= url_for('index')->to_abs %> pour un délai que vous pouvez définir.\n\nLa particularité de Lutim est que l'image est chiffrée et que son usage est aussi anonyme que possible. Voir la page d'information (<%= url_for('about')->to_abs %>) pour plus de détails.\nLicence : AGPLv3 (https://www.gnu.org/licenses/agpl-3.0.html)"
"description": "Envoyons cette image !\n\nCeci est une application de partage simple d'images qui utilise <%= url_for('/')->to_abs %> pour enregistrer les images. Une fois que vous avez envoyé une image, vous obtiendrez différents liens :\n un lien de visualisation, qui pointe directement sur l'image\n un lien de téléchargement, qui force le téléchargement de l'image\n un lien twitter, que vous pouvez partager sur twitter : l'image apparaîtra nativement dans twitter\n un lien de suppression, qui vous permet de supprimer l'image quand vous le souhaitez\n\nL'image est conservée sur <%= url_for('/')->to_abs %> pour un délai que vous pouvez définir.\n\nLa particularité de Lutim est que l'image est chiffrée et que son usage est aussi anonyme que possible. Voir la page d'information (<%= url_for('about')->to_abs %>) pour plus de détails.\nLicence : AGPLv3 (https://www.gnu.org/licenses/agpl-3.0.html)"
}
},
"activities": {
@@ -25,7 +25,7 @@
"filters": {
"type": [ "image/*"]
},
"href": "<%= url_for('index') %>",
"href": "<%= url_for('/') %>",
"disposition": "window"
}
},

View File

@@ -10,4 +10,4 @@
<div id="total-holder"></div>
<p><small><%= l('The graph\'s datas are not updated in real-time.') %></small></p>
<%= link_to url_for('index') => ( class => "btn btn-primary btn-lg" ) => begin %><%= l('Back to homepage') %><% end%>
<%= link_to url_for('/') => ( class => "btn btn-primary btn-lg" ) => begin %><%= l('Back to homepage') %><% end%>

View File

@@ -1,24 +1,25 @@
% # vim:set sw=4 ts=4 sts=4 ft=html.epl expandtab:
% my $g = ($mimetype eq 'image/gif') ? 1 : 0;
% my $g = ($mimetype eq 'image/gif') ? 1 : 0;
% my $abs = url_for('/'.$short)->to_abs();
<!DOCTYPE html>
<html style="max-height:100%;">
<head>
<title>Lutim</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="utf-8" />
<link rel="icon" type="image/png" href="<%= index_url(1) %>img/favicon.png">
<link rel="icon" type="image/png" href="<%= url_for('/img/favicon.png')->to_abs() %>">
<meta property="og:title" content="Lutim" />
<meta property="og:type" content="website" />
<meta property="og:url" content="<%= index_url(1).$short %>?t" />
<meta property="og:image" content="<%= index_url(1).$short %>" />
<meta property="og:image:url" content="<%= index_url(1).$short %>" />
<meta property="og:url" content="<%= $abs %>?t" />
<meta property="og:image" content="<%= $abs %>" />
<meta property="og:image:url" content="<%= $abs %>" />
<meta property="og:image:type" content="<%= $mimetype %>" />
<meta name="twitter:site" content="<%= config('tweet_card_via') %>">
<meta name="twitter:image:src" content="<%= index_url(1).$short %>">
<meta name="twitter:image:src" content="<%= $abs %>">
% if ($g) {
<meta name="twitter:card" content="player">
<meta name="twitter:image" content="<%= index_url(1).$short %>">
<meta name="twitter:player" content="<%= index_url(1).$short.'?t' %>">
<meta name="twitter:image" content="<%= $abs %>">
<meta name="twitter:player" content="<%= $abs %>?t">
<meta name="twitter:title" content="<%= $filename %>">
<meta name="twitter:player:width" content="<%= $width %>">
<meta name="twitter:player:height" content="<%= $height %>">
@@ -33,8 +34,8 @@
<meta name="twitter:card" content="photo">
% }
</head>
<body<%= ($g) ? '' : ' style="height: 97%;"' %>>
<img<%= ' class="freezeframe"' if ($g) %> style="<%= 'max-' unless ($g) %>width:100%; max-height:100%;" src="<%= index_url(1).$short %><%= '.gif' if ($g) %>" alt="<%= $filename %>">
<body<%== ($g) ? '' : ' style="height: 97%;"' %>>
<img<%= ' class="freezeframe"' if ($g) %> style="<%= 'max-' unless ($g) %>width:100%; max-height:100%;" src="<%= $abs %><%= '.gif' if ($g) %>" alt="<%= $filename %>">
</body>
</html>