3
# Copyright 2002 by Stefan Hornburg (Racke) <racke@linuxia.de>
5
# Based on a sample implementation of Chris Tillman
6
# <tillman@azstarnet.com>.
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public
19
# License along with this program; if not, write to the Free
20
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27
use File::Temp qw(tempfile);
33
# version (replaced on packaging time)
34
my $version = '__VERSION__';
37
chomp(my $msg = shift );
38
print STDERR $msg, "\n";
43
# check if there is a CGI capable WWW server running on the localhost, and
44
# return some identification string for it if any found. Return '' otherwise
45
sub detected_local_webserver {
46
my $testdoc = "/doc/HTML/index.html";
49
my $sock = IO::Socket::INET->new('127.0.0.1:80');
50
my $httpd_running = '';
54
print $sock "HEAD $testdoc HTTP/1.0$eol";
55
print $sock "Host: localhost" . $blank;
57
while (my $line = <$sock>) {
58
if ($line =~ s/^Server: //) {
59
$httpd_running = $line;
60
$httpd_running =~ s/\r?\n?//go;
65
if ($httpd_running =~ /dhttpd/) {
66
# this server is not CGI capable
71
return $httpd_running;
74
# process commandline options
76
my $whandler = $SIG{__WARN__};
77
$SIG{__WARN__} = sub {print STDERR "$0: @_";};
78
unless (GetOptions(\%opts,
82
fatal_error(pod2usage(1));
88
} elsif ($opts{version}) {
89
print "dhelp version $version\n";
93
my $searchterm = join(" ", @ARGV);
95
# home directory of the current user
98
if (exists $ENV{'HOME'} && -d $ENV{'HOME'}) {
99
$homedir = $ENV{'HOME'};
101
$homedir = (getpwent()) [7];
104
# always use sensible-browser
105
my $browser = "/usr/bin/sensible-browser";
107
my $online_mode = ! $opts{file};
108
my $httpd_running = detected_local_webserver;
112
if ($online_mode && $httpd_running) {
113
# we can query the web server directly
115
my $searchterm_uri = uri_escape($searchterm);
116
$searchterm_uri =~ s/'/'\\''/go;
117
$document = "http://localhost/cgi-bin/dsearch?search=$searchterm_uri";
119
$document = "http://localhost/doc/HTML/index.html";
121
print "Starting browser (using HTTP $httpd_running) ...\n";
124
my ($basedir) = File::Spec->tmpdir();
125
my ($fh, $tmpfile) = tempfile('dhelp' . 'X' x 6,
129
print "Starting dsearch for $searchterm\n";
130
$searchterm =~ s/'/'\\''/go;
132
open (DSEARCH, "/usr/lib/cgi-bin/dsearch file=1 search='$searchterm'|");
136
close (DSEARCH) || fatal_error "$0: dsearch failed\n";
137
system ( "$browser $tmpfile" ) and fatal_error( "${browser}: Failed to open $tmpfile: $!\n" );
140
$document = "/usr/share/doc/HTML/index.html";
141
print "Starting browser (using local filesystem) ...\n";
145
system("$browser '$document'") and fatal_error("${browser}: Failed to open $document: $!\n");
152
dhelp - Accessing Debian Online Help System
156
dhelp [ -h | -v | search-term ]
165
Direct the browser to use the local file system instead of
166
contacting the local WWW server.
170
Show a brief help message and exit.
172
=item B<-v, --version>
174
Show the program version number and exit.
180
B<dhelp> presents a list of installed html documentation. The
181
list can be browsed directly with Lynx, or if a web server
182
is installed then any web browser can be used.
184
In addition, you can search for terms indexed in the documentation
185
using B<dhelp search-term> .