use strict; use Irssi::TextUI; use Net::DNS; use vars qw($VERSION %IRSSI); $VERSION = '1.0'; %IRSSI = ( authors => 'Rob Mitchelmore (cheesey)', contact => 'cheesestraws@gmail.com', name => 'webchat-utils', description => 'adds a webchat ip revealing utility.', license => 'GPL2' ); my $wcres = Net::DNS::Resolver->new; Irssi::theme_register([ 'join', '{channick_hilight $0} {chanhost_hilight $1} has joined {channel $2}', 'joinwc', '{channick_hilight $0} is from $1 via cgi:irc', 'whoisuh', '{nick $0} {nickhost $1@$2}', 'whoisrh', '{whois actually $0}', 'whoisrn', '{whois ircname $0}', 'whowas', '{nick $0} {nickhost $1@$2}', 'whowasrh', '{whois actually $0}', 'whowasrn', '{whois was $0}' ]); sub getptr($) { my $ip = shift; my $lup = (join '.', (reverse (split /\./, $ip))) . ".in-addr.arpa"; my $ans = $wcres->search($ip); if (defined $ans) { my @rrs = $ans->answer; my $rr; foreach $rr (@rrs) { return $rr->ptrdname; } return $ip; } else { return $ip; } } sub getrealhost { if (shift =~ /([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/) { my $one = hex($1); my $two = hex($2); my $three = hex($3); my $four = hex($4); my $ip = "$one.$two.$three.$four"; return getptr($ip); } else { return undef; } } sub joinhandler { my ($server, $channel, $nick, $host) = @_; if (!$server) { return; } # Trap for ircu that doesn't prefix its channel with a colon! # Took me ages to figure this one out, which is depressing given # how much time I've spent hanging around inside it my $chan; if ((substr $channel, 0, 1) eq ":") { $chan = substr $channel, 1; } else { $chan = $channel; } my $win = $server->window_item_find($chan); if (!$win) { return; } $win->printformat(MSGLEVEL_JOINS, 'join', $nick, $host, $chan); my ($ident, $addy) = split /@/, $host; my $h = getrealhost($ident); if ($h) { $win->printformat(MSGLEVEL_JOINS, 'joinwc', $nick, $h); } Irssi::signal_stop(); } sub whoishandler { my ($server, $argv, $nick, $host) = @_; if (!$server) { return; } # This is an event 311, which is given in RFC as having the form # * : # first split on /:/. my ($first, @last) = split /:/, $argv; my $realname = join ':', @last; my @argv = split / /, $first; my ($nick, $rnick, $ident, $rhost) = @argv; $server->printformat($rnick, MSGLEVEL_CRAP, 'whoisuh', $rnick, $ident, $rhost); my $h = getrealhost($ident); if ($h) { $server->printformat($rnick, MSGLEVEL_CRAP, 'whoisrh', $h); } $server->printformat($rnick, MSGLEVEL_CRAP, 'whoisrn', $realname); Irssi::signal_stop(); } sub whowashandler { my ($server, $argv, $nick, $host) = @_; if (!$server) { return; } # This is an event 314, which is given in the RFC as being # * : my ($first, @last) = split /:/, $argv; my $realname = join ':', @last; my @argv = split / /, $first; my ($nick, $rnick, $ident, $rhost) = @argv; $server->printformat($rnick, MSGLEVEL_CRAP, 'whowas', $rnick, $ident, $rhost); my $h = getrealhost($ident); if ($h) { $server->printformat($rnick, MSGLEVEL_CRAP, 'whowasrh', $h); } $server->printformat($rnick, MSGLEVEL_CRAP, 'whowasrn', $realname); } Irssi::signal_add("event join", \&joinhandler); Irssi::signal_add("event 311", \&whoishandler); Irssi::signal_add("event 314", \&whowashandler);