commit bcee9bd5aa53b81ed3d6c66eac7df4908e008a51 from: jrmu date: Tue Aug 01 05:03:07 2023 UTC Minor fixes and reorganization commit - 71d1e25001b7351b471a19c15a0a1633938f7f4d commit + bcee9bd5aa53b81ed3d6c66eac7df4908e008a51 blob - b5156896312b287db974aecd9bcbae60f58b6ea0 blob + 31a1d636a82601eb62fb523378af90ef07118a37 --- BNC.pm +++ BNC.pm @@ -230,8 +230,8 @@ sub mbnc { SQLite::set("bnc", "ircid", $ircid, "email", $email); SQLite::set("bnc", "ircid", $ircid, "captcha", $captcha); SQLite::set("bnc", "ircid", $ircid, "hashid", $hashid); - main::whois($bot->{sock}, $nick); - main::ctcp($bot->{sock}, $nick); + main::whois($bot, $nick); + main::ctcp($bot, $nick); main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`); #main::putserv($bot, "PRIVMSG $nick :https://$hostname/$hashid/captcha.png"); #main::putserv($bot, "PRIVMSG $nick :https://$hostname/register.php?hashirc=$hashid"); blob - d62b6590fa4a32e12ed973c95b93d8ef33f59340 blob + 05d15dadf59244a9965f24f31dc5d10e59f07a6e --- Mail.pm +++ Mail.pm @@ -178,8 +178,8 @@ sub mmail { SQLite::set("mail", "ircid", $ircid, "email", $email); SQLite::set("mail", "ircid", $ircid, "captcha", $captcha); SQLite::set("mail", "ircid", $ircid, "hashid", $hashid); - main::whois($bot->{sock}, $nick); - main::ctcp($bot->{sock}, $nick); + main::whois($bot, $nick); + main::ctcp($bot, $nick); main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`); #main::putserv($bot, "PRIVMSG $nick :https://$hostname/$hashid/captcha.png"); #main::putserv($bot, "PRIVMSG $nick :https://$hostname/register.php?hashirc=$hashid"); blob - b548c1f34c6a20fdaa4ad8088ddd766dff6cda88 blob + fdecabd5e6ad2389c035cefd6e66af6952fd031c --- Shell.pm +++ Shell.pm @@ -175,8 +175,8 @@ sub mshell { SQLite::set("shell", "ircid", $ircid, "username", $username); SQLite::set("shell", "ircid", $ircid, "email", $email); SQLite::set("shell", "ircid", $ircid, "captcha", $captcha); - main::whois($bot->{sock}, $nick); - main::ctcp($bot->{sock}, $nick); + main::whois($bot, $nick); + main::ctcp($bot, $nick); main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`); # main::putserv($bot, "PRIVMSG $nick :$captchaURL".encode_base64($captcha)); main::putserv($bot, "PRIVMSG $nick :Type !shell captcha "); blob - 922c5d3ab0fcb632c7562c93dca8fc2b9fd94563 blob + c4e3f6af459a52333aed4f9ba0cc6bcddcbc75a2 --- VPN.pm +++ VPN.pm @@ -100,8 +100,8 @@ EOF SQLite::set("vpn", "ircid", $ircid, "username", $username); SQLite::set("vpn", "ircid", $ircid, "email", $email); SQLite::set("vpn", "ircid", $ircid, "captcha", $captcha); - main::whois($bot->{sock}, $nick); - main::ctcp($bot->{sock}, $nick); + main::whois($bot, $nick); + main::ctcp($bot, $nick); main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`); # main::putserv($bot, "PRIVMSG $nick :$captchaURL".encode_base64($captcha)); main::putserv($bot, "PRIVMSG $nick :Type !vpn captcha "); blob - 7a377ea442291577a084b97eaba84c6bc7d64614 blob + 56e8c1c3f9446c9728425a7af09d8534eef525d5 --- botnow +++ botnow @@ -66,6 +66,7 @@ sub gettime { return $localtime; } +# Send email using sendmail sub mail { my( $from, $to, $fromname, $subject, $body )=@_; my $msg = <<"EOF"; @@ -145,7 +146,7 @@ if (!defined($conf{mailname})) { } } -# Terms of Service; don't edit lines with the word EOF +# Terms of Service $conf{terms} = $conf{terms} or die "ERROR: botnow.conf terms"; # Number of words in password @@ -170,6 +171,7 @@ use constant { WARNINGS => 2, ALL => 3, }; + $conf{verbose} = $conf{verbose} || ERRORS; if(defined($conf{die})) { die $conf{die}; } @@ -202,6 +204,7 @@ my @stafflist = split(/ /,$staff); my $verbose = $conf{verbose}; my $expires = $conf{expires}; +# Unveil limits files and directories that botnow can access unveil("./", "r") or die "Unable to unveil $!"; unveil("$confpath", "r") or die "Unable to unveil $!"; unveil("$backupspath", "rwc") or die "Unable to unveil $!"; @@ -209,12 +212,77 @@ unveil("/usr/sbin/sendmail", "rx") or die "Unable to u unveil("/bin/sh", "rx") or die "Unable to unveil $!"; unveil() or die "Unable to lock unveil $!"; -#dns and inet for sockets, proc and exec for figlet -#rpath for reading file, wpath for writing file, cpath for creating path -#flock, fattr for sqlite +# Pledge limits botnow's syscalls +# dns and inet for sockets, proc and exec for figlet +# rpath for reading file, wpath for writing file, cpath for creating path +# flock, fattr for sqlite pledge( qw(stdio rpath wpath cpath inet dns proc exec flock fattr) ) or die "Unable to pledge: $!"; -# create sockets +# Writes text to the network socket +sub putserv { + my( $bot, $text )=@_; + my $socket = $bot->{sock}; + # If a multiline command, write multiple times; else write once + if ($text =~ /^([^:]+):([[:ascii:]]*)$/m) { + my ($cmd, $line) = ($1, $2); + my @lines = split /\r?\n/m, $line; + foreach my $l (@lines) { + print $socket "$cmd:$l\r\n"; + } + } else { + print $socket "$text\r\n"; + } +} + +# Writes text to the local network socket +sub putservlocalnet { + my( $bot, $text )=@_; + foreach my $b (@bots) { + if($b->{name} =~ /^$localnet$/i) { + putserv($b, $text); + return; + } + } +} + +sub whois { + my( $bot, $target )=@_; + my $socket = $bot->{sock}; + print $socket "WHOIS $target $target\r\n"; +} + +sub ctcp { + my( $bot, $target )=@_; + my $socket = $bot->{sock}; +# print $socket "PRIVMSG $target :".chr(01)."CLIENTINFO".chr(01)."\r\n"; +# print $socket "PRIVMSG $target :".chr(01)."FINGER".chr(01)."\r\n"; +# print $socket "PRIVMSG $target :".chr(01)."SOURCE".chr(01)."\r\n"; + print $socket "PRIVMSG $target :".chr(01)."TIME".chr(01)."\r\n"; +# print $socket "PRIVMSG $target :".chr(01)."USERINFO".chr(01)."\r\n"; + print $socket "PRIVMSG $target :".chr(01)."VERSION".chr(01)."\r\n"; +# print $socket "PRIVMSG $target :".chr(01)."PING".chr(01)."\r\n"; +} + +sub debug { + my ($level, $msg) = @_; + if ($verbose >= $level) { print "$msg\n"; } +} + +sub isstaff { + my( $bot, $nick ) = @_; + if( !( $bot->{name} =~ /^$localnet$/i ) ) { + return 0; + } + foreach( @stafflist ) { + if( $nick eq $_ ) { + return 1; + } + } + return 0; +} + + +# Create sockets my $sel = IO::Select->new( ); foreach my $network (@networks) { my $socket = IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port, Proto=>'tcp', Timeout=>'300') || print "Failed to establish connection\n"; @@ -226,8 +294,7 @@ foreach my $network (@networks) { } while(my @ready = $sel->can_read) { - my ($bot, $response); - my ($sender, $val); + my ($bot, $response, $sender, $val); foreach my $socket (@ready) { foreach my $b (@bots) { if($socket == $b->{sock}) { @@ -235,6 +302,7 @@ while(my @ready = $sel->can_read) { last; } } + ### TODO: Reconnect if znc crashes if (!defined($response = <$socket>)) { debug(ERRORS, "ERROR ".$bot->{name}." has no response:"); next; @@ -510,50 +578,8 @@ while(my @ready = $sel->can_read) { debug(ERRORS, "Unexpected bncnow.pl 460: $response"); } } -} - -sub putserv { - my( $bot, $text )=@_; - my $socket = $bot->{sock}; - if ($text =~ /^([^:]+):([[:ascii:]]*)$/m) { - my ($cmd, $line) = ($1, $2); - my @lines = split /\r?\n/m, $line; - foreach my $l (@lines) { - print $socket "$cmd:$l\r\n"; - } - } else { - print $socket "$text\r\n"; - } -} - -sub putservlocalnet { - my( $bot, $text )=@_; - my $botlocalnet; - foreach my $b (@bots) { - if($b->{name} =~ /^$localnet$/i) { - $botlocalnet = $b; - last; - } - } - putserv($botlocalnet, $text); } -sub whois { - my( $socket, $target )=@_; - print $socket "WHOIS $target $target\r\n"; -} - -sub ctcp { - my( $socket, $target )=@_; -# print $socket "PRIVMSG $target :".chr(01)."CLIENTINFO".chr(01)."\r\n"; -# print $socket "PRIVMSG $target :".chr(01)."FINGER".chr(01)."\r\n"; -# print $socket "PRIVMSG $target :".chr(01)."SOURCE".chr(01)."\r\n"; - print $socket "PRIVMSG $target :".chr(01)."TIME".chr(01)."\r\n"; -# print $socket "PRIVMSG $target :".chr(01)."USERINFO".chr(01)."\r\n"; - print $socket "PRIVMSG $target :".chr(01)."VERSION".chr(01)."\r\n"; -# print $socket "PRIVMSG $target :".chr(01)."PING".chr(01)."\r\n"; -} - sub cbind { my ($type, $flags, $cmd, $proc) = @_; if ($type eq "pub") { @@ -574,21 +600,3 @@ sub cbind { push(@{$call->{msgm}}, {mask => $cmd, proc => $proc}); } } - -sub debug { - my ($level, $msg) = @_; - if ($verbose >= $level) { print "$msg\n"; } -} - -sub isstaff { - my( $bot, $nick ) = @_; - if( !( $bot->{name} =~ /^$localnet$/i ) ) { - return 0; - } - foreach( @stafflist ) { - if( $nick eq $_ ) { - return 1; - } - } - return 0; -}