Commit Diff


commit - 2a82acd0d20f1fc7f958327aa94108dca12dab55
commit + 7ce84f65840e798d163b2760cd72d71fda4c082e
blob - 55a19e68ec7f0ca1a317cae696d50dc342aa5336
blob + 849c46713219b11040ac3e891ee4c4ce3cbcf7ce
--- lib/BotNow/BNC.pm
+++ lib/BotNow/BNC.pm
@@ -120,7 +120,7 @@ sub mbnc {
 		my $username = $1;
 		if (BotNow::SQLite::selectrows("bnc", "username", $username)) {
 			my $email = BotNow::SQLite::get("bnc", "username", $username, "email");
-			my $password = Hash::newpass();
+			my $password = BotNow::Hash::newpass();
 			main::putserv($bot,"privmsg *controlpanel :set Password $username $password");
  			main::putserv($bot, "PRIVMSG *blockuser :unblock $username");
 			mailbncApproved($username,$email,$password);
@@ -155,14 +155,14 @@ sub mbnc {
 			main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !bnc <username> <email>");
 			return;
 		}
-		my $pass = Hash::newpass();
+		my $pass = BotNow::Hash::newpass();
 		chomp(my $encrypted = `encrypt $pass`);
 		my $username = BotNow::SQLite::get("bnc", "ircid", $ircid, "username");
 		my $email = BotNow::SQLite::get("bnc", "ircid", $ircid, "email");
 		my $hashirc = BotNow::SQLite::get("irc", "id", $ircid, "hashid");
 		my $bindhost = "$username.$hostname";
 		BotNow::SQLite::set("bnc", "ircid", $ircid, "password", $encrypted);
-		if (DNS::nextdns($username)) {
+		if (BotNow::DNS::nextdns($username)) {
 			sleep(2);
 			createbnc($bot, $username, $pass, $bindhost);
 			if ($approval eq "true") {
@@ -343,7 +343,7 @@ sub regexlist {
 sub createclone {
 	my ($bot) = @_;
 	my $socket = $bot->{sock};
-	my $password = Hash::newpass();
+	my $password = BotNow::Hash::newpass();
 	my $msg = <<"EOF";
 adduser cloneuser $password
 set Nick cloneuser cloneuser
@@ -430,7 +430,7 @@ Enjoy!
 $conf{localnet}
 IRCNow Federation
 EOF
-	main::mail($mailfrom, $email, $mailname, "Your $conf{localnet} Bouncer", $body);
+	IRCNOW::IO::mail($mailfrom, $email, $mailname, "Your $conf{localnet} Bouncer", $body);
 }
 
 sub mailbncPending {
@@ -447,7 +447,7 @@ instructions.  This may take up to 48 hours.
 $conf{localnet}
 IRCNow Federation
 EOF
-	main::mail($mailfrom, $email, $mailname, "Confirm $conf{localnet} Bouncer", $body);
+	IRCNOW::IO::mail($mailfrom, $email, $mailname, "Confirm $conf{localnet} Bouncer", $body);
 }
  
 sub mtaillog {
blob - 48e016f8a436f386d522aaa725c3ff7e62dca254
blob + 2cee5193d1821c0d1d63f8ca6a14f35c5766baea
--- lib/BotNow/Mail.pm
+++ lib/BotNow/Mail.pm
@@ -6,7 +6,7 @@ use OpenBSD::Pledge;
 use OpenBSD::Unveil;
 use lib qw(./lib);
 use IRCNOW::IO qw(readarray writefile);
-
+use BotNow::Hash;
 use File::Copy qw(copy);
 use MIME::Base64;
 use Digest::SHA qw(sha256_hex);
@@ -64,7 +64,7 @@ sub mmail {
 		return;
 	} elsif (main::isstaff($bot, $nick) && $text =~ /^delete\s+([[:ascii:]]+)/) {
 		my $username = $1;
-		if (SQLite::deleterows("mail", "username", $username)) {
+		if (BotNow::SQLite::deleterows("mail", "username", $username)) {
 			deletemail($username);
 			foreach my $chan (@teamchans) {
 				main::putserv($bot, "PRIVMSG $chan :$username email deleted");
@@ -89,9 +89,9 @@ sub mmail {
 		return;
 	}
 	### Check duplicate hostmasks ###
-	my @rows = SQLite::selectrows("irc", "hostmask", $hostmask);
+	my @rows = BotNow::SQLite::selectrows("irc", "hostmask", $hostmask);
 	foreach my $row (@rows) {
-		my $password = SQLite::get("mail", "ircid", $row->{id}, "password");
+		my $password = BotNow::SQLite::get("mail", "ircid", $row->{id}, "password");
 		if (defined($password)) {
 			main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
 			return;
@@ -101,18 +101,18 @@ sub mmail {
 	if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
 		my $text = $1;
 		# TODO avoid using host mask because cloaking can cause problems
-		my $ircid = SQLite::id("irc", "nick", $nick, $expires);
-		my $captcha = SQLite::get("mail", "ircid", $ircid, "captcha");
+		my $ircid = BotNow::SQLite::id("irc", "nick", $nick, $expires);
+		my $captcha = BotNow::SQLite::get("mail", "ircid", $ircid, "captcha");
 		if ($text ne $captcha) {
 			main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !mail <username> <email>");
 			return;
 		}
-		my $pass = Hash::newpass();
+		my $pass = BotNot::Hash::newpass();
 		chomp(my $encrypted = `encrypt $pass`);
-		my $username = SQLite::get("mail", "ircid", $ircid, "username");
-		my $email = SQLite::get("mail", "ircid", $ircid, "email");
-		my $hashirc = SQLite::get("irc", "id", $ircid, "hashid");
-		SQLite::set("mail", "ircid", $ircid, "password", $encrypted);
+		my $username = BotNow::SQLite::get("mail", "ircid", $ircid, "username");
+		my $email = BotNow::SQLite::get("mail", "ircid", $ircid, "email");
+		my $hashirc = BotNow::SQLite::get("irc", "id", $ircid, "hashid");
+		BotNow::SQLite::set("mail", "ircid", $ircid, "password", $encrypted);
 		sleep(2);
 		createmail($pass, $username);
 		main::putserv($bot, "PRIVMSG $nick :Check your email!");
@@ -141,17 +141,17 @@ sub mmail {
 		return;
 	} elsif ($text =~ /^([[:alnum:]]+)\s+([[:ascii:]]+)/) {
 		my ($username, $email) = ($1, $2);
-		my @userrows = SQLite::selectrows("mail", "username", $username);
+		my @userrows = BotNow::SQLite::selectrows("mail", "username", $username);
 		foreach my $row (@userrows) {
-			my $password = SQLite::get("mail", "ircid", $row->{id}, "password");
+			my $password = BotNow::SQLite::get("mail", "ircid", $row->{id}, "password");
 			if (defined($password)) {
 				main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
 				return;
 			}
 		}
-		my @emailrows = SQLite::selectrows("mail", "email", $email);
+		my @emailrows = BotNow::SQLite::selectrows("mail", "email", $email);
 		foreach my $row (@userrows) {
-			my $password = SQLite::get("mail", "ircid", $row->{id}, "password");
+			my $password = BotNow::SQLite::get("mail", "ircid", $row->{id}, "password");
 			if (defined($password)) {
 				main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
 				return;
@@ -170,15 +170,15 @@ sub mmail {
 		my $captcha = int(rand(999));
 		my $ircid = int(rand(9223372036854775807));
 		my $hashid = sha256_hex("$ircid");
-		SQLite::set("irc", "id", $ircid, "localtime", time());
-		SQLite::set("irc", "id", $ircid, "hashid", sha256_hex($ircid));
-		SQLite::set("irc", "id", $ircid, "date", main::date());
-		SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
-		SQLite::set("irc", "id", $ircid, "nick", $nick);
-		SQLite::set("mail", "ircid", $ircid, "username", $username);
-		SQLite::set("mail", "ircid", $ircid, "email", $email);
-		SQLite::set("mail", "ircid", $ircid, "captcha", $captcha);
-		SQLite::set("mail", "ircid", $ircid, "hashid", $hashid);
+		BotNow::SQLite::set("irc", "id", $ircid, "localtime", time());
+		BotNow::SQLite::set("irc", "id", $ircid, "hashid", sha256_hex($ircid));
+		BotNow::SQLite::set("irc", "id", $ircid, "date", IRCNOW::IO::data());
+		BotNow::SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
+		BotNow::SQLite::set("irc", "id", $ircid, "nick", $nick);
+		BotNow::SQLite::set("mail", "ircid", $ircid, "username", $username);
+		BotNow::SQLite::set("mail", "ircid", $ircid, "email", $email);
+		BotNow::SQLite::set("mail", "ircid", $ircid, "captcha", $captcha);
+		BotNow::SQLite::set("mail", "ircid", $ircid, "hashid", $hashid);
 		main::whois($bot->{sock}, $nick);
 		main::ctcp($bot->{sock}, $nick);
 		main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
@@ -229,7 +229,7 @@ Connection Instructions: https://wiki.ircnow.org/?n=Em
 
 IRCNow
 EOF
-	main::mail($mailfrom, $email, $mailname, "Verify IRCNow Account", $body);
+	IRCNOW::IO::mail($mailfrom, $email, $mailname, "Verify IRCNow Account", $body);
 }
 
 
blob - 9b9558224d98a5b8ea25c5a25027ac4a584b1e09
blob + d0635f8de487aacb83c0d4a8d28ca9b93691aadf
--- lib/BotNow/SQLite.pm
+++ lib/BotNow/SQLite.pm
@@ -5,7 +5,7 @@ use warnings;
 use OpenBSD::Pledge;
 use OpenBSD::Unveil;
 use lib qw(./lib);
-use IRCNOW::IO qw(readstr);
+use IRCNOW::IO qw(readstr :DEBUG);
 
 use Data::Dumper;
 use DBI;
@@ -178,7 +178,7 @@ sub connectdb {
 			$dbh->do($s);
 		}
 	}
-	main::debug(ALL, "connected to $dbpath");
+	debug(ALL, "connected to $dbpath");
 	return defined($dbh);
 }
 
@@ -189,9 +189,9 @@ sub insertrow {
 	if (!defined($dbh)) { connectdb(); }
 	my $rows = $dbh->do("INSERT INTO $table ($keys) values ($vals)");
 	if ($rows) {
-		main::debug(ALL, "INSERT INTO $table ($keys) values ($vals)");
+		debug(ALL, "INSERT INTO $table ($keys) values ($vals)");
 	} else {
-		main::debug(ERRORS, "ERRORS: Failed INSERT INTO $table ($keys) values ($vals)");
+		debug(ERRORS, "ERRORS: Failed INSERT INTO $table ($keys) values ($vals)");
 	}
 	return $rows;
 }
@@ -203,9 +203,9 @@ sub updaterow {
 	if (!defined($dbh)) { connectdb(); }
 	my $rows = $dbh->do("UPDATE $table SET $key = ? where $idkey = ?", undef, $val, $idval);
 	if ($rows) {
-		main::debug(ALL, "UPDATE $table SET $key = $val where $idkey = $idval");
+		debug(ALL, "UPDATE $table SET $key = $val where $idkey = $idval");
 	} else {
-		main::debug(ERRORS, "ERRORS: Failed UPDATE $table SET $key = $val where $idkey = $idval");
+		debug(ERRORS, "ERRORS: Failed UPDATE $table SET $key = $val where $idkey = $idval");
 	}
 	return $rows;
 }
@@ -217,9 +217,9 @@ sub deleterows {
 	if (!defined($dbh)) { connectdb(); }
 	my $rows = $dbh->do("DELETE FROM $table WHERE $key = ?", undef, $val);
 	if ($rows) {
-		main::debug(ALL, "DELETE FROM $table WHERE $key = $val");
+		debug(ALL, "DELETE FROM $table WHERE $key = $val");
 	} else {
-		main::debug(ERRORS, "ERRORS: Failed DELETE FROM $table WHERE $key = $val");
+		debug(ERRORS, "ERRORS: Failed DELETE FROM $table WHERE $key = $val");
 	}
 	return $rows;
 }
@@ -272,10 +272,10 @@ sub get {
 	if (my $row = $sth->fetchrow_hashref) {
 		my $val = $row->{$key};
 		if (!defined($val)) { $val = "undefined"; }
-		main::debug(ALL, "get: $table $key => $val where $idkey = $idval");
+		debug(ALL, "get: $table $key => $val where $idkey = $idval");
 		return $row->{$key};
 	} else {
-		main::debug(ERRORS, "ERRORS: $table $key undefined where $idkey = $idval");
+		debug(ERRORS, "ERRORS: $table $key undefined where $idkey = $idval");
 		return;
 	}
 }
@@ -285,10 +285,10 @@ sub get {
 sub set {
 	my ($table, $idkey, $idval, $key, $val) = @_;
 	if (defined(get($table, $idkey, $idval, $idkey))) {
-		main::debug(ALL, "set: update");
+		debug(ALL, "set: update");
 		return updaterow($table, $idkey, $idval, $key, $val) > 0;
 	} else {
-		main::debug(ALL, "set: insert");
+		debug(ALL, "set: insert");
 		return insertrow($table, "$idkey,$key", "\"$idval\",\"$val\"") > 0;
 	}
 }
@@ -308,10 +308,10 @@ sub id {
 		}
 	}
 	if (abs(time() - $maxrow->{localtime}) <= $expires) {
-		main::debug(ALL, "id: $maxrow->{id} where $key = $val at $expires");
+		debug(ALL, "id: $maxrow->{id} where $key = $val at $expires");
 		return $maxrow->{id};
 	} else {
-		main::debug(ERRORS, "no id found");
+		debug(ERRORS, "no id found");
 		return;
 	}
 }
blob - 5e7a3a9e2720a5370a8fd078f15ff727d6f8c4bc
blob + fc9c7f68334fbf37df0bdade7e009c8cb8be410a
--- lib/BotNow/Shell.pm
+++ lib/BotNow/Shell.pm
@@ -9,9 +9,9 @@ use MIME::Base64;
 use Digest::SHA qw(sha256_hex);
 
 use lib './lib';
-use IRCNOW::IO qw(:FILEIO);
-require "BotNow::SQLite";
-require "BotNow::Hash";
+use IRCNOW::IO qw(:FILEIO :DEBUG);
+use BotNow::SQLite;
+use BotNow::Hash;
 
 use Data::Dumper;
 
@@ -92,7 +92,7 @@ sub mshell {
 		return;
 	} elsif (main::isstaff($bot, $nick) && $text =~ /^delete\s+([[:ascii:]]+)/) {
 		my $username = $1;
-		if (SQLite::deleterows("shell", "username", $username)) {
+		if (BotNow::SQLite::deleterows("shell", "username", $username)) {
 			# TODO delete shell
 			deleteshell($username);
 			foreach my $chan (@teamchans) {
@@ -109,9 +109,9 @@ sub mshell {
 		return;
 	}
 	### TODO: Check duplicate emails ###
-	my @rows = SQLite::selectrows("irc", "nick", $nick);
+	my @rows = BotNow::SQLite::selectrows("irc", "nick", $nick);
 	foreach my $row (@rows) {
-		my $password = SQLite::get("shell", "ircid", $row->{id}, "password");
+		my $password = BotNow::SQLite::get("shell", "ircid", $row->{id}, "password");
 		if (defined($password)) {
 			main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
 			return;
@@ -121,20 +121,20 @@ sub mshell {
 	}
 	if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
 		my $text = $1;
-		my $ircid = SQLite::id("irc", "nick", $nick, $expires);
+		my $ircid = BotNow::SQLite::id("irc", "nick", $nick, $expires);
 		if (!defined($ircid)) { die "undefined ircid"; }
-		my $captcha = SQLite::get("shell", "ircid", $ircid, "captcha");
+		my $captcha = BotNow::SQLite::get("shell", "ircid", $ircid, "captcha");
 		if ($text ne $captcha) {
 			main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !shell <username> <email>");
 			return;
 		}
-		my $pass = Hash::newpass();
+		my $pass = BotNow::Hash::newpass();
 		chomp(my $encrypted = `encrypt $pass`);
-		my $username = SQLite::get("shell", "ircid", $ircid, "username");
-		my $email = SQLite::get("shell", "ircid", $ircid, "email");
-		my $version = SQLite::get("shell", "ircid", $ircid, "version");
+		my $username = BotNow::SQLite::get("shell", "ircid", $ircid, "username");
+		my $email = BotNow::SQLite::get("shell", "ircid", $ircid, "email");
+		my $version = BotNow::SQLite::get("shell", "ircid", $ircid, "version");
 		my $bindhost = "$username.$hostname";
-		SQLite::set("shell", "ircid", $ircid, "password", $encrypted);
+		BotNow::SQLite::set("shell", "ircid", $ircid, "password", $encrypted);
 		if (DNS::nextdns($username)) {
 			sleep(2);
 			createshell($username, $pass, $bindhost);
@@ -170,13 +170,13 @@ sub mshell {
 		#		my $captcha = join'', map +(0..9,'a'..'z','A'..'Z')[rand(10+26*2)], 1..4;
 		my $captcha = int(rand(999));
 		my $ircid = int(rand(2147483647));
-		SQLite::set("irc", "id", $ircid, "localtime", time());
-		SQLite::set("irc", "id", $ircid, "date", main::date());
-		SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
-		SQLite::set("irc", "id", $ircid, "nick", $nick);
-		SQLite::set("shell", "ircid", $ircid, "username", $username);
-		SQLite::set("shell", "ircid", $ircid, "email", $email);
-		SQLite::set("shell", "ircid", $ircid, "captcha", $captcha);
+		BotNow::SQLite::set("irc", "id", $ircid, "localtime", time());
+		BotNow::SQLite::set("irc", "id", $ircid, "date", BotNow::IO::date());
+		BotNow::SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
+		BotNow::SQLite::set("irc", "id", $ircid, "nick", $nick);
+		BotNow::SQLite::set("shell", "ircid", $ircid, "username", $username);
+		BotNow::SQLite::set("shell", "ircid", $ircid, "email", $email);
+		BotNow::SQLite::set("shell", "ircid", $ircid, "captcha", $captcha);
 		main::whois($bot->{sock}, $nick);
 		main::ctcp($bot->{sock}, $nick);
 		main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
@@ -225,7 +225,7 @@ reply in order to keep your account.
 
 IRCNow
 EOF
-	main::mail($mailfrom, $email, $mailname, "Verify IRCNow Account", $body);
+	BotNow::IO::mail($mailfrom, $email, $mailname, "Verify IRCNow Account", $body);
 }
 
 
@@ -439,7 +439,7 @@ sub configurerelayd {  
 		$newconf = "$`$&\n\t$block$'";
 	} else {
 		$newconf = $relaydconf;
-		main::debug(ERRORS, "ERROR: regex can't match tls { keypair \$username.$hostname }");
+		debug(ERRORS, "ERROR: regex can't match tls { keypair \$username.$hostname }");
 	}
 	writefile($relaydconfpath, $newconf);
 }
blob - 55a663ffe2734c35459040f3f564428abb69af3a
blob + a4458d218b90f0eb6900a88a8106198c9b7cc12e
--- lib/BotNow/VPN.pm
+++ lib/BotNow/VPN.pm
@@ -4,8 +4,10 @@ use strict;
 use warnings;
 use OpenBSD::Pledge;
 use OpenBSD::Unveil;
-require "DNS.pm";
-require "SQLite.pm";
+use lib qw(./lib);
+use IRCNOW::IO qw(:DEBUG readarray);
+use BotNow::DNS;
+use BotNow::SQLite;
 
 my %conf = %main::conf;
 my $chans = $conf{chans};
@@ -43,9 +45,9 @@ sub vpn {
 		}
 		return;
 	}
-	my @rows = SQLite::selectrows("irc", "nick", $nick);
+	my @rows = BotNow::SQLite::selectrows("irc", "nick", $nick);
 	foreach my $row (@rows) {
-		my $password = SQLite::get("vpn", "ircid", $row->{id}, "password");
+		my $password = BotNow::SQLite::get("vpn", "ircid", $row->{id}, "password");
 		if (defined($password)) {
 			main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
 			return;
@@ -53,19 +55,19 @@ sub vpn {
 	}
 	if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
 		my $text = $1;
-		my $ircid = SQLite::id("irc", "nick", $nick, $expires);
+		my $ircid = BotNow::SQLite::id("irc", "nick", $nick, $expires);
 		if (!defined($ircid)) { die "undefined ircid"; }
-		my $captcha = SQLite::get("vpn", "ircid", $ircid, "captcha");
+		my $captcha = BotNow::SQLite::get("vpn", "ircid", $ircid, "captcha");
 		if ($text ne $captcha) {
 			main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !vpn <username> <email>");
 			return;
 		}
 		my $pass = Hash::newpass();
 		chomp(my $encrypted = `encrypt $pass`);
-		my $username = SQLite::get("vpn", "ircid", $ircid, "username");
-		my $email = SQLite::get("vpn", "ircid", $ircid, "email");
-		my $version = SQLite::get("vpn", "ircid", $ircid, "version");
-		SQLite::set("vpn", "ircid", $ircid, "password", $encrypted);
+		my $username = BotNow::SQLite::get("vpn", "ircid", $ircid, "username");
+		my $email = BotNow::SQLite::get("vpn", "ircid", $ircid, "email");
+		my $version = BotNow::SQLite::get("vpn", "ircid", $ircid, "version");
+		BotNow::SQLite::set("vpn", "ircid", $ircid, "password", $encrypted);
 
 		createvpn($username, $pass);
 		foreach my $chan (@teamchans) {
@@ -91,13 +93,13 @@ EOF
 
 		my $captcha = int(rand(999));
 		my $ircid = int(rand(2147483647));
-		SQLite::set("irc", "id", $ircid, "localtime", time());
-		SQLite::set("irc", "id", $ircid, "date", main::date());
-		SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
-		SQLite::set("irc", "id", $ircid, "nick", $nick);
-		SQLite::set("vpn", "ircid", $ircid, "username", $username);
-		SQLite::set("vpn", "ircid", $ircid, "email", $email);
-		SQLite::set("vpn", "ircid", $ircid, "captcha", $captcha);
+		BotNow::SQLite::set("irc", "id", $ircid, "localtime", time());
+		BotNow::SQLite::set("irc", "id", $ircid, "date", BotNow::IO::date());
+		BotNow::SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
+		BotNow::SQLite::set("irc", "id", $ircid, "nick", $nick);
+		BotNow::SQLite::set("vpn", "ircid", $ircid, "username", $username);
+		BotNow::SQLite::set("vpn", "ircid", $ircid, "email", $email);
+		BotNow::SQLite::set("vpn", "ircid", $ircid, "captcha", $captcha);
 		main::whois($bot->{sock}, $nick);
 		main::ctcp($bot->{sock}, $nick);
 		main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
@@ -115,7 +117,7 @@ sub createvpn {
 }
 sub col {
 	my ($filename) = @_;
-	my @rows = main::readarray($filename);
+	my @rows = readarray($filename);
 	my @results;
 	foreach my $row (@rows) {
 		if ($row =~ /^user (.*?) /) {