use Irssi; use Irssi::Irc; use IO::Socket; use POSIX; use vars qw($VERSION %IRSSI); use strict; $VERSION = "0.27"; %IRSSI = ( authors => "hannu_", contact => "hannu at hannu.biz", name => "urllog", description => "urllog client", license => "GPLv2" ); # # JULKINEN IRC-URLS.NET SCRIPTI # # Scripti vaatii, että irssin IRC-verkot on asetettu oikein. # # Sallittujen kanavien asetus: # (Lista pitää olla muotoa #kanava1@ircnet,#kanava2@ircnet # ja kaikki kanavat on eroteltava pilkulla. # Myös merkinnät *@ircnet tai #kanava@* on sallittuja) # /set urllog_channels_allow #kanava1@ircnet,#kanava2@ircnet # # Estettyjen kanavien asetus: # (Annetaan samassa muodossa kuin sallittujen kanavien lista) # /set urllog_channels_deny #kanava3@ircnet,#kanava4@ircnet # # Estettyjen nickien asetus: # (Nickit annetaan pilkulla eroteltuna) # /set urllog_nicks_deny nick1,nick2 # # Tallenna asetukset /save komennolla. # # Asetusten muuttaminen ei vaadi scriptin uudelleenkäynnistystä $SIG{CHLD}="IGNORE"; my %urllog; sub log_public { my ($server, $data, $nick, $mask, $target) = @_; return logurl($server->{chatnet}, $nick, $data, $target); } sub log_own{ my ($server, $data, $target) = @_; return logurl($server->{chatnet}, $server->{nick}, $data, $target); } sub log_topic { my ($server, $target, $data, $nick, $mask) = @_; return logurl($server->{chatnet}, $nick, $data, $target); } sub parse_url { my ($url) = @_; if($url =~ /((http|https):\/\/[a-zA-Z0-9\|\[\]\/\\\:\?\%\.\,\&\;=#\-\_\!\+\~]*)/i){ return $1; }elsif($url =~ /(www\.[a-zA-Z0-9\/\\\:\?\%\.\,\&\;=#\-\_\!\+\~]*)/i){ return "http://".$1; } return 0; } sub logurl { my ($ircnet, $nick, $data, $channel) = @_; my $url=parse_url($data); if ($url) { my @channels_allow=split(',', lc $urllog{'channels_allow'}); my @channels_deny=split(',', lc $urllog{'channels_deny'}); my @nicks_deny=split(',', lc $urllog{'nicks_deny'}); my $allowed=0; $ircnet = lc $ircnet; $channel = lc $channel; foreach my $target_a(@channels_allow) { if (($target_a eq '*') || ($target_a eq $channel.'@'.$ircnet) || ($target_a eq '*@*') || ($target_a eq $channel.'@*') || ($target_a eq '*@'.$ircnet)) { $allowed=1; } } if ($allowed) { foreach my $target_d(@channels_deny) { if (($target_d eq '*') || ($target_d eq $channel.'@'.$ircnet) || ($target_d eq '*@*') || ($target_d eq $channel.'@*') || ($target_d eq '*@'.$ircnet)) { $allowed=0; } } foreach my $nick_d(@nicks_deny) { if ($nick_d eq lc $nick) { $allowed=0; } } if ($allowed) { my $forkpid; $forkpid = fork() or Irssi::print("Urllog: Failed to fork"); if ($forkpid == 0) { send_url($ircnet, $nick, $channel, $url); POSIX::_exit(1); } } } } return 0; } sub send_url { my ($ircnet, $nick, $channel, $url) = @_; my $sock; $sock = IO::Socket::INET->new( PeerAddr => 'irc-urls.net',PeerPort => 7889,Proto => 'tcp',Timeout => 10 ); if ($sock) { print $sock "pub:logger $nick $ircnet $channel $url"; close $sock; } return 0; } sub refresh_config { $urllog{'channels_allow'} = Irssi::settings_get_str('urllog_channels_allow'); $urllog{'channels_deny'} = Irssi::settings_get_str('urllog_channels_deny'); $urllog{'nicks_deny'} = Irssi::settings_get_str('urllog_nicks_deny'); return 0; }; Irssi::signal_add_last('message public', 'log_public'); Irssi::signal_add_last('message own_public', 'log_own'); Irssi::signal_add_last('message topic', 'log_topic'); Irssi::signal_add_last('setup changed', 'refresh_config'); Irssi::settings_add_str('urllog', 'urllog_channels_allow', ''); Irssi::settings_add_str('urllog', 'urllog_channels_deny', ''); Irssi::settings_add_str('urllog', 'urllog_nicks_deny', ''); refresh_config(); Irssi::print("Urllog-client v$VERSION loaded");