added show/425 command
[spider.git] / cmd / show / 425.pl
1 #
2 # Query the 425 Database server for a callsign
3 #
4 # from an idea by Leonardo Lastrucci IZ5FSA and information from Mauro I1JQJ
5 #
6 # $Id$
7 #
8 my ($self, $line) = @_;
9 my @list = map {uc} split /\s+/, $line;               # generate a list of callsigns
10 my $l;
11 my $call = $self->call;
12 my @out;
13
14 return (1, $self->msg('e24')) unless $Internet::allow;
15 return (1, "SHOW/425 <callsign>, e.g. SH/425 3B9FR") unless @list;
16 my $target = $Internet::http_proxy || $Internet::dx425_url || "www.ariscandicci.it";
17 my $port = $Internet::http_proxy_port || 80;
18 my $url = '';
19 $url = 'http://' . ($Internet::dx425_url || 'www.ariscandicci.it'); #  if $Internet::http_proxy; 
20
21 use Net::Telnet;
22
23 my $t = new Net::Telnet;
24
25 foreach $l (@list) {
26         eval {
27                 $t->open(Host     =>  $target,
28                                  Port     =>  $port,
29                                  Timeout  =>  15);
30         };
31         if (!$t || $@) {
32                 push @out, $self->msg('e18', 'Open(425.org)');
33         } else {
34                 my $s = "GET $url/modules.php?name=425dxn&op=spider&query=$l";
35                 dbg($s) if isdbg('425');
36                 $t->print($s);
37                 Log('call', "$call: show/425 \U$l");
38                 my $state = "blank";
39                 while (my $result = eval { $t->getline(Timeout => 30) } || $@) {
40                         dbg($result) if isdbg('425') && $result;
41                                 chomp $result;
42                                 push @out, $result;
43                 }
44                 $t->close;
45                 push @out, $self->msg('e3', 'Search(425.org)', uc $l) unless @out;
46         }
47 }
48
49 return (1, @out);