From 917638dfdf31e26ae9115dabb5c2fe528866c549 Mon Sep 17 00:00:00 2001 From: William Heimbigner Date: Mon, 8 Oct 2007 13:28:23 +0000 Subject: added a db command, improved the user set flags command, added linked channels, added a showhilights command, eliminated flooding of alerts, fixed nickspam check, added something to watch chancounts. --- config-default/channels.xml | 127 +++++++++++++++++++++++++++++++++++++------- config-default/commands.xml | 75 ++++++++++++++++++++++---- config-default/users.xml | 11 +++- meta.pl | 2 +- modules/classes.pl | 8 +-- modules/event.pl | 37 +++++++------ modules/inspect.pl | 6 +-- modules/log.pl | 3 ++ modules/util.pl | 33 +++++++++--- modules/xml.pl | 3 +- 10 files changed, 244 insertions(+), 61 deletions(-) diff --git a/config-default/channels.xml b/config-default/channels.xml index 7633dbb..c79d99b 100644 --- a/config-default/channels.xml +++ b/config-default/channels.xml @@ -1,11 +1,16 @@ - + + + + ST47 + alindeman + seanw a b c @@ -17,13 +22,17 @@ + ST47 WildPikachu nalioth quux denny - Fieldy numist + Fieldy + savetheWorld + tomaw PhilKC + rob ##linux-ops @@ -35,14 +44,19 @@ WildPikachu quux denny - Fieldy numist PhilKC - + + ##linux-ops + + + + + njan numist quux HentaiXP @@ -51,6 +65,7 @@ JonathanD Cpudan80 AndrewB + pinpoint @@ -58,6 +73,47 @@ + + + + + + + tomaw + Dave2 + ST47 + Dave2 + tomaw + njan + Dave2 + AndrewB + AndrewB + denny + Dave2 + tomaw + ompaul + kloeri + PhilKC + Dave2 + + + #freenode-adb + + + + + + + + + flyingparchment + seanw + ST47 + + + #wikimedia-ops + + Shadow_mil @@ -68,6 +124,8 @@ Mbimmler + Majorly + Fabexplosive #wikimedia-ops @@ -76,6 +134,7 @@ White_cat + Majorly #wikimedia-ops @@ -90,18 +149,23 @@ - + + Cbrown1023 + Cbrown1023 Sean_William - ST47 + Majorly + TheLetterE + Golbez + Mbimmler Karlprof + Martinp23 Pilotguy Eagle-101 - Mbimmler skenmy Ral315 tomaw @@ -116,6 +180,15 @@ SWATJester njan mike42 + Pilotguy + + + #wikimedia-ops + + + + + TheFearow #wikimedia-ops @@ -123,18 +196,38 @@ - White_Cat Cometstyles + Majorly + Worby + kmccoy + Golbez + KFP + wimt + werdan7 + Animum AppleBoy Soms - ST47 Martinp23 Cbrown1023 + TheLetterE + KFP #wikimedia-ops + + + TheLetterE + werdan7 + + + #wikimedia-ops + + + + + vishwin60 @@ -148,8 +241,8 @@ Eagle-101 Mbimmler Pilotguy - ST47 skenmy + AndrewB #wikimedia-ops @@ -157,20 +250,19 @@ - ST47 + Golbez #wikimedia-ops - - - 15:45 + + - requested by ChanServ + ^requested by ChanServ tinyurl\.com/ypvk4n blah .* @@ -181,8 +273,6 @@ ^... DDOS COUNTDOWN.* dnsbl.dronebl.org rbl.efnet.org - 10:30 - 5:3 ([^ ]{4,} +)\1{5,} goatse\.cz 3:20 @@ -193,12 +283,13 @@ i=magical 5:3 150:20 - .* + .* RED ARMY OF LOL \.com/sms.exe (?i)^sure are a ?lot of .*fags? in here AfterDeath + ST47 alindeman seanw diff --git a/config-default/commands.xml b/config-default/commands.xml index eedf584..3ab49e9 100644 --- a/config-default/commands.xml +++ b/config-default/commands.xml @@ -4,6 +4,11 @@ $conn->privmsg($event->{to}->[0], "help is at http://meta.wikimedia.org/wiki/User:WHeimbigner/AntiSpamMeta"); ]]> + + privmsg($event->{to}->[0], "db is at http://antispammeta.net/query.html"); + ]]> + privmsg($event->{to}->[0], "Hiya $nick"); ]]> - + {person}->{$nick}->{flags}); } else { + if ($flags eq '') { + if (defined($::users->{person}->{$nick}->{flags})) { + $conn->privmsg($event->{to}->[0], "Flags for $nick: $::users->{person}->{$nick}->{flags}"); + } else { + $conn->privmsg($event->{to}->[0], "$nick has no flags"); + } +# delete($::users->{person}->{$nick}->{flags}); + } else { $::users->{person}->{$nick}->{flags} = $flags; + ASM::XML->writeUsers(); + $conn->privmsg($event->{to}->[0], "Flags for $nick set to $flags"); } - ASM::XML->writeUsers(); - $conn->privmsg($event->{to}->[0], "Flags for $nick set to $flags"); ]]> @@ -41,7 +53,7 @@ $conn->privmsg($event->{to}->[0], "Byebye $nick"); ]]> - + getLink(lc $chan); + if ( lc $link ne lc $chan ) { + $conn->privmsg($event->{to}->[0], "Error: $chan is linked to $link - use $link instead."); + return; + } if ($level eq '') { $level = 'low'; } unless (defined($::channels->{channel}->{$chan}->{msgs})) { $::channels->{channel}->{$chan}->{msgs} = {}; @@ -83,6 +100,11 @@ getLink(lc $chan); + if ( lc $link ne lc $chan ) { + $conn->privmsg($event->{to}->[0], "Error: $chan is linked to $link - use $link instead."); + return; + } foreach my $risk ( keys %::RISKS ) { next unless defined($::channels->{channel}->{$chan}->{msgs}->{$risk}); my @ppl = @{$::channels->{channel}->{$chan}->{msgs}->{$risk}}; @@ -90,7 +112,25 @@ $::channels->{channel}->{$chan}->{msgs}->{$risk} = \@ppl; } ASM::XML->writeChannels(); - $conn->privmsg($event->{to}->[0], "no moar msgs for $nick"); + $conn->privmsg($event->{to}->[0], "$nick removed from targets for $chan"); + ]]> + + + {channel}})) { + foreach my $level (keys(%{$::channels->{channel}->{$chan}->{hilights}})) { + if (grep(/^${nick}$/i, @{$::channels->{channel}->{$chan}->{hilights}->{$level}})) { + push @channels, $chan . " ($level)"; + } + } + } + if (! @channels) { + $conn->privmsg($event->{to}->[0], "$nick isn't on any hilights"); + } else { + $conn->privmsg($event->{to}->[0], "$nick is hilighted for " . join(', ', @channels)); + } ]]> @@ -99,6 +139,11 @@ my $nick = $2; my $level= $3; if ($level eq '') { $level = 'low'; } + my $link = ASM::Util->getLink(lc $chan); + if ( lc $link ne lc $chan ) { + $conn->privmsg($event->{to}->[0], "Error: $chan is linked to $link - use $link instead."); + return; + } unless (defined($::channels->{channel}->{$chan}->{hilights})) { $::channels->{channel}->{$chan}->{hilights} = {}; } @@ -116,6 +161,11 @@ getLink(lc $chan); + if ( lc $link ne lc $chan ) { + $conn->privmsg($event->{to}->[0], "Error: $chan is linked to $link - use $link instead."); + return; + } foreach my $risk ( keys %::RISKS ) { next unless defined($::channels->{channel}->{$chan}->{hilights}->{$risk}); my @ppl = @{$::channels->{channel}->{$chan}->{hilights}->{$risk}}; @@ -123,7 +173,7 @@ $::channels->{channel}->{$chan}->{hilights}->{$risk} = \@ppl; } ASM::XML->writeChannels(); - $conn->privmsg($event->{to}->[0], "kthxbai $nick"); + $conn->privmsg($event->{to}->[0], "Removing hilights for $nick in $chan"); ]]> @@ -189,10 +239,13 @@ $conn->privmsg($event->{to}->[0], $x . " exempted"); ]]> - + commaAndify(ASM::Util->getAlert($event->{to}->[0], 'opalert', 'hilights')); - $conn->privmsg($_, "[$event->{to}->[0]] - $event->{nick} wants op attention ($1) $hilite") foreach ASM::Util->getAlert($event->{to}->[0], 'opalert', 'msgs'); + my $tgt = $event->{to}->[0]; + $tgt = $1 if (defined($1)); + my $msg = $2; + my $hilite=ASM::Util->commaAndify(ASM::Util->getAlert($tgt, 'opalert', 'hilights')); + $conn->privmsg($_, "[$tgt] - $event->{nick} wants op attention ($msg) $hilite") foreach ASM::Util->getAlert($tgt, 'opalert', 'msgs'); ]]> diff --git a/config-default/users.xml b/config-default/users.xml index 0c59b57..88fbd66 100644 --- a/config-default/users.xml +++ b/config-default/users.xml @@ -1,12 +1,21 @@ + + + + + + + + - + + diff --git a/meta.pl b/meta.pl index 31059f8..faadd93 100755 --- a/meta.pl +++ b/meta.pl @@ -19,7 +19,7 @@ $::pass = ''; @::string_blacklist=(); BEGIN { -my @modules = qw/Xml Util Inspect Event Services Log Command Classes Actions Mysql OperQueue/; +my @modules = qw/Util Xml Inspect Event Services Log Command Classes Actions Mysql OperQueue/; require 'modules/' . lc $_ . '.pl' foreach @modules; } diff --git a/modules/classes.pl b/modules/classes.pl index 4233d88..36a8031 100644 --- a/modules/classes.pl +++ b/modules/classes.pl @@ -3,6 +3,7 @@ package ASM::Classes; use strict; use warnings; use Text::LevenshteinXS qw(distance); +use Data::Dumper; my %sf = (); @@ -93,9 +94,10 @@ sub nickspam { my ($chk, $id, $event, $chan) = @_; my @cut = split(/:/, $chk->{content}); if ( length $event->{args}->[0] >= int($cut[0]) ) { - %_ = map { $_=>$_ } lc keys %{$::sc{lc $chan}{users}}; - my @uniq = grep( $_{$_}, split( / / , lc $event->{args}->[0]) ); - return 1 if ( $#{ @uniq } >= int($cut[1]) ); + my %users = %{$::sc{lc $chan}->{users}}; + my %x = map { $_=>$_ } keys %users; + my @uniq = grep( $x{$_}, split( /[ ,]+/ , lc $event->{args}->[0]) ); + return 1 if ( @uniq >= int($cut[1]) ); } return 0; } diff --git a/modules/event.pl b/modules/event.pl index e7b3a66..c77fda1 100644 --- a/modules/event.pl +++ b/modules/event.pl @@ -67,8 +67,6 @@ sub on_connect { $conn->privmsg( 'NickServ', "ghost $::settings->{nick} $::settings->{pass}" ) if lc $event->{args}->[0] ne lc $::settings->{nick}; } -#my @leven = (); - sub on_join { my ($conn, $event) = @_; my %evcopyx = %{$event}; @@ -80,6 +78,11 @@ sub on_join { mkdir($::settings->{log}->{dir} . $chan); $conn->sl("who $chan"); $conn->privmsg('ChanServ', "op $chan" ) if (defined cs($chan)->{op}) && (cs($chan)->{op} eq 'yes'); + #TODO: make it settable via config. Hardcoded channames ftl. + if ($chan eq '##linux') { + $conn->schedule(300, \&do_chancount, $chan, 300); + #TODO: mark this as a channel we're watching so we don't schedule this multiple times + } } $::sc{$chan}{users}{$nick} = {}; $::sc{$chan}{users}{$nick}{hostmask} = $event->{userhost}; @@ -104,21 +107,6 @@ sub on_join { } } $::log->logg( $event ); -# if ( $#leven ne -1 ) { -# my $ld = ( ( maxlen($nick, $leven[0]) - distance($nick, $leven[0]) ) / maxlen($nick, $leven[0]) ); -# my $mx = $leven[0]; -# foreach my $item ( @leven ) { -# next if $nick eq $item; # avoid dups -# my $tld = ( ( maxlen($nick, $item) - distance($nick, $item) ) / maxlen($nick, $item) ); -# if ($tld > $ld) { -# $ld = $tld; -# $mx = $item; -# } -# } -# print "Best match for $nick was $mx with $ld\n" -# } -# push(@leven, $nick); -# shift @leven if $#leven > 5; } sub on_part @@ -139,6 +127,7 @@ sub on_part if ( lc $conn->{_nick} eq lc $nick ) { delete( $::sc{lc $event->{to}->[0]} ); + on_byechan(lc $event->{to}->[0]); } else { @@ -278,6 +267,7 @@ sub on_kick { if ( lc $conn->{_nick} eq lc $nick ) { delete( $::sc{lc $event->{args}->[0]} ); + on_byechan(lc $event->{to}->[0]); } else { @@ -431,4 +421,17 @@ sub on_bannedfromchan { $conn->privmsg('ChanServ', "unban $event->{args}->[1]"); } +sub on_byechan { + my ($chan) = @_; + #TODO do del event stuff +} + +sub do_chancount { + my ($conn, $chan, $repeat) = @_; + my @users = keys(%{$::sc{$chan}{users}}); + my $count = @users; + system('/home/icxcnika/AntiSpamMeta/chancount.pl ' . $chan . sprintf(' %d', $count)); + $conn->schedule($repeat, \&do_chancount, $chan, $repeat); +} + return 1; diff --git a/modules/inspect.pl b/modules/inspect.pl index a995202..faa4dd7 100644 --- a/modules/inspect.pl +++ b/modules/inspect.pl @@ -64,13 +64,13 @@ sub inspect { $conn->schedule(int($dct{$id}{time}), sub { $::oq->o_send($lconn,$lunmode); }); } } - unless (defined($::ignored{$event->{host}}) && ($::ignored{$event->{host}} >= $::RISKS{$dct{$id}{risk}})) { + unless (defined($::ignored{$chan}) && ($::ignored{$chan} >= $::RISKS{$dct{$id}{risk}})) { my @tgts = ASM::Util->getAlert($chan, $dct{$id}{risk}, 'msgs'); foreach my $tgt (@tgts) { $conn->privmsg($tgt, $txtz); } - $::ignored{$event->{host}} = $::RISKS{$dct{$id}{risk}}; - $conn->schedule(60, sub { delete($::ignored{$event->{host}})}); + $::ignored{$chan} = $::RISKS{$dct{$id}{risk}}; + $conn->schedule(45, sub { delete($::ignored{$chan})}); } } } diff --git a/modules/log.pl b/modules/log.pl index e8a178a..6f25c48 100644 --- a/modules/log.pl +++ b/modules/log.pl @@ -27,6 +27,9 @@ sub logg foreach my $chan ( @chans ) { $chan = lc $chan; + if (substr($chan, 0, 1) eq '@') { + $chan = substr($chan, 1); + } my $path = ">>$cfg->{dir}${chan}/${chan}" . strftime($cfg->{filefmt}, @time); $_ = ''; $_ = "<$event->{nick}> $event->{args}->[0]" if $event->{type} eq 'public'; diff --git a/modules/util.pl b/modules/util.pl index a385790..4fe63ee 100644 --- a/modules/util.pl +++ b/modules/util.pl @@ -1,4 +1,5 @@ package ASM::Util; +use Array::Utils qw(:all); use warnings; use strict; @@ -7,6 +8,7 @@ my %oq; %::RISKS = ( + 'disable'=> -1, #this isn't really an alert 'debug' => 10, 'info' => 20, 'low' => 30, @@ -66,8 +68,22 @@ sub maxlen { sub cs { my ($module, $chan) = @_; $chan = lc $chan; - return $::channels->{channel}->{$chan} if ( defined($::channels->{channel}->{$chan}) ); - return $::channels->{channel}->{default}; + return $::channels->{channel}->{default} unless defined($::channels->{channel}->{$chan}); + if ( defined($::channels->{channel}->{$chan}->{link}) ) { + return $::channels->{channel}->{ $::channels->{channel}->{$chan}->{link} }; + } + return $::channels->{channel}->{$chan}; +} + +sub getLink +{ + my ($module, $chan) = @_; + $chan = lc $chan; + my $link = $::channels->{channel}->{$chan}->{link}; + if ( defined($link) ) { + return $link; + } + return $chan; } #this item is a stub, dur @@ -126,15 +142,20 @@ sub flood_process { sub getAlert { my ($module, $c, $risk, $t) = @_; - @_ = (); + my @disable = (); + my @x = (); $c = lc $c; foreach my $prisk ( keys %::RISKS) { if ( $::RISKS{$risk} >= $::RISKS{$prisk} ) { - push( @_, @{$::channels->{channel}->{master}->{$t}->{$prisk}} ) if defined $::channels->{channel}->{master}->{$t}->{$prisk}; - push( @_, @{cs($module, $c)->{$t}->{$prisk}} ) if defined cs($module, $c)->{$t}->{$prisk}; + push( @x, @{$::channels->{channel}->{master}->{$t}->{$prisk}} ) if defined $::channels->{channel}->{master}->{$t}->{$prisk}; + push( @x, @{cs($module, $c)->{$t}->{$prisk}} ) if defined cs($module, $c)->{$t}->{$prisk}; } } - return @_; + push( @disable, @{$::channels->{channel}->{master}->{$t}->{disable}} ) if defined $::channels->{channel}->{master}->{$t}->{disable}; + push( @disable, @{cs($module, $c)->{$t}->{disable}} ) if defined cs($module, $c)->{$t}->{disable}; + @x = unique(@x); + @x = array_diff(@x, @disable); + return @x; } sub commaAndify { diff --git a/modules/xml.pl b/modules/xml.pl index c3da924..1978af9 100644 --- a/modules/xml.pl +++ b/modules/xml.pl @@ -11,8 +11,9 @@ sub readXML { my ( $p ) = $::cset; #@_; $p = 'default' if $p eq ''; $p = "config-$p"; + my @fchan = ( 'event', keys %::RISKS ); $::settings = $::xs1->XMLin( "$p/settings.xml", ForceArray => ['host'], 'GroupTags' => { altnicks => 'altnick', server => 'host', autojoins => 'autojoin' }); - $::channels = $::xs1->XMLin( "$p/channels.xml", ForceArray => [qw/event debug info low medium high/]); + $::channels = $::xs1->XMLin( "$p/channels.xml", ForceArray => \@fchan ); $::users = $::xs1->XMLin( "$p/users.xml", ForceArray => 'person'); $::commands = $::xs1->XMLin( "$p/commands.xml", ForceArray => [qw/command/]); $::mysql = $::xs1->XMLin( "$p/mysql.xml", ForceArray => []); -- cgit v1.2.3