commit b2b6fd905726aa542457f819ce4acd7799e198cc from: jrmu date: Fri Feb 17 05:16:06 2023 UTC Moved the readnetworks subroutine into BNC.pm commit - 36684717edbce0c82962bfe1cc406d07e1e53bc6 commit + b2b6fd905726aa542457f819ce4acd7799e198cc blob - edd59f3042d5a57f11bf0ccbb9734409e0cbada1 blob + ff2df436c956bc21160f1837c8f91c7df654b8a1 --- BNC.pm +++ BNC.pm @@ -29,6 +29,9 @@ my $sslport = $conf{sslport}; my $plainport = $conf{plainport}; my $mailfrom = $conf{mailfrom}; my $mailname = $conf{mailname}; +# File containing IRC networks +my $netpath = "networks"; +my @networks; #my $zncconfpath = $conf{zncconfpath} || "$zncdir/.znc/configs/znc.conf"; my $znctree = { Node => "root" }; @@ -58,6 +61,36 @@ main::cbind("msgm", "-", "*", \&mcontrolpanel); main::cbind("msg", "-", "taillog", \&mtaillog); main::cbind("msg", "-", "lastseen", \&mlastseen); +# Return list of networks from filename +# To add multiple servers for a single network, simply create a new entry with +# the same net name; znc ignores addnetwork commands when a network already exists +sub readnetworks { + my ($filename) = @_; + my @lines = main::readarray($filename); + my @networks; + foreach my $line (@lines) { + if ($line =~ /^#/ or $line =~ /^\s*$/) { # skip comments and whitespace + next; + } elsif ($line =~ /^\s*([-a-zA-Z0-9]+)\s*([-_.:a-zA-Z0-9]+)\s*(~|\+)?([0-9]+)\s*$/) { + my ($name, $server, $port) = ($1, $2, $4); + my $trustcerts; + if (!defined($3)) { + $trustcerts = 0; + } elsif ($3 eq "~") { # Use SSL but trust all certs + $port = "+".$port; + $trustcerts = 1; + } else { # Use SSL and verify certs + $port = "+".$port; + $trustcerts = 0; + } + push(@networks, {"name" => $name, "server" => $server, "port" => $port, "trustcerts" => $trustcerts }); + } else { + die "network format invalid: $line\n"; + } + } + return @networks; +} + sub init { #znc.conf file #unveil("$zncconfpath", "r") or die "Unable to unveil $!"; @@ -66,6 +99,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("$netpath", "r") or die "Unable to unveil $!"; #znc.log file #unveil("$znclog", "r") or die "Unable to unveil $!"; #print treeget($znctree, "AnonIPLimit")."\n"; @@ -74,6 +108,11 @@ sub init { #print "treeget\n"; #print Dumper \treeget($znctree, "User", "Node"); #print Dumper \treeget($znctree, "User", "Network", "Node"); + + @networks = readnetworks($netpath); + + # networks must be sorted to avoid multiple connections + @networks = sort @networks; } # parseml($tree, @lines) @@ -262,7 +301,7 @@ sub mforeach { if ($staff !~ /$nick/) { return; } if ($text =~ /^network\s+del\s+([[:graph:]]+)\s+(#[[:graph:]]+)$/) { my ($user, $chan) = ($1, $2); - foreach my $n (@main::networks) { + foreach my $n (@networks) { main::putserv($bot, "PRIVMSG *controlpanel :delchan $user $n->{name} $chan"); } } @@ -363,7 +402,7 @@ LoadModule cloneuser chansaver EOF #LoadModule cloneuser buffextras main::putserv($bot, "PRIVMSG *controlpanel :$msg"); - foreach my $n (@main::networks) { + foreach my $n (@networks) { my $net = $n->{name}; my $server = $n->{server}; my $port = $n->{port}; blob - 456d4c05620636017f5740d85390d00f0e1b00ea blob + dcf14b3a7a1e6dbc1c1f984d43bbcc5cad7b271f --- botnow +++ botnow @@ -95,19 +95,6 @@ if (!defined($conf{mailname})) { } } -my @modules; -if (defined($conf{modules})) { - @modules = split(/\s+/, $conf{modules}); -} -use lib './'; -foreach my $mod (@modules) { - require "$mod.pm"; -} -foreach my $mod (@modules) { - my $init = "${mod}::init"; - $init->(); -} - # Terms of Service; don't edit lines with the word EOF $conf{terms} = $conf{terms} or die "ERROR: botnow.conf terms"; @@ -135,12 +122,22 @@ use constant { }; $conf{verbose} = $conf{verbose} || ERRORS; -# File containing IRC networks -$conf{netpath} = "networks"; - if(defined($conf{die})) { die $conf{die}; } -our @networks; +my @modules; +if (defined($conf{modules})) { + @modules = split(/\s+/, $conf{modules}); +} +use lib './'; +foreach my $mod (@modules) { + require "$mod.pm"; +} +foreach my $mod (@modules) { + my $init = "${mod}::init"; + $init->(); +} + + my @bots; my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun); @@ -156,53 +153,16 @@ my $localnet = $conf{localnet}; my $staff = $conf{staff}; my @stafflist = split(/ /,$staff); my $verbose = $conf{verbose}; -my $netpath = $conf{netpath}; my $expires = $conf{expires}; unveil("./", "r") or die "Unable to unveil $!"; unveil("$confpath", "r") or die "Unable to unveil $!"; -unveil("$netpath", "r") 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( qw(stdio rpath wpath cpath inet dns proc exec flock fattr) ) or die "Unable to pledge: $!"; -# Return list of networks from filename -# To add multiple servers for a single network, simply create a new entry with -# the same net name; znc ignores addnetwork commands when a network already exists -sub readnetworks { - my ($filename) = @_; - my @lines = readarray($filename); - my @networks; - foreach my $line (@lines) { - if ($line =~ /^#/ or $line =~ /^\s*$/) { # skip comments and whitespace - next; - } elsif ($line =~ /^\s*([-a-zA-Z0-9]+)\s*([-_.:a-zA-Z0-9]+)\s*(~|\+)?([0-9]+)\s*$/) { - my ($name, $server, $port) = ($1, $2, $4); - my $trustcerts; - if (!defined($3)) { - $trustcerts = 0; - } elsif ($3 eq "~") { # Use SSL but trust all certs - $port = "+".$port; - $trustcerts = 1; - } else { # Use SSL and verify certs - $port = "+".$port; - $trustcerts = 0; - } - push(@networks, {"name" => $name, "server" => $server, "port" => $port, "trustcerts" => $trustcerts }); - } else { - die "network format invalid: $line\n"; - } - } - return @networks; -} - -@networks = readnetworks($netpath); - -# networks must be sorted to avoid multiple connections -@networks = sort @networks; - # create sockets my $sel = IO::Select->new( ); foreach my $network (@activenets) {