diff --git a/README.md b/README.md index 794da41..3e46466 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,43 @@ cp lutim.conf.template lutim.conf carton exec hypnotoad script/lutim ``` -Yup, that's all, it will listen at "http://127.0.0.1:8080". +Yup, that's all (Mojolicious magic), it will listen at "http://127.0.0.1:8080". For more options (interfaces, user, etc.), change the configuration in `lutim.conf` (have a look at http://mojolicio.us/perldoc/Mojo/Server/Hypnotoad#SETTINGS for the available options). ##Reverse proxy You can use a reverse proxy like Nginx or Varnish (or Apache with the mod\_proxy module). The web is full of tutos. +Here's a valid *Varnish* configuration: +``` +backend lutim { + .host = "127.0.0.1"; + .port = "8080"; +} +sub vcl_recv { + if (req.restarts == 0) { + set req.http.X-Forwarded-For = client.ip; + } + if (req.http.host == "lut.im") { + set req.backend = lutim; + return(pass); + } +} +``` + +##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`. + +Then: +``` +sudo cp utilities/Shutter.pm /usr/share/shutter/resources/system/upload_plugins/upload/Lutim.pm +``` + +And restart Shutter if it was running. + +Of course, this plugin is configured for the official instance of LUTIm (), feel free to edit it for your own instance. + ##Internationalization LUTIm comes with english and french languages. It will choose the language to display from the browser's settings. diff --git a/utilities/Shutter.pm b/utilities/Shutter.pm new file mode 100755 index 0000000..3a8fd4a --- /dev/null +++ b/utilities/Shutter.pm @@ -0,0 +1,154 @@ +#! /usr/bin/env perl +################################################### +# +# Copyright (C) 2010-2011 Vadim Rutkovsky , Mario Kemper and Shutter Team +# +# This file is part of Shutter. +# +# Shutter is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Shutter is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Shutter; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +################################################### + +package Lutim; + +use lib $ENV{'SHUTTER_ROOT'}.'/share/shutter/resources/modules'; + +use utf8; +use strict; +use POSIX qw/setlocale/; +use Locale::gettext; +use Glib qw/TRUE FALSE/; + +use Shutter::Upload::Shared; +our @ISA = qw(Shutter::Upload::Shared); + +my $d = Locale::gettext->domain("shutter-upload-plugins"); +$d->dir( $ENV{'SHUTTER_INTL'} ); + +my %upload_plugin_info = ( + 'module' => "Lutim", + 'url' => "http://lut.im/", + 'registration' => "-", + 'description' => $d->get( "Upload screenshots to lut.im" ), + 'supports_anonymous_upload' => TRUE, + 'supports_authorized_upload' => FALSE, +); + +binmode( STDOUT, ":utf8" ); +if ( exists $upload_plugin_info{$ARGV[ 0 ]} ) { + print $upload_plugin_info{$ARGV[ 0 ]}; + exit; +} + +################################################### + +sub new { + my $class = shift; + + #call constructor of super class (host, debug_cparam, shutter_root, gettext_object, main_gtk_window, ua) + my $self = $class->SUPER::new( shift, shift, shift, shift, shift, shift ); + + bless $self, $class; + return $self; +} + +sub init { + my $self = shift; + + #do custom stuff here + use WWW::Mechanize; + use HTTP::Status; + use HTTP::Request::Common 'POST'; + + $self->{_mech} = WWW::Mechanize->new( agent => "$self->{_ua}", timeout => 20 ); + $self->{_http_status} = undef; + + return TRUE; +} + +sub upload { + my ( $self, $upload_filename, $username, $password ) = @_; + + #store as object vars + $self->{_filename} = $upload_filename; + $self->{_username} = $username; + $self->{_password} = $password; + + my $filesize = -s $upload_filename; + my $max_filesize = 15360000; + if ( $filesize > $max_filesize ) { + $self->{_links}{'status'} = 998; + $self->{_links}{'max_filesize'} = sprintf( "%.2f", $max_filesize / 1024 ) . " KB"; + return %{ $self->{_links} }; + } + + utf8::encode $upload_filename; + utf8::encode $password; + utf8::encode $username; + + eval{ + + my $url = "http://lut.im"; + $self->{_mech}->get($url); + $self->{_http_status} = $self->{_mech}->status(); + + if ( is_success( $self->{_http_status} ) ) { + + $self->{_mech}->request(POST $url, + Content_Type => 'form-data', + Content => [ + file => [$upload_filename], + format => 'json' + ], + ); + + $self->{_http_status} = $self->{_mech}->status(); + + if ( is_success( $self->{_http_status} ) ) { + my $html_file = $self->{_mech}->content; + + my @links = $html_file =~ m/"short":"([^"]+)"/; + #my @links = $html_file =~ m{ }gx; + + $self->{_links}{'view_image'} = $url.'/'.$links[0]; + $self->{_links}{'download_link'} = $url.'/'.$links[0].'?dl'; + $self->{_links}{'twitter_link'} = $url.'/'.$links[0].'?t'; + + if ( $self->{_debug} ) { + print "The following links were returned by http://lut.im:\n"; + print $self->{_links}{'view_image'},"\n"; + print $self->{_links}{'download_link'},"\n"; + print $self->{_links}{'twitter_link'},"\n"; + } + + $self->{_links}{'status'} = $self->{_http_status}; + } else { + $self->{_links}{'status'} = $self->{_http_status}; + } + + }else{ + $self->{_links}{'status'} = $self->{_http_status}; + } + + }; + if($@){ + $self->{_links}{'status'} = $@; + } + + return %{ $self->{_links} }; + +} + +1;