Commit Diff


commit - 0f1839cb8eb6c873a99d1568e34d96d450767862
commit + c8955f309a194e89ac95e693e0803dfb4d2c009e
blob - 803e30c732c0446fce3b6e12349424af16d133fa (mode 644)
blob + /dev/null
--- lib/IRCNOW/Acct/Sh.pm
+++ /dev/null
@@ -1,41 +0,0 @@
-package BotNow::Shell;
-
-use strict;
-use warnings;
-use OpenBSD::Pledge;
-use OpenBSD::Unveil;
-use lib qw(./lib);
-use IRCNOW::IO qw(readarray);
-
-use Data::Dumper;
-
-my $authlog = "/var/log/authlog";
-my $etcpasswd = "/etc/master.passwd";
-my @etcpasswd = readarray($etcpasswd);
-my @users;
-foreach my $line (@etcpasswd) {
-	if ($line =~ /^([^:]+):[^:]+:([^:]+)/) {
-		my ($username, $uid) = ($1, $2);
-		if ($uid > 1000) {
-			push(@users, $username);
-		}
-	}
-}
-my @files = ("/var/log/authlog");
-push(@files, glob q("/var/log/authlog.?"));
-push(@files, glob q("/var/log/authlog.1?"));
-foreach my $user (@users) {
-	my $lastseen;
-	foreach my $file (@files) {
-		my @logs = readarray($file);
-		my @seen = grep(/$user/, @logs);
-		if (scalar(@seen) && $seen[0] =~ /^(\w+ \d+ \d\d:\d\d:\d\d)/) {
-			$lastseen = $1;
-			print "$user => $lastseen\n";
-			last;
-		}
-	}
-	if (!defined($lastseen)) {
-		print "$user => Never logged in\n";
-	}
-}
blob - b29fc08961862de6e3c59c2afb6ba166869f76ea
blob + 53343aeb1798d3b145be5c7a4bd5544de98f7648
--- lib/IRCNOW/Acct/Shell.pm
+++ lib/IRCNOW/Acct/Shell.pm
@@ -1,4 +1,4 @@
-package BotNow::Shell;
+package IRCNOW::Acct::Shell;
 
 use strict;
 use warnings;
@@ -12,7 +12,7 @@ use lib './lib';
 use IRCNOW::IO qw(:FILEIO :DEBUG);
 use IRCNOW::IO::IRC;
 use BotNow::SQLite;
-use BotNow::Hash;
+use IRCNOW::Acct;
 
 use Data::Dumper;
 
@@ -37,16 +37,6 @@ my $relaydconfpath = "/etc/relayd.conf";
 my $startPort;
 my $endPort;
 
-use constant {
-	NONE => 0,
-	ERRORS => 1,
-	WARNINGS => 2,
-	ALL => 3,
-};
-
-IRCNOW::IO::IRC::cbind("pub", "-", "shell", \&mshell);
-IRCNOW::IO::IRC::cbind("msg", "-", "shell", \&mshell);
-
 sub init {
 	#dependencies for figlet
 	unveil("/usr/local/bin/figlet", "rx") or die "Unable to unveil $!";
@@ -73,126 +63,6 @@ sub init {
 	unveil("/home/", "rwxc") or die "Unable to unveil $!";
 }
 
-# !shell <username> <email>
-# !shell captcha <captcha>
-sub mshell {
-	my ($bot, $nick, $host, $hand, @args) = @_;
-	my ($chan, $text);
-	if (@args == 2) {
-		($chan, $text) = ($args[0], $args[1]);
-	} else { $text = $args[0]; }
-	my $hostmask = "$nick!$host";
-	if (defined($chan) && $chans =~ /$chan/) {
-		IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $chan :$nick: Please check private message");
-	}
-	if ($text =~ /^$/) {
-		IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Type !help for new instructions");
-		foreach my $chan (@teamchans) {
-			IRCNOW::IO::IRC::putservlocalnet($bot, "PRIVMSG $chan :$staff: Help *$nick* on network ".$bot->{name}." with shell registration");
-		}
-		return;
-	} elsif (IRCNOW::IO::IRC::isstaff($bot, $nick) && $text =~ /^delete\s+([[:ascii:]]+)/) {
-		my $username = $1;
-		if (BotNow::SQLite::deleterows("shell", "username", $username)) {
-			# TODO delete shell
-			deleteshell($username);
-			foreach my $chan (@teamchans) {
-				IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $chan :$username deleted");
-			}
-		}
-		return;
-	} elsif (IRCNOW::IO::IRC::isstaff($bot, $nick) && $text =~ /^approve\s+([[:ascii:]]+)/) {
-		my $username = $1;
-		system "doas usermod -U $username";
-		foreach my $chan (@teamchans) {
-			IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $chan :$username approved");
-		}
-		return;
-	}
-	### TODO: Check duplicate emails ###
-	my @rows = BotNow::SQLite::selectrows("irc", "nick", $nick);
-	foreach my $row (@rows) {
-		my $password = BotNow::SQLite::get("shell", "ircid", $row->{id}, "password");
-		if (defined($password)) {
-			IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
-			return;
-		}
-	}
-	if ($text =~ /^lastseen\s+([[:alnum:]]+)/) {
-	}
-	if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
-		my $text = $1;
-		my $ircid = BotNow::SQLite::id("irc", "nick", $nick, $expires);
-		if (!defined($ircid)) { die "undefined ircid"; }
-		my $captcha = BotNow::SQLite::get("shell", "ircid", $ircid, "captcha");
-		if ($text ne $captcha) {
-			IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !shell <username> <email>");
-			return;
-		}
-		my $pass = BotNow::Hash::newpass();
-		chomp(my $encrypted = `encrypt $pass`);
-		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";
-		BotNow::SQLite::set("shell", "ircid", $ircid, "password", $encrypted);
-		if (DNS::nextdns($username)) {
-			sleep(2);
-			createshell($username, $pass, $bindhost);
-			mailshell($username, $email, $pass, "shell", $version);
-			IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Check your email!");
-			if ($approval eq "true") {
-				system "doas usermod -Z $username";
-				IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Your account has been created but must be manually approved by your admins ($staff) before it can be used.");
-				foreach my $chan (@teamchans) {
-					IRCNOW::IO::IRC::putservlocalnet($bot, "PRIVMSG $chan :$staff: $nick\'s account $username must be manually unblocked before it can be used.");
-				}
-			}
-			foreach my $chan (@teamchans) {
-				IRCNOW::IO::IRC::putservlocalnet($bot, "PRIVMSG $chan :$staff: $nick\'s shell registration of $username on $bot->{name} was successful, *but* you *must* help him connect. Most users are unable to connect. Show him https://wiki.ircnow.org/?n=Shell.Shell");
-			}
-
-
-			#www($newnick, $reply, $password, "bouncer");
-		} else {
-			foreach my $chan (@teamchans) {
-				IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $chan :Assigning bindhost $bindhost failed");
-			}
-		}
-		return;
-	} elsif ($text =~ /^([[:alnum:]]+)\s+([[:ascii:]]+)/) {
-		my ($username, $email) = ($1, $2);
-		my @users = col($passpath, 1, ":");
-		my @matches = grep(/^$username$/i, @users);
-		if (scalar(@matches) > 0) {
-			IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Sorry, username taken. Please choose another username, or contact staff for help.");
-			return;
-		}
-		#		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));
-		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);
-		IRCNOW::IO::IRC::whois($bot->{sock}, $nick);
-		IRCNOW::IO::IRC::ctcp($bot->{sock}, $nick);
-		IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
-		#		IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :$captchaURL".encode_base64($captcha));
-		IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Type !shell captcha <text>");
-		foreach my $chan (@teamchans) {
-			IRCNOW::IO::IRC::putservlocalnet($bot, "PRIVMSG $chan :$nick\'s captcha on $bot->{name} is $captcha");
-		}
-	} else {
-		IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $nick :Invalid username or email. Type !shell <username> <email> to try again.");
-		foreach my $chan (@teamchans) {
-			IRCNOW::IO::IRC::putserv($bot, "PRIVMSG $chan :$staff: Help *$nick* on network ".$bot->{name}." with shell registration");
-		}
-	}
-}
 sub mailshell {
 	my( $username, $email, $password, $service, $version )=@_;
 	my $passhash = sha256_hex("$username");
@@ -444,6 +314,45 @@ sub configurerelayd {  
 	}
 	writefile($relaydconfpath, $newconf);
 }
+
+# Code found in BotNow::Sh.pm
+# Looks like something that was started but not finished
+# provides a list of when shell users were last seen.
+# Needs to be properly wrapped as a function
+# XXX
+#my $authlog = "/var/log/authlog";
+#my $etcpasswd = "/etc/master.passwd";
+#my @etcpasswd = readarray($etcpasswd);
+#my @users;
+#foreach my $line (@etcpasswd) {
+#	if ($line =~ /^([^:]+):[^:]+:([^:]+)/) {
+#		my ($username, $uid) = ($1, $2);
+#		if ($uid > 1000) {
+#			push(@users, $username);
+#		}
+#	}
+#}
+#my @files = ("/var/log/authlog");
+#push(@files, glob q("/var/log/authlog.?"));
+#push(@files, glob q("/var/log/authlog.1?"));
+#foreach my $user (@users) {
+#	my $lastseen;
+#	foreach my $file (@files) {
+#		my @logs = readarray($file);
+#		my @seen = grep(/$user/, @logs);
+#		if (scalar(@seen) && $seen[0] =~ /^(\w+ \d+ \d\d:\d\d:\d\d)/) {
+#			$lastseen = $1;
+#			print "$user => $lastseen\n";
+#			last;
+#		}
+#	}
+#	if (!defined($lastseen)) {
+#		print "$user => Never logged in\n";
+#	}
+#}
+#
 
+
+
 #unveil("./newacct", "rx") or die "Unable to unveil $!";
 1; # MUST BE LAST STATEMENT IN FILE