313fb0fe8151efa51aab4adcfcab6d153daa06cb
[spider.git] / cmd / show / wm7d.pl
1 #
2 # Query the WM7D Database server for a callsign
3 #
4 # Largely based on "sh/qrz" and info in the Net::Telnet documentation
5 #
6 # Copyright (c) 2002 Charlie Carroll K1XX
7 #
8 #
9 #
10
11 # wm7d accepts only single callsign
12 sub handle
13 {
14
15         my ($self, $line) = @_;
16         my $call = $self->call;
17         my @out;
18
19         # send 'e24' if allow in Internet.pm is not set to 1
20         return (1, $self->msg('e24')) unless $Internet::allow;
21         return (1, "SHOW/WM7D <callsign>, e.g. SH/WM7D k1xx") unless $line;
22         my $target = $Internet::wm7d_url || 'www.wm7d.net';
23         my $port = 5000;
24         my $cmdprompt = '/query->.*$/';
25
26         my($info, $t);
27                                     
28         $t = new Net::Telnet;
29         $info =  $t->open(Host    => $target,
30                                           Port    => $port,
31                                           Timeout => 20);
32
33         if (!$info) {
34                 push @out, $self->msg('e18', 'WM7D.net');
35         }
36         else {
37         ## Wait for prompt and respond with callsign.
38         $t->waitfor($cmdprompt);
39                 $t->print($line);
40         ($info) = $t->waitfor($cmdprompt);
41     
42                 # Log the lookup
43                 Log('call', "$call: show/wm7d \U$line");
44                 $t->close;
45                 push @out, split /[\r\n]+/, $info;
46         }
47         return (1, @out);
48 }
49