Commit Diff
Diff:
e2d655dd6b6cdd74018cd94e4dd4b8bce3e140f3
2c11865618a8ef011ebed8350c8d628581b881b6
Commit:
2c11865618a8ef011ebed8350c8d628581b881b6
Tree:
9f2cb76dcfb337f0dfdf606a4ebe282b1fcf4aac
Author:
jrmu <jrmu@lecturify.com>
Committer:
jrmu <jrmu@lecturify.com>
Date:
Tue Sep 22 08:54:58 2020 UTC
Message:
Refactored configuration files
blob - 1d817767f895ed4ab0f36665dd90d3fa49a72024
blob + 7cccbed62c96573d71b02d0eba94adc6b8dba21e
--- botnow.pl
+++ botnow.pl
@@ -1,88 +1,93 @@
#!/usr/bin/perl
+use strict;
+use warnings;
+use IO::Socket;
+use IO::Select;
+use OpenBSD::Pledge;
+use OpenBSD::Unveil;
+use File::Copy qw(copy);
+use Digest::SHA qw(sha256_hex);
+use MIME::Base64;
+use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
+use DBI;
+use DBD::SQLite;
+
+my $confpath = "botnow.conf";
+my %conf;
+foreach my $line (readfile($confpath)) {
+ if ($line =~ /^#/ or $line =~ /^\s*$/) { # skip comments and whitespace
+ next;
+ } elsif ($line =~ /^([-_a-zA-Z0-9]+)\s*=\s*([[:print:]]+)$/) {
+ $conf{$1} = $2;
+ } else {
+ die "ERROR: botnow.conf: $line";
+ }
+}
+
# Name of local network
-my $localnet = "ircnow";
+my $localnet = $conf{localnet} || "ircnow";
# Internal IPv4 address and plaintext port
-my $host = "127.0.0.1";
-my $port = "1337";
+my $host = $conf{host} || "127.0.0.1";
+my $port = $conf{port} || 1337;
# Bouncer hostname
-my $hostname = "example.ircnow.org";
+chomp(my $hostname = $conf{hostname} || `hostname`);
# External IPv4 address, plaintext and ssl port
-my $ip4 = "192.168.0.1";
-my $plainport = "1337";
-my $sslport = "31337";
+my $ip4 = $conf{ip4} || host($hostname,4);
+my $plainport = $conf{plainport} || 1337;
+my $sslport = $conf{sslport} || 31337;
# Nick and password of bot -- Make sure to add to oper block
-my $nick = "botnick";
-my $pass = "BotPassword";
+my $nick = $conf{nick} || "botnow";
+my $pass = $conf{pass} or die "ERROR: botnow.conf: pass";
# Comma-separated list of channels for requesting bouncers
-my $chans = "#ircnow,#testing";
+my $chans = $conf{chans} || "#ircnow";
# Number of words in password
-my $passlength = 3;
+my $passlength = $conf{passlength} || 3;
# Comma-separated list of staff nicks; comment out to avoid highlights
-my $staff = "jrmu,test";
+my $staff = $conf{staff};
# Comma-separated list of team channels on localnet; comment out to disable
-my $teamchans = "#ircnow-team";
+my $teamchans = $conf{teamchans};
# Mail from address
-my $mailfrom = 'support@ircnow.org';
-my $mailname = 'support';
+my $mailfrom = $conf{mailfrom} or die "ERROR: botnow.conf: mailfrom";
+my $mailname = $conf{mailname};
+if (!defined($mailname)) {
+ if ($mailfrom =~ /^([^@]+)@/) {
+ $mailname = $1;
+ } else {
+ die "ERROR: botnow.conf mailname";
+ }
+}
# DNS zone directory
-my $zonedir = "/var/nsd/zones/master/";
+my $zonedir = $conf{zonedir} || "/var/nsd/zones/master/";
# rDNS keys from Stallion in BuyVM
-my ($key, $hash) = ("ABCDE-FGHIJ-KLMNO", "ABCDEFGHIJKLMNOPQRST");
+my $key = $conf{key} or die "ERROR: botnow.conf: key";
+my $hash = $conf{hash} or die "ERROR: botnow.conf: hash";
# ZNC install directory
-my $zncdir = "/home/znc/home/znc/";
+my $zncdir = $conf{zncdir} || "/home/znc/home/znc";
# Network Interface Config File
-my $hostnameif = "/etc/hostname.vio0";
+my $hostnameif = $conf{hostnameif} || "/etc/hostname.vio0";
# Verbosity: 0 (no errors), 1 (errors), 2 (warnings), 3 (diagnostic)
-my $verbose = "0";
+my $verbose = $conf{verbose} || 1;
# Terms of Service; don't edit lines with the word EOF
-my $terms = <<"EOF";
-IRCNow is a Christian network. Rules: no profanity, no porn, no illegal drugs, no gambling, no slander, no warez, no promoting violence, no spam, illegal cracking, or DDoS.
-Only one account per person. Don't share passwords. Religious or political content may be moderated. Full terms: https://ircnow.org/terms.php . Do you agree? (yes/no)
-EOF
+my $terms = $conf{terms} || "IRCNow is a Christian network. Rules: no profanity, no porn, no illegal drugs, no gambling, no slander, no warez, no promoting violence, no spam, illegal cracking, or DDoS. Only one account per person. Don't share passwords. Religious or political content may be moderated. Full terms: https://ircnow.org/terms.php . Do you agree? (yes/no)";
-# Comment out the line below
-die("You did not configure the bot!");
+if(defined($conf{die})) { die $conf{die}; }
-
-
-
-
-##### Do not edit code below #####
-
-
-
-
-
-use strict;
-use warnings;
-use IO::Socket;
-use IO::Select;
-use OpenBSD::Pledge;
-use OpenBSD::Unveil;
-use File::Copy qw(copy);
-use Digest::SHA qw(sha256_hex);
-use MIME::Base64;
-use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
-use DBI;
-use DBD::SQLite;
-
-my $confpath = "botnow.conf"; # Bot conf path
my $wwwpath = "/var/www/htdocs/botnow"; # Web folder path
my $ipv6path = "ipv6s"; # ipv6 file path
my $netpath = "networks"; # networks file path
@@ -694,8 +699,8 @@ EOF
} elsif ($reply =~ /^Queued network (.*) of user (.*) for a reconnect.$/) {
print "$2 now connecting to $1...\r\n";
} elsif ($reply =~ /^Admin = false/) {
- sendteam("", "Error: $nick is not admin");
- die "Error: $nick is not admin";
+ sendteam("", "ERROR: $nick is not admin");
+ die "ERROR: $nick is not admin";
} elsif ($reply =~ /^Admin = true/) {
if ($verbose >= 3) { print "$nick is ZNC admin\n"; }
} elsif ($reply =~ /(.*) = (.*)/) {
@@ -1153,8 +1158,9 @@ sub ipsmatching {
}
# given hostname, return IP address; or given IP address, return hostname
+# if defined, v indicates version
sub host {
- my ($name) = @_;
+ my ($name, $v) = @_;
my @matches;
my @lines = split /\n/m, `host $name`;
if ($name =~ /^[0-9\.]+$/ or $name =~ /^$/) { # IP address
@@ -1165,8 +1171,12 @@ sub host {
}
} else { # hostname
foreach my $line (@lines) {
- if ($line =~ /$name has (IPv6 )?address ([0-9a-fA-F\.:]+)/) {
+ if (!defined($v) && $line =~ /$name has (IPv6 )?address ([0-9a-fA-F\.:]+)/) {
push(@matches, $2);
+ } elsif ($v == 4 && $line =~ /$name has address ([0-9\.]+)/) {
+ push(@matches, $1);
+ } elsif ($v == 6 && $line =~ /$name has IPv6 address ([0-9a-fA-F\.:]+)/) {
+ push(@matches, $1);
}
}
}
@@ -1237,7 +1247,7 @@ sub deldns {
if ($domain =~ /^([a-zA-Z][-\.a-zA-Z0-9]+)\.$hostname$/) {
$subdomain = $1;
} else {
- sendteam("", "Error: not authoritative");
+ sendteam("", "ERROR: not authoritative");
return 0;
}
my ($line, $lines);
blob - /dev/null
blob + 6b4e09b147e0e1d8f35fe940951d3de592bf686a (mode 644)
--- /dev/null
+++ botnow.conf
@@ -0,0 +1,27 @@
+# Simplified config for botnow -- see botnow.conf.full for all options
+
+# Nick and password of bot -- make sure to add to oper block
+nick = botnow
+pass = password
+
+# Comma-separated list of channels for requesting bouncers
+# chans = #ircnow,#testing
+
+# Comma-separated list of staff nicks; comment out to avoid highlights
+staff = jrmu,test
+
+# Comma-separated list of team channels on localnet; comment out to disable
+teamchans = #ircnow-team
+
+# Mail from address
+mailfrom = support@ircnow.org
+
+# rDNS keys from Stallion in BuyVM
+key = ABCDE-FGHIJ-KLMNO
+hash = ABCDEFGHIJKLMNOPQRST
+
+# ZNC install directory
+# zncdir = /home/znc/home/znc/
+
+# Comment out the line below
+die = You did not configure botnow.conf!
blob - 304367dd33ae13af5de343acaec2f92679e8f5c3
blob + 4c425309ecebbdaf64b6fd087682e1945daad5f7
--- makefile
+++ makefile
@@ -22,7 +22,7 @@ botnow: figlet php sqlite
chmod ug+rw ${ZONES}/*
echo "permit nopass ${USERNAME} as _nsd cmd nsd-control" >> /etc/doas.conf
cp register.php ${HTDOCS}/
- cp LICENSE README botnow.pl makefile networks register.php words ${HOMEDIR}/
+ cp LICENSE README botnow.pl botnow.conf botnow.conf.full makefile networks register.php words ${HOMEDIR}/
chown -R ${USERNAME}:${USERNAME} ${HOMEDIR}
chmod u+x ${HOMEDIR}/botnow.pl
chown -R ${ZNCUSER}:daemon ${ZNCDIR}
blob - /dev/null
blob + c083ae01cf9be4d0183eb27f62ba95909ed8f398 (mode 644)
--- /dev/null
+++ botnow.conf.full
@@ -0,0 +1,56 @@
+# Name of local network; default ircnow
+# localnet = ircnow
+
+# Internal IPv4 address and plaintext port; default 127.0.0.1@1337
+# host = 127.0.0.1
+# port = 1337
+
+# Bouncer hostname; default uses return of `hostname`
+# hostname = example.ircnow.org
+
+# External IPv4 address, plaintext and ssl port
+# ip4 = 192.168.0.1
+# plainport = 1337
+# sslport = 31337
+
+# Nick and password of bot -- make sure to add to oper block
+nick = botnow
+pass = password
+
+# Comma-separated list of channels for requesting bouncers
+# chans = #ircnow,#testing
+
+# Number of words in password
+# passlength = 3
+
+# Comma-separated list of staff nicks; comment out to avoid highlights
+staff = jrmu,test
+
+# Comma-separated list of team channels on localnet; comment out to disable
+# teamchans = #ircnow-team
+
+# Mail from address
+mailfrom = support@ircnow.org
+# mailname = support
+
+# DNS zone directory
+# zonedir = /var/nsd/zones/master/
+
+# rDNS keys from Stallion in BuyVM
+key = ABCDE-FGHIJ-KLMNO
+hash = ABCDEFGHIJKLMNOPQRST
+
+# ZNC install directory
+# zncdir = /home/znc/home/znc/
+
+# Network Interface Config File
+# hostnameif = /etc/hostname.vio0
+
+# Verbosity: 0 (no errors), 1 (errors), 2 (warnings), 3 (diagnostic)
+# verbose = 0
+
+# Terms of Service
+# terms = IRCNow is a Christian network. Rules: no profanity, no porn, no illegal drugs, no gambling, no slander, no warez, no promoting violence, no spam, illegal cracking, or DDoS. Only one account per person. Don't share passwords. Religious or political content may be moderated. Full terms: https://ircnow.org/terms.php . Do you agree? (yes/no)
+
+# Comment out the line below
+die = You did not configure botnow.conf!