X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fxscreensaver-getimage-file;h=f5b7c10748044fae26de2f3e6ecff4ee7fda93d5;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=be772267e3f24dd22cdba706764f173cc656d123;hpb=2762a7d7cf8d83e68b8f635941f6609119d630ae;p=xscreensaver diff --git a/driver/xscreensaver-getimage-file b/driver/xscreensaver-getimage-file index be772267..f5b7c107 100755 --- a/driver/xscreensaver-getimage-file +++ b/driver/xscreensaver-getimage-file @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2001-2013 Jamie Zawinski . +# Copyright © 2001-2017 Jamie Zawinski . # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -45,10 +45,6 @@ import Fcntl ':mode' unless defined &S_ISUID; # but it is here in Perl 5.8 # but in Perl 5.10, both of these load, and cause errors! # So we have to check for S_ISUID instead of S_ISDIR? WTF? -use bytes; # Larry can take Unicode and shove it up his ass sideways. - # Perl 5.8.0 causes us to start getting incomprehensible - # errors about UTF-8 all over the place without this. - use Digest::MD5 qw(md5_base64); # Some Linux systems don't install LWP by default! @@ -57,7 +53,7 @@ BEGIN { eval 'use LWP::Simple;' } my $progname = $0; $progname =~ s@.*/@@g; -my $version = q{ $Revision: 1.36 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; +my ($version) = ('$Revision: 1.43 $' =~ m/\s(\d[.\d]+)\s/s); my $verbose = 0; @@ -250,7 +246,11 @@ sub read_cache($) { my $dd = "$ENV{HOME}/Library/Caches"; # MacOS location if (-d $dd) { $cache_file_name = "$dd/org.jwz.xscreensaver.getimage.cache"; - } elsif (-d "$ENV{HOME}/tmp") { + } elsif (-d "$ENV{HOME}/.cache") { # Gnome "FreeDesktop XDG" location + $dd = "$ENV{HOME}/.cache/xscreensaver"; + if (! -d $dd) { mkdir ($dd) || error ("mkdir $dd: $!"); } + $cache_file_name = "$dd/xscreensaver-getimage.cache" + } elsif (-d "$ENV{HOME}/tmp") { # If ~/tmp/ exists, use it. $cache_file_name = "$ENV{HOME}/tmp/.xscreensaver-getimage.cache"; } else { $cache_file_name = "$ENV{HOME}/.xscreensaver-getimage.cache"; @@ -312,7 +312,7 @@ sub write_cache($) { print $cache_fd "$dir\n"; foreach (@all_files) { my $f = $_; # stupid Perl. do this to avoid modifying @all_files! - $f =~ s@^\Q$dir\L/@@so || die; # remove $dir from front + $f =~ s@^\Q$dir/@@so || die; # remove $dir from front print $cache_fd "$f\n"; } } @@ -356,19 +356,28 @@ sub html_unquote($) { +# Figure out what the proxy server should be, either from environment +# variables or by parsing the output of the (MacOS) program "scutil", +# which tells us what the system-wide proxy settings are. +# sub set_proxy($) { my ($ua) = @_; - if (!defined($ENV{http_proxy}) && !defined($ENV{HTTP_PROXY})) { - my $proxy_data = `scutil --proxy 2>/dev/null`; - my ($server) = ($proxy_data =~ m/\bHTTPProxy\s*:\s*([^\s]+)/s); - my ($port) = ($proxy_data =~ m/\bHTTPPort\s*:\s*([^\s]+)/s); - if ($server) { + my $proxy_data = `scutil --proxy 2>/dev/null`; + foreach my $proto ('http', 'https') { + my ($server) = ($proxy_data =~ m/\b${proto}Proxy\s*:\s*([^\s]+)/si); + my ($port) = ($proxy_data =~ m/\b${proto}Port\s*:\s*([^\s]+)/si); + my ($enable) = ($proxy_data =~ m/\b${proto}Enable\s*:\s*([^\s]+)/si); + + if ($server && $enable) { # Note: this ignores the "ExceptionsList". - $ENV{http_proxy} = "http://" . $server . ($port ? ":$port" : "") . "/"; - print STDERR "$progname: MacOS proxy: $ENV{http_proxy}\n" - if ($verbose > 2) - } + my $proto2 = 'http'; + $ENV{"${proto}_proxy"} = ("${proto2}://" . $server . + ($port ? ":$port" : "") . "/"); + print STDERR "$progname: MacOS $proto proxy: " . + $ENV{"${proto}_proxy"} . "\n" + if ($verbose > 2); + } } $ua->env_proxy(); @@ -378,7 +387,7 @@ sub set_proxy($) { sub init_lwp() { if (! defined ($LWP::Simple::ua)) { error ("\n\n\tPerl is broken. Do this to repair it:\n" . - "\n\tsudo cpan LWP::Simple\n"); + "\n\tsudo cpan LWP::Simple LWP::Protocol::https Mozilla::CA\n"); } set_proxy ($LWP::Simple::ua); } @@ -395,11 +404,28 @@ sub parse_feed($) { $LWP::Simple::ua->agent ("$progname/$version"); $LWP::Simple::ua->timeout (10); # bail sooner than the default of 3 minutes + + # Half the time, random Linux systems don't have Mozilla::CA installed, + # which results in "Can't verify SSL peers without knowning which + # Certificate Authorities to trust". + # + # In xscreensaver-text we just disabled certificate checks. However, + # malicious images really do exist, so for xscreensaver-getimage-file, + # let's actually require that SSL be installed properly. + + my $body = (LWP::Simple::get($url) || ''); - if ($body !~ m@^<\?xml\s@si) { + if ($body !~ m@^\s*<(\?xml|rss)\b@si) { # Not an RSS/Atom feed. Try RSS autodiscovery. + # (Great news, everybody: Flickr no longer provides RSS for "Sets", + # only for "Photostreams", and only the first 20 images of those. + # Thanks, assholes.) + + error ("null response: $url") + if ($body =~ m/^\s*$/s); + error ("not an RSS or Atom feed, or HTML: $url") unless ($body =~ m@<(HEAD|BODY|A|IMG)\b@si); @@ -412,6 +438,10 @@ sub parse_feed($) { $p =~ m! \b HREF \s* = \s* ['"] ( [^<>'"]+ ) !six ) { my $u2 = html_unquote ($1); + if ($u2 =~ m!^/!s) { + my ($h) = ($url =~ m!^([a-z]+://[^/]+)!si); + $u2 = "$h$u2"; + } print STDERR "$progname: found feed: $u2\n" if ($verbose); return parse_feed ($u2); @@ -585,10 +615,26 @@ sub download_image($$$) { # Special-case kludge for Flickr: # Their RSS feeds sometimes include only the small versions of the images. - # So if the URL ends in "s" (75x75), "t" (100x100) or "m" (240x240),then - # munge it to be "b" (1024x1024). + # So if the URL ends in one of the "small-size" letters, change it to "b". + # + # _o orig, 1600 + + # _k large, 2048 max + # _h large, 1600 max + # _b large, 1024 max + # _c medium, 800 max + # _z medium, 640 max + # "" medium, 500 max + # _n small, 320 max + # _m small, 240 max + # _t thumb, 100 max + # _q square, 150x150 + # _s square, 75x75 + # + # Note: if we wanted to get the _k or _o version instead of the _b or _h + # version, we'd need to crack the DRM -- which is easy: see crack_secret + # in "https://www.jwz.org/hacks/galdown". # - $url =~ s@_[stm](\.[a-z]+)$@_b$1@si + $url =~ s@_[sqtmnzc](\.[a-z]+)$@_b$1@si if ($url =~ m@^https?://[^/?#&]*?flickr\.com/@si); print STDERR "$progname: downloading: $dir/$file for $uid / $url\n" @@ -614,7 +660,12 @@ sub mirror_feed($) { my $dir = "$ENV{HOME}/Library/Caches"; # MacOS location if (-d $dir) { $dir = "$dir/org.jwz.xscreensaver.feeds"; - } elsif (-d "$ENV{HOME}/tmp") { + } elsif (-d "$ENV{HOME}/.cache") { # Gnome "FreeDesktop XDG" location + $dir = "$ENV{HOME}/.cache/xscreensaver"; + if (! -d $dir) { mkdir ($dir) || error ("mkdir $dir: $!"); } + $dir .= "/feeds"; + if (! -d $dir) { mkdir ($dir) || error ("mkdir $dir: $!"); } + } elsif (-d "$ENV{HOME}/tmp") { # If ~/tmp/ exists, use it. $dir = "$ENV{HOME}/tmp/.xscreensaver-feeds"; } else { $dir = "$ENV{HOME}/.xscreensaver-feeds"; @@ -818,7 +869,7 @@ sub find_random_file($) { my $file = $all_files[$n]; if (large_enough_p ($file)) { if (! $url) { - $file =~ s@^\Q$dir\L/@@so || die; # remove $dir from front + $file =~ s@^\Q$dir/@@so || die; # remove $dir from front } return $file; }