]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/Wingate.pl
changed email address
[infobot.git] / src / Modules / Wingate.pl
1 #
2 #  Wingate.pl: Wingate checker.
3 #      Author: dms
4 #     Version: v0.3 (20000526).
5 #     Created: 20000116
6 #        NOTE: based on wingate.pl by fooz.
7 #
8
9 package Wingate;
10
11 use strict;
12 my $select = IO::Select->new;
13
14 sub Wingates {
15     my $file = "$main::infobot_base_dir/$main::param{'ircUser'}.wingate";
16     my @hosts;
17
18     open(IN, $file);
19     while (<IN>) {
20         chop;
21         next if (/\*$/);        # wingate. or forget about it?
22         push(@hosts,$_);
23     }
24     close IN;
25
26     foreach (@_) {
27         next if (grep /^$_$/, @hosts);
28
29         &main::DEBUG("W: _ => '$_'.");
30         &Wingate($_);
31     }
32 }
33
34 sub Wingate {
35     my ($host) = @_;
36
37     my $sock = IO::Socket::INET->new(
38         PeerAddr        => $host,
39         PeerPort        => 'telnet(23)',
40         Proto           => 'tcp'
41 ###     Timeout         => 10,          # enough :)
42     );
43
44     if (!defined $sock) {
45         &main::status("Wingate: connection refused to $host");
46         return;
47     }
48
49     $sock->timeout(10);
50     $select->add($sock);
51
52     my $errors = 0;
53     my ($luser);
54     foreach $luser ($select->can_read(1)) {
55         my $buf;
56         my $len = 0;
57         if (!defined($len = sysread($luser, $buf, 512))) {
58             &main::status("Wingate: connection lost to $luser/$host.");
59             $select->remove($luser);
60             close($luser);
61             next;
62         }
63
64         if ($len == 9) {
65             $len = sysread($luser, $buf, 512);
66         }
67
68         my $wingate = 0;
69         $wingate++ if ($buf =~ /^WinGate\>/);
70         $wingate++ if ($buf =~ /^Too many connected users - try again later$/);
71
72         if ($wingate) {
73             &main::status("Wingate: RUNNING ON $host BY $main::who.");
74
75             if (&main::IsParam("wingateBan")) {
76                 &main::ban("*!*\@$host", "");
77             }
78
79             if (&main::IsParam("wingateKick")) {
80                 &main::kick($main::who, "", $main::param{'wingateKick'});
81             }
82
83             push(@main::wingateBad, "$host\*");
84             &main::wingateWriteFile();
85         } else {
86 ###         &main::DEBUG("no wingate.");
87         }
88
89         ### TODO: close telnet connection correctly!
90         $select->remove($luser);
91         close($luser);
92     }
93
94     return;
95 }
96
97 1;