"Fossies" - the Fresh Open Source Software Archive 
Member "tin-2.6.2/tools/url_handler.pl" (23 Aug 2021, 3791 Bytes) of package /linux/misc/tin-2.6.2.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "url_handler.pl" see the
Fossies "Dox" file reference documentation and the last
Fossies "Diffs" side-by-side code changes report:
2.4.4_vs_2.4.5.
1 #! /usr/bin/perl -w
2 # example of how to call an appropriate viewer
3 #
4 # URLs must start with a scheme and shell metas should be already quoted
5 # (tin doesn't recognize URLs without a scheme and it quotes the metas)
6
7 use strict;
8 use warnings;
9
10 (my $pname = $0) =~ s#^.*/##;
11 die "Usage: $pname URL" if $#ARGV != 0;
12
13 # version Number
14 my $version = "0.1.3";
15
16 my ($method, $url, $match, @try);
17 $method = $url = $ARGV[0];
18 $method =~ s#^([^:]+):.*#$1#io;
19
20 # shell escape
21 $url =~ s#([\&\;\`\'\\\"\|\*\?\~\<\>\^\(\)\[\]\{\}\$\010\013\020\011])#\\$1#g;
22
23 if ($ENV{"BROWSER_".uc($method)}) {
24 push(@try, split(/:/, $ENV{"BROWSER_".uc($method)}));
25 } else {
26 if ($ENV{BROWSER}) {
27 push(@try, split(/:/, $ENV{BROWSER}));
28 } else { # set some defaults
29 push(@try, 'firefox -a firefox -remote openURL\(%s\)');
30 push(@try, 'mozilla -remote openURL\(%s\)');
31 push(@try, 'opera -remote openURL\(%s\)');
32 push(@try, qw(chromium 'galeon -n' 'epiphany -n' konqueror));
33 push(@try, 'lynx'); # prefer lynx over links as it can handle news:-urls
34 push(@try, qw('links2 -g' links w3m surf arora));
35 push(@try, 'kfmclient newTab'); # has no useful return-value on error
36 push(@try, 'xdg-open'); # xdg-open evaluates $BROWSER which is unset
37 }
38 }
39
40 for my $browser (@try) {
41 # ignore empty parts
42 next if ($browser =~ m/^$/o);
43 # expand %s if not preceded by odd number of %
44 $match = $browser =~ s/(?<!%)((?:%%)*)%s/$1$url/og;
45 # expand %c if not preceded by odd number of %
46 $browser =~ s/(?<!%)((?:%%)*)%c/$1:/og;
47 # reduce dubble %
48 $browser =~ s/%%/%/og;
49 # append URL if no %s expansion took place
50 $browser .= " ".$url if (!$match);
51 # leave loop if $browser was started successful
52 last if (system("$browser 2>/dev/null") == 0);
53 }
54 exit 0;
55
56 __END__
57
58 =head1 NAME
59
60 url_handler.pl - Spawn appropriate viewer for a given URL
61
62 =head1 SYNOPSIS
63
64 B<url_handler.pl> I<URL>
65
66 =head1 DESCRIPTION
67
68 B<url_handler.pl> takes an URL as argument and spawns the first executable
69 viewer found in either B<$BROWSER_I<SCHEME>> or B<$BROWSER>.
70
71 =head1 ENVIRONMENT
72
73 =over 4
74
75 =item B<$BROWSER_I<SCHEME>>
76
77 =back
78
79 The user's preferred utility to browse URLs of type I<SCHEME>. May actually
80 consist of a sequence of colon-separated browser commands to be tried in
81 order until one succeeds. If a command part contains %s, the URL is
82 substituted there, otherwise the browser command is simply called with the
83 URL as its last argument. %% is replaced by a single percent sign (%), and
84 %c is replaced by a colon (:).
85 Examples:
86
87 =over 2
88
89 =item $BROWSER_FTP="wget:ncftp"
90
91 =item $BROWSER_GOPHER="lynx:links"
92
93 =item $BROWSER_MAILTO="mutt:pine -url"
94
95 =item $BROWSER_NEWS="lynx"
96
97 =item $BROWSER_NNTP="lynx"
98
99 =back
100
101 Z<>
102
103 =over 4
104
105 =item B<$BROWSER>
106
107 =back
108
109 The user's preferred utility to browse URLs for which there is no special
110 viewer defined via B<$BROWSER_I<SCHEME>>. Again it may actually consist of a
111 sequence of colon-separated browser commands to be tried in order until one
112 succeeds. If a command part contains %s, the URL is substituted there,
113 otherwise the browser command is simply called with the URL as its last
114 argument. %% is replaced by a single percent sign (%), and %c is replaced
115 by a colon (:).
116 Examples:
117
118 =over 2
119
120 =item $BROWSER="firefox -a firefox -remote openURL\(%s\):opera:konqueror:links2 -g:lynx:w3m"
121
122 =back
123
124 =head1 SECURITY
125
126 B<url_handler.pl> was designed to work together with L<tin(1)> which only
127 issues shell escaped absolute URLs thus B<url_handler.pl> does not try hard
128 to shell escape its input nor does it convert relative URLs into absolute
129 ones! If you use B<url_handler.pl> from other applications be sure to at
130 least shell escape its input!
131
132 =head1 AUTHOR
133
134 Urs Janssen E<lt>urs@tin.orgE<gt>
135
136 =head1 SEE ALSO
137
138 L<http://www.catb.org/~esr/BROWSER/>
139 L<http://www.dwheeler.com/browse/secure_browser.html>
140
141 =cut