Funny issue with libOPM

"Jeff Katz" <[email protected]> Wed, 11 Jul 2007 22:21:54 -0400
Newsgroups gmane.network.irc.bopm
Message-ID <[email protected]>
Hello,

I wasn't quite sure where to turn to, but I'm having a funny problem
with libopm and perl. I have a cgi script setup where it takes the
querystring and checks it for proxies - this works fine - but when I
take the same script and integrate it with a perl irc bot (using
net::irc), it appears the callbacks aren't being called.

here's the code in question:

----------------------- SNIP

#!/usr/bin/perl -w

use Net::IRC;
use Socket;
use IO::Select;
use OPM;
use strict;

$SIG{PIPE} = 'IGNORE';

my $irc = new Net::IRC;

my %open;
my $numopen;

my $scan = OPM->new or die("Error loading OPM");

sub add_default {
   my $remote = shift;

   print "adding default scans... \n";
   for(80, 81, 2282, 3128, 3332, 3382, 3777, 3802, 4044, 4480, 5490,
6588, 6682, 8000, 8080, 8081, 8090, 22788, 28178, 46214, 48316, 57123,
65506) {
       $remote->addtype(OPM->TYPE_HTTP, $_);
   }
   for(80, 81, 808, 1075, 1182, 2282, 3128, 3382, 4480, 6588, 8000,
8080, 8081, 8090, 46213, 53201) {
       $remote->addtype(OPM->TYPE_HTTPPOST, $_);
   }
   for(81, 889, 1027, 1028, 1029, 1066, 1075, 1080, 1180, 1478, 2280,
2425, 3330, 3380, 4044, 4455, 4777, 4894, 4914, 5748, 6000, 6042,
6826, 7198, 7366, 7441, 8799, 9036, 9938, 10000, 10001, 14728, 15859,
17878, 22799, 26859, 30021, 30022, 32343, 34167, 38994, 40934, 41934,
43934, 53201, 53311, 53412, 57123) {
       $remote->addtype(OPM->TYPE_SOCKS4, $_);
   }
   for(81, 1080, 1813, 1978, 2280, 4438, 5104, 5113, 5262, 5634, 6552,
6561, 7464, 7810, 8130, 8148, 8175, 8520, 8814, 9100, 9186, 9447,
9578, 17879, 25791) {
       $remote->addtype(OPM->TYPE_SOCKS5, $_);
   }
   $remote->addtype(OPM->TYPE_ROUTER, 23);
   for(23, 1181) {
       $remote->addtype(OPM->TYPE_WINGATE, $_);
   }
}

my $conn = $irc->newconn(
	Server 		=> shift || 'irc.blitzed.org',
	Port		=> shift || '6667',
	Nick		=> 'DSDevr',
	Ircname		=> 'I proxyscan.',
	Username	=> 'dsdevr'
);

$conn->{channel} = shift || '#dsdev';

sub on_connect {
	my $conn = shift;

	$conn->join($conn->{channel});
	$conn->{connected} = 1;
	
	print "bot connected... \n";
}

sub on_join {
	my ($conn, $event) = @_;

	my $nick = $event->{nick};
	my $host = $event->{host};

             my $ip = inet_ntoa(inet_aton($host));
            my $remote = OPM->new($ip);

	print "user joined... ip $ip nick $nick host $host\n";

	add_default($remote);

        my $error = $scan->scan($remote);

	if($$error != OPM->SUCCESS) {
		$conn->privmsg("Kraln", "User $nick joined #dsdev, host ($host) -
OPM Error: $error->string ");
	} else {
		$conn->privmsg("Kraln", "User $nick joined #dsdev, host ($host) -
scanning...");
	}
}

sub callback_openproxy {
   my($scan, $remote, $val) = @_;
	print "callback 1 called... \n";
   push @{$open{$remote->ip}}, [$remote->port, $remote->protocol];
}

sub callback_end {
   my($scan, $remote, $val) = @_;
	print "callback 2 called... \n";

   my $ip = $remote->ip;

   if(exists $open{$ip}) {
      my $output = sprintf("%s open %s %s\n", $ip,
         join(",", map { $_->[0] } @{$open{$ip}}),
         join(",", map { $_->[1] } @{$open{$ip}}));
      delete $open{$ip};
      $conn->privmsg("Kraln", "Open proxy detected: $output");
	print "$output \n";
      $numopen++;
   }else{
      print "$ip closed\n";
   }
}

$conn->add_handler('join', \&on_join);
$conn->add_handler('376', \&on_connect);

# local interface to bind to
$scan->config(OPM->CONFIG_BIND_IP, "67.106.81.130");
$scan->config(OPM->CONFIG_FD_LIMIT, 1024);
$scan->config(OPM->CONFIG_MAX_READ, 512);

$scan->config(OPM->CONFIG_SCAN_IP, "irc.blitzed.org");
$scan->config(OPM->CONFIG_SCAN_PORT, 6667);
$scan->config(OPM->CONFIG_TARGET_STRING, "*** Looking up your hostname...");

$scan->callback(OPM->CALLBACK_END, \&callback_end);
$scan->callback(OPM->CALLBACK_OPENPROXY, \&callback_openproxy);

$irc->start();

--------------------- /SNIP

It connects, signs on, messages me when users join, tells me it's
adding the default scans - but never, ever do I see "callback 1
called" or "callback 2 called".

I am positively stumped.

Thanks in advance for your help,

-Jeff