a8558da9c184ac1eed18561d7363aaaa77284a20
[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 $target = $Internet::http_proxy || $Internet::dx425_url || "192.168.0.2";
18 my $port = $Internet::http_proxy_port || 80;
19 my $url = '';
20 $url = 'http://' . ($Internet::dx425_url || 'www.ariscandicci.it'); #  if $Internet::http_proxy; 
21 #$url = 'http://' . ($Internet::dx425_url || '192.168.0.2'); #  if $Internet::http_proxy; 
22
23 use Net::Telnet;
24
25 my $t = new Net::Telnet;
26
27 foreach $l (@list) {
28         eval {
29                 $t->open(Host     =>  $target,
30                                  Port     =>  $port,
31                                  Timeout  =>  15);
32         };
33         if (!$t || $@) {
34                 push @out, $self->msg('e18', 'Open(425.org)');
35         } else {
36                 my $s = "GET $url/modules.php?name=425dxn&op=spider&query=$l HTTP/1.0\n"
37                 ."User-Agent:DxSpider;$main::version;$main::build;$^O;$main::mycall;$call;$l\n\n";
38                 dbg($s) if isdbg('425');
39                 $t->print($s);
40                 Log('call', "$call: show/425 \U$l");
41                 my $state = "blank";
42                 my $count = 1;
43 #               push @out, $s;
44                 while (my $result = eval { $t->getline(Timeout => 30) } || $@) {
45                         dbg($result) if isdbg('425') && $result;
46                                 ++$count;
47                                 if ($count > 10)
48                                 {
49                                   #chomp $result;
50                                 push @out, $result;
51                 }
52                 }
53                 $t->close;
54                 push @out, $self->msg('e3', 'Search(425.org)', uc $l) unless @out;
55         }
56 }
57
58 return (1, @out);