diff options
| author | 2007-11-25 21:33:40 +0000 | |
|---|---|---|
| committer | 2007-11-25 21:33:40 +0000 | |
| commit | 0293b9d684ce2f89a1850b7a0d4819bdd1c947ef (patch) | |
| tree | c7ea8fc9bd40b46797ba690ebe7b4066c178518d | |
| parent | 917638dfdf31e26ae9115dabb5c2fe528866c549 (diff) | |
better logging, better flood detection, command ignoring
| -rw-r--r-- | config-default/channels.xml | 31 | ||||
| -rw-r--r-- | config-default/commands.xml | 9 | ||||
| -rw-r--r-- | config-default/users.xml | 1 | ||||
| -rwxr-xr-x | meta.pl | 3 | ||||
| -rw-r--r-- | modules/classes.pl | 32 | ||||
| -rw-r--r-- | modules/command.pl | 1 | ||||
| -rw-r--r-- | modules/event.pl | 12 | ||||
| -rw-r--r-- | modules/mysql.pl | 66 | ||||
| -rw-r--r-- | modules/util.pl | 11 |
9 files changed, 157 insertions, 9 deletions
diff --git a/config-default/channels.xml b/config-default/channels.xml index c79d99b..a91e4af 100644 --- a/config-default/channels.xml +++ b/config-default/channels.xml @@ -6,7 +6,7 @@ <hilights></hilights> <msgs></msgs> </channel> - <channel id="##asb-testing" op="when"> + <channel id="##asb-testing" op="when" silence="yes"> <hilights> <disable>ST47</disable> <disable>alindeman</disable> @@ -54,6 +54,7 @@ <channel id="##tomaw" op="no"> <hilights></hilights> </channel> + <channel id="##wikimedia-ops" op="no" /> <channel id="##windows" op="no"> <hilights> <info>njan</info> @@ -77,7 +78,7 @@ <channel id="#defocus" link="#freenode"> <hilights></hilights> </channel> - <channel id="#freenode" op="no"> + <channel id="#freenode" op="no" silence="yes"> <hilights> <debug>tomaw</debug> <debug>Dave2</debug> @@ -100,6 +101,10 @@ <debug>#freenode-adb</debug> </msgs> </channel> + <channel id="#gentoo" op="no" silence="yes"> + <hilights></hilights> + <msgs></msgs> + </channel> <channel id="#freenode-adb" op="no"> <hilights></hilights> <msgs></msgs> @@ -121,6 +126,10 @@ </hilights> <msgs></msgs> </channel> + <channel id="#ubuntu" op="no" silence="yes"> + <hilights></hilights> + <msgs></msgs> + </channel> <channel id="#wikimedia" op="no"> <hilights> <debug>Mbimmler</debug> @@ -128,7 +137,7 @@ <low>Fabexplosive</low> </hilights> <msgs> - <low>#wikimedia-ops</low> + <debug>#wikimedia-ops</debug> </msgs> </channel> <channel id="#wikimedia-commons" op="no"> @@ -164,6 +173,7 @@ <debug>Mbimmler</debug> <info>Karlprof</info> <info>Martinp23</info> + <info>Pilotguy</info> <low>Pilotguy</low> <low>Eagle-101</low> <low>skenmy</low> @@ -181,9 +191,11 @@ <low>njan</low> <low>mike42</low> <low>Pilotguy</low> + <low>kloeri</low> </hilights> <msgs> <debug>#wikimedia-ops</debug> + <debug>##wikimedia-ops</debug> </msgs> </channel> <channel id="#wikipedia-bag" op="no"> @@ -195,7 +207,7 @@ </msgs> </channel> <channel id="#wikipedia-en" op="yes"> - <hilights> + <hilights none="ST47"> <debug>Cometstyles</debug> <debug>Majorly</debug> <debug>Worby</debug> @@ -205,6 +217,7 @@ <debug>wimt</debug> <debug>werdan7</debug> <debug>Animum</debug> + <debug>Deskana</debug> <low>AppleBoy</low> <low>Soms</low> <low>Martinp23</low> @@ -214,12 +227,15 @@ </hilights> <msgs> <debug>#wikimedia-ops</debug> + <debug>##wikimedia-ops</debug> </msgs> </channel> <channel id="#wikipedia-en-help" op="no"> <hilights> <debug>TheLetterE</debug> <debug>werdan7</debug> + <debug>GDonato</debug> + <debug>TheLetterE</debug> </hilights> <msgs> <debug>#wikimedia-ops</debug> @@ -251,6 +267,7 @@ <channel id="#wikipedia-social" op="no"> <hilights> <debug>Golbez</debug> + <debug>TheLetterE</debug> </hilights> <msgs> <low>#wikimedia-ops</low> @@ -263,8 +280,7 @@ </channel> <channel id="master"> <event id="autoremove" action="none" class="re" reason="on chanserv autoremove" risk="info" time="0" type="part">^requested by ChanServ</event> - <event id="badurl1" action="ban" class="re" reason="sending spam url" risk="medium" time="0" type="public">tinyurl\.com/ypvk4n</event> - <event id="blacklist" action="none" class="strbl" reason="sending pm matching string blacklist" risk="low" time="0" type="public">blah</event> + <event id="blacklist" action="none" class="strbl" reason="sending message containing blacklisted content" risk="low" time="0" type="public">blah</event> <event id="ctcp-dcc" action="ban" class="re" reason="ctcp-dcc" risk="high" time="0" type="cdcc">.*</event> <event id="dcc" action="ban" class="re" override="dcc-medium" reason="using the DC.C SE.ND exploit" risk="high" time="0" type="public">^DCC SEND |\bDCC SEND "?[A-Za-z0-9]+"? \d+ \d+ \d+</event> <event id="dcc-medium" action="ban" class="re" reason="using the DC.C SE.ND exploit" risk="medium" time="0" type="public">DCC SEND </event> @@ -282,6 +298,7 @@ <event id="levenflood" action="none" class="levenflood" override="flood-5to3" reason="levenshtein flood match" risk="debug" time="0" type="public">contentisuseless</event> <event id="magical" action="none" class="ident" reason="typical w00t ident" risk="info" time="0" type="join">i=magical</event> <event id="massflood" action="ban" class="splitflood" reason="distributed flooding" risk="high" time="0" type="public,part,caction">5:3</event> + <event id="advflood" action="ban" class="advsplitflood" reason="advanced distributed flooding" risk="debug" time="0" type="public,part,caction">5:3</event> <event id="nickspam" action="ban" class="nickspam" reason="nickspamming" risk="high" time="0" type="public">150:20</event> <event id="notice" action="ban" class="re" reason="sending a notice to the channel" risk="medium" time="0" type="notice">.*</event> <event id="redarmyoflol" action="ban" class="re" reason="parting with 'red army of lol'" risk="low" time="0" type="part">RED ARMY OF LOL</event> @@ -290,8 +307,10 @@ <hilights> <debug>AfterDeath</debug> <debug>ST47</debug> + <debug>troubled</debug> <low>alindeman</low> <low>seanw</low> + <medium>dave2</medium> </hilights> <msgs> <debug>##asb-nexus</debug> diff --git a/config-default/commands.xml b/config-default/commands.xml index 3ab49e9..5a4341c 100644 --- a/config-default/commands.xml +++ b/config-default/commands.xml @@ -1,4 +1,13 @@ <commands> + <command cmd="^;sql (main|log) (.*)"> + <![CDATA[ + my $dbh = $::db->{DBH}; + if ($1 eq 'log') { + $dbh = $::db->{DBH_LOG}; + } + $::db->raw($conn, $event->{to}->[0], $dbh, $2); + ]]> + </command> <command cmd="^;help$"> <![CDATA[ $conn->privmsg($event->{to}->[0], "help is at http://meta.wikimedia.org/wiki/User:WHeimbigner/AntiSpamMeta"); diff --git a/config-default/users.xml b/config-default/users.xml index 88fbd66..f0fc3a6 100644 --- a/config-default/users.xml +++ b/config-default/users.xml @@ -17,5 +17,6 @@ <person id="slowking_man" flags="ot" host="IDENTIFY" /> <person id="st47" flags="odat" host="IDENTIFY" /> <person id="tomaw" flags="odat" host="freenode/staff/tomaw" /> + <person id="troubled" flags="oat" host="pdpc/supporter/sustaining/troubled" /> <person id="wildpikachu" flags="odat" host="about/linux/staff/wildpikachu" /> </people> @@ -32,6 +32,7 @@ sub init { 'pass|p:s' => \$::pass, 'config|c:s' => \$::cset ); + $::debug = $debug; ASM::XML->readXML(); mkdir($::settings->{log}->{dir}); $::log = ASM::Log->new($::settings->{log}); @@ -39,7 +40,7 @@ sub init { $host = ${$::settings->{server}}[rand @{$::settings->{server}}]; print "Connecting to $host\n"; $irc->debug($debug); - $::db = ASM::DB->new($::mysql->{db}, $::mysql->{host}, $::mysql->{port}, $::mysql->{user}, $::mysql->{pass}, $::mysql->{table}); + $::db = ASM::DB->new($::mysql->{db}, $::mysql->{host}, $::mysql->{port}, $::mysql->{user}, $::mysql->{pass}, $::mysql->{table}, $::mysql->{dblog}); $conn = $irc->newconn( Server => $host, Port => $::settings->{port} || '6667', Nick => $::settings->{nick}, diff --git a/modules/classes.pl b/modules/classes.pl index 36a8031..775eae6 100644 --- a/modules/classes.pl +++ b/modules/classes.pl @@ -17,6 +17,7 @@ sub new "floodqueue" => \&floodqueue, "nickspam" => \&nickspam, "splitflood" => \&splitflood, + "advsplitflood" => \&advsplitflood, "re" => \&re, "nick" => \&nick, "ident" => \&ident, @@ -151,6 +152,37 @@ sub splitflood { return 0; } +sub advsplitflood { + my ($chk, $id, $event, $chan) = @_; + my $text; + my @cut = split(/:/, $chk->{content}); + $cf{$id}{timeout}=int($cut[1]); + if ($event->{type} =~ /^(public|notice|part|caction)$/) { + $text=$event->{args}->[0]; + } + return unless defined($text); + $text=~s/^\d+(.*)\d+$/$1/; + return unless length($text) >= 10; + if (defined($bs{$id}{$text}) && (time <= $bs{$id}{$text} + 600)) { + return 1; + } + push( @{$cf{$id}{$chan}{$text}}, time ); + while ( time >= $cf{$id}{$chan}{$text}[0] + $cf{$id}{'timeout'} ) { + last if ( $#{$cf{$id}{$chan}{$text}} == 0 ); + shift ( @{$cf{$id}{$chan}{$text}} ); + } + $cfc = $cfc + 1; + if ( $cfc >= 100 ) { + $cfc = 0; + process_cf(); + } + if ( $#{@{$cf{$id}{$chan}{$text}}}+1 == int($cut[0]) ) { + $bs{$id}{$text} = time; + return 1; + } + return 0; +} + sub re { my ($chk, $id, $event, $chan) = @_; my $match = $event->{args}->[0]; diff --git a/modules/command.pl b/modules/command.pl index 04f1d90..27cc5a9 100644 --- a/modules/command.pl +++ b/modules/command.pl @@ -19,6 +19,7 @@ sub command my $cmd = $args; my $d1; my $nick = lc $event->{nick}; + return 0 unless (ASM::Util->speak($event->{to}->[0])); foreach my $command ( @{$::commands->{command}} ) { if (defined($command->{flag})) { diff --git a/modules/event.pl b/modules/event.pl index c77fda1..2d247b6 100644 --- a/modules/event.pl +++ b/modules/event.pl @@ -96,11 +96,13 @@ sub on_join { @mship = (@mship, $chan); $::sn{$nick}->{mship} = \@mship; $::inspector->inspect( $conn, $event ); + $::db->logg($event); } else { $::sn{$nick} = {}; $::sn{$nick}->{mship} = [ $chan ]; if (defined($::needgeco{$nick})) { $::needgeco{$nick} = [ @{$::needgeco{$nick}}, $evcopy ]; + $::db->logg($event); } else { $::needgeco{$nick} = [ $evcopy ]; $conn->sl("whois $nick"); @@ -115,6 +117,7 @@ sub on_part $::inspector->inspect( $conn, $event ); my $nick = lc $event->{nick}; $::log->logg( $event ); + $::db->logg( $event ); if (defined($::sn{$nick}) && defined($::sn{$nick}->{mship})) { my @mship = @{$::sn{$nick}->{mship}}; @mship = grep { lc $_ ne lc $event->{to}->[0] } @mship; @@ -146,6 +149,7 @@ sub on_public my ($conn, $event) = @_; $::inspector->inspect( $conn, $event ); $::log->logg( $event ); + $::db->logg( $event ); $::commander->command( $conn, $event ); } @@ -154,6 +158,7 @@ sub on_notice my ($conn, $event) = @_; $::inspector->inspect( $conn, $event ); $::log->logg( $event ); + $::db->logg( $event ); $::services->doServices($conn, $event); } @@ -173,6 +178,7 @@ sub on_quit push ( @channels, $_ ) if delete $::sc{lc $_}{users}{lc $event->{nick}}; } $event->{to} = \@channels; + $::db->logg( $event ); delete($::sn{lc $event->{nick}}); $::inspector->inspect( $conn, $event ); $::log->logg( $event ); @@ -226,6 +232,7 @@ sub irc_topic { $::sc{lc $event->{to}->[0]}{topic}{text} = $event->{args}->[0]; } $::log->logg($event); + $::db->logg( $event ); } } @@ -242,10 +249,11 @@ sub on_nick { } } $::sn{lc $event->{args}->[0]} = $::sn{lc $event->{nick}}; + $::db->logg( $event ); delete( $::sn{lc $event->{nick}}); $event->{to} = \@channels; $::inspector->inspect($conn, $event); - $::log->logg($event) + $::log->logg($event); } sub on_kick { @@ -255,6 +263,7 @@ sub on_kick { } my $nick = lc $event->{to}->[0]; $::log->logg( $event ); + $::db->logg( $event ); if (defined($::sn{$nick}) && defined($::sn{$nick}->{mship})) { my @mship = @{$::sn{$nick}->{mship}}; @mship = grep { lc $_ ne lc $event->{to}->[0] } @mship; @@ -380,6 +389,7 @@ sub whois_user { if (defined( $::needgeco{$lnick} )) { foreach my $event (@{$::needgeco{$lnick}}) { $::inspector->inspect($conn, $event); + $::db->logg( $event ); } delete $::needgeco{$lnick}; } diff --git a/modules/mysql.pl b/modules/mysql.pl index 998c647..22369e1 100644 --- a/modules/mysql.pl +++ b/modules/mysql.pl @@ -6,10 +6,12 @@ use DBI; sub new { my $module = shift; - my ($db, $host, $port, $user, $pass, $table) = @_; + my ($db, $host, $port, $user, $pass, $table, $dblog) = @_; my $self = {}; $self->{DBH} = DBI->connect("DBI:mysql:database=$db;host=$host;port=$port", $user, $pass); + $self->{DBH_LOG} = DBI->connect("DBI:mysql:database=$dblog;host=$host;port=$port", $user, $pass); $self->{DBH}->{mysql_auto_reconnect} = 1; + $self->{DBH_LOG}->{mysql_auto_reconnect} = 1; $self->{TABLE} = $table; bless($self); return $self; @@ -22,6 +24,28 @@ sub new { # $::dbh->{mysql_auto_reconnect} = 1; #} +sub raw +{ + my $self = shift; + my ($conn, $tgt, $dbh, $qry) = @_; + my $sth = $dbh->prepare($qry); + $sth->execute; + my $names = $sth->{'NAME'}; + my $numFields = $sth->{'NUM_OF_FIELDS'}; + my $string = ""; + for (my $i = 0; $i < $numFields; $i++) { + $string = $string . sprintf("%s%s", $i ? "," : "", $$names[$i]); + } + $conn->privmsg($tgt, $string); + while (my $ref = $sth->fetchrow_arrayref) { + $string = ""; + for (my $i = 0; $i < $numFields; $i++) { + $string = $string . sprintf("%s%s", $i ? "," : "", $$ref[$i]); + } + $conn->privmsg($tgt, $string); + } +} + sub record { my $self = shift; @@ -36,6 +60,46 @@ sub record $dbh->quote($id) . ", " . $dbh->quote($reason) . ");"); } +#FIXME: This function is shit. Also, it doesn't work like I want it to with mode. +sub logg +{ + my $self = shift; + my ($event) = @_; + my $dbh = $self->{DBH_LOG}; + my $table = $event->{type}; + $table = 'action' if ($table eq 'caction'); + $table = 'privmsg' if ($table eq 'public'); + my $realtable = $table; + $realtable = 'joins' if $realtable eq 'join'; #mysql doesn't like a table named join + my $string = 'INSERT INTO `' . $realtable . '` ('; + if (($table ne 'nick') && ($table ne 'quit')) { + $string = $string . 'channel, '; + } + $string = $string . 'nick, user, host, geco'; + if ($table ne 'join') { + $string = $string . ', content1'; + } + if (($table eq 'kick') || ($table eq 'mode')) { + $string = $string . ', content2'; + } + $string = $string . ') VALUES ('; + if (($table ne 'nick') && ($table ne 'quit')) { + $string = $string . $dbh->quote($event->{to}->[0]) . ", "; + } + my $geco = $::sn{lc $event->{nick}}->{gecos}; + $string = $string . $dbh->quote($event->{nick}) . ", " . $dbh->quote($event->{user}) . ", " . + $dbh->quote($event->{host}) . ", " . $dbh->quote($geco); + if ($table ne 'join') { + $string = $string. ', ' . $dbh->quote($event->{args}->[0]); + } + if (($table eq 'kick') || ($table eq 'mode')) { + $string = $string . ', ' . $dbh->quote($event->{args}->[1]); + } + $string = $string . ');'; + print $string . "\n" if $::debug; + $dbh->do($string); +} + sub query { my $self = shift; diff --git a/modules/util.pl b/modules/util.pl index 4fe63ee..5a32e11 100644 --- a/modules/util.pl +++ b/modules/util.pl @@ -86,6 +86,17 @@ sub getLink return $chan; } +sub speak +{ + my ($module, $chan) = @_; + $chan = lc $chan; + if ( defined(cs($module, $chan)->{silence}) && (cs($module, $chan)->{silence} eq "yes") ) { + return 0; + } else { + return 1; + } +} + #this item is a stub, dur sub hostip { return gethostbyname($_[0]); |
