Hello community, here is the log from the commit of package shutter for openSUSE:Factory checked in at 2017-08-22 11:08:59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/shutter (Old) and /work/SRC/openSUSE:Factory/.shutter.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "shutter" Tue Aug 22 11:08:59 2017 rev:4 rq:517858 version:0.94 Changes: -------- --- /work/SRC/openSUSE:Factory/shutter/shutter.changes 2017-01-11 12:05:05.218165750 +0100 +++ /work/SRC/openSUSE:Factory/.shutter.new/shutter.changes 2017-08-22 11:09:08.872436474 +0200 @@ -1,0 +2,23 @@ +Sun Aug 20 22:15:23 UTC 2017 - [email protected] + +- Update to version 0.94: + * This is a bugfix release implementing some of the patches. + available for quite some time. Following bugs are fixed: + - lp#731874: Launching a second instance of Shutter if one + instance is already open causes a crash. + - lp#1369330: [patch] i18n for desktop file. + - lp#1396368: Shutter screenshots uploaded to Dropbox expires. + - lp#1406324: Imgur uploaded links dialog shows links in random + order on every upload. + - lp#1469840: Send by e-mail generates error (ctrl-shft-E). + - lp#1495163: Insecure use of system() allows arbitrary code + execution via "Show in Folder". + - lp#1556021: 'Window' does not show non-latin characters. + - lp#1565048: imgur upload plugin no longer works due to now + unsupported API 1 and 2. + - lp#1624795: Linux software store metadata. +- Drop shutter-0.93.1-fix-send-email.patch and + CVE-2016-10081.patch: Fixed upstream. +- Drop shutter.appdata.xml source, now included in tarball. + +------------------------------------------------------------------- Old: ---- CVE-2016-10081.patch shutter-0.93.1-fix-send-email.patch shutter-0.93.1.tar.gz shutter.appdata.xml New: ---- shutter-0.94.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ shutter.spec ++++++ --- /var/tmp/diff_new_pack.vvDrsR/_old 2017-08-22 11:09:09.860297378 +0200 +++ /var/tmp/diff_new_pack.vvDrsR/_new 2017-08-22 11:09:09.872295689 +0200 @@ -20,23 +20,17 @@ Name: shutter -Version: 0.93.1 +Version: 0.94 Release: 0 Summary: Featureful screenshot tool License: GPL-3.0+ Group: Productivity/Graphics/Other Url: http://shutter-project.org/ -Source0: http://shutter-project.org/wp-content/uploads/releases/tars/%{name}-%{version}.tar.gz -# PATCH-FEATURE-UPSTREAM https://bugs.launchpad.net/shutter/+bug/1624795 -Source1: shutter.appdata.xml +Source0: https://launchpad.net/shutter/0.9x/0.94/+download/%{name}-%{version}.tar.gz # PATCH-FIX-OPENSUSE Remove Unity only actions Patch0: desktop-shortcut-fix.diff # PATCH-FIX-OPENSUSE make Dropbox support optional Patch2: remove-provide-dropbox.diff -# PATCH-FIX-UPSTREAM https://bugs.launchpad.net/shutter/+bug/1469840 -Patch3: shutter-0.93.1-fix-send-email.patch -# PATCH-FIX-DEBIAN https://bugs.launchpad.net/shutter/+bug/1652600 -Patch4: https://anonscm.debian.org/cgit/collab-maint/shutter.git/plain/debian/patches/CVE-2016-10081.patch BuildRequires: fdupes BuildRequires: hicolor-icon-theme BuildRequires: update-desktop-files @@ -92,8 +86,6 @@ %setup -q %patch0 %patch2 -%patch3 -p 2 -%patch4 -p1 %build @@ -111,9 +103,7 @@ %find_lang %{name} --all-name rm -f %{buildroot}%{_datadir}/applications/%{name}.desktop~ - -mkdir -p %{buildroot}%{_datadir}/appdata/ -cp -a %{S:1} %{buildroot}%{_datadir}/appdata/ +rm -f %{buildroot}%{_datadir}/applications/%{name}.desktop.orig %fdupes %{buildroot}%{_datadir}/ ++++++ shutter-0.93.1.tar.gz -> shutter-0.94.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/.bzrignore new/shutter-0.94/.bzrignore --- old/shutter-0.93.1/.bzrignore 1970-01-01 01:00:00.000000000 +0100 +++ new/shutter-0.94/.bzrignore 2017-08-11 20:58:00.000000000 +0200 @@ -0,0 +1,2 @@ +.project +.settings diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/CHANGES new/shutter-0.94/CHANGES --- old/shutter-0.93.1/CHANGES 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/CHANGES 2017-08-16 20:53:59.000000000 +0200 @@ -1,3 +1,19 @@ +shutter (0.64) + +This is a bugfix release implementing some of the patches available for quite some time. Following bugs are fixed: + + -- LP: #731874 Launching a second instance of Shutter if one instance is already open causes a crash + -- LP: #1369330 [patch] i18n for desktop file + -- LP: #1396368 Shutter screenshots uploaded to Dropbox expires + -- LP: #1406324 Imgur uploaded links dialog shows links in random order on every upload + -- LP: #1469840 Send by e-mail generates error (ctrl-shft-E) + -- LP: #1495163 Insecure use of system() allows arbitrary code execution via "Show in Folder" + -- LP: #1556021 'Window' does not show non-latin characters + -- LP: #1565048 imgur upload plugin no longer works due to now unsupported API 1 and 2 + -- LP: #1624795 Linux software store metadata + + -- Michael Kogan <[email protected]> Wed, 16 Aug 2017 20:53:00 +0100 + shutter (0.93.1) * updated Dropbox.pm and XFIXES.pm diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/bin/shutter new/shutter-0.94/bin/shutter --- old/shutter-0.93.1/bin/shutter 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/bin/shutter 2017-08-17 15:50:36.000000000 +0200 @@ -30,6 +30,9 @@ use strict; use warnings; +#Deal with encoding problem +use Encode; + #Gnome2 libraries use Gnome2; use Gnome2::Wnck; @@ -103,9 +106,9 @@ #define constants #-------------------------------------- use constant MAX_ERROR => 5; -use constant SHUTTER_REV => 'Rev.1278'; +use constant SHUTTER_REV => 'Rev.1290'; use constant SHUTTER_NAME => 'Shutter'; -use constant SHUTTER_VERSION => '0.93.1'; +use constant SHUTTER_VERSION => '0.94'; #-------------------------------------- #configure path settings @@ -442,12 +445,14 @@ #set export filename } elsif ( $cmd eq 'exfilename' ) { - $sc->set_export_filename( $message->get_text ); + my $arg = defined $message->get ? $message->get_text : ""; + $sc->set_export_filename( $arg ); #set delay } elsif ( $cmd eq 'delay' ) { - $sc->set_delay( $message->get_text ); + my $arg = defined $message->get ? $message->get_text : ""; + $sc->set_delay( $arg ); #set include_cursor flag } @@ -464,12 +469,13 @@ #set nosession flag } elsif ( $cmd eq 'nosession' ) { - $sc->set_no_session( $message->get_text ); + my $arg = defined $message->get ? $message->get_text : ""; + $sc->set_no_session( $arg ); #open new files } elsif ( $cmd eq 'fopen' ) { - my @init_files = $message->get_uris; + my @init_files = defined $message->get ? $message->get_uris : (); if ( scalar @init_files > 0 ) { &fct_open_files(@init_files); } @@ -483,7 +489,8 @@ #take screenshot } else { - &evt_take_screenshot( 'global_keybinding', $cmd, undef, $message->get_text ); + my $arg = defined $message->get ? $message->get_text : ""; + &evt_take_screenshot( 'global_keybinding', $cmd, undef, $arg ); } } @@ -6964,7 +6971,7 @@ ); } else { - push( @files_to_email, $session_screens{$key}->{'uri'}->to_string ); + push( @files_to_email, $session_screens{$key}->{'long'} ); } my $mail_string = undef; @@ -7159,8 +7166,13 @@ elsif ( $pid == 0 ) { #see Bug #661424 - my $qfilename = quotemeta $session_screens{$key}->{'long'}; - exec( sprintf( "$^X $plugin_value %d $qfilename $session_screens{$key}->{'width'} $session_screens{$key}->{'height'} $session_screens{$key}->{'filetype'}\n", $socket->get_id ) ); + #my $qfilename = quotemeta $session_screens{$key}->{'long'}; + exec( $^X, $plugin_value, + $socket->get_id, + $session_screens{$key}->{'long'}, + $session_screens{$key}->{'width'}, + $session_screens{$key}->{'height'}, + $session_screens{$key}->{'filetype'} ); } $sdialog->show_all; @@ -7193,11 +7205,15 @@ my $plugin_process = Proc::Simple->new; #see Bug #661424 - my $qfilename = quotemeta $session_screens{$key}->{'long'}; + #my $qfilename = quotemeta $session_screens{$key}->{'long'}; $plugin_process->start( sub { - system("'$plugin_value' $qfilename '$session_screens{$key}->{'width'}' '$session_screens{$key}->{'height'}' '$session_screens{$key}->{'filetype'}' "); + system( $plugin_value, + $session_screens{$key}->{'long'}, + $session_screens{$key}->{'width'}, + $session_screens{$key}->{'height'}, + $session_screens{$key}->{'filetype'} ); POSIX::_exit(0); } ); @@ -8353,7 +8369,10 @@ #~ print $name, $folder, $type, "\n"; if ( !exists $accounts{$name} - || !exists $accounts{$name}->{module} ) + || !exists $accounts{$name}->{module} + || $accounts{$name}->{supports_anonymous_upload} ne &fct_upload_plugin_get_info( $ukey, 'supports_anonymous_upload' ) || + $accounts{$name}->{supports_authorized_upload} ne &fct_upload_plugin_get_info( $ukey, 'supports_authorized_upload' ) || + $accounts{$name}->{supports_oauth_upload} ne &fct_upload_plugin_get_info( $ukey, 'supports_oauth_upload' ) ) { #show dialog and progress bar @@ -8624,7 +8643,9 @@ #add all windows to menu to capture it directly foreach my $win ( $wnck_screen->get_windows_stacked ) { if ( $active_workspace && $win->is_on_workspace($active_workspace) ) { - my $window_item = Gtk2::ImageMenuItem->new_with_label( $win->get_name ); + my $win_name = $win->get_name; + Encode::_utf8_on( $win_name ); + my $window_item = Gtk2::ImageMenuItem->new_with_label( $win_name ); foreach my $child ( $window_item->get_children ) { if ( $child =~ /Gtk2::AccelLabel/ ) { $child->set_width_chars(50); @@ -10632,7 +10653,7 @@ my $uploader = $hosting_module->new( $hosting_host, $sc->get_debug, $shutter_root, $d, $window, SHUTTER_VERSION ); #init module - if ( $uploader->init ) { + if ( $uploader->init($hosting_username) ) { my $counter = 1; $hosting_progress->set_fraction(0); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/appdata/shutter.appdata.xml new/shutter-0.94/share/appdata/shutter.appdata.xml --- old/shutter-0.93.1/share/appdata/shutter.appdata.xml 1970-01-01 01:00:00.000000000 +0100 +++ new/shutter-0.94/share/appdata/shutter.appdata.xml 2016-09-18 07:44:36.000000000 +0200 @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<application> + <id type="desktop">shutter.desktop</id> + <metadata_license>CC0-1.0</metadata_license> + <license>GPL-3.0+</license> + <description> + <p> + Shutter is a feature-rich screenshot program. You can take a screenshot of a + specific area, window, your whole screen, or even of a website - apply different + effects to it, draw on it to highlight points, and then upload to an image + hosting site, all within one window. + </p> + <p> + Shutter allows you to capture nearly anything on your screen without losing + control over your screenshots (tabbed interface). + You don't need to open an external graphics editor like GIMP, because Shutter + ships with its own built-in editor. + </p> + </description> + <url type="homepage">http://shutter-project.org/</url> + <screenshots> + <screenshot type="default">http://shutter-project.org/wp-content/uploads/key_feature_030.png</screenshot> + <screenshot>http://shutter-project.org/wp-content/uploads/key_feature_042.png</screenshot> + <screenshot>http://shutter-project.org/wp-content/uploads/key_feature_036.png</screenshot> + <screenshot>http://shutter-project.org/wp-content/uploads/key_feature_073.png</screenshot> + </screenshots> +</application> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/applications/shutter.desktop new/shutter-0.94/share/applications/shutter.desktop --- old/shutter-0.93.1/share/applications/shutter.desktop 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/share/applications/shutter.desktop 2017-08-12 17:36:41.000000000 +0200 @@ -6,9 +6,65 @@ GenericName=Screenshot Tool GenericName[de_DE]=Anwendung für Bildschirmfotos GenericName[pt_BR]=Captura de tela +GenericName[de]=Anwendung für Bildschirmfotos +GenericName[ar]=أداة لقطة شاشة +GenericName[ca]=Eina de captura de pantalla +GenericName[cs]=Snímkovací nástroj +GenericName[da]=Værktøj til skærmbilleder +GenericName[el]=Εργαλείο στιγμιότυπου οθόνης +GenericName[es]=Herramienta para la captura de la pantalla +GenericName[fi]=Kuvaruutukaappaus +GenericName[hu]=Képernyőkép-készítő eszköz +GenericName[it]=Strumento di istantanee dello schermo +GenericName[ja]=スクリーンショットツール +GenericName[lt]=Momentinė ekrano kopija +GenericName[nb]=Skjermdumpverktøy +GenericName[nl]=Hulpmiddel voor schermafdruk +GenericName[pl]=Narzędzie zrzutów ekranu +GenericName[ro]=Utilitar pentru capturi de ecran +GenericName[ru]=Утилита для экранных снимков +GenericName[zh_CN]=截图工具 +GenericName[zh_TW]=螢幕抓圖工具 Comment=Capture, edit and share screenshots Comment[de_DE]=Bildschirmfotos aufnehmen, bearbeiten und mit Anderen teilen Comment[pt_BR]=Aplicativo avançado para capturar imagens da tela +Comment[eu]=Egin, editatu eta partekatu pantaila-argazkiak +Comment[sq]=Kap modifiko dhe shpërnda pamjet e ekranit +Comment[ast]=Captura, edita y comparte captures de pantalla +Comment[bn]=স্ক্রীনশট শেয়ার এবং সম্পাদনা, অধিগ্রহন করুন +Comment[bs]=Hvatanje, uređivanje i dijeljenje snimaka ekrana +Comment[bg]=Снимайте, редактирайте и споделете снимките на екрана +Comment[ca]=Captureu, editeu i compartiu captures de pantalla +Comment[ca@valencia]=Captureu, editeu i compartiu captures de pantalla +Comment[zh_HK]=捕捉、編輯、分享螢幕截圖 +Comment[zh_TW]=捕捉、編輯和分享螢幕擷取圖 +Comment[crh]=Ekran görüntüleri yakalayın, düzenleyin ve paylaşın +Comment[zh_CN]=获取、编辑和共享截图 +Comment[cs]=Zachycování, úprava a sdílení snímků obrazovky +Comment[nl]=Schermafdrukken maken, bewerken en delen +Comment[da]=Fang, rediger og del skærmbilleder +Comment[et]=Ekraanikuvade salvestamine, redigeerimine ning jagamine +Comment[fi]=Ota, muokkaa ja jaa kuvankaappauksia +Comment[fr]=Faire des captures d'acran, les modifier et les partager +Comment[gl]=Capture, edite e comparta capturas de pantalla +Comment[de]=Bildschirmfotos aufnehmen, bearbeiten und mit Anderen teilen +Comment[el]=Λήψη, επεξεργασία και κοινή χρήση στιγμιότυπων οθόνης +Comment[hu]=Képernyőkép készítés, szerkesztés, megosztás +Comment[it]=Cattura, modifica e condivide schermate +Comment[ja]=スクリーンショットのキャプチャ/編集/共有 +Comment[ky]=Скриншотторду тартуу, оңдоо жана башкалар менен бөлүшүү +Comment[ms]=Tangkap, sunting dan kongsi cekupan skrin +Comment[oc]=Far de capturas d'ecran, las modificar e las partejar +Comment[nb]=Ta bilder, rediger og del bilder av skjermen med andre +Comment[ro]=Realizați. editați și partajați capturi de ecran +Comment[pl]=Pobieranie, edycja i udostępnianie zrzutów ekranu +Comment[pt]=Capture, edite e partilhe capturas de ecrã +Comment[ru]=Захват, редактирование и выкладывание в общий доступ снимков экрана +Comment[sv]=Fånga, redigera och dela skärmbilder +Comment[es]=Capture, edite y comparta capturas de pantallas +Comment[sl]=Zajemite, uredite in souporabljajte zaslonske posnetke +Comment[uk]=Захоплення, редагування та оприлюднення знімків вікон +Comment[tr]=Ekran görüntüleri yakalayın, düzenleyin ve paylaşın Exec=shutter %F Icon=shutter Terminal=false diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/shutter/resources/modules/Shutter/App/Common.pm new/shutter-0.94/share/shutter/resources/modules/Shutter/App/Common.pm --- old/shutter-0.93.1/share/shutter/resources/modules/Shutter/App/Common.pm 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/share/shutter/resources/modules/Shutter/App/Common.pm 2017-08-11 20:58:00.000000000 +0200 @@ -48,7 +48,7 @@ my $self = { _shutter_root => shift, _mainwindow => shift, _appname => shift, _version => shift, _rev => shift, _pid => shift }; #vars - $self->{_debug_cparam} = FALSE; + $self->{_debug_cparam} = TRUE; $self->{_clear_cache} = FALSE; $self->{_min_cparam} = FALSE; $self->{_disable_systray_cparam} = FALSE; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/shutter/resources/modules/Shutter/App/HelperFunctions.pm new/shutter-0.94/share/shutter/resources/modules/Shutter/App/HelperFunctions.pm --- old/shutter-0.93.1/share/shutter/resources/modules/Shutter/App/HelperFunctions.pm 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/share/shutter/resources/modules/Shutter/App/HelperFunctions.pm 2017-08-12 15:54:15.000000000 +0200 @@ -53,7 +53,8 @@ sub xdg_open { my ( $self, $dialog, $link, $user_data ) = @_; - system("xdg-open $link"); + my @args = ("xdg-open", "$link"); + system(@args); if($?){ my $response = $self->{_dialogs}->dlg_error_message( sprintf( $self->{_d}->get("Error while executing %s."), "'xdg-open'"), diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm new/shutter-0.94/share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm --- old/shutter-0.93.1/share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm 2017-08-11 20:58:00.000000000 +0200 @@ -59,6 +59,7 @@ my $detail_message = shift; my $detail_checkbox = shift; my $content_widget = shift; + my $content_widget2 = shift; my $info_dialog = Gtk2::MessageDialog->new( $self->{_window}, [qw/modal destroy-with-parent/], 'info', 'none', undef ); @@ -71,6 +72,9 @@ if($content_widget){ $info_dialog->get_content_area()->add($content_widget); } + if($content_widget2){ + $info_dialog->get_content_area()->add($content_widget2); + } $info_dialog->add_button( $button_text_extra1, 10 ) if $button_text_extra1; $info_dialog->add_button( $button_text_extra2, 20 ) if $button_text_extra2; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/shutter/resources/modules/Shutter/Upload/Shared.pm new/shutter-0.94/share/shutter/resources/modules/Shutter/Upload/Shared.pm --- old/shutter-0.93.1/share/shutter/resources/modules/Shutter/Upload/Shared.pm 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/share/shutter/resources/modules/Shutter/Upload/Shared.pm 2017-08-11 20:58:00.000000000 +0200 @@ -67,7 +67,7 @@ my $sg = Gtk2::SizeGroup->new('horizontal'); #create entry for each link - foreach (keys %{$self->{_links}}){ + foreach (sort keys %{$self->{_links}}){ next if $_ eq 'status'; my $box = $self->create_entry_for_notebook($_, $self->{_links}->{$_}, $sg); $upload_vbox->pack_start($box, FALSE, FALSE, 3); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/shutter/resources/system/upload_plugins/upload/Dropbox.pm new/shutter-0.94/share/shutter/resources/system/upload_plugins/upload/Dropbox.pm --- old/shutter-0.93.1/share/shutter/resources/system/upload_plugins/upload/Dropbox.pm 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/share/shutter/resources/system/upload_plugins/upload/Dropbox.pm 2017-08-12 15:40:21.000000000 +0200 @@ -195,7 +195,7 @@ $upload_file->close(); if(! $self->{_box}->error) { - $res = $self->{_box}->media($self->{_config}->{upload_folder} . "/" . basename($upload_filename)); + $res = $self->{_box}->shares($self->{_config}->{upload_folder} . "/" . basename($upload_filename), {short_url => 0}); } if(! $self->{_box}->error){ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/shutter-0.93.1/share/shutter/resources/system/upload_plugins/upload/Imgur.pm new/shutter-0.94/share/shutter/resources/system/upload_plugins/upload/Imgur.pm --- old/shutter-0.93.1/share/shutter/resources/system/upload_plugins/upload/Imgur.pm 2014-12-24 00:12:32.000000000 +0100 +++ new/shutter-0.94/share/shutter/resources/system/upload_plugins/upload/Imgur.pm 2017-08-11 20:58:00.000000000 +0200 @@ -29,7 +29,8 @@ use strict; use POSIX qw/setlocale/; use Locale::gettext; -use Glib qw/TRUE FALSE/; +use Glib qw/TRUE FALSE/; +use MIME::Base64; use Shutter::Upload::Shared; our @ISA = qw(Shutter::Upload::Shared); @@ -38,12 +39,13 @@ $d->dir( $ENV{'SHUTTER_INTL'} ); my %upload_plugin_info = ( - 'module' => "Imgur", + 'module' => "Imgur", 'url' => "http://imgur.com/", 'registration' => "https://imgur.com/register", 'description' => $d->get( "Imgur is used to share photos with social networks and online communities, and has the funniest pictures from all over the Internet" ), - 'supports_anonymous_upload' => TRUE, + 'supports_anonymous_upload' => TRUE, 'supports_authorized_upload' => FALSE, + 'supports_oauth_upload' => TRUE, ); binmode( STDOUT, ":utf8" ); @@ -66,15 +68,130 @@ sub init { my $self = shift; + my $username = shift; - #do custom stuff here + #do custom stuff here use JSON; use LWP::UserAgent; use HTTP::Request::Common; + use Path::Class; + + $self->{_config} = { }; + $self->{_config_file} = file( $ENV{'HOME'}, '.imgur-api-config' ); + + $self->load_config; + if ($username eq $d->get("OAuth")) + { + return $self->connect; + } + + return TRUE; +} + +sub load_config { + my $self = shift; + if (-f $self->{_config_file}) { + eval { + $self->{_config} = decode_json($self->{_config_file}->slurp); + }; + if ($@) { + $self->{_config}->{client_id} = '9490811e0906b6e'; + $self->{_config}->{client_secret} = '158b57f13e9a51f064276bd9e31529fb065f741e'; + } + } + else { + $self->{_config}->{client_id} = '9490811e0906b6e'; + $self->{_config}->{client_secret} = '158b57f13e9a51f064276bd9e31529fb065f741e'; + } + return TRUE; } +sub connect { + my $self = shift; + return $self->setup; +} + +sub setup { + my $self = shift; + + if ($self->{_debug_cparam}) { + print "Setting up Imgur...\n"; + } + + #some helpers + my $sd = Shutter::App::SimpleDialogs->new; + + #Authentication + my $login_link = 'https://api.imgur.com/oauth2/authorize?response_type=pin&client_id=' . $self->{_config}->{client_id}; + + my $pin_entry = Gtk2::Entry->new(); + my $pin = ''; + $pin_entry->signal_connect(changed => sub { + $pin = $pin_entry->get_text; + }); + + my $response = $sd->dlg_info_message( + $d->get("Please click on the button below to authorize with Imgur. Input the PIN you receive and press 'Apply' when you are done."), + $d->get("Authorize with Imgur"), + 'gtk-cancel','gtk-apply', undef, + undef, undef, undef, undef, undef, + Gtk2::LinkButton->new ($login_link, $d->get("Authorize")), + $pin_entry, + ); + if ($response == 20) { + + if ($self->{_debug_cparam}) { + print "Imgur: Authorizing...\n"; + } + + my %params = ( + 'client_id' => $self->{_config}->{client_id}, + 'client_secret' => $self->{_config}->{client_secret}, + 'grant_type' => 'pin', + 'pin' => $pin, + ); + + my @params = ( + "https://api.imgur.com/oauth2/token", + 'Content' => [%params] + ); + + my $req = HTTP::Request::Common::POST(@params, 'Authorization' => 'Client-ID ' . $self->{_config}->{client_id}); + + my $client = LWP::UserAgent->new( + 'timeout' => 20, + 'keep_alive' => 10, + 'env_proxy' => 1, + ); + my $rsp = $client->request($req); + + my $json = JSON->new(); + my $json_rsp = $json->decode($rsp->content); + + if ($self->{_debug_cparam}) { + print $pin . ' ' . $rsp->content; + } + if (exists $json_rsp->{status} && $json_rsp->{status} ne 200) { + return $self->setup; + } + + $self->{_config}->{access_token} = $json_rsp->{access_token}; + $self->{_config}->{refresh_token} = $json_rsp->{refresh_token}; + $self->{_config}->{account_id} = $json_rsp->{account_id}; + $self->{_config}->{account_username} = $json_rsp->{account_username}; + + $self->{_config_file}->openw->print(encode_json($self->{_config})); + chmod 0600, $self->{_config_file}; + + return TRUE; + } + else { + return FALSE; + } +} + sub upload { my ( $self, $upload_filename, $username, $password ) = @_; @@ -87,62 +204,66 @@ utf8::encode $password; utf8::encode $username; - #~ if ( $username ne "" && $password ne "" ) { + my $client = LWP::UserAgent->new( + 'timeout' => 20, + 'keep_alive' => 10, + 'env_proxy' => 1, + ); + + eval { + + my $json = JSON->new(); + + open( IMAGE, $upload_filename ) or die "$!"; + my $binary_data = do { local $/ = undef; <IMAGE>; }; + close IMAGE; + my $encoded_image = encode_base64($binary_data); - my $client = LWP::UserAgent->new( - 'timeout' => 20, - 'keep_alive' => 10, - 'env_proxy' => 1, + my %params = ( + 'image' => $encoded_image, + ); + + my @params = ( + "https://api.imgur.com/3/image", + 'Content' => [%params] ); - eval{ + my $req; + if ($username eq $d->get("OAuth") && $self->{_config}->{access_token}) { + $req = HTTP::Request::Common::POST(@params, 'Authorization' => 'Bearer ' . $self->{_config}->{access_token}); + } + else { + $req = HTTP::Request::Common::POST(@params, 'Authorization' => 'Client-ID ' . $self->{_config}->{client_id}); + } + my $rsp = $client->request($req); + + #~ print Dumper $json->decode( $rsp->content ); - my $json = JSON->new(); + my $json_rsp = $json->decode( $rsp->content ); - my %params = ( - 'image' => [$upload_filename], - 'key' => '12ea5e932124142c5ef3c8d5a02557de', - ); - - my @params = ( - "http://api.imgur.com/1/upload.json", - 'Content_Type' => 'multipart/form-data', - 'Content' => [%params] - ); - - my $req = HTTP::Request::Common::POST(@params); - my $rsp = $client->request($req); - - #~ print Dumper $json->decode( $rsp->content ); - - $self->{_links} = $json->decode( $rsp->content ); - $self->{_links} = $self->{_links}->{'rsp'}; - if(defined $self->{_links}->{'stat'} && $self->{_links}->{'stat'} eq 'ok'){ - $self->{_links} = $self->{_links}->{'image'}; - #clean hash - foreach (keys %{$self->{_links}}){ - if($_ eq 'delete_hash' || $_ eq 'image_hash'){ - delete $self->{_links}->{$_}; - next; - } - if( $self->{_debug_cparam}) { - print $_.": ".$self->{_links}->{$_}, "\n"; - } - } - #set status (success) - $self->{_links}{'status'} = 200; - }else{ - $self->{_links}{'status'} = $self->{_links}->{'image'}->{'error_msg'}; + if ($json_rsp->{'status'} ne 200) { + unlink $self->{_config_file}; + $self->{_links}{'status'} = ''; + if (exists $json_rsp->{'data'}->{'error'}) { + $self->{_links}{'status'} .= $json_rsp->{'data'}->{'error'} . ': '; } - - }; - if($@){ - $self->{_links}{'status'} = $@; - #~ print "$@\n"; + $self->{_links}{'status'} .= $d->get("Maybe you or Imgur revoked or expired an access token. Please close this dialog and try again. Your account will be re-authenticated the next time you upload a file."); + return %{ $self->{_links} }; } - #~ } - + $self->{_links}{'status'} = $json_rsp->{'status'}; + $self->{_links}->{'direct_link'} = $json_rsp->{'data'}->{'link'}; + $self->{_links}->{'deletion_link'} = 'https://imgur.com/delete/' . $json_rsp->{'data'}->{'deletehash'}; + $self->{_links}->{'post_link'} = $json_rsp->{'data'}->{'link'}; + $self->{_links}->{'post_link'} =~ s/i\.imgur/imgur/; + $self->{_links}->{'post_link'} =~ s/\.[^.]+$//; + + }; + if ($@) { + $self->{_links}{'status'} = $@; + #~ print "$@\n"; + } + #and return links return %{ $self->{_links} }; }
