-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathns-cli.cgi
executable file
·102 lines (82 loc) · 2.95 KB
/
ns-cli.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl -w
#
# ns-cli.cgi -- replace Netscape's "smart search" with stuff we like.
#
# See the file README for instructions on how to use this. (If you don't
# have the file, you can get it from <http://www.lafferty.ca/software/>.)
#
# Thanks to Stefan `Sec` Zehl for the pointer about that NS preference.
#
# SEND ME <[email protected]> YOUR USEFUL SEARCHES! :-)
#
# 2002/08/09 Rich <[email protected]>
# - Fix mozilla instructions again
# - Rewrite with conf file instead of inline configuration
# - Add "help me"
# - More example commands
# 2002/05/16 Rich <[email protected]>
# - Fix mozilla instructions
# - More example commands
# 2001/03/19 Rich <[email protected]>
# - use regex that works!
# 2001/03/19 Rich <[email protected]>
# - expect 'keyword' or 'kwoff', not just 'kwoff', which means that
# keywords are turned off.
# 2001/03/19 Rich Lafferty <[email protected]>
# - first clean version.
use strict;
use CGI qw(:cgi);
use URI::Escape;
use vars qw(%search $allowed);
# We expect ns-cli.conf to be in the current working directory.
# Chane the following line if it isn't.
my $conf = "./ns-cli.conf";
do $conf;
# Allowed hosts
if (defined $allowed and $ENV{REMOTE_ADDR} !~ /$allowed/) {
print header;
print "<p>This host is not permitted to access this function.\n";
exit;
}
my $request = $ENV{QUERY_STRING};
# Uses "keyword" if Internet Keywords is enabled, "kwoff" if they're not.
# Interesting -- if you didn't use nscli, you'd still be sending your
# mistyped URLs to Netscape.
$request =~ s,^keyword/,,;
my $word_delimeter = qr/(?:\s+|\+|%20)/;
my ($func, $words) = split($word_delimeter, $request, 2);
my @words = map { uri_unescape($_) } split($word_delimeter, $words);
show_help() if $func eq 'help';
unless (exists $search{$func}) {
unshift (@words, $func);
$func = 'default';
}
if (exists $search{$func}->{SYNONYM}) {
$func = $search{$func}->{SYNONYM};
}
die "Default action '$func' doesn't exist in \%search\n"
unless exists ($search{$func});
my $query = uri_escape (join (" ", @words));
die "No URL listed for $func in $conf\n" unless exists $search{$func}->{URL};
$search{$func}->{URL} =~ s/%%QUERY%%/$query/g;
print redirect($search{$func}->{URL});
sub show_help {
print <<__HTML__;
Content-Type:text/html
<H2><a href="http://www.lafferty.ca/software/">ns-cli</a>, the Netscape command-line interface</H2>
<H3>Available Commands</H3>
<pre>
__HTML__
for my $key (sort keys %search) {
my $text = exists $search{$key}->{SYNONYM} ? "Synonym for <b>$search{$key}->{SYNONYM}</b>" :
$search{$key}->{DESC};
printf(" %12s %s\n", $key, $text);
}
print <<__HTML__;
<p><small>This is free software with ABSOLUTELY NO WARRANTY. This program is
released under the same terms as Perl itself (specifically, under your
choice of either the GNU Public License version 2, or the Perl
Artistic License). Copyright (c) 2002 Rich Lafferty.</small></p>
__HTML__
exit;
}