diff options
Diffstat (limited to 'lib/ASM/Log.pm')
| -rw-r--r-- | lib/ASM/Log.pm | 122 |
1 files changed, 121 insertions, 1 deletions
diff --git a/lib/ASM/Log.pm b/lib/ASM/Log.pm index 46bda4c..e9a6d6f 100644 --- a/lib/ASM/Log.pm +++ b/lib/ASM/Log.pm @@ -34,12 +34,118 @@ sub new return $self; } +sub actionlog +{ + my ($self, $event, $modedata1, $modedata2) = @_; + my ($action, $reason, $channel, + $nick, $user, $host, $gecos, $account, $ip, + $bynick, $byuser, $byhost, $bygecos, $byaccount); + my ($lcnick, $lcbynick); + + if ($event->{type} eq 'mode') { + $action = $modedata1; + $nick = $modedata2; + $channel = lc $event->{to}->[0]; + $bynick = $event->{nick}; + $byuser = $event->{user}; + $byhost = $event->{host}; + } elsif ($event->{type} eq 'quit') { + my $quitmsg = $event->{args}->[0]; + if ($quitmsg =~ /^Killed \((\S+) \((.*)\)\)$/) { + $bynick = $1; + $reason = $2 unless ($2 eq '<No reason given>'); + return if (($reason // '') =~ /Nickname regained by services/); + $action = 'kill'; + } elsif ($quitmsg =~ /^K-Lined$/) { + $action = 'k-line'; + } else { + return; #quit not forced/tracked + } + $nick = $event->{nick}; + $user = $event->{user}; + $host = $event->{host}; + } elsif (($event->{type} eq 'part') && ($event->{args}->[0] =~ /^requested by (\S+) \((.*)\)/)) { + $bynick = $1; + $reason = $2 unless (lc $2 eq lc $event->{nick}); + $action = 'remove'; + $nick = $event->{nick}; + $user = $event->{user}; + $host = $event->{host}; + $channel = $event->{to}->[0]; + } elsif ($event->{type} eq 'kick') { + $action = 'kick'; + $bynick = $event->{nick}; + $byuser = $event->{user}; + $byhost = $event->{host}; + $reason = $event->{args}->[1] unless ($event->{args}->[1] eq $event->{to}->[0]); + $nick = $event->{to}->[0]; + $channel = $event->{args}->[0]; + } + return unless defined($action); + $lcbynick = lc $bynick if defined $bynick; #we will lowercase the NUHGA info later. + if ( (defined($bynick)) && (defined($::sn{$lcbynick})) ) { #we have the nick taking the action available, fill in missing NUHGA info + $byuser //= $::sn{$lcbynick}{user}; + $byhost //= $::sn{$lcbynick}{host}; + $bygecos //= $::sn{$lcbynick}{gecos}; + $byaccount //= $::sn{$lcbynick}{account}; + if (($byaccount eq '0') or ($byaccount eq '*')) { + $byaccount = undef; + } + } + $lcnick = lc $nick if defined $nick; + if ( (defined($nick)) && (defined($::sn{$lcnick})) ) { #this should always be true, else something has gone FUBAR + $user //= $::sn{$lcnick}{user}; + $host //= $::sn{$lcnick}{host}; + $gecos //= $::sn{$lcnick}{gecos}; + $account //= $::sn{$lcnick}{account}; + if (($account eq '0') or ($account eq '*')) { + $account = undef; + } + $ip = ASM::Util->getNickIP($lcnick); + } + + return $::db->resultset('Actionlog')->create({ + action => $action, + reason => $reason, + channel => $channel, + + nick => $nick, + user => $user, + host => $host, + gecos => $gecos, + account => $account, + ip => $ip, + + bynick => $bynick, + byuser => $byuser, + byhost => $byhost, + bygecos => $bygecos, + byaccount => $byaccount, + })->id; +# $::sn{ow} looks like: +#$VAR1 = { +# "account" => "afterdeath", +# "gecos" => "William Athanasius Heimbigner", +# "user" => "icxcnika", +# "mship" => [ +# "#baadf00d", +# "#antispammeta-debug", +# "#antispammeta" +# ], +# "host" => "freenode/weird-exception/network-troll/afterdeath" +# }; + +} + sub incident { my $self = shift; - my ($chan, $header) = @_; + my ($chan, $nick, $user, $host, $gecos, $risk, $id, $reason) = @_; $chan = lc $chan; my $uuid = $self->{UUID}->create_str(); + + my $header = "$chan: $risk risk: $nick - $reason\n"; + open(FH, '>', $self->{CONFIG}->{detectdir} . $uuid . '.txt'); print FH $header; if (defined($self->{backlog}->{$chan})) { @@ -47,6 +153,20 @@ sub incident } print FH "\n\n"; close(FH); + + $gecos //= "NOT_DEFINED"; + + $::db->resultset('Alertlog')->create({ + channel => $chan, + nick => $nick, + user => $user, + host => $host, + gecos => $gecos, + level => $risk, + id => $id, + reason => $reason, + }); + return $uuid; } |
