[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bugfix patch for botnow


I've come across some bugs that crash botnow  while working on my libIRCNOW branch so have back ported them to main branch.  I found them while playing with the !lastseen and !taillog commands.  Both caused botnow to silently crash or hang.  Here's a summery of changes:

1) missing unveil for znclog
2) Improved debug messages
3) replaced tail -f with tail -10. -f doesn't return so hangs the bot
4) output of these commands was coded to go to teamchannels but wasn't working. should go to pm anyway; corrected.
5) $sender and $val should be local scope like the rest in the response loop

Attached is a patch, or you can pull it from the main branch of my repo here: git://got.ircnow.org/izzyb-botnow.git

...Izzy
diff --git a/BNC.pm b/BNC.pm
index b515689..d2c4f03 100644
--- a/BNC.pm
+++ b/BNC.pm
@@ -57,6 +57,7 @@ sub init {
 	unveil("/usr/lib/libc.so.95.1", "r") or die "Unable to unveil $!";
 	unveil("/usr/libexec/ld.so", "r") or die "Unable to unveil $!";
 	unveil("/usr/bin/tail", "rx") or die "Unable to unveil $!";
+	unveil("$znclog", "r") or die "unable to unveil $!";
 	unveil("$netpath", "r") or die "Unable to unveil $!";
 	
 	@networks = readnetworks($netpath);
@@ -308,7 +309,7 @@ sub mcontrolpanel {
 	}
 }
 sub loadlog {
-	open(my $fh, '<', "$znclog") or die "Could not read file 'znc.log' $!";
+	open(my $fh, '<', "$znclog") or die "Could not read znc log file: '$znclog' $!";
 	chomp(@logs = <$fh>);
 	close $fh;
 }
@@ -461,11 +462,9 @@ sub mtaillog {
 		($chan, $text) = ($args[0], $args[1]);
 	} else { $text = $args[0]; }
 	my $hostmask = "$nick!$host";
-	open(my $fh, "-|", "/usr/bin/tail", "-f", $znclog) or die "could not start tail: $!";
+	open(my $fh, "-|", "/usr/bin/tail", '-10', $znclog) or die "could not tail $znclog: $!";
 	while (my $line = <$fh>) {
-		foreach my $chan (@teamchans) {
-			main::putserv($bot, "PRIVMSG $chan :$line");
-		}
+		main::putserv($bot, "PRIVMSG $nick :$line");
 	}
 }
 
@@ -481,17 +480,13 @@ sub mlastseen {
 	foreach my $user (@users) {
 		my @lines = grep(/^\[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\] \[$user\] connected to ZNC from [.0-9a-fA-F:]+/, @logs);
 		if (scalar(@lines) == 0) {
-			foreach my $chan (@teamchans) {
-				main::putserv($bot, "PRIVMSG $chan :$user never logged in");
-			}
+			main::putserv($bot, "PRIVMSG $nick :$user never logged in");
 			next;
 		}
 		my $recent = pop(@lines);
 		if ($recent =~ /^\[(\d{4}-\d\d-\d\d) \d\d:\d\d:\d\d\] \[$user\] connected to ZNC from [.0-9a-fA-F:]+/) {
 			my $date = $1;
-			foreach my $chan (@teamchans) {
-				main::putserv($bot, "PRIVMSG $chan :$user $date");
-			}
+			main::putserv($bot, "PRIVMSG $nick :$user $date");
 		}
 	}
 }
diff --git a/botnow b/botnow
index 7a377ea..4905f46 100755
--- a/botnow
+++ b/botnow
@@ -227,7 +227,6 @@ foreach my $network (@networks) {
 
 while(my @ready = $sel->can_read) {
 	my ($bot, $response);
-	my ($sender, $val);
 	foreach my $socket (@ready) {
 		foreach my $b (@bots) {
 			if($socket == $b->{sock}) {
@@ -413,7 +412,7 @@ while(my @ready = $sel->can_read) {
 				debug(ALL, "$text");
 			} elsif ($code == 307 && $text =~ /^([-_\|`a-zA-Z0-9]+) (.*)/) {
 				my ($sender, $key) = ($1, "registered");
-				$val = $2 eq ":is a registered nick" ? "True" : "$2";
+				my $val = $2 eq ":is a registered nick" ? "True" : "$2";
 				my $id = SQLite::id("irc", "nick", $sender, $expires);
 				SQLite::set("irc", "id", $id, "identified", $val);
 				debug(ALL, "$key: $val");
@@ -435,7 +434,7 @@ while(my @ready = $sel->can_read) {
 			} elsif ($code == 315 && $text =~ /^([-_\|`a-zA-Z0-9]+) :End of \/?WHO(IS)? list/) {
 				debug(ALL, "End of WHOIS");
 			} elsif ($code == 317 && $text =~ /^([-_\|`a-zA-Z0-9]+) (\d+) (\d+) :?(.*)/) {
-				($sender, my $idle, my $epochtime) = ($1, $2, $3);
+				my ($sender, $idle, $epochtime) = ($1, $2, $3);
 				my $id = SQLite::id("irc", "nick", $sender, $expires);
 				SQLite::set("irc", "id", $id, "idle", $idle);
 #				SQLite::set("irc", "id", $id, "epochtime", time());