From acdcedfa7099659be22df3dd57ec4926809dc1a6 Mon Sep 17 00:00:00 2001 From: Janik Kleinhoff Date: Fri, 4 Sep 2015 03:44:40 +0000 Subject: Allow running without a database This is mostly a workaround for the DB being a bit of a PITA to set up, but not all we do requires a DB so we might as well offer to run without one. --- config-default/commands.xml | 8 ++++++++ meta.pl | 8 +++++--- modules/event.pl | 34 +++++++++++++++++++--------------- modules/inspect.pl | 4 +++- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/config-default/commands.xml b/config-default/commands.xml index 5674fac..6e12076 100644 --- a/config-default/commands.xml +++ b/config-default/commands.xml @@ -123,6 +123,11 @@ privmsg($event->replyto, "I am set to run without a database, fool."); + return; + } + my $dbh = $::db->{DBH}; if ($1 eq 'log') { $dbh = $::db->{DBH_LOG}; @@ -175,6 +180,7 @@ query($channel, $nuh[0], $nuh[2], $nuh[4]); @@ -183,6 +189,7 @@ privmsg($event->replyto, "I don't see $nick in my state tracking database, so I can't run any queries on their info, sorry :(" . @@ -223,6 +230,7 @@ {server}}[rand @{$::settings->{server}}]; ASM::Util->dprint( "Connecting to $host", "startup"); $irc->debug($::debug); - $::db = ASM::DB->new($::mysql->{db}, $::mysql->{host}, $::mysql->{port}, - $::mysql->{user}, $::mysql->{pass}, $::mysql->{table}, - $::mysql->{actiontable}, $::mysql->{dblog}); + if (!$::mysql->{disable}) { + $::db = ASM::DB->new($::mysql->{db}, $::mysql->{host}, $::mysql->{port}, + $::mysql->{user}, $::mysql->{pass}, $::mysql->{table}, + $::mysql->{actiontable}, $::mysql->{dblog}); + } $conn = $irc->newconn( Server => $host, Port => $::settings->{port} || '6667', SSL => defined($::settings->{ssl}), diff --git a/modules/event.pl b/modules/event.pl index b1ab1be..b8dd159 100644 --- a/modules/event.pl +++ b/modules/event.pl @@ -275,7 +275,7 @@ sub on_join { $::sn{$nick}->{user} = $event->{user}; $::sn{$nick}->{host} = $event->{host}; $::sn{$nick}->{account} = lc $event->{args}->[0]; - $::db->logg($event); + $::db->logg($event) if defined $::db; $::log->logg( $event ); $::inspector->inspect( $conn, $event ) unless $::netsplit; } @@ -286,8 +286,8 @@ sub on_part my $nick = lc $event->{nick}; my $chan = lc $event->{to}->[0]; $::log->logg( $event ); - $::db->logg( $event ); - if ($event->{args}->[0] =~ /^requested by/) { + $::db->logg( $event ) if defined $::db; + if (defined $::db and $event->{args}->[0] =~ /^requested by/) { my $idx = $::db->actionlog( $event); $::log->sqlIncident($chan, $idx) if $idx; } @@ -333,7 +333,7 @@ sub on_public my $chan = lc $event->{to}[0]; $chan =~ s/^[+@]//; $::log->logg( $event ); - $::db->logg( $event ); + $::db->logg( $event ) if defined $::db; if ($event->{args}->[0] =~ /(https?:\/\/bitly.com\/\w+|https?:\/\/bit.ly\/\w+|https?:\/\/j.mp\/\w+|https?:\/\/tinyurl.com\/\w+)/i) { my $reqid = $::async->add( HTTP::Request->new( GET => $1 ) ); $::httpRequests{$reqid} = $event; @@ -372,7 +372,7 @@ sub on_notice my ($conn, $event) = @_; return if ( $event->{to}->[0] eq '$*' ); # if this is a global notice FUCK THAT SHIT $::log->logg( $event ); - $::db->logg( $event ); + $::db->logg( $event ) if defined $::db; $::inspector->inspect( $conn, $event ); $::services->doServices($conn, $event); } @@ -401,9 +401,11 @@ sub on_quit push ( @channels, lc $_ ) if delete $::sc{lc $_}{users}{lc $event->{nick}}; } $event->{to} = \@channels; - my $idx = $::db->actionlog($event); - $::log->sqlIncident( join(',', @channels), $idx ) if $idx; - $::db->logg( $event ); + if (defined $::db) { + my $idx = $::db->actionlog($event); + $::log->sqlIncident( join(',', @channels), $idx ) if $idx; + $::db->logg( $event ); + } $::log->logg( $event ); if (($::netsplit == 0) && ($event->{args}->[0] eq "*.net *.split") && (lc $event->{nick} ne 'chanserv')) { #special, netsplit situation @@ -472,7 +474,7 @@ sub irc_topic { $::sc{$chan}{topic}{by} = $event->{from}; } $::log->logg($event); - $::db->logg( $event ); + $::db->logg( $event ) if defined $::db; $::inspector->inspect($conn, $event); } } @@ -503,7 +505,7 @@ sub on_nick { } $::sn{$newnick} = $::sn{$oldnick} if ($oldnick ne $newnick); - $::db->logg( $event ); + $::db->logg( $event ) if defined $::db; delete( $::sn{$oldnick}) if ($oldnick ne $newnick); $event->{to} = \@channels; $::log->logg($event); @@ -519,9 +521,11 @@ sub on_kick { my $nick = lc $event->{to}->[0]; my $chan = lc $event->{args}->[0]; $::log->logg( $event ); - $::db->logg( $event ); - my $idx = $::db->actionlog($event); - $::log->sqlIncident($chan, $idx) if $idx; + if (defined $::db) { + $::db->logg( $event ); + my $idx = $::db->actionlog($event); + $::log->sqlIncident($chan, $idx) if $idx; + } if (defined($::sn{$nick}) && defined($::sn{$nick}->{mship})) { my @mship = @{$::sn{$nick}->{mship}}; @mship = grep { lc $_ ne $chan } @mship; @@ -654,7 +658,7 @@ sub on_mode $::sc{$chan}{bans}{$ex[1]} = { bannedBy => $event->{from}, bannedOn => time }; if (lc $event->{nick} !~ /^(floodbot)/) { #ignore the ubuntu floodbots 'cause they quiet people a lot my @affected = whoGotHit($chan, $ex[1]); - if ( (@affected) && (scalar @affected <= 4) ) { + if ( defined($::db) && (@affected) && (scalar @affected <= 4) ) { foreach my $victim (@affected) { my $idx = $::db->actionlog($event, 'ban', $victim); $::log->sqlIncident( $chan, $idx ) if $idx; @@ -678,7 +682,7 @@ sub on_mode $::sc{$chan}{quiets}{$ex[1]} = { bannedBy => $event->{from}, bannedOn => time }; if (lc $event->{nick} !~ /^(floodbot)/) { my @affected = whoGotHit($chan, $ex[1]); - if ( (@affected) && (scalar @affected <= 4) ) { + if ( defined($::db) && (@affected) && (scalar @affected <= 4) ) { foreach my $victim (@affected) { my $idx = $::db->actionlog($event, 'quiet', $victim); $::log->sqlIncident( $chan, $idx ) if $idx; diff --git a/modules/inspect.pl b/modules/inspect.pl index ea287ff..df515dc 100644 --- a/modules/inspect.pl +++ b/modules/inspect.pl @@ -74,7 +74,9 @@ sub inspect { return unless (ASM::Util->notRestricted($nick, "notrigger") && ASM::Util->notRestricted($nick, "no$id")); $xresult = $dct{$id}{xresult}; my $nicereason = interpolate($dct{$id}{reason}); - $::db->record($chan, $event->{nick}, $event->{user}, $event->{host}, $::sn{lc $event->{nick}}->{gecos}, $dct{$id}{risk}, $id, $nicereason); + if (defined $::db) { + $::db->record($chan, $event->{nick}, $event->{user}, $event->{host}, $::sn{lc $event->{nick}}->{gecos}, $dct{$id}{risk}, $id, $nicereason); + } $txtz = "\x03" . $::RCOLOR{$::RISKS{$dct{$id}{risk}}} . "\u$dct{$id}{risk}\x03 risk threat [\x02$chan\x02] - ". "\x02$event->{nick}\x02 - ${nicereason}; ping "; $txtz = $txtz . ASM::Util->commaAndify(ASM::Util->getAlert(lc $chan, $dct{$id}{risk}, 'hilights')) if (ASM::Util->getAlert(lc $chan, $dct{$id}{risk}, 'hilights')); -- cgit v1.2.3