This file is indexed.

/usr/bin/WebSearch is in libwww-search-perl 2.51.30-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/perl -w

eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
    if 0; # not running under some shell
#
# WebSearch
# Copyright (C) 1996-1997 by USC/ISI
# $Id: WebSearch,v 1.1 2008/07/14 03:28:13 Martin Exp $
#
# Complete copyright notice follows below.

sub usage
  {
  my $msg = shift;
  defined($msg) && ($msg ne '') && print STDERR "$0: $msg\n";
  print STDERR <<"END";
usage: WebSearch [--engine <name>] [--gui] [--max <integer>] [--options <key=value>]... [--count] [--terse] [--all] [--raw] [--list] [--verbose] [--VERSION] [--help] [--host <hostname>] [--port <portnum>] [--username bbunny --password c4rr0t5] [--lwpdebug] [--debug] query

Make a query to a web search engine, printing to STDOUT the URLs which match (one per line).

See `perldoc WebSearch` for details.

END
  exit 1;
  } # usage


=head1 NAME

WebSearch - a web-searching application demonstrating WWW::Search


=head1 SYNOPSIS

B<WebSearch [-m MaxCount] [-e SearchEngine] [-o option] [-o option...] [-ardvV] query>


=head1 DESCRIPTION

This program is provides a command-line interface to web search engines,
listing all URLs found for a given query.  This program also provides
a simple demonstration of the WWW::Search Perl library for web searches.

The program supports a number of search engines;
use WebSearch --list to see which backends are installed.

A more sophisticated client is L<AutoSearch>
which maintains a change list of found objects.

For examples and hints about searches,
see L<AutoSearch>.


=head1 OPTIONS

WebSearch uses Getopt::Long, so you can use double-minus with long
option names, or single-minus with one-letter abbreviations.

=over 8

=item --engine e_name, -e e_name

The string e_name is the name of (the module for) the desired search
engine.  Capitalization matters.  See `perldoc WWW::Search` to find
out what the default is (probably Null).

Use --list to get a list of installed backends.

=item --gui, -g

Perform the search to mimic the default browser-based search.
Not implemented for all backends, see the documentation for each backend.

=item --list

Prints to STDERR a \n-separated list of installed backends.

=item --max max_count, -m max_count

Specify the maximum number of hits to retrieve.

=item --option o_string, -o o_string

Specify a search-engine option in the form 'key=value' (or just
'key').  Can be repeated for as many options are needed.  Keys can be
repeated.

=item --count, -c

As the first line of output, print the approximate hit count.
As the last line of output, print the actual hit count.

=item --terse, -t

Do not print any URLs.
Only useful if you also specify --count.
If you specify --terse but not --count,
there will be no output no matter how many hits are found!

=item --all, -a

For each hit result, print all the URLs that the search engine
indicated were equivalent to it.  (Some URLs may refer to the same
object.)  Can be combined with --verbose; can not be combined with
--raw.

=item --raw, -r

For each hit result, print the raw HTML.
Not implemented for all backends.

=item --verbose, -v

Verbose mode.  Enumerate the returned URLs and show the description,
score, date, etc. for each.

=item --VERSION, -V

Print version information and exit immediately.

=item --debug <i>, -d <i>

Display back-end debugging information (with debug level <i>)

=item --host <hostname.sub.domain>

Set the _host option for the WWW::Search object (backend-dependent).

=item --port <i>

Set the _port option for the WWW::Search object (backend-dependent).

=item --username <bbunny>

Set the username with which to login to the backend.

=item --password <c4rr0t5>

Set the password with which to login to the backend.

=item --lwpdebug, -l

Display low-level libwww-perl debugging information

=back


=head1 ENVIRONMENT VARIABLES

The environment variable F<http_proxy> (or F<HTTP_PROXY>)
specifies a proxy, if any.


=head1 SEE ALSO

For the library, see L<WWW::Search>.

For a more sophisticated client, see L<AutoSearch>.


=head1 AUTHOR

C<WebSearch> was written by John Heidemann, <johnh@isi.edu>.
C<WebSearch> is maintained by Martin Thurn, <mthurn@cpan.org>.


=head1 COPYRIGHT

Copyright (c) 1996-1997 University of Southern California.
All rights reserved.

Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
duplicated in all such forms and that any documentation, advertising
materials, and other materials related to such distribution and use
acknowledge that the software was developed by the University of
Southern California, Information Sciences Institute.  The name of the
University may not be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.



=cut

use strict;

&usage('no arguments given') if ($#ARGV == -1);
# &usage if ($#ARGV >= 0 && $ARGV[0] eq '-?');

use Getopt::Long;
use WWW::Search;

use vars qw( $VERSION );
$VERSION = '2.14';

use vars qw( $sEngine $all $verbose $raw $iMax $print_version $debuglwp $debug );
use vars qw( @options $_host $_port $help $iShowCount $iGui $opt_list );
use vars qw( $opt_username $opt_password );
# Set default values:
$iShowCount = 0;
$iGui = 0;
my $iTerse = 0;
$_host = '';
$_port = '';
$sEngine = '';
undef $debug;
$debuglwp = 0;
$opt_list = 0;
# Get the command-line options:
&Getopt::Long::config(qw(no_ignore_case no_getopt_compat));
&usage('getopt failed') unless &GetOptions('all', \$all,
                                           'count', \$iShowCount,
                                           'debug:i', \$debug,
                                           'engine=s', \$sEngine,
                                           'gui', \$iGui,
                                           'help', \$help,
                                           'host=s', \$_host,
                                           'list',
                                           'lwpdebug', \$debuglwp,
                                           'max=i', \$iMax,
                                           'options=s@', \@options,
                                           'password=s',
                                           'port=s', \$_port,
                                           'raw', \$raw,
                                           'terse', \$iTerse,
                                           'username=s',
                                           'verbose', \$verbose,
                                           'VERSION', \$print_version,
                                          );
&usage('user requested help') if $help;
$debug = 1 if (defined($debug) and ($debug < 1));

&print_version() if defined($print_version);
&list_engines() if ($opt_list);
# there MUST be some argument(s) left, the query:
&usage('no query found on command line') if (scalar(@ARGV) <= 0);

&main(join(" ", @ARGV));

exit 0;

sub print_version
  {
  print "$0 version $VERSION\nWWW::Search version $WWW::Search::VERSION\n";
  if ($sEngine ne '')
    {
    my $mod = "WWW::Search::$sEngine";
    if (eval "use $mod; 1;")
      {
      my $e = '$'. $mod .'::VERSION';
      # print STDERR " + e is ===$e===\n";
      my $iVersion = eval $e;
      $iVersion ||= 'unknown';
      print "$mod version $iVersion\n";
      } # if
    } # if
  exit 0;
  } # print_version

sub list_engines
  {
  my @as = WWW::Search::installed_engines();
  $, = "\n";
  print STDERR (sort @as), '';
  exit 0;
  } # list_engines

my $verbose_code;

sub print_result {
    my($result, $count) = @_;
    return if $iTerse;
    my($prefix) = "";
    if ($verbose) {
	my(@attribs) = ();
        $prefix = "$count. ";
	if (!defined($verbose_code)) {
	    $verbose_code = "";
	    foreach (qw(title description score normalized_score size change_date index_date)) {
	        $verbose_code .= "push(\@attribs, \"$_: \" . \$result->$_())\n" .
		    "\tif (defined(\$result->$_()));\n";
            };
	};
	eval $verbose_code;
        $prefix .= "(" . join(",\n\t", @attribs) . ")\n\t"
	    if ($#attribs >= 0);
    };

    if (defined($all)) {
        foreach ($result->urls()) {
            print "$prefix$_\n";
            $prefix = "\t";
        };
    } else {
	if (defined($raw)) {
	    print $result->raw(), "\n";
	} else {
	    print $prefix, $result->url, "\n";
	};
    };
}

sub print_error {
    my ($msg, $count) = @_;
    my $error = $verbose ? sprintf("[%3d] ", $count) : '';
    $error .= $msg;
    print STDERR $error, "\n" if $error ne '';
}

sub main {
    my $query = shift;
    my $count = 0;
    my $search = new WWW::Search($sEngine);
    $search->{_host} = $_host if $_host ne '';
    $search->{_port} = $_port if $_port ne '';
    my %hsOptions = ();

    if (0 < $debuglwp) {
	require LWP::Debug;
	LWP::Debug::level('+');
    }

    $search->http_proxy($ENV{'HTTP_PROXY'}) if ($ENV{'HTTP_PROXY'});
    $search->http_proxy($ENV{'http_proxy'}) if ($ENV{'http_proxy'});

    if (0 < scalar(@options))
      {
      foreach my $sPair (@options)
        {
        if ($sPair =~ m/^([^=]+)=(.*)$/)
          {
          my ($key, $value) = ($1, $2);
          # This is a bit of a hack.  A set of CGI options is not
          # strictly a hash, because multiple values for the same key
          # can be specified.  To get around this, we rely on the fact
          # that this hash of options is only used to construct a CGI
          # parameter list.  If we see multiple values for the same key,
          # we append the multiple values onto the value of the key in
          # CGI '?key=value' format.
          if (exists($hsOptions{$key}) && $hsOptions{$key} ne '')
            {
            # There was already an option of this key given; append
            # multiple values as CGI arguments:
            $hsOptions{$key} .= '&'.$key.'='.WWW::Search::escape_query($value);
            } # if exists
          else
            {
            # This is the only instance of this key; just insert the
            # hash value:
            $hsOptions{$key} = WWW::Search::escape_query($value);
            }
          } # if option is of the form key=value
        else
          {
          $hsOptions{$sPair} = '';
          }
        } # foreach $sPair
      } # if @options

    if (defined($iMax))
      {
      $search->maximum_to_retrieve($iMax);
      }
    else
      {
      $iMax = 10000;
      }

    $hsOptions{'search_debug'} = $debug if (defined($debug) and (0 < $debug));

    $iGui
    ? $search->gui_query(WWW::Search::escape_query($query), \%hsOptions)
    : $search->native_query(WWW::Search::escape_query($query), \%hsOptions);
    $search->login($opt_username, $opt_password);

    my($way) = 0; # 0=piecemeal, 1=all at once
    my($result);
    if (($iShowCount) && defined($search->approximate_result_count))
      {
      print "There are approximately " if $verbose;
      print $search->approximate_result_count;
      print " results." if $verbose;
      print "\n";
      } # if
    my $iNumPrinted = 0;
    if ($way) # return all at once.
      {
      foreach $result ($search->results())
        {
        print_result($result, ++$count);
        $iNumPrinted++;
        last if ($iMax < $count);
        };
      }
    else # return page by page
      {
      while ($result = $search->next_result())
        {
        print_result($result, ++$count);
        $iNumPrinted++;
        last if ($iMax < $count);
        } # while
      } # else page by page
    if ($iShowCount)
      {
      print "There are exactly " if $verbose;
      print $iNumPrinted;
      print " results (maximum of $iMax were requested)." if $verbose;
      print "\n";
      } # if

    # handle errors
    if ($count == 0) {
        my($response) = $search->response();
	my $nothing = $verbose ? "Nothing found." : '';
        if ($response->is_success) {
            print_error($nothing, $count);
        } else {
            print_error("Error:  " . $response->as_string(), $count);
        };
    };

};