diff options
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/command.pl | 23 | ||||
| -rw-r--r-- | modules/event.pl | 29 | ||||
| -rw-r--r-- | modules/inspect.pl | 3 | ||||
| -rw-r--r-- | modules/log.pl | 16 | ||||
| -rw-r--r-- | modules/mysql.pl | 60 | ||||
| -rw-r--r-- | modules/util.pl | 7 | ||||
| -rw-r--r-- | modules/xml.pl | 4 |
7 files changed, 118 insertions, 24 deletions
diff --git a/modules/command.pl b/modules/command.pl index 7576850..014e89b 100644 --- a/modules/command.pl +++ b/modules/command.pl @@ -27,18 +27,29 @@ sub command # return 0 unless (ASM::Util->speak($event->{to}->[0])); foreach my $command ( @{$::commands->{command}} ) { - unless (ASM::Util->speak($event->{to}->[0])) { + my $fail = 0; + unless ( (ASM::Util->speak($event->{to}->[0])) or (!ASM::Util->notRestricted($nick, "nocommands")) ) { next unless (defined($command->{nohush}) && ($command->{nohush} eq "nohush")); } if (defined($command->{flag})) { #If the command is restricted, - next unless defined($::users->{person}->{$acct}); #make sure the requester has an account - next unless defined($::users->{person}->{$acct}->{flags}); #make sure the requester has flags defined - next unless (grep {$_ eq $command->{flag}} split('', $::users->{person}->{$acct}->{flags})); #make sure the requester has the needed flags + if (!defined($::users->{person}->{$acct})) { #make sure the requester has an account + $fail = 1; + } + elsif (!defined($::users->{person}->{$acct}->{flags})) { #make sure the requester has flags defined + $fail = 1; + } + elsif (!(grep {$_ eq $command->{flag}} split('', $::users->{person}->{$acct}->{flags}))) { #make sure the requester has the needed flags + $fail = 1; + } } if ($cmd=~/$command->{cmd}/) { ASM::Util->dprint("$event->{from} told me: $cmd", "commander"); - eval $command->{content}; - warn $@ if $@; + if ($fail == 1) { + $conn->privmsg($nick, "You don't have permission to use that command, or you're not signed into nickserv."); + } else { + eval $command->{content}; + warn $@ if $@; + } last; } } diff --git a/modules/event.pl b/modules/event.pl index 42ee2c1..401a51d 100644 --- a/modules/event.pl +++ b/modules/event.pl @@ -106,9 +106,9 @@ sub on_endofstats if ($event->{args}->[1] eq 'p') { $clearstatsp=1; my $tmp = Dumper(\%statsp); chomp $tmp; - if ( join(",", sort(keys %oldstatsp)) ne join(",", sort(keys %statsp)) ) { + if ( join(',', sort(keys %oldstatsp)) ne join(',', sort(keys %statsp)) ) { open(FH, '>>', 'statsplog.txt'); - print FH strftime("%F %T ", gmtime) . join(",", sort(keys %statsp)) . "\n"; + say FH strftime('%F %T ', gmtime) . join(',', sort(keys %statsp)); close(FH); ASM::Util->dprint(join(",", keys %statsp), 'statsp'); } @@ -127,6 +127,24 @@ sub on_pong $conn->schedule( 30, sub { $conn->sl("PING :" . time); } ); ASM::Util->dprint('Pong? ... Ping!', 'pingpong'); my $lag = time - $event->{args}->[0]; + my @changes = $::fm->scan(); + if (@changes) { + if ($::settingschanged) { + $::settingschanged = 0; + } else { + $conn->privmsg($::settings->{masterchan}, "Config files changed, auto rehash triggered. Check console for possible errors."); + ASM::XML->readXML(); + my @strbl = io('string_blacklist.txt')->getlines; + chomp @strbl; + @::string_blacklist = @strbl; +# my @eline=io('exempt.txt')->getlines; +# chomp @eline; +# %::eline = (); +# foreach my $item (@eline) { +# $::eline{lc $item} = 1; +# } + } + } if ($lag > 1) { ASM::Util->dprint("Latency: $lag", 'latency'); } @@ -173,7 +191,7 @@ sub on_dchat my $chan = lc $1; my $out = $event->{to}[0]; my @time = ($::settings->{log}->{zone} eq 'local') ? localtime : gmtime; - print $out "Retriving " . "$::settings->{log}->{dir}${chan}/${chan}" . strftime($::settings->{log}->{filefmt}, @time) . "\n"; + say $out 'Retrieving ' . "$::settings->{log}->{dir}${chan}/${chan}" . strftime($::settings->{log}->{filefmt}, @time); open(FHX, "$::settings->{log}->{dir}${chan}/${chan}" . strftime($::settings->{log}->{filefmt}, @time)); while (<FHX>) { print $out $_; @@ -201,7 +219,7 @@ sub on_account sub on_connect { my ($conn, $event) = @_; # need to check for no services - $conn->sl("MODE $event->{args}->[0] +Q"); + $conn->sl("MODE $event->{args}->[0] +Q-i"); if (lc $event->{args}->[0] ne lc $::settings->{nick}) { ASM::Util->dprint('Attempting to regain my main nick', 'startup'); $conn->privmsg( 'NickServ', "regain $::settings->{nick} $::settings->{pass}" ); @@ -295,7 +313,8 @@ sub on_msg $::commander->command($conn, $event); ASM::Util->dprint($event->{from} . " - " . $event->{args}->[0], 'msg'); if ((ASM::Util->notRestricted($event->{nick}, "nomsgs")) && ($event->{args}->[0] !~ /^;;/)) { - $conn->privmsg($::settings->{masterchan}, $event->{from} . ' told me: ' . $event->{args}->[0]); +# disabled by DL 130513 due to spammer abuse +# $conn->privmsg($::settings->{masterchan}, $event->{from} . ' told me: ' . $event->{args}->[0]); } } diff --git a/modules/inspect.pl b/modules/inspect.pl index 4466d69..3b72a3a 100644 --- a/modules/inspect.pl +++ b/modules/inspect.pl @@ -1,6 +1,7 @@ package ASM::Inspect; use warnings; use strict; +use feature qw(say); use Data::Dumper; #use List::Util qw(first); @@ -61,7 +62,7 @@ sub inspect { foreach $id ( keys %dct ) { return unless (ASM::Util->notRestricted($nick, "notrigger")); if (defined($::eline{$nick}) || defined($::eline{lc $event->{user}}) || defined($::eline{lc $event->{host}})) { - print "Deprecated eline found for $nick / $event->{user} / $event->{host} !\n"; + say "Deprecated eline found for $nick / $event->{user} / $event->{host} !"; return; } $xresult = $dct{$id}{xresult}; diff --git a/modules/log.pl b/modules/log.pl index bdf4821..fe92159 100644 --- a/modules/log.pl +++ b/modules/log.pl @@ -41,9 +41,8 @@ sub sqlIncident open(FH, '>', $self->{CONFIG}->{actiondir} . $index . '.txt'); foreach my $chan (@chans) { if (defined($self->{backlog}->{$chan})) { - print FH "$chan\n"; - print FH join('', @{$self->{backlog}->{$chan}}); - print FH "\n"; + say FH "$chan"; + say FH join('', @{$self->{backlog}->{$chan}}); } } close(FH); @@ -95,13 +94,14 @@ sub logg } else { print "COULDN'T PRINT TO $path - $line"; } + my $spy; if (defined($::spy{$chan})) { - my $spy = $::spy{$chan}; - print $spy $chan .": " . $nostamp . "\n"; + $spy = $::spy{$chan}; + } elsif (defined($::spy{lc $event->{nick}})) { + $spy = $::spy{lc $event->{nick}}; } - if (defined($::spy{lc $event->{nick}})) { - my $spy = $::spy{lc $event->{nick}}; - print $spy $chan .": " . $nostamp . "\n"; + if (defined($spy)) { + say $spy "$chan: $nostamp"; } # $_ >> io($path); } diff --git a/modules/mysql.pl b/modules/mysql.pl index 7484ca3..4ff4441 100644 --- a/modules/mysql.pl +++ b/modules/mysql.pl @@ -3,6 +3,7 @@ package ASM::DB; use warnings; use strict; use DBI; +use Data::Dumper; sub new { my $module = shift; @@ -190,6 +191,65 @@ sub logg my $realtable = $table; $realtable = 'joins' if $realtable eq 'join'; #mysql doesn't like a table named join my $string = 'INSERT INTO `' . $realtable . '` ('; +## begin saner code for this function + if ($table eq 'quit') { + $string = 'INSERT INTO `quit` (nick, user, host, geco, ip, account, content1) VALUES (' . + $dbh->quote($event->{nick}) . ',' . $dbh->quote($event->{user}) . ',' . + $dbh->quote($event->{host}) . ',' . $dbh->quote($::sn{lc $event->{nick}}->{gecos}) . ','; + my $ip = ASM::Util->getNickIP(lc $event->{nick}); + if (defined($ip)) { $ip = $dbh->quote($ip); } else { $ip = 'NULL'; } + my $account = $::sn{lc $event->{nick}}->{account}; + if (($account eq '0') or ($account eq '*')) { + $account = 'NULL'; + } else { + $account = $dbh->quote($account); + } + $string = $string . $ip . ',' . $account . ',' . $dbh->quote($event->{args}->[0]) . ');'; + $dbh->do($string); + ASM::Util->dprint($string, 'mysql'); + return; + } elsif ($table eq 'part') { + $string = 'INSERT INTO `part` (channel, nick, user, host, geco, ip, account, content1) VALUES (' . + $dbh->quote($event->{to}->[0]) . ',' . + $dbh->quote($event->{nick}) . ',' . $dbh->quote($event->{user}) . ',' . + $dbh->quote($event->{host}) . ',' . $dbh->quote($::sn{lc $event->{nick}}->{gecos}) . ','; + my $ip = ASM::Util->getNickIP(lc $event->{nick}); + if (defined($ip)) { $ip = $dbh->quote($ip); } else { $ip = 'NULL'; } + my $account = $::sn{lc $event->{nick}}->{account}; + if (($account eq '0') or ($account eq '*')) { + $account = 'NULL'; + } else { + $account = $dbh->quote($account); + } + $string = $string . $ip . ',' . $account . ',' . $dbh->quote($event->{args}->[0]) . ');'; + $dbh->do($string); + ASM::Util->dprint($string, 'mysql'); + return; + } elsif ($table eq 'kick') { + $string = 'INSERT INTO `kick` (channel, nick, user, host, geco, ip, account, ' . + 'victim_nick, victim_user, victim_host, victim_geco, victim_ip, victim_account, content1) VALUES (' . + $dbh->quote($event->{args}->[0]) . ',' . + $dbh->quote($event->{nick}) . ',' . $dbh->quote($event->{user}) . ',' . + $dbh->quote($event->{host}) . ',' . $dbh->quote($::sn{lc $event->{nick}}->{gecos}) . ','; + my $ip = ASM::Util->getNickIP(lc $event->{nick}); + if (defined($ip)) { $ip = $dbh->quote($ip); } else { $ip = 'NULL'; } + my $account = $::sn{lc $event->{nick}}->{account}; + if (($account eq '0') or ($account eq '*')) { $account = 'NULL'; } else { $account = $dbh->quote($account); } + $string = $string . $ip . ',' . $account; + $string = $string . ', ' . $dbh->quote($event->{to}->[0]); + $string = $string . ', ' . $dbh->quote($::sn{lc $event->{to}->[0]}->{user}); + $string = $string . ', ' . $dbh->quote($::sn{lc $event->{to}->[0]}->{host}); + $string = $string . ', ' . $dbh->quote($::sn{lc $event->{to}->[0]}->{gecos}); + my $vic_ip = ASM::Util->getNickIP(lc $event->{to}->[0]); + if (defined($vic_ip)) { $vic_ip = $dbh->quote($vic_ip); } else { $vic_ip = 'NULL'; } + my $vic_account = $::sn{lc $event->{to}->[0]}->{account}; + if (($vic_account eq '0') or ($vic_account eq '*')) { $vic_account = 'NULL'; } else { $vic_account = $dbh->quote($vic_account); } + $string = $string . ', ' . $vic_ip . ',' . $vic_account . ',' . $dbh->quote($event->{args}->[1]) . ');'; + $dbh->do($string); + ASM::Util->dprint($string, 'mysql'); + return; + } +## end saner code for this function if (($table ne 'nick') && ($table ne 'quit')) { $string = $string . 'channel, '; } diff --git a/modules/util.pl b/modules/util.pl index 9a104c1..35a66ae 100644 --- a/modules/util.pl +++ b/modules/util.pl @@ -179,9 +179,8 @@ sub dprint { if ($::debugx{$type} eq 0) { return; } - print STDERR strftime("%F %T ", gmtime); - print STDERR GREEN, 'DEBUG', RESET, '(', $::debugx{$type}, $type, RESET, ') '; - print STDERR $text, "\n"; + say STDERR strftime("%F %T ", gmtime), + GREEN, 'DEBUG', RESET, '(', $::debugx{$type}, $type, RESET, ') ', $text; } @@ -207,7 +206,7 @@ sub getHostIP { my ($module, $host) = @_; if ( ($host =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) or - ($host =~ /^gateway\/web\/freenode\/ip\.(\d+)\.(\d+)\.(\d+)\.(\d+)$/) ) { + ($host =~ /^gateway\/web\/.*\/ip\.(\d+)\.(\d+)\.(\d+)\.(\d+)$/) ) { #yay, easy IP! return dottedQuadToInt(undef, "$1.$2.$3.$4"); } elsif (index($host, '/') != -1) { diff --git a/modules/xml.pl b/modules/xml.pl index e18e4c4..551dc3f 100644 --- a/modules/xml.pl +++ b/modules/xml.pl @@ -31,19 +31,23 @@ sub writeXML { } sub writeChannels { + $::settingschanged=1; $::xs1->XMLout($::channels, RootName => 'channels', KeyAttr => ['id'], NumericEscape => 2) > io("$::cset/channels.xml"); } sub writeUsers { + $::settingschanged=1; $::xs1->XMLout($::users, RootName => 'people', KeyAttr => ['id']) > io("$::cset/users.xml"); } sub writeSettings { + $::settingschanged=1; $::xs1->XMLout($::settings, RootName => 'settings', GroupTags => { altnicks => 'altnick', server => 'host', autojoins => 'autojoin' }, NoAttr => 1) > io("$::cset/settings.xml"); } sub writeRestrictions { + $::settingschanged=1; $::xs1->XMLout($::restrictions, RootName => 'restrictions', KeyAttr => ['id'], GroupTags => { hosts => "host", nicks => "nick", accounts => "account"}) > io("$::cset/restrictions.xml"); } |
