Blame
Date:
Tue Sep 22 09:18:42 2020 UTC
Message:
Added more options to botnow.conf
0001
2020-09-08
jrmu
#!/usr/bin/perl
0002
2020-09-08
jrmu
0003
2020-09-22
jrmu
use strict;
0004
2020-09-22
jrmu
use warnings;
0005
2020-09-22
jrmu
use IO::Socket;
0006
2020-09-22
jrmu
use IO::Select;
0007
2020-09-22
jrmu
use OpenBSD::Pledge;
0008
2020-09-22
jrmu
use OpenBSD::Unveil;
0009
2020-09-22
jrmu
use File::Copy qw(copy);
0010
2020-09-22
jrmu
use Digest::SHA qw(sha256_hex);
0011
2020-09-22
jrmu
use MIME::Base64;
0012
2020-09-22
jrmu
use Time::HiRes qw ( setitimer ITIMER_VIRTUAL time );
0013
2020-09-22
jrmu
use DBI;
0014
2020-09-22
jrmu
use DBD::SQLite;
0015
2020-09-22
jrmu
0016
2020-09-22
jrmu
my $confpath = "botnow.conf";
0017
2020-09-22
jrmu
my %conf;
0018
2020-09-22
jrmu
foreach my $line (readfile($confpath)) {
0019
2020-09-22
jrmu
if ($line =~ /^#/ or $line =~ /^\s*$/) { # skip comments and whitespace
0020
2020-09-22
jrmu
next;
0021
2020-09-22
jrmu
} elsif ($line =~ /^([-_a-zA-Z0-9]+)\s*=\s*([[:print:]]+)$/) {
0022
2020-09-22
jrmu
$conf{$1} = $2;
0023
2020-09-22
jrmu
} else {
0024
2020-09-22
jrmu
die "ERROR: botnow.conf: $line";
0025
2020-09-22
jrmu
}
0026
2020-09-22
jrmu
}
0027
2020-09-22
jrmu
0028
2020-09-13
jrmu
# Name of local network
0029
2020-09-22
jrmu
my $localnet = $conf{localnet} || "ircnow";
0030
2020-09-08
jrmu
0031
2020-09-13
jrmu
# Internal IPv4 address and plaintext port
0032
2020-09-22
jrmu
my $host = $conf{host} || "127.0.0.1";
0033
2020-09-22
jrmu
my $port = $conf{port} || 1337;
0034
2020-09-13
jrmu
0035
2020-09-08
jrmu
# Bouncer hostname
0036
2020-09-22
jrmu
chomp(my $hostname = $conf{hostname} || `hostname`);
0037
2020-09-08
jrmu
0038
2020-09-10
jrmu
# External IPv4 address, plaintext and ssl port
0039
2020-09-22
jrmu
my $ip4 = $conf{ip4} || host($hostname,4);
0040
2020-09-22
jrmu
my $plainport = $conf{plainport} || 1337;
0041
2020-09-22
jrmu
my $sslport = $conf{sslport} || 31337;
0042
2020-09-08
jrmu
0043
2020-09-10
jrmu
# Nick and password of bot -- Make sure to add to oper block
0044
2020-09-22
jrmu
my $nick = $conf{nick} || "botnow";
0045
2020-09-22
jrmu
my $pass = $conf{pass} or die "ERROR: botnow.conf: pass";
0046
2020-09-08
jrmu
0047
2020-09-08
jrmu
# Comma-separated list of channels for requesting bouncers
0048
2020-09-22
jrmu
my $chans = $conf{chans} || "#ircnow";
0049
2020-09-08
jrmu
0050
2020-09-08
jrmu
# Number of words in password
0051
2020-09-22
jrmu
my $passlength = $conf{passlength} || 3;
0052
2020-09-08
jrmu
0053
2020-09-10
jrmu
# Comma-separated list of staff nicks; comment out to avoid highlights
0054
2020-09-22
jrmu
my $staff = $conf{staff};
0055
2020-09-08
jrmu
0056
2020-09-10
jrmu
# Comma-separated list of team channels on localnet; comment out to disable
0057
2020-09-22
jrmu
my $teamchans = $conf{teamchans};
0058
2020-09-08
jrmu
0059
2020-09-08
jrmu
# Mail from address
0060
2020-09-22
jrmu
my $mailfrom = $conf{mailfrom} or die "ERROR: botnow.conf: mailfrom";
0061
2020-09-22
jrmu
my $mailname = $conf{mailname};
0062
2020-09-22
jrmu
if (!defined($mailname)) {
0063
2020-09-22
jrmu
if ($mailfrom =~ /^([^@]+)@/) {
0064
2020-09-22
jrmu
$mailname = $1;
0065
2020-09-22
jrmu
} else {
0066
2020-09-22
jrmu
die "ERROR: botnow.conf mailname";
0067
2020-09-22
jrmu
}
0068
2020-09-22
jrmu
}
0069
2020-09-08
jrmu
0070
2020-09-08
jrmu
# DNS zone directory
0071
2020-09-22
jrmu
my $zonedir = $conf{zonedir} || "/var/nsd/zones/master/";
0072
2020-09-08
jrmu
0073
2020-09-08
jrmu
# rDNS keys from Stallion in BuyVM
0074
2020-09-22
jrmu
my $key = $conf{key} or die "ERROR: botnow.conf: key";
0075
2020-09-22
jrmu
my $hash = $conf{hash} or die "ERROR: botnow.conf: hash";
0076
2020-09-08
jrmu
0077
2020-09-16
jrmu
# ZNC install directory
0078
2020-09-22
jrmu
my $zncdir = $conf{zncdir} || "/home/znc/home/znc";
0079
2020-09-16
jrmu
0080
2020-09-08
jrmu
# Network Interface Config File
0081
2020-09-22
jrmu
my $hostnameif = $conf{hostnameif} || "/etc/hostname.vio0";
0082
2020-09-08
jrmu
0083
2020-09-10
jrmu
# Verbosity: 0 (no errors), 1 (errors), 2 (warnings), 3 (diagnostic)
0084
2020-09-22
jrmu
my $verbose = $conf{verbose} || 1;
0085
2020-09-10
jrmu
0086
2020-09-08
jrmu
# Terms of Service; don't edit lines with the word EOF
0087
2020-09-22
jrmu
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)";
0088
2020-09-08
jrmu
0089
2020-09-22
jrmu
if(defined($conf{die})) { die $conf{die}; }
0090
2020-09-08
jrmu
0091
2020-09-08
jrmu
my $wwwpath = "/var/www/htdocs/botnow"; # Web folder path
0092
2020-09-08
jrmu
my $ipv6path = "ipv6s"; # ipv6 file path
0093
2020-09-21
jrmu
my $netpath = "networks"; # networks file path
0094
2020-09-08
jrmu
my $database = "/var/www/botnow/"; # database path
0095
2020-09-16
jrmu
my $znclog = "$zncdir/.znc/moddata/adminlog/znc.log"; # znc.log path
0096
2020-09-21
jrmu
my $dbpath = "/var/www/botnow/users.db";
0097
2020-09-08
jrmu
0098
2020-09-08
jrmu
unveil("./", "r") or die "Unable to unveil $!";
0099
2020-09-21
jrmu
unveil("$confpath", "r") or die "Unable to unveil $!";
0100
2020-09-21
jrmu
unveil("$netpath", "r") or die "Unable to unveil $!";
0101
2020-09-08
jrmu
unveil("$ipv6path", "rwc") or die "Unable to unveil $!";
0102
2020-09-08
jrmu
unveil("$database", "rwxc") or die "Unable to unveil $!";
0103
2020-09-08
jrmu
unveil("$zonedir", "rwc") or die "Unable to unveil $!";
0104
2020-09-21
jrmu
unveil("$dbpath", "rwc") or die "Unable to unveil $!";
0105
2020-09-21
jrmu
unveil("$dbpath-journal", "rwc") or die "Unable to unveil $!";
0106
2020-09-08
jrmu
0107
2020-09-08
jrmu
#dependencies for figlet
0108
2020-09-08
jrmu
unveil("/usr/local/bin/figlet", "rx") or die "Unable to unveil $!";
0109
2020-09-08
jrmu
unveil("/usr/lib/libc.so.95.1", "r") or die "Unable to unveil $!";
0110
2020-09-08
jrmu
unveil("/usr/libexec/ld.so", "r") or die "Unable to unveil $!";
0111
2020-09-08
jrmu
0112
2020-09-08
jrmu
#dependencies for mail
0113
2020-09-08
jrmu
unveil("/usr/sbin/sendmail", "rx") or die "Unable to unveil $!";
0114
2020-09-08
jrmu
unveil("/usr/lib/libutil.so.13.1", "r") or die "Unable to unveil $!";
0115
2020-09-08
jrmu
unveil("/bin/sh", "rx") or die "Unable to unveil $!";
0116
2020-09-08
jrmu
0117
2020-09-08
jrmu
#dependencies for doas
0118
2020-09-08
jrmu
unveil("/usr/bin/doas", "rx") or die "Unable to unveil $!";
0119
2020-09-08
jrmu
0120
2020-09-08
jrmu
#dependencies for encrypt
0121
2020-09-08
jrmu
unveil("/usr/bin/encrypt", "rx") or die "Unable to unveil $!";
0122
2020-09-08
jrmu
0123
2020-09-16
jrmu
#znc.log file
0124
2020-09-16
jrmu
unveil("$znclog", "r") or die "Unable to unveil $!";
0125
2020-09-13
jrmu
0126
2020-09-16
jrmu
#dependencies for host
0127
2020-09-16
jrmu
unveil("/usr/bin/host", "rx") or die "Unable to unveil $!";
0128
2020-09-16
jrmu
0129
2020-09-08
jrmu
unveil() or die "Unable to lock unveil $!";
0130
2020-09-08
jrmu
0131
2020-09-08
jrmu
#dns and inet for sockets, proc and exec for figlet
0132
2020-09-08
jrmu
#rpath for reading file, wpath for writing file, cpath for creating path
0133
2020-09-21
jrmu
#flock, fattr for sqlite
0134
2020-09-21
jrmu
pledge( qw(stdio rpath wpath cpath inet dns proc exec flock fattr) ) or die "Unable to pledge: $!";
0135
2020-09-08
jrmu
0136
2020-09-08
jrmu
my @networks;
0137
2020-09-08
jrmu
my @bots;
0138
2020-09-08
jrmu
my @words;
0139
2020-09-08
jrmu
my $records;
0140
2020-09-08
jrmu
my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
0141
2020-09-08
jrmu
my @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
0142
2020-09-08
jrmu
my @chans = split /,/m, $chans;
0143
2020-09-10
jrmu
my @teamchans;
0144
2020-09-16
jrmu
my @logs;
0145
2020-09-21
jrmu
my $dbh;
0146
2020-09-21
jrmu
my $fh;
0147
2020-09-10
jrmu
if (defined($teamchans)) { @teamchans = split /,/m, $teamchans; }
0148
2020-09-08
jrmu
0149
2020-09-21
jrmu
sub readfile {
0150
2020-09-21
jrmu
my ($filename) = @_;
0151
2020-09-21
jrmu
my (@lines, $fh);
0152
2020-09-21
jrmu
open($fh, '<', "$filename") or die "Could not read file '$filename' $!";
0153
2020-09-21
jrmu
chomp(@lines = <$fh>);
0154
2020-09-21
jrmu
close $fh;
0155
2020-09-21
jrmu
return @lines;
0156
2020-09-21
jrmu
}
0157
2020-09-21
jrmu
sub writefile {
0158
2020-09-21
jrmu
my ($filename, $str) = @_;
0159
2020-09-21
jrmu
my (@lines, $fh);
0160
2020-09-21
jrmu
open($fh, '>', "$filename") or die "Could not write to $filename";
0161
2020-09-21
jrmu
print $fh $str;
0162
2020-09-21
jrmu
close $fh;
0163
2020-09-21
jrmu
}
0164
2020-09-21
jrmu
0165
2020-09-08
jrmu
# Load list of networks
0166
2020-09-21
jrmu
# To add multiple servers for a single network, simply create a new
0167
2020-09-21
jrmu
# entry with the same net name; znc ignores addnetwork commands when a network
0168
2020-09-08
jrmu
# already exists
0169
2020-09-21
jrmu
my @lines = readfile($netpath);
0170
2020-09-21
jrmu
foreach my $line (@lines) {
0171
2020-09-08
jrmu
if ($line =~ /^#/ or $line =~ /^\s*$/) { # skip comments and whitespace
0172
2020-09-08
jrmu
next;
0173
2020-09-08
jrmu
} elsif ($line =~ /^\s*([-a-zA-Z0-9]+)\s*([-_.:a-zA-Z0-9]+)\s*(~|\+)?([0-9]+)\s*$/) {
0174
2020-09-21
jrmu
my ($name, $server, $port) = ($1, $2, $4);
0175
2020-09-21
jrmu
my $trustcerts;
0176
2020-09-08
jrmu
if (!defined($3)) {
0177
2020-09-08
jrmu
$trustcerts = 0;
0178
2020-09-08
jrmu
} elsif ($3 eq "~") { # Use SSL but trust all certs
0179
2020-09-08
jrmu
$port = "+".$port;
0180
2020-09-08
jrmu
$trustcerts = 1;
0181
2020-09-08
jrmu
} else { # Use SSL and verify certs
0182
2020-09-08
jrmu
$port = "+".$port;
0183
2020-09-08
jrmu
$trustcerts = 0;
0184
2020-09-08
jrmu
}
0185
2020-09-08
jrmu
push(@networks, {"name" => $name, "server" => $server, "port" => $port, "trustcerts" => $trustcerts });
0186
2020-09-08
jrmu
} else {
0187
2020-09-08
jrmu
die "network format invalid: $line\n";
0188
2020-09-08
jrmu
}
0189
2020-09-08
jrmu
}
0190
2020-09-21
jrmu
0191
2020-09-08
jrmu
# networks must be sorted to avoid multiple connections
0192
2020-09-08
jrmu
@networks = sort @networks;
0193
2020-09-08
jrmu
0194
2020-09-08
jrmu
# dictionary words for passwords
0195
2020-09-21
jrmu
@words = readfile("words");
0196
2020-09-08
jrmu
0197
2020-09-08
jrmu
# Validate ipv6s if it exists, otherwise load addresses from /etc/hostname.if
0198
2020-09-08
jrmu
0199
2020-09-08
jrmu
if (!(-s "$ipv6path")) {
0200
2020-09-21
jrmu
print "No IPv6 addresses in $ipv6path, loading from $hostnameif...\n";
0201
2020-09-21
jrmu
@lines = readfile($hostnameif);
0202
2020-09-21
jrmu
my $ipv6s;
0203
2020-09-21
jrmu
foreach my $line (@lines) {
0204
2020-09-21
jrmu
if ($line =~ /^\s*inet6 (alias )?([0-9a-f:]{4,}) [0-9]+\s*$/i) {
0205
2020-09-21
jrmu
$ipv6s .= "$2\n";
0206
2020-09-08
jrmu
}
0207
2020-09-08
jrmu
}
0208
2020-09-21
jrmu
writefile($ipv6path, $ipv6s);
0209
2020-09-08
jrmu
}
0210
2020-09-08
jrmu
0211
2020-09-21
jrmu
@lines = readfile($ipv6path);
0212
2020-09-21
jrmu
my $ipv6s;
0213
2020-09-21
jrmu
foreach my $line (@lines) {
0214
2020-09-21
jrmu
if ($line =~ /^\s*([0-9a-f:]{4,})\s*$/i) {
0215
2020-09-21
jrmu
$ipv6s .= "$1\n";
0216
2020-09-08
jrmu
}
0217
2020-09-08
jrmu
}
0218
2020-09-21
jrmu
writefile($ipv6path, $ipv6s);
0219
2020-09-08
jrmu
0220
2020-09-08
jrmu
# create sockets
0221
2020-09-08
jrmu
my $sel = IO::Select->new( );
0222
2020-09-08
jrmu
my $lastname = "";
0223
2020-09-08
jrmu
foreach my $network (@networks) {
0224
2020-09-21
jrmu
# avoid duplicate connections
0225
2020-09-21
jrmu
if ($lastname eq $network->{name}) { next; }
0226
2020-09-08
jrmu
$lastname = $network->{name};
0227
2020-09-08
jrmu
my $socket = IO::Socket::INET->new(PeerAddr=>$host, PeerPort=>$port, Proto=>'tcp', Timeout=>'300') || print "Failed to establish connection\n";
0228
2020-09-08
jrmu
$sel->add($socket);
0229
2020-09-08
jrmu
my $tmp = {"sock" => $socket};
0230
2020-09-08
jrmu
push(@bots, {%$tmp, %$network});
0231
2020-09-10
jrmu
print $socket "NICK $nick\r\n";
0232
2020-09-10
jrmu
print $socket "USER $nick * * :$nick\r\n";
0233
2020-09-08
jrmu
}
0234
2020-09-08
jrmu
0235
2020-09-08
jrmu
while(my @ready = $sel->can_read) {
0236
2020-09-10
jrmu
my ($bot, $response);
0237
2020-09-08
jrmu
foreach my $socket (@ready) {
0238
2020-09-08
jrmu
foreach my $b (@bots) {
0239
2020-09-08
jrmu
if($socket == $b->{sock}) {
0240
2020-09-08
jrmu
$bot = $b;
0241
2020-09-08
jrmu
last;
0242
2020-09-08
jrmu
}
0243
2020-09-08
jrmu
}
0244
2020-09-08
jrmu
if (!defined($response = <$socket>)) {
0245
2020-09-08
jrmu
next;
0246
2020-09-08
jrmu
}
0247
2020-09-08
jrmu
if ($response =~ /^PING :ZNC\r\n$/i) {
0248
2020-09-08
jrmu
print $socket "PONG :ZNC\r\n";
0249
2020-09-08
jrmu
if ($bot->{name} =~ /$localnet/i) {
0250
2020-09-21
jrmu
updaterecords();
0251
2020-09-08
jrmu
}
0252
2020-09-10
jrmu
} elsif ($response =~ /^:irc.znc.in (.*) (.*) :(.*)\r\n$/) {
0253
2020-09-10
jrmu
my ($type, $target, $reply) = ($1, $2, $3);
0254
2020-09-10
jrmu
parseznc($bot, $type, $target, $reply);
0255
2020-09-08
jrmu
} elsif($response =~ /^:([^!]+![^@]+@[^@ ]+) PRIVMSG ([^ ]+) :(.*)\r\n$/i) {
0256
2020-09-08
jrmu
my ($hostmask, $target, $reply) = ($1, $2, $3);
0257
2020-09-08
jrmu
parsemsg($bot, $hostmask, $target, $reply);
0258
2020-09-08
jrmu
} elsif($response =~ /^:([^!]+![^@]+@[^@ ]+) NOTICE ([^ ]+) :(.*)\r\n$/i) {
0259
2020-09-08
jrmu
my ($hostmask, $target, $reply) = ($1, $2, $3);
0260
2020-09-08
jrmu
parsenotice($bot, $hostmask, $target, $reply);
0261
2020-09-10
jrmu
} elsif($response =~ /^:([^!]+![^@]+@[^@ ]+) MODE ([^ ]+) :(.*)\r\n$/i) {
0262
2020-09-10
jrmu
my ($hostmask, $target, $reply) = ($1, $2, $3);
0263
2020-09-10
jrmu
parsemode($bot, $hostmask, $target, $reply);
0264
2020-09-10
jrmu
} elsif($response =~ /^:([^!]+![^@]+@[^@ ]+) JOIN :?(.*)\r\n$/i) {
0265
2020-09-10
jrmu
my ($hostmask, $chan) = ($1, $2);
0266
2020-09-10
jrmu
parsejoin($bot, $hostmask, $chan);
0267
2020-09-10
jrmu
} elsif($response =~ /^:([^!]+![^@]+@[^@ ]+) PART ([^ ]+) :(.*)\r\n$/i) {
0268
2020-09-10
jrmu
my ($hostmask, $chan, $msg) = ($1, $2, $3);
0269
2020-09-10
jrmu
parsepart($bot, $hostmask, $chan, $msg);
0270
2020-09-10
jrmu
} elsif($response =~ /^:([^!]+![^@]+@[^@ ]+) NICK :(.*)\r\n$/i) {
0271
2020-09-10
jrmu
my ($hostmask, $nick) = ($1, $2);
0272
2020-09-10
jrmu
parsenick($bot, $hostmask, $nick);
0273
2020-09-10
jrmu
} elsif ($response =~ /^:([[:graph:]]+) (\d\d\d) $nick.? :?(.*)\r?\n?\r$/i) {
0274
2020-09-10
jrmu
my ($server, $code, $reply) = ($1, $2, $3);
0275
2020-09-10
jrmu
parseserver($bot, $server, $code, $reply);
0276
2020-09-08
jrmu
} else {
0277
2020-09-10
jrmu
if ($verbose >= 2) { print "Unexpected: $response\r\n"; }
0278
2020-09-08
jrmu
}
0279
2020-09-08
jrmu
}
0280
2020-09-08
jrmu
}
0281
2020-09-08
jrmu
0282
2020-09-10
jrmu
sub parseznc {
0283
2020-09-10
jrmu
my ($bot, $type, $target, $reply) = @_;
0284
2020-09-10
jrmu
my $socket = $bot->{sock};
0285
2020-09-10
jrmu
if ($type eq "001" && $target =~ /^$nick.?$/ && $reply eq "Welcome to ZNC") {
0286
2020-09-10
jrmu
} elsif ($type eq "NOTICE" && $target =~ /^$nick.?$/ && $reply eq "*** To connect now, you can use /quote PASS <username>:<password>, or /quote PASS <username>/<network>:<password> to connect to a specific network.") {
0287
2020-09-10
jrmu
} elsif ($type eq "NOTICE" && $target =~ /^$nick.?$/ && $reply eq "*** You need to send your password. Configure your client to send a server password.") {
0288
2020-09-10
jrmu
} elsif ($type eq "464" && $target =~ /^$nick.?$/ && $reply eq "Password required") {
0289
2020-09-10
jrmu
print $socket "PASS $nick/$bot->{name}:$pass\r\n";
0290
2020-09-10
jrmu
foreach my $chan (@chans) {
0291
2020-09-10
jrmu
print $socket "JOIN ".$chan."\r\n";
0292
2020-09-10
jrmu
}
0293
2020-09-10
jrmu
if ($bot->{name} =~ /$localnet/i) {
0294
2020-09-10
jrmu
print $socket "OPER $nick $pass\r\n";
0295
2020-09-10
jrmu
print $socket "PRIVMSG *status :LoadMod --type=user controlpanel\r\n";
0296
2020-09-10
jrmu
print $socket "PRIVMSG *controlpanel :get Admin $nick\r\n";
0297
2020-09-10
jrmu
print $socket "PRIVMSG *controlpanel :get Nick cloneuser\r\n";
0298
2020-09-10
jrmu
foreach my $chan (@teamchans) {
0299
2020-09-10
jrmu
print $socket "JOIN ".$chan."\r\n";
0300
2020-09-10
jrmu
}
0301
2020-09-10
jrmu
}
0302
2020-09-13
jrmu
} elsif ($type eq "464" && $target =~ /^$nick.?$/ && $reply eq "Invalid Password") {
0303
2020-09-13
jrmu
print "ERROR: Wrong Username/Password: $bot->{name}\r\n";
0304
2020-09-10
jrmu
} else {
0305
2020-09-10
jrmu
print "Unexpected: type: $type, target: $target, reply: $reply\r\n";
0306
2020-09-10
jrmu
}
0307
2020-09-10
jrmu
}
0308
2020-09-21
jrmu
0309
2020-09-10
jrmu
sub parseserver {
0310
2020-09-10
jrmu
my ($bot, $server, $code, $reply) = @_;
0311
2020-09-13
jrmu
my ($sender, $val, $key);
0312
2020-09-10
jrmu
my $socket = $bot->{sock};
0313
2020-09-13
jrmu
if ($code =~ /^001$/) { # Server Info
0314
2020-09-13
jrmu
if ($verbose >= 3) { print "botnow successfully connected to $bot->{name}\r\n"; }
0315
2020-09-13
jrmu
} elsif ($code =~ /^00\d$/) { # Server Info
0316
2020-09-10
jrmu
# print "$server $reply\r\n";
0317
2020-09-10
jrmu
} elsif ($code =~ /^2\d\d$/) { # Server Stats
0318
2020-09-13
jrmu
# print "$server $reply\r\n";
0319
2020-09-21
jrmu
} elsif ($code == 301 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :([[:graph:]]+)/) {
0320
2020-09-21
jrmu
if ($verbose >= 3) { print "$reply\r\n"; }
0321
2020-09-13
jrmu
} elsif ($code == 307 && $reply =~ /^([-_\|`a-zA-Z0-9]+) (.*)/) {
0322
2020-09-13
jrmu
($sender, $key) = ($1, "registered");
0323
2020-09-13
jrmu
$val = $2 eq ":is a registered nick" ? "True" : "$2";
0324
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0325
2020-09-21
jrmu
setkeyval($hostmask, "identified", $val);
0326
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0327
2020-09-13
jrmu
} elsif ($code == 311 && $reply =~ /^([-_\|`a-zA-Z0-9]+) ([^:]+)\s+([^:]+) \* :([^:]*)/) {
0328
2020-09-13
jrmu
($sender, $key, $val) = ($1, "vhost", "$1\!$2\@$3");
0329
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0330
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0331
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0332
2020-09-13
jrmu
} elsif ($code == 312 && $reply =~ /^([-_\|`a-zA-Z0-9]+) ([^:]+) :([^:]+)/) {
0333
2020-09-13
jrmu
($sender, $key, $val) = ($1, "server", $2);
0334
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0335
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0336
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0337
2020-09-13
jrmu
} elsif ($code == 313 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :?(.*)/) {
0338
2020-09-13
jrmu
($sender, $key, $val) = ($1, "oper", ($2 eq "is an IRC operator" ? "True" : "$2"));
0339
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0340
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0341
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0342
2020-09-21
jrmu
} elsif ($code == 315 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :End of \/?WHOIS list/) {
0343
2020-09-21
jrmu
if ($verbose >= 3) { print "End of WHOIS\r\n"; }
0344
2020-09-13
jrmu
} elsif ($code == 317 && $reply =~ /^([-_\|`a-zA-Z0-9]+) (\d+) (\d+) :?(.*)/) {
0345
2020-09-13
jrmu
($sender, my $idle, my $epochtime) = ($1, $2, $3);
0346
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0347
2020-09-13
jrmu
setkeyval($hostmask, "idle", $idle);
0348
2020-09-13
jrmu
setkeyval($hostmask, "epochtime", $epochtime);
0349
2020-09-13
jrmu
if ($verbose >= 3) { print "idle: $idle, epochtime: $epochtime\r\n"; }
0350
2020-09-13
jrmu
} elsif ($code == 318 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :End of \/?WHOIS list/) {
0351
2020-09-13
jrmu
if ($verbose >= 3) { print "End of WHOIS\r\n"; }
0352
2020-09-13
jrmu
} elsif ($code == 319 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :(.*)/) {
0353
2020-09-13
jrmu
($sender, $key, $val) = ($1, "chans", $2);
0354
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0355
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0356
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0357
2020-09-13
jrmu
} elsif ($code == 330 && $reply =~ /^([-_\|`a-zA-Z0-9]+) ([-_\|`a-zA-Z0-9]+) :?(.*)/) {
0358
2020-09-13
jrmu
($sender, $key, $val) = ($1, "loggedin", ($3 eq "is logged in as" ? "True" : $2));
0359
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0360
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0361
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0362
2020-09-13
jrmu
} elsif ($code == 338 && $reply =~ /^([-_\|`a-zA-Z0-9]+) ([0-9a-fA-F:.]+) :actually using host/) {
0363
2020-09-13
jrmu
($sender, $key, $val) = ($1, "ip", $2);
0364
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0365
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0366
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0367
2020-09-13
jrmu
print "$key: $val\r\n";
0368
2020-09-13
jrmu
#Unexpected: efnet.port80.se 338 jrmu 206.253.167.44 :actually using host
0369
2020-09-13
jrmu
} elsif ($code == 378 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :is connecting from ([^ ]+)\s*([0-9a-fA-F:.]+)?/) {
0370
2020-09-13
jrmu
($sender, $key, $val) = ($1, "ip", $3);
0371
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0372
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0373
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0374
2020-09-13
jrmu
} elsif ($code == 671 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :is using a secure connection/) {
0375
2020-09-13
jrmu
($sender, $key, $val) = ($1, "ssl", "True");
0376
2020-09-13
jrmu
my $hostmask = firstval("oldnick", $sender);
0377
2020-09-13
jrmu
setkeyval($hostmask, $key, $val);
0378
2020-09-13
jrmu
if ($verbose >= 3) { print "$key: $val\r\n"; }
0379
2020-09-13
jrmu
print "$key: $val\r\n";
0380
2020-09-13
jrmu
} elsif ($code =~ /^332$/) { # Topic
0381
2020-09-13
jrmu
# print "$reply\r\n";
0382
2020-09-13
jrmu
} elsif ($code =~ /^333$/) { # Topic
0383
2020-09-13
jrmu
# print "$server $reply\r\n";
0384
2020-09-13
jrmu
#karatkievich.freenode.net 333 #ircnow jrmu!znc@206.253.167.44 1579277253
0385
2020-09-13
jrmu
} elsif ($code =~ /^353$/) { # Names
0386
2020-09-10
jrmu
# print "$server $code $reply\r\n";
0387
2020-09-13
jrmu
} elsif ($code =~ /^366$/) { # End of names
0388
2020-09-13
jrmu
# print "$server $code $reply\r\n";
0389
2020-09-13
jrmu
} elsif ($code =~ /^37\d$/) { # MOTD
0390
2020-09-13
jrmu
# print "$server $code $reply\r\n";
0391
2020-09-13
jrmu
} elsif ($code =~ /^381$/) { # IRC Operator Verified
0392
2020-09-13
jrmu
# print "IRC Oper Verified\r\n";
0393
2020-09-13
jrmu
} elsif ($code =~ /^401$/) { # IRC Operator Verified
0394
2020-09-13
jrmu
# print "IRC Oper Verified\r\n";
0395
2020-09-13
jrmu
} elsif ($code =~ /^422$/) { # MOTD missing
0396
2020-09-13
jrmu
# print "$server $code $reply\r\n";
0397
2020-09-13
jrmu
} elsif ($code =~ /^464$/) { # Invalid password for oper
0398
2020-09-13
jrmu
foreach my $chan (@teamchans) {
0399
2020-09-16
jrmu
sendmsg($bot, $chan, "ERROR: $nick oper password failed; the bot will be unable to view uncloaked IP addresses\r\n");
0400
2020-09-13
jrmu
}
0401
2020-09-13
jrmu
} elsif ($code =~ /^477$/) { # Can't join channel
0402
2020-09-13
jrmu
foreach my $chan (@teamchans) {
0403
2020-09-13
jrmu
sendmsg($bot, $chan, "ERROR: $nick on $server: $reply\r\n");
0404
2020-09-13
jrmu
}
0405
2020-09-21
jrmu
} elsif ($code == 716 && $reply =~ /^([-_\|`a-zA-Z0-9]+) :is in \+g mode \(server-side ignore.\)/) {
0406
2020-09-21
jrmu
if ($verbose >= 3) { print "$reply\r\n"; }
0407
2020-09-13
jrmu
} else {
0408
2020-09-13
jrmu
print "Unexpected: $server $code $reply\r\n";
0409
2020-09-10
jrmu
}
0410
2020-09-10
jrmu
}
0411
2020-09-13
jrmu
0412
2020-09-10
jrmu
sub parsemode {
0413
2020-09-10
jrmu
my ($bot, $hostmask, $target, $reply) = @_;
0414
2020-09-10
jrmu
if ($verbose >= 3) { print "$hostmask MODE $target $reply\r\n"; }
0415
2020-09-10
jrmu
#:guava!guava@guava.guava.ircnow.org MODE guava :+Ci
0416
2020-09-10
jrmu
#:ChanServ!services@services.irc.ircnow.org MODE #testing +q jrmu
0417
2020-09-10
jrmu
#:jrmu!jrmu@jrmu.staff.ircnow.org MODE #testing +o jrmu
0418
2020-09-10
jrmu
}
0419
2020-09-10
jrmu
sub parsejoin {
0420
2020-09-10
jrmu
my ($bot, $hostmask, $chan) = @_;
0421
2020-09-10
jrmu
if ($verbose >= 3) { print "$hostmask JOIN $chan\r\n"; }
0422
2020-09-10
jrmu
#:jrmu!jrmu@jrmu.staff.ircnow.org JOIN :#testing
0423
2020-09-10
jrmu
}
0424
2020-09-10
jrmu
sub parsepart {
0425
2020-09-10
jrmu
my ($bot, $hostmask, $chan, $msg) = @_;
0426
2020-09-10
jrmu
print "$hostmask PART $chan :$msg\r\n";
0427
2020-09-10
jrmu
#:jrmu!jrmu@jrmu.staff.ircnow.org PART #testing :
0428
2020-09-10
jrmu
}
0429
2020-09-10
jrmu
sub parsenick {
0430
2020-09-10
jrmu
my ($bot, $hostmask, $nick) = @_;
0431
2020-09-10
jrmu
print "$hostmask NICK $nick\r\n";
0432
2020-09-10
jrmu
#:Fly0nDaWaLL|dal!psybnc@do.not.h4ck.me NICK :nec|dal
0433
2020-09-10
jrmu
}
0434
2020-09-10
jrmu
0435
2020-09-08
jrmu
sub sendmsg {
0436
2020-09-08
jrmu
my( $bot, $target, $msg )=@_;
0437
2020-09-08
jrmu
my $socket = $bot->{sock};
0438
2020-09-08
jrmu
my @lines = split /\r?\n\r?/m, $msg;
0439
2020-09-08
jrmu
foreach my $l (@lines) {
0440
2020-09-08
jrmu
print $socket "PRIVMSG $target :$l\r\n";
0441
2020-09-08
jrmu
# if not sending to znc
0442
2020-09-10
jrmu
if ($bot->{name} =~ /^$localnet$/i and $target !~ /^\*/) {
0443
2020-09-08
jrmu
sleep(1);
0444
2020-09-08
jrmu
}
0445
2020-09-08
jrmu
}
0446
2020-09-08
jrmu
}
0447
2020-09-08
jrmu
0448
2020-09-08
jrmu
sub mailverify {
0449
2020-09-13
jrmu
my( $username, $email, $password, $service, $version )=@_;
0450
2020-09-13
jrmu
my $passhash = sha256_hex("$username");
0451
2020-09-13
jrmu
if ($version =~ /mIRC/) {
0452
2020-09-13
jrmu
$version = "mIRC";
0453
2020-09-13
jrmu
}
0454
2020-09-13
jrmu
my $versionhash = encode_base64($version);
0455
2020-09-08
jrmu
0456
2020-09-08
jrmu
my $msg = <<"EOF";
0457
2020-09-10
jrmu
From: $mailname \<$mailfrom\>
0458
2020-09-08
jrmu
To: $email
0459
2020-09-08
jrmu
Subject: Verify IRCNow Account
0460
2020-09-08
jrmu
MIME-Version: 1.0
0461
2020-09-08
jrmu
Content-Type: text/plain; charset=us-ascii
0462
2020-09-08
jrmu
Content-Disposition: inline
0463
2020-09-08
jrmu
0464
2020-09-13
jrmu
You created a bouncer!
0465
2020-09-08
jrmu
0466
2020-09-13
jrmu
Username: $username
0467
2020-09-13
jrmu
Password: $password
0468
2020-09-13
jrmu
Server: $hostname
0469
2020-09-13
jrmu
Port: $sslport for SSL (secure connection)
0470
2020-09-13
jrmu
Port: $plainport for plaintext
0471
2020-09-08
jrmu
0472
2020-09-13
jrmu
*IMPORTANT*: Verify your email address:
0473
2020-09-08
jrmu
0474
2020-09-13
jrmu
https://www.$hostname/register.php?id=$hash&version=$versionhash
0475
2020-09-13
jrmu
0476
2020-09-08
jrmu
You *MUST* click on the link or your account will be deleted.
0477
2020-09-08
jrmu
0478
2020-09-08
jrmu
IRCNow
0479
2020-09-08
jrmu
EOF
0480
2020-09-08
jrmu
open(my $fh, "| /usr/sbin/sendmail -tv -F support -f $mailfrom") or die "Could not send mail $!";
0481
2020-09-08
jrmu
print $fh $msg;
0482
2020-09-08
jrmu
close $fh;
0483
2020-09-08
jrmu
}
0484
2020-09-08
jrmu
0485
2020-09-10
jrmu
sub getrecords {
0486
2020-09-21
jrmu
if (!defined($records)) {
0487
2020-09-21
jrmu
my @rows = selectall();
0488
2020-09-21
jrmu
if (@rows) {
0489
2020-09-21
jrmu
foreach my $row (@rows) {
0490
2020-09-21
jrmu
my $hostmask = $row->{vhost};
0491
2020-09-21
jrmu
$records->{$hostmask} = ();
0492
2020-09-21
jrmu
foreach $key (keys %$row) {
0493
2020-09-21
jrmu
my $val = $row->{$key} || "";
0494
2020-09-21
jrmu
$records->{$hostmask}->{$key} = $val;
0495
2020-09-21
jrmu
}
0496
2020-09-21
jrmu
}
0497
2020-09-21
jrmu
} else {
0498
2020-09-21
jrmu
print "Error getting records\n";
0499
2020-09-10
jrmu
}
0500
2020-09-10
jrmu
}
0501
2020-09-10
jrmu
}
0502
2020-09-10
jrmu
sub getkeyval {
0503
2020-09-10
jrmu
my ($hostmask, $key) = @_;
0504
2020-09-10
jrmu
my $val;
0505
2020-09-10
jrmu
if (!defined($records)) { getrecords(); }
0506
2020-09-10
jrmu
$val = $records->{$hostmask}->{$key};
0507
2020-09-10
jrmu
if ($verbose >= 3) { print "getkeyval $hostmask: $key => ".($val or "undefined")."\r\n"; }
0508
2020-09-10
jrmu
return $val;
0509
2020-09-10
jrmu
}
0510
2020-09-10
jrmu
sub setkeyval {
0511
2020-09-10
jrmu
my ($hostmask, $key, $val) = @_;
0512
2020-09-10
jrmu
if (!defined($records)) { getrecords(); }
0513
2020-09-21
jrmu
if (!defined($records->{$hostmask})) {
0514
2020-09-21
jrmu
insert("vhost", $hostmask);
0515
2020-09-21
jrmu
}
0516
2020-09-10
jrmu
$records->{$hostmask}->{$key} = $val; # autovivifies
0517
2020-09-10
jrmu
if ($verbose >= 3) { print "setkeyval $hostmask: $key => $val\r\n"; }
0518
2020-09-10
jrmu
}
0519
2020-09-10
jrmu
sub delkey {
0520
2020-09-10
jrmu
my ($hostmask, $key) = @_;
0521
2020-09-10
jrmu
if (!defined($records)) { getrecords(); }
0522
2020-09-10
jrmu
delete($records->{$hostmask}->{$key});
0523
2020-09-10
jrmu
if ($verbose >= 3) { print "delkey $hostmask: $key\r\n"; }
0524
2020-09-10
jrmu
}
0525
2020-09-10
jrmu
sub delhost {
0526
2020-09-10
jrmu
my ($hostmask) = @_;
0527
2020-09-10
jrmu
if (!defined($records)) { getrecords(); }
0528
2020-09-21
jrmu
deleterow($hostmask);
0529
2020-09-10
jrmu
delete($records->{$hostmask});
0530
2020-09-10
jrmu
}
0531
2020-09-10
jrmu
sub firstval {
0532
2020-09-10
jrmu
my ($key, $val) = @_;
0533
2020-09-10
jrmu
if (!defined($records)) { getrecords(); }
0534
2020-09-10
jrmu
foreach my $hostmask (keys %$records) {
0535
2020-09-10
jrmu
if (exists($records->{$hostmask}->{$key}) && $records->{$hostmask}->{$key} eq $val) {
0536
2020-09-10
jrmu
return $hostmask;
0537
2020-09-10
jrmu
}
0538
2020-09-10
jrmu
}
0539
2020-09-10
jrmu
return;
0540
2020-09-10
jrmu
}
0541
2020-09-21
jrmu
sub createrecord {
0542
2020-09-21
jrmu
my ($hostmask) = @_;
0543
2020-09-10
jrmu
if (!defined($records)) { getrecords(); }
0544
2020-09-21
jrmu
insert("vhost", $hostmask);
0545
2020-09-21
jrmu
return 1;
0546
2020-09-21
jrmu
}
0547
2020-09-21
jrmu
sub updaterecords {
0548
2020-09-21
jrmu
if (!defined($records)) { getrecords(); }
0549
2020-09-10
jrmu
while (my ($hostmask, $record) = each (%$records)) {
0550
2020-09-21
jrmu
foreach my $key (keys %$record) {
0551
2020-09-21
jrmu
print "key: $key, val: ".$record->{$key}.", hostmask: $hostmask\n";
0552
2020-09-21
jrmu
update($key, $record->{$key}, $hostmask);
0553
2020-09-10
jrmu
}
0554
2020-09-10
jrmu
}
0555
2020-09-10
jrmu
if ($verbose >= 3) { print "records saved\n"; }
0556
2020-09-10
jrmu
return 1;
0557
2020-09-10
jrmu
}
0558
2020-09-10
jrmu
sub date {
0559
2020-09-10
jrmu
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
0560
2020-09-10
jrmu
my $localtime = sprintf("%04d%02d%02d", $year+1900, $mon+1, $mday);
0561
2020-09-10
jrmu
return $localtime;
0562
2020-09-10
jrmu
}
0563
2020-09-10
jrmu
sub mytime {
0564
2020-09-10
jrmu
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
0565
2020-09-10
jrmu
my $localtime = sprintf("%s %s %d %02d:%02d:%02d", $days[$wday], $months[$mon], $mday, $hour, $min, $sec);
0566
2020-09-10
jrmu
return $localtime;
0567
2020-09-10
jrmu
}
0568
2020-09-10
jrmu
0569
2020-09-08
jrmu
sub www {
0570
2020-09-08
jrmu
my( $username, $email, $password, $service )=@_;
0571
2020-09-08
jrmu
my $hash = sha256_hex("$username");
0572
2020-09-08
jrmu
my $filename = "$database/www";
0573
2020-09-08
jrmu
my $lines = "";
0574
2020-09-08
jrmu
if (open($fh, '+<', $filename)) {
0575
2020-09-08
jrmu
while (my $line = <$fh>) {
0576
2020-09-08
jrmu
$lines .= $line;
0577
2020-09-08
jrmu
}
0578
2020-09-08
jrmu
close $fh;
0579
2020-09-08
jrmu
}
0580
2020-09-08
jrmu
open($fh, '>', "$filename") or die "Could not write to '$database/www' $!";
0581
2020-09-08
jrmu
print $fh $lines;
0582
2020-09-08
jrmu
print $fh "Hash: $hash, Username: $username, Email: $email, Password: $password\n";
0583
2020-09-08
jrmu
close $fh;
0584
2020-09-08
jrmu
}
0585
2020-09-08
jrmu
0586
2020-09-10
jrmu
sub newpass {
0587
2020-09-10
jrmu
my $len = scalar @words;
0588
2020-09-10
jrmu
my $pass;
0589
2020-09-10
jrmu
for (my $i=0; $i < $passlength; $i++) {
0590
2020-09-10
jrmu
my $word = $words[int(rand($len))];
0591
2020-09-10
jrmu
$word =~ s/(\w+)/\u$1/g;
0592
2020-09-10
jrmu
$pass .= $word;
0593
2020-09-10
jrmu
}
0594
2020-09-10
jrmu
return $pass;
0595
2020-09-10
jrmu
}
0596
2020-09-10
jrmu
sub nickfromhost {
0597
2020-09-10
jrmu
my ($hostmask) = @_;
0598
2020-09-10
jrmu
if ($hostmask =~ /([^!]+)!/i) {
0599
2020-09-10
jrmu
return $1;
0600
2020-09-10
jrmu
}
0601
2020-09-10
jrmu
return;
0602
2020-09-10
jrmu
}
0603
2020-09-10
jrmu
0604
2020-09-13
jrmu
# Send $msg to every nick in $staff on the team channel
0605
2020-09-13
jrmu
sub sendteam {
0606
2020-09-08
jrmu
my( $sender, $msg )=@_;
0607
2020-09-08
jrmu
my @nicks = split /,/m, $staff;
0608
2020-09-08
jrmu
my $bot;
0609
2020-09-08
jrmu
0610
2020-09-10
jrmu
if (!defined($teamchans)) { return; }
0611
2020-09-08
jrmu
0612
2020-09-08
jrmu
#prevent duplicates on other networks
0613
2020-09-08
jrmu
if ($sender =~ /\|/) {
0614
2020-09-08
jrmu
return;
0615
2020-09-08
jrmu
}
0616
2020-09-08
jrmu
0617
2020-09-08
jrmu
foreach my $b (@bots) {
0618
2020-09-08
jrmu
if($b->{name} =~ /$localnet/i) {
0619
2020-09-08
jrmu
$bot = $b;
0620
2020-09-08
jrmu
last;
0621
2020-09-08
jrmu
}
0622
2020-09-08
jrmu
}
0623
2020-09-10
jrmu
foreach my $chan (@teamchans) {
0624
2020-09-10
jrmu
if (defined($staff)) {
0625
2020-09-10
jrmu
sendmsg($bot, $chan, join(" ", split /,/m, $staff).": $msg");
0626
2020-09-10
jrmu
} else {
0627
2020-09-10
jrmu
sendmsg($bot, $chan, $msg);
0628
2020-09-10
jrmu
}
0629
2020-09-08
jrmu
}
0630
2020-09-08
jrmu
}
0631
2020-09-08
jrmu
0632
2020-09-08
jrmu
sub whois {
0633
2020-09-08
jrmu
my( $socket, $target )=@_;
0634
2020-09-08
jrmu
print $socket "WHOIS $target $target\r\n";
0635
2020-09-08
jrmu
}
0636
2020-09-08
jrmu
0637
2020-09-08
jrmu
sub ctcp {
0638
2020-09-08
jrmu
my( $socket, $target )=@_;
0639
2020-09-08
jrmu
# print $socket "PRIVMSG $target :".chr(01)."CLIENTINFO".chr(01)."\r\n";
0640
2020-09-08
jrmu
# print $socket "PRIVMSG $target :".chr(01)."FINGER".chr(01)."\r\n";
0641
2020-09-08
jrmu
# print $socket "PRIVMSG $target :".chr(01)."SOURCE".chr(01)."\r\n";
0642
2020-09-08
jrmu
print $socket "PRIVMSG $target :".chr(01)."TIME".chr(01)."\r\n";
0643
2020-09-08
jrmu
# print $socket "PRIVMSG $target :".chr(01)."USERINFO".chr(01)."\r\n";
0644
2020-09-08
jrmu
print $socket "PRIVMSG $target :".chr(01)."VERSION".chr(01)."\r\n";
0645
2020-09-08
jrmu
# print $socket "PRIVMSG $target :".chr(01)."PING".chr(01)."\r\n";
0646
2020-09-08
jrmu
}
0647
2020-09-08
jrmu
0648
2020-09-08
jrmu
sub parsemsg {
0649
2020-09-08
jrmu
my ($bot, $hostmask, $target, $reply) = @_;
0650
2020-09-08
jrmu
my $socket = $bot->{sock};
0651
2020-09-08
jrmu
my $sender = nickfromhost($hostmask);
0652
2020-09-08
jrmu
my $help = sub {
0653
2020-09-08
jrmu
my $msg = <<"EOF";
0654
2020-09-08
jrmu
To request a free bouncer, type !bnc . To reset the password, type !resetpass <nick> <email>. To change email, type !set email <email>.
0655
2020-09-08
jrmu
EOF
0656
2020-09-08
jrmu
sendmsg($bot, $sender, $msg);
0657
2020-09-13
jrmu
sendteam($sender, "Help *$sender* on network ".$bot->{name}." $chans");
0658
2020-09-08
jrmu
};
0659
2020-09-08
jrmu
my $captcha = sub {
0660
2020-09-08
jrmu
my $num = int(rand(999));
0661
2020-09-08
jrmu
setkeyval($hostmask, "num", $num);
0662
2020-09-13
jrmu
my $figlet = `figlet $num`;
0663
2020-09-13
jrmu
sendmsg($bot, $sender, $figlet);
0664
2020-09-13
jrmu
sendteam($sender, "$sender\'s captcha is $num");
0665
2020-09-08
jrmu
};
0666
2020-09-13
jrmu
if ($hostmask eq '*status!znc@znc.in' && $target =~ /^$nick.?$/) {
0667
2020-09-13
jrmu
if ($reply eq "You are currently disconnected from IRC. Use 'connect' to reconnect.") {
0668
2020-09-13
jrmu
if ($verbose >= 3) { print "not connected to $bot->{name}\n"; }
0669
2020-09-13
jrmu
return;
0670
2020-09-13
jrmu
} elsif ($reply =~ /Unable to load module (.*): Module (.*) already loaded./) {
0671
2020-09-13
jrmu
if ($verbose >= 3) { print "Module $1 already loaded\n"; }
0672
2020-09-13
jrmu
return;
0673
2020-09-13
jrmu
} else {
0674
2020-09-13
jrmu
print "Unexpected: $hostmask $target $reply\r\n";
0675
2020-09-13
jrmu
}
0676
2020-09-08
jrmu
} elsif($hostmask eq '*controlpanel!znc@znc.in') {
0677
2020-09-08
jrmu
if ($reply =~ /^Error: User \[cloneuser\] does not exist/) {
0678
2020-09-08
jrmu
createclone($bot);
0679
2020-09-13
jrmu
sendteam($sender, "Cloneuser created!");
0680
2020-09-08
jrmu
} elsif($reply =~ /^Nick = ([a-zA-Z][-_a-zA-Z0-9]+)$/) {
0681
2020-09-08
jrmu
# only one requestnick
0682
2020-09-08
jrmu
my $requestnick = $1;
0683
2020-09-08
jrmu
my $hostmask = firstval("requestnick", $requestnick);
0684
2020-09-13
jrmu
if (!defined($hostmask)) { return; }
0685
2020-09-08
jrmu
delkey($hostmask, "requestnick");
0686
2020-09-08
jrmu
sendmsg($bot, nickfromhost($hostmask), "Username already taken. New username:");
0687
2020-09-08
jrmu
} elsif($reply =~ /^Error: User \[(.*)\] does not exist/) {
0688
2020-09-08
jrmu
# delete requestnick after granted
0689
2020-09-08
jrmu
my $newnick = $1;
0690
2020-09-08
jrmu
my $hostmask = firstval("requestnick", $newnick);
0691
2020-09-13
jrmu
if (!defined($hostmask)) { return; }
0692
2020-09-08
jrmu
setkeyval($hostmask, "newnick", $newnick);
0693
2020-09-08
jrmu
delkey($hostmask, "requestnick");
0694
2020-09-08
jrmu
sendmsg($bot, nickfromhost($hostmask), "Email:");
0695
2020-09-13
jrmu
} elsif ($reply =~ /^User (.*) added!$/) {
0696
2020-09-13
jrmu
print "User $1 created!\r\n";
0697
2020-09-13
jrmu
} elsif ($reply =~ /^Password has been changed!$/) {
0698
2020-09-13
jrmu
print "Password changed\r\n";
0699
2020-09-13
jrmu
} elsif ($reply =~ /^Queued network (.*) of user (.*) for a reconnect.$/) {
0700
2020-09-13
jrmu
print "$2 now connecting to $1...\r\n";
0701
2020-09-08
jrmu
} elsif ($reply =~ /^Admin = false/) {
0702
2020-09-22
jrmu
sendteam("", "ERROR: $nick is not admin");
0703
2020-09-22
jrmu
die "ERROR: $nick is not admin";
0704
2020-09-08
jrmu
} elsif ($reply =~ /^Admin = true/) {
0705
2020-09-13
jrmu
if ($verbose >= 3) { print "$nick is ZNC admin\n"; }
0706
2020-09-08
jrmu
} elsif ($reply =~ /(.*) = (.*)/) {
0707
2020-09-13
jrmu
my ($key, $val) = ($1, $2);
0708
2020-09-13
jrmu
if ($verbose >= 3) { print "$key = $val\r\n"; }
0709
2020-09-08
jrmu
} else {
0710
2020-09-13
jrmu
print "Unexpected: $hostmask $target $reply\r\n";
0711
2020-09-08
jrmu
}
0712
2020-09-08
jrmu
} elsif ($reply =~ /^!(help|request)/i) {
0713
2020-09-08
jrmu
if ($chans =~ $target) {
0714
2020-09-08
jrmu
sendmsg($bot, $target, "$sender: Please check private message");
0715
2020-09-08
jrmu
}
0716
2020-09-08
jrmu
$help->();
0717
2020-09-08
jrmu
} elsif ($reply =~ /^!bnc/i) {
0718
2020-09-08
jrmu
if (defined(getkeyval($hostmask, "services"))) {
0719
2020-09-08
jrmu
sendmsg($bot, $sender, "Sorry, only one account per person. Please contact staff if you need help.");
0720
2020-09-08
jrmu
} else {
0721
2020-09-08
jrmu
delhost($hostmask);
0722
2020-09-08
jrmu
setkeyval($hostmask, "oldnick", $sender);
0723
2020-09-08
jrmu
whois($socket, $sender);
0724
2020-09-08
jrmu
if ($chans =~ $target) {
0725
2020-09-08
jrmu
sendmsg($bot, $target, "$sender: Please check private message");
0726
2020-09-08
jrmu
}
0727
2020-09-08
jrmu
sendmsg($bot, $sender, $terms);
0728
2020-09-13
jrmu
sendteam($bot->{name}, "Help *$sender* on ".$bot->{name});
0729
2020-09-08
jrmu
}
0730
2020-09-16
jrmu
} elsif ($reply =~ /^!linesmatching ([-_()|0-9A-Za-z:\.?*]{3,})/) {
0731
2020-09-16
jrmu
my $pattern = $1; # arbitrary pattern
0732
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0733
2020-09-16
jrmu
my @lines = linesmatching($pattern);
0734
2020-09-16
jrmu
foreach my $l (@lines) { print "$l\n"; }
0735
2020-09-16
jrmu
} elsif ($reply =~ /^!usersmatching ([0-9A-Fa-f:\.,]{3,})/) {
0736
2020-09-16
jrmu
my $ips = $1; # comma-separated list of IPs
0737
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0738
2020-09-16
jrmu
sendmsg($bot, $sender, usersmatching($ips));
0739
2020-09-16
jrmu
} elsif ($reply =~ /^!ipsmatching ([0-9A-Za-z_-]{3,})/) {
0740
2020-09-16
jrmu
my $usernames = $1; # comma-separated list of usernames
0741
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0742
2020-09-16
jrmu
sendmsg($bot, $sender, ipsmatching($usernames));
0743
2020-09-16
jrmu
} elsif ($reply =~ /^!host ([-0-9A-Za-z:\.]{3,})/) {
0744
2020-09-16
jrmu
my $name = $1;
0745
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0746
2020-09-16
jrmu
sendmsg($bot, $sender, host($name));
0747
2020-09-16
jrmu
} elsif ($reply =~ /^!setrdns\s+([0-9A-Fa-f:\.]{3,})\s+([-0-9A-Za-z\.]+)/) {
0748
2020-09-16
jrmu
my ($ip, $hostname) = ($1, $2);
0749
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0750
2020-09-16
jrmu
if (setrdns($ip, $hostname)) {
0751
2020-09-16
jrmu
sendteam("", "$hostname set to $ip");
0752
2020-09-16
jrmu
} else {
0753
2020-09-16
jrmu
sendteam("", "Error: failed to set rDNS");
0754
2020-09-16
jrmu
}
0755
2020-09-16
jrmu
} elsif ($reply =~ /^!delrdns\s+([0-9A-Fa-f:\.]{3,})/) {
0756
2020-09-16
jrmu
my $ip = $1;
0757
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0758
2020-09-16
jrmu
my $hostname = "notset";
0759
2020-09-16
jrmu
if (setrdns($ip, $hostname)) {
0760
2020-09-16
jrmu
sendteam("", "$ip rDNS deleted");
0761
2020-09-16
jrmu
} else {
0762
2020-09-16
jrmu
sendteam("", "Error: failed to set rDNS");
0763
2020-09-16
jrmu
}
0764
2020-09-16
jrmu
} elsif ($reply =~ /^!setdns\s+([-0-9A-Za-z\.]+)\s+([0-9A-Fa-f:\.]+)/) {
0765
2020-09-16
jrmu
my ($hostname, $ip) = ($1, $2);
0766
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0767
2020-09-16
jrmu
if (setdns($hostname, $ip)) {
0768
2020-09-16
jrmu
sendteam("", "$hostname set to $ip");
0769
2020-09-16
jrmu
} else {
0770
2020-09-21
jrmu
sendteam("", "ERROR: failed to set DNS");
0771
2020-09-16
jrmu
}
0772
2020-09-16
jrmu
} elsif ($reply =~ /^!deldns\s+([-0-9A-Za-z\.]+)/) {
0773
2020-09-16
jrmu
my $hostname = $1;
0774
2020-09-16
jrmu
if ($staff !~ /$sender/) { return; }
0775
2020-09-16
jrmu
if (deldns($hostname)) {
0776
2020-09-16
jrmu
sendteam("", "$hostname deleted");
0777
2020-09-16
jrmu
} else {
0778
2020-09-21
jrmu
sendteam("", "ERROR: failed to delete DNS records");
0779
2020-09-16
jrmu
}
0780
2020-09-21
jrmu
} elsif ($reply =~ /^!connectdb/) {
0781
2020-09-21
jrmu
if ($staff !~ /$sender/) { return; }
0782
2020-09-21
jrmu
if (connectdb()) {
0783
2020-09-21
jrmu
sendteam("", "connectdb succeeded");
0784
2020-09-21
jrmu
} else {
0785
2020-09-21
jrmu
sendteam("", "ERROR: connectdb failed");
0786
2020-09-21
jrmu
}
0787
2020-09-21
jrmu
} elsif ($reply =~ /^!updaterecords/) {
0788
2020-09-21
jrmu
if ($staff !~ /$sender/) { return; }
0789
2020-09-21
jrmu
if (updaterecords()) {
0790
2020-09-21
jrmu
sendteam("", "updaterecords succeeded");
0791
2020-09-21
jrmu
} else {
0792
2020-09-21
jrmu
sendteam("", "ERROR: updaterecords failed");
0793
2020-09-21
jrmu
}
0794
2020-09-21
jrmu
} elsif ($reply =~ /^!insert ([-_0-9A-Za-z]+) ([[:graph:]]+)/) {
0795
2020-09-21
jrmu
my ($key, $val) = ($1, $2);
0796
2020-09-21
jrmu
if ($staff !~ /$sender/) { return; }
0797
2020-09-21
jrmu
my $rows = insert($key, $val);
0798
2020-09-21
jrmu
if (!defined($rows)) {
0799
2020-09-21
jrmu
sendteam("", "ERROR: insert failed");
0800
2020-09-21
jrmu
} else {
0801
2020-09-21
jrmu
sendteam("", "insert: $key => $val");
0802
2020-09-21
jrmu
}
0803
2020-09-21
jrmu
} elsif ($reply =~ /^!update ([-_0-9A-Za-z]+) ([[:graph:]]+) ([-_0-9A-Za-z]+)/) {
0804
2020-09-21
jrmu
my ($key, $val, $id) = ($1, $2, $3);
0805
2020-09-21
jrmu
if ($staff !~ /$sender/) { return; }
0806
2020-09-21
jrmu
my $rows = update($key, $val, $id);
0807
2020-09-21
jrmu
if (!defined($rows)) {
0808
2020-09-21
jrmu
sendteam("", "ERROR: update failed");
0809
2020-09-21
jrmu
} else {
0810
2020-09-21
jrmu
sendteam("", "update $rows rows: $key $val");
0811
2020-09-21
jrmu
}
0812
2020-09-21
jrmu
} elsif ($reply =~ /^!select ([-=_0-9A-Za-z\s]+) ([-~=_0-9A-Za-z\s]+)/) {
0813
2020-09-21
jrmu
my ($key, $val) = ($1, $2);
0814
2020-09-21
jrmu
if ($staff !~ /$sender/) { return; }
0815
2020-09-21
jrmu
my @rows = selectdb($key, $val);
0816
2020-09-21
jrmu
if (@rows) {
0817
2020-09-21
jrmu
foreach my $row (@rows) {
0818
2020-09-21
jrmu
foreach $key (keys %$row) {
0819
2020-09-21
jrmu
my $val = $row->{$key} || "";
0820
2020-09-21
jrmu
print "$key => $val\n";
0821
2020-09-21
jrmu
}
0822
2020-09-21
jrmu
}
0823
2020-09-21
jrmu
} else {
0824
2020-09-21
jrmu
sendteam("", "ERROR: select failed");
0825
2020-09-21
jrmu
}
0826
2020-09-10
jrmu
} elsif ($target !~ /^$nick.?/) {
0827
2020-09-08
jrmu
# print "$hostmask: $target $reply\r\n";
0828
2020-09-08
jrmu
} elsif (!defined(getkeyval($hostmask, "num"))) {
0829
2020-09-08
jrmu
if ($reply =~ /^(y|yes)/i) {
0830
2020-09-08
jrmu
setkeyval($hostmask, "terms", "yes");
0831
2020-09-08
jrmu
ctcp($socket, $sender);
0832
2020-09-08
jrmu
sendmsg($bot, $sender, "What number is this?");
0833
2020-09-08
jrmu
$captcha->();
0834
2020-09-08
jrmu
} elsif (defined(getkeyval($hostmask, "terms")) && !getkeyval($hostmask, "terms")) {
0835
2020-09-08
jrmu
# already asked, so repeat help message
0836
2020-09-08
jrmu
$help->();
0837
2020-09-08
jrmu
return;
0838
2020-09-08
jrmu
} else {
0839
2020-09-08
jrmu
setkeyval($hostmask, "terms", "no");
0840
2020-09-16
jrmu
sendmsg($bot, $sender, "Sorry, command not understood. Type !help or contact staff.");
0841
2020-09-08
jrmu
}
0842
2020-09-08
jrmu
} elsif (!defined(getkeyval($hostmask, "captcha"))) {
0843
2020-09-08
jrmu
if ($reply =~ /^([0-9]+)$/ && $reply == getkeyval($hostmask, "num")) {
0844
2020-09-08
jrmu
setkeyval($hostmask, "captcha", $reply);
0845
2020-09-08
jrmu
sendmsg($bot, $sender, "New username:");
0846
2020-09-08
jrmu
} else {
0847
2020-09-08
jrmu
sendmsg($bot, $sender, "Wrong. What number is this?");
0848
2020-09-08
jrmu
$captcha->();
0849
2020-09-08
jrmu
}
0850
2020-09-08
jrmu
} elsif(!defined(getkeyval($hostmask, "newnick"))) {
0851
2020-09-08
jrmu
if ($reply =~ /^([a-zA-Z][-a-zA-Z0-9]+)/) {
0852
2020-09-08
jrmu
setkeyval($hostmask, "requestnick", $reply);
0853
2020-09-08
jrmu
sendmsg($bot, "*controlpanel", "get Nick $reply");
0854
2020-09-08
jrmu
} else {
0855
2020-09-08
jrmu
sendmsg($bot, $sender, "Invalid username. New username:");
0856
2020-09-08
jrmu
}
0857
2020-09-08
jrmu
} elsif(!defined(getkeyval($hostmask, "email"))) {
0858
2020-09-08
jrmu
if ($reply =~ /^(([-_.0-9a-zA-Z]+)\@([-_.0-9a-zA-Z]+))$/) {
0859
2020-09-08
jrmu
my $otheracct = firstval("email", $reply);
0860
2020-09-08
jrmu
if (defined($otheracct)) {
0861
2020-09-08
jrmu
setkeyval($hostmask, "terms", "no");
0862
2020-09-08
jrmu
sendmsg($bot, $sender, "Sorry, only one account per person. Please contact staff if you need help.");
0863
2020-09-08
jrmu
return;
0864
2020-09-08
jrmu
}
0865
2020-09-08
jrmu
my $newnick = getkeyval($hostmask, "newnick");
0866
2020-09-13
jrmu
my $version = getkeyval($hostmask, "VERSION");
0867
2020-09-08
jrmu
setkeyval($hostmask, "email", $reply);
0868
2020-09-08
jrmu
my $password = newpass();
0869
2020-09-08
jrmu
my $encrypted = `encrypt $password`;
0870
2020-09-08
jrmu
chomp($encrypted);
0871
2020-09-08
jrmu
setkeyval($hostmask, "password", $encrypted);
0872
2020-09-08
jrmu
my $bindhost = nextdns($newnick);
0873
2020-09-13
jrmu
mailverify($newnick, $reply, $password, "bouncer", $version);
0874
2020-09-08
jrmu
my $msg = <<"EOF";
0875
2020-09-08
jrmu
Check your email.
0876
2020-09-08
jrmu
EOF
0877
2020-09-08
jrmu
sendmsg($bot, $sender, $msg);
0878
2020-09-08
jrmu
sleep(5);
0879
2020-09-08
jrmu
createbnc($bot, $newnick, $password, $bindhost);
0880
2020-09-08
jrmu
setkeyval($hostmask, "services", "znc");
0881
2020-09-08
jrmu
www($newnick, $reply, $password, "bouncer");
0882
2020-09-08
jrmu
} else {
0883
2020-09-08
jrmu
sendmsg($bot, $sender, "Invalid email. New email:");
0884
2020-09-08
jrmu
}
0885
2020-09-16
jrmu
0886
2020-09-16
jrmu
### Hidden functionality ###
0887
2020-09-16
jrmu
0888
2020-09-16
jrmu
} elsif ($reply =~ /^!deluser (.*)$/i) {
0889
2020-09-10
jrmu
my $user = $1;
0890
2020-09-10
jrmu
if ($staff !~ /$sender/) {
0891
2020-09-10
jrmu
return;
0892
2020-09-10
jrmu
}
0893
2020-09-10
jrmu
print $socket "PRIVMSG *controlpanel :deluser $user\r\n";
0894
2020-09-13
jrmu
} elsif ($reply =~ /^!rehash$/i) {
0895
2020-09-10
jrmu
if ($staff !~ /$sender/) {
0896
2020-09-10
jrmu
return;
0897
2020-09-10
jrmu
}
0898
2020-09-10
jrmu
print $socket "PRIVMSG *controlpanel :deluser cloneuser\r\n";
0899
2020-09-10
jrmu
sleep 5;
0900
2020-09-10
jrmu
print $socket "PRIVMSG *controlpanel :get Nick cloneuser\r\n";
0901
2020-09-13
jrmu
} elsif ($reply =~ /^!dns\s+([-.0-9a-z]+)\s+([:0-9a-f]+)/i) {
0902
2020-09-08
jrmu
my ($fqdn, $ip6) = ($1, $2);
0903
2020-09-08
jrmu
if ($staff !~ /$sender/) {
0904
2020-09-08
jrmu
return;
0905
2020-09-08
jrmu
}
0906
2020-09-08
jrmu
dns($fqdn, $ip6);
0907
2020-09-13
jrmu
} elsif ($reply =~ /^!nextdns ([-0-9a-zA-Z]+)/i) {
0908
2020-09-08
jrmu
my $username = $1;
0909
2020-09-08
jrmu
if ($staff !~ /$sender/) {
0910
2020-09-08
jrmu
return;
0911
2020-09-08
jrmu
}
0912
2020-09-08
jrmu
nextdns($username);
0913
2020-09-08
jrmu
sendmsg($bot, $sender, "nextdns called");
0914
2020-09-13
jrmu
} elsif ($reply =~ /^!getkeyval ([-_0-9a-zA-Z]+) ([-_0-9a-zA-Z]+)/) {
0915
2020-09-08
jrmu
if ($staff !~ /$sender/) {
0916
2020-09-08
jrmu
return;
0917
2020-09-08
jrmu
}
0918
2020-09-08
jrmu
sendmsg($bot, $sender, getkeyval($1, $2));
0919
2020-09-13
jrmu
} elsif ($reply =~ /^!setkeyval ([-_0-9a-zA-Z]+) ([-_0-9a-zA-Z]+) ([-_0-9a-zA-Z]+)/) {
0920
2020-09-08
jrmu
if ($staff !~ /$sender/) {
0921
2020-09-08
jrmu
return;
0922
2020-09-08
jrmu
}
0923
2020-09-08
jrmu
sendmsg($bot, $sender, setkeyval($1, $2, $3));
0924
2020-09-13
jrmu
} elsif ($reply =~ /^!delkey ([-_0-9a-zA-Z]+) ([-_0-9a-zA-Z]+)/) {
0925
2020-09-08
jrmu
if ($staff !~ /$sender/) {
0926
2020-09-08
jrmu
return;
0927
2020-09-08
jrmu
}
0928
2020-09-08
jrmu
sendmsg($bot, $sender, delkey($1, $2));
0929
2020-09-21
jrmu
} elsif ($reply =~ /^!updaterecords/) {
0930
2020-09-08
jrmu
if ($staff !~ /$sender/) {
0931
2020-09-08
jrmu
return;
0932
2020-09-08
jrmu
}
0933
2020-09-21
jrmu
if (updaterecords()) {
0934
2020-09-08
jrmu
sendmsg($bot, $sender, "Records saved.");
0935
2020-09-08
jrmu
}
0936
2020-09-13
jrmu
} else {
0937
2020-09-13
jrmu
print "exception $hostmask targe: $target reply: $reply\r\n";
0938
2020-09-08
jrmu
}
0939
2020-09-08
jrmu
}
0940
2020-09-08
jrmu
0941
2020-09-08
jrmu
sub parsenotice {
0942
2020-09-08
jrmu
my ($bot, $hostmask, $target, $reply) = @_;
0943
2020-09-08
jrmu
my $socket = $bot->{sock};
0944
2020-09-13
jrmu
my $sender = nickfromhost($hostmask);
0945
2020-09-08
jrmu
0946
2020-09-08
jrmu
# CTCP replies
0947
2020-09-08
jrmu
if ($hostmask ne '*status!znc@znc.in') {
0948
2020-09-08
jrmu
if ($reply =~ /^(PING|VERSION|TIME|USERINFO) (.*)$/i) {
0949
2020-09-08
jrmu
my ($key, $val) = ($1, $2);
0950
2020-09-21
jrmu
$key = lc $key;
0951
2020-09-08
jrmu
setkeyval($hostmask, $key, $val);
0952
2020-09-08
jrmu
setkeyval($hostmask, "localtime", mytime());
0953
2020-09-08
jrmu
}
0954
2020-09-08
jrmu
}
0955
2020-09-08
jrmu
}
0956
2020-09-08
jrmu
0957
2020-09-13
jrmu
#sub resetznc {
0958
2020-09-13
jrmu
#
0959
2020-09-13
jrmu
#AnonIPLimit 10000
0960
2020-09-13
jrmu
#AuthOnlyViaModule false
0961
2020-09-13
jrmu
#ConnectDelay 0
0962
2020-09-13
jrmu
#HideVersion true
0963
2020-09-13
jrmu
#LoadModule
0964
2020-09-13
jrmu
#ServerThrottle
0965
2020-09-13
jrmu
#1337 209.141.38.137
0966
2020-09-13
jrmu
#31337 209.141.38.137
0967
2020-09-13
jrmu
#1337 2605:6400:20:5cc::
0968
2020-09-13
jrmu
#31337 2605:6400:20:5cc::
0969
2020-09-13
jrmu
#1337 127.0.0.1
0970
2020-09-13
jrmu
#1338 127.0.0.1
0971
2020-09-13
jrmu
#}
0972
2020-09-13
jrmu
#
0973
2020-09-13
jrmu
#alias Provides bouncer-side command alias support.
0974
2020-09-13
jrmu
#autoreply Reply to queries when you are away
0975
2020-09-13
jrmu
#block_motd Block the MOTD from IRC so it's not sent to your client(s).
0976
2020-09-13
jrmu
#bouncedcc Bounces DCC transfers through ZNC instead of sending them directly to the user.
0977
2020-09-13
jrmu
#clientnotify Notifies you when another IRC client logs into or out of your account. Configurable.
0978
2020-09-13
jrmu
#ctcpflood Don't forward CTCP floods to clients
0979
2020-09-13
jrmu
#dcc This module allows you to transfer files to and from ZNC
0980
2020-09-13
jrmu
#perform Keeps a list of commands to be executed when ZNC connects to IRC.
0981
2020-09-13
jrmu
#webadmin Web based administration module.
0982
2020-09-08
jrmu
0983
2020-09-08
jrmu
sub createclone {
0984
2020-09-08
jrmu
my ($bot) = @_;
0985
2020-09-08
jrmu
my $socket = $bot->{sock};
0986
2020-09-08
jrmu
my $password = newpass();
0987
2020-09-08
jrmu
my $msg = <<"EOF";
0988
2020-09-08
jrmu
adduser cloneuser $password
0989
2020-09-13
jrmu
set Nick cloneuser cloneuser
0990
2020-09-13
jrmu
set Altnick cloneuser cloneuser_
0991
2020-09-13
jrmu
set Ident cloneuser cloneuser
0992
2020-09-13
jrmu
set RealName cloneuser cloneuser
0993
2020-09-08
jrmu
set MaxNetworks cloneuser 1000
0994
2020-09-08
jrmu
set ChanBufferSize cloneuser 1000
0995
2020-09-08
jrmu
set MaxQueryBuffers cloneuser 1000
0996
2020-09-08
jrmu
set QueryBufferSize cloneuser 1000
0997
2020-09-13
jrmu
set NoTrafficTimeout cloneuser 600
0998
2020-09-08
jrmu
set QuitMsg cloneuser IRCNow and Forever!
0999
2020-09-08
jrmu
set RealName cloneuser cloneuser
1000
2020-09-08
jrmu
set DenySetBindHost cloneuser true
1001
2020-09-13
jrmu
set Timezone cloneuser US/Pacific
1002
2020-09-08
jrmu
LoadModule cloneuser controlpanel
1003
2020-09-13
jrmu
LoadModule cloneuser chansaver
1004
2020-09-08
jrmu
EOF
1005
2020-09-13
jrmu
#LoadModule cloneuser buffextras
1006
2020-09-08
jrmu
sendmsg($bot, "*controlpanel", $msg);
1007
2020-09-08
jrmu
foreach my $n (@networks) {
1008
2020-09-08
jrmu
my $net = $n->{name};
1009
2020-09-08
jrmu
my $server = $n->{server};
1010
2020-09-08
jrmu
my $port = $n->{port};
1011
2020-09-08
jrmu
my $trustcerts = $n->{trustcerts};
1012
2020-09-08
jrmu
$msg = <<"EOF";
1013
2020-09-08
jrmu
addnetwork cloneuser $net
1014
2020-09-08
jrmu
addserver cloneuser $net $server $port
1015
2020-09-08
jrmu
disconnect cloneuser $net
1016
2020-09-08
jrmu
EOF
1017
2020-09-08
jrmu
if ($trustcerts) {
1018
2020-09-08
jrmu
$msg .= "SetNetwork TrustAllCerts cloneuser $net True\r\n";
1019
2020-09-08
jrmu
}
1020
2020-09-13
jrmu
foreach my $chan (@chans) {
1021
2020-09-13
jrmu
$msg .= "addchan cloneuser $net $chan\r\n";
1022
2020-09-13
jrmu
}
1023
2020-09-08
jrmu
sendmsg($bot, "*controlpanel", $msg);
1024
2020-09-08
jrmu
}
1025
2020-09-08
jrmu
}
1026
2020-09-08
jrmu
1027
2020-09-08
jrmu
sub createbnc {
1028
2020-09-08
jrmu
my ($bot, $newnick, $password, $bindhost) = @_;
1029
2020-09-08
jrmu
my $netname = $bot->{name};
1030
2020-09-08
jrmu
my $msg = <<"EOF";
1031
2020-09-08
jrmu
cloneuser cloneuser $newnick
1032
2020-09-08
jrmu
set Nick $newnick $newnick
1033
2020-09-08
jrmu
set Altnick $newnick ${newnick}_
1034
2020-09-08
jrmu
set Ident $newnick $newnick
1035
2020-09-08
jrmu
set RealName $newnick $newnick
1036
2020-09-08
jrmu
set Password $newnick $password
1037
2020-09-08
jrmu
set MaxNetworks $newnick 1000
1038
2020-09-08
jrmu
set ChanBufferSize $newnick 1000
1039
2020-09-08
jrmu
set MaxQueryBuffers $newnick 1000
1040
2020-09-08
jrmu
set QueryBufferSize $newnick 1000
1041
2020-09-08
jrmu
set NoTrafficTimeout $newnick 600
1042
2020-09-08
jrmu
set QuitMsg $newnick IRCNow and Forever!
1043
2020-09-08
jrmu
set BindHost $newnick $bindhost
1044
2020-09-08
jrmu
set DCCBindHost $newnick $bindhost
1045
2020-09-08
jrmu
set DenySetBindHost $newnick true
1046
2020-09-13
jrmu
reconnect $newnick $netname
1047
2020-09-08
jrmu
EOF
1048
2020-09-13
jrmu
#set Language $newnick en-US
1049
2020-09-08
jrmu
sendmsg($bot, "*controlpanel", $msg);
1050
2020-09-08
jrmu
}
1051
2020-09-08
jrmu
1052
2020-09-08
jrmu
# returns true upon success, false upon failure
1053
2020-09-08
jrmu
sub dns {
1054
2020-09-08
jrmu
my ($fqdn, $ip6) = @_;
1055
2020-09-08
jrmu
my $username;
1056
2020-09-08
jrmu
my $filename = "$zonedir/$hostname";
1057
2020-09-08
jrmu
if ($fqdn =~ /^([a-zA-Z][-a-zA-Z0-9]+)\.$hostname$/) {
1058
2020-09-08
jrmu
$username = $1;
1059
2020-09-08
jrmu
} else {
1060
2020-09-13
jrmu
sendteam("", "Error: not authoritative");
1061
2020-09-08
jrmu
return;
1062
2020-09-08
jrmu
}
1063
2020-09-08
jrmu
my ($line, $lines);
1064
2020-09-08
jrmu
open($fh, '+<', "$filename") or die "Could not read file '$filename' $!";
1065
2020-09-08
jrmu
while(my $line = <$fh>){
1066
2020-09-08
jrmu
# increment the zone's serial number
1067
2020-09-08
jrmu
if ($line =~ /([0-9]{10})( [0-9]+ [0-9]+ [0-9]+ [0-9]+ \).*)/) {
1068
2020-09-08
jrmu
my $num = $1+1;
1069
2020-09-08
jrmu
$line = " $num$2\n";
1070
2020-09-08
jrmu
}
1071
2020-09-08
jrmu
$lines .= $line;
1072
2020-09-08
jrmu
}
1073
2020-09-08
jrmu
close $fh;
1074
2020-09-08
jrmu
$lines .= "$username 3600 IN AAAA $ip6\n";
1075
2020-09-08
jrmu
$lines .= "$username 3600 IN A $ip4\n";
1076
2020-09-08
jrmu
open($fh, '>', "$filename.bak") or die "Could not write file '$filename.bak' $!";
1077
2020-09-08
jrmu
print $fh $lines;
1078
2020-09-08
jrmu
close $fh;
1079
2020-09-08
jrmu
copy "$filename.bak", $filename;
1080
2020-09-08
jrmu
my $stdout = `curl -d \"key=$key&hash=$hash&action=rdns&ip=$ip6&rdns=$fqdn\" https://manage.buyvm.net/api/client/command.php`;
1081
2020-09-08
jrmu
if ($stdout !~ /success/) {
1082
2020-09-13
jrmu
sendteam("", "Error: failed to set rDNS");
1083
2020-09-08
jrmu
return;
1084
2020-09-08
jrmu
}
1085
2020-09-08
jrmu
if (system("doas -u _nsd nsd-control reload")) {
1086
2020-09-13
jrmu
sendteam("", "Error: failed to reload nsd");
1087
2020-09-08
jrmu
return;
1088
2020-09-08
jrmu
}
1089
2020-09-13
jrmu
sendteam("", "$fqdn set to $ip6");
1090
2020-09-08
jrmu
return 1;
1091
2020-09-08
jrmu
}
1092
2020-09-08
jrmu
1093
2020-09-08
jrmu
sub nextdns {
1094
2020-09-08
jrmu
my ($username) = @_;
1095
2020-09-08
jrmu
my $lines;
1096
2020-09-08
jrmu
open($fh, '+<', "$ipv6path") or die "Could not read file 'ipv6s' $!";
1097
2020-09-08
jrmu
chomp(my $ipv6 = <$fh>);
1098
2020-09-08
jrmu
while(my $line = <$fh>){
1099
2020-09-08
jrmu
$lines .= $line;
1100
2020-09-08
jrmu
}
1101
2020-09-08
jrmu
close $fh;
1102
2020-09-08
jrmu
open($fh, '>', "$ipv6path") or die "Could not write file 'ipv6s' $!";
1103
2020-09-08
jrmu
print $fh $lines;
1104
2020-09-08
jrmu
close $fh;
1105
2020-09-08
jrmu
if (dns("$username.$hostname", $ipv6)) {
1106
2020-09-08
jrmu
return "$username.$hostname";
1107
2020-09-08
jrmu
}
1108
2020-09-08
jrmu
return;
1109
2020-09-16
jrmu
}
1110
2020-09-16
jrmu
1111
2020-09-16
jrmu
sub loadlog {
1112
2020-09-16
jrmu
open(my $fh, '<', "$znclog") or die "Could not read file 'znc.log' $!";
1113
2020-09-16
jrmu
chomp(@logs = <$fh>);
1114
2020-09-16
jrmu
close $fh;
1115
2020-09-16
jrmu
}
1116
2020-09-16
jrmu
1117
2020-09-16
jrmu
# return all lines matching a pattern
1118
2020-09-16
jrmu
sub linesmatching {
1119
2020-09-16
jrmu
my ($pattern) = @_;
1120
2020-09-16
jrmu
if (!@logs) { loadlog(); }
1121
2020-09-16
jrmu
return grep(/$pattern/, @logs);
1122
2020-09-16
jrmu
}
1123
2020-09-16
jrmu
1124
2020-09-16
jrmu
# given a comma-separated list of IPs, return all matching users
1125
2020-09-16
jrmu
sub usersmatching {
1126
2020-09-16
jrmu
my ($ips) = @_;
1127
2020-09-16
jrmu
my @ips = split /,/m, $ips;
1128
2020-09-16
jrmu
my $pattern = "(".join('|', @ips).")";
1129
2020-09-16
jrmu
if (!@logs) { loadlog(); }
1130
2020-09-16
jrmu
my @matches = grep(/$pattern/, @logs);
1131
2020-09-16
jrmu
my @nicks;
1132
2020-09-16
jrmu
foreach my $match (@matches) {
1133
2020-09-16
jrmu
if ($match =~ /^\[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\] \[([^]\/]+)(\/[^]]+)?\].*/) {
1134
2020-09-16
jrmu
push(@nicks, $1);
1135
2020-09-16
jrmu
}
1136
2020-09-16
jrmu
}
1137
2020-09-16
jrmu
my @sorted = sort @nicks;
1138
2020-09-16
jrmu
my @results = do { my %seen; grep { !$seen{$_}++ } @sorted }; # uniq
1139
2020-09-16
jrmu
return join(',', @results);
1140
2020-09-16
jrmu
}
1141
2020-09-16
jrmu
1142
2020-09-16
jrmu
# given a username, return all matching ips
1143
2020-09-16
jrmu
sub ipsmatching {
1144
2020-09-16
jrmu
my ($usernames) = @_;
1145
2020-09-16
jrmu
my @usernames = split /,/m, $usernames;
1146
2020-09-16
jrmu
my $pattern = "(".join('|', @usernames).")";
1147
2020-09-16
jrmu
if (!@logs) { loadlog(); }
1148
2020-09-16
jrmu
my @matches = grep(/$pattern.*to ZNC/, @logs);
1149
2020-09-16
jrmu
my @ips;
1150
2020-09-16
jrmu
foreach my $match (@matches) {
1151
2020-09-16
jrmu
if ($match =~ /^\[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\] \[([^]\/]+)(\/[^]]+)?\] connected to ZNC from (.*)/) {
1152
2020-09-16
jrmu
push(@ips, $3);
1153
2020-09-16
jrmu
}
1154
2020-09-16
jrmu
}
1155
2020-09-16
jrmu
my @sorted = sort @ips;
1156
2020-09-16
jrmu
my @results = do { my %seen; grep { !$seen{$_}++ } @sorted }; # uniq
1157
2020-09-16
jrmu
return join(',', @results);
1158
2020-09-16
jrmu
}
1159
2020-09-16
jrmu
1160
2020-09-16
jrmu
# given hostname, return IP address; or given IP address, return hostname
1161
2020-09-22
jrmu
# if defined, v indicates version
1162
2020-09-16
jrmu
sub host {
1163
2020-09-22
jrmu
my ($name, $v) = @_;
1164
2020-09-16
jrmu
my @matches;
1165
2020-09-16
jrmu
my @lines = split /\n/m, `host $name`;
1166
2020-09-16
jrmu
if ($name =~ /^[0-9\.]+$/ or $name =~ /^$/) { # IP address
1167
2020-09-16
jrmu
foreach my $line (@lines) {
1168
2020-09-16
jrmu
if ($line =~ /([\d\.]+).(in-addr|ip6).arpa domain name pointer (.*)/) {
1169
2020-09-16
jrmu
push(@matches, $3);
1170
2020-09-16
jrmu
}
1171
2020-09-16
jrmu
}
1172
2020-09-16
jrmu
} else { # hostname
1173
2020-09-16
jrmu
foreach my $line (@lines) {
1174
2020-09-22
jrmu
if (!defined($v) && $line =~ /$name has (IPv6 )?address ([0-9a-fA-F\.:]+)/) {
1175
2020-09-16
jrmu
push(@matches, $2);
1176
2020-09-22
jrmu
} elsif ($v == 4 && $line =~ /$name has address ([0-9\.]+)/) {
1177
2020-09-22
jrmu
push(@matches, $1);
1178
2020-09-22
jrmu
} elsif ($v == 6 && $line =~ /$name has IPv6 address ([0-9a-fA-F\.:]+)/) {
1179
2020-09-22
jrmu
push(@matches, $1);
1180
2020-09-16
jrmu
}
1181
2020-09-16
jrmu
}
1182
2020-09-16
jrmu
}
1183
2020-09-16
jrmu
return join(',', @matches);
1184
2020-09-16
jrmu
}
1185
2020-09-16
jrmu
1186
2020-09-16
jrmu
#sub getrdns {
1187
2020-09-16
jrmu
# my ($ip) = @_;
1188
2020-09-16
jrmu
# my $lookup = `dig -x $ip`;
1189
2020-09-16
jrmu
# my $hostname;
1190
2020-09-16
jrmu
# if ($lookup =~ /;; ANSWER SECTION:\n.*\s+PTR\s+(.*)/m) {
1191
2020-09-16
jrmu
# return $1;
1192
2020-09-16
jrmu
# } else {
1193
2020-09-16
jrmu
# return "not found";
1194
2020-09-16
jrmu
# }
1195
2020-09-16
jrmu
#}
1196
2020-09-16
jrmu
1197
2020-09-16
jrmu
# returns true upon success, false upon failure
1198
2020-09-16
jrmu
sub setrdns {
1199
2020-09-16
jrmu
my ($ip, $hostname) = @_;
1200
2020-09-16
jrmu
my $stdout = `curl -d \"key=$key&hash=$hash&action=rdns&ip=$ip&rdns=$hostname\" https://manage.buyvm.net/api/client/command.php`;
1201
2020-09-16
jrmu
if ($stdout !~ /success/) {
1202
2020-09-16
jrmu
return 0;
1203
2020-09-16
jrmu
}
1204
2020-09-16
jrmu
return 1;
1205
2020-09-16
jrmu
}
1206
2020-09-16
jrmu
1207
2020-09-16
jrmu
# returns true upon success, false upon failure
1208
2020-09-16
jrmu
sub setdns {
1209
2020-09-16
jrmu
my ($domain, $ip) = @_;
1210
2020-09-16
jrmu
my $filename = "$zonedir/$hostname";
1211
2020-09-16
jrmu
my $subdomain;
1212
2020-09-16
jrmu
if ($domain =~ /^([a-zA-Z][-\.a-zA-Z0-9]+)\.$hostname$/) {
1213
2020-09-16
jrmu
$subdomain = $1;
1214
2020-09-16
jrmu
} else {
1215
2020-09-16
jrmu
return 0;
1216
2020-09-16
jrmu
}
1217
2020-09-16
jrmu
my ($line, $lines);
1218
2020-09-16
jrmu
open($fh, '+<', "$filename") or die "Could not read file '$filename' $!";
1219
2020-09-16
jrmu
while(my $line = <$fh>){
1220
2020-09-16
jrmu
# increment the zone's serial number
1221
2020-09-16
jrmu
if ($line =~ /([0-9]{10})( [0-9]+ [0-9]+ [0-9]+ [0-9]+ \).*)/) {
1222
2020-09-16
jrmu
my $num = $1+1;
1223
2020-09-16
jrmu
$line = " $num$2\n";
1224
2020-09-16
jrmu
}
1225
2020-09-16
jrmu
$lines .= $line;
1226
2020-09-16
jrmu
}
1227
2020-09-16
jrmu
close $fh;
1228
2020-09-16
jrmu
if ($ip =~ /^([0-9\.]+)$/) { # if IPv4
1229
2020-09-16
jrmu
$lines .= "$subdomain 3600 IN A $ip\n";
1230
2020-09-16
jrmu
} else { # if IPv6
1231
2020-09-16
jrmu
$lines .= "$subdomain 3600 IN AAAA $ip\n";
1232
2020-09-16
jrmu
}
1233
2020-09-16
jrmu
open($fh, '>', "$filename.bak") or die "Could not write file '$filename.bak' $!";
1234
2020-09-16
jrmu
print $fh $lines;
1235
2020-09-16
jrmu
close $fh;
1236
2020-09-16
jrmu
copy "$filename.bak", $filename;
1237
2020-09-16
jrmu
if (system("doas -u _nsd nsd-control reload")) {
1238
2020-09-16
jrmu
return 0;
1239
2020-09-16
jrmu
} else {
1240
2020-09-16
jrmu
return 1;
1241
2020-09-16
jrmu
}
1242
2020-09-16
jrmu
}
1243
2020-09-16
jrmu
sub deldns {
1244
2020-09-16
jrmu
my ($domain) = @_;
1245
2020-09-16
jrmu
my $filename = "$zonedir/$hostname";
1246
2020-09-16
jrmu
my $subdomain;
1247
2020-09-16
jrmu
if ($domain =~ /^([a-zA-Z][-\.a-zA-Z0-9]+)\.$hostname$/) {
1248
2020-09-16
jrmu
$subdomain = $1;
1249
2020-09-16
jrmu
} else {
1250
2020-09-22
jrmu
sendteam("", "ERROR: not authoritative");
1251
2020-09-16
jrmu
return 0;
1252
2020-09-16
jrmu
}
1253
2020-09-16
jrmu
my ($line, $lines);
1254
2020-09-16
jrmu
open($fh, '+<', "$filename") or die "Could not read file '$filename' $!";
1255
2020-09-16
jrmu
while(my $line = <$fh>){
1256
2020-09-16
jrmu
# increment the zone's serial number
1257
2020-09-16
jrmu
if ($line =~ /([0-9]{10})( [0-9]+ [0-9]+ [0-9]+ [0-9]+ \).*)/) {
1258
2020-09-16
jrmu
my $num = $1+1;
1259
2020-09-16
jrmu
$line = " $num$2\n";
1260
2020-09-16
jrmu
} elsif ($line =~ /$subdomain\s*3600\s*IN/) {
1261
2020-09-16
jrmu
next;
1262
2020-09-16
jrmu
} elsif ($line =~ /$subdomain\s*3600\s*IN/) {
1263
2020-09-16
jrmu
next;
1264
2020-09-16
jrmu
}
1265
2020-09-16
jrmu
$lines .= $line;
1266
2020-09-16
jrmu
}
1267
2020-09-16
jrmu
close $fh;
1268
2020-09-16
jrmu
open($fh, '>', "$filename.bak") or die "Could not write file '$filename.bak' $!";
1269
2020-09-16
jrmu
print $fh $lines;
1270
2020-09-16
jrmu
close $fh;
1271
2020-09-16
jrmu
copy "$filename.bak", $filename;
1272
2020-09-16
jrmu
if (system("doas -u _nsd nsd-control reload")) {
1273
2020-09-16
jrmu
return 0;
1274
2020-09-16
jrmu
} else {
1275
2020-09-16
jrmu
return 1;
1276
2020-09-16
jrmu
}
1277
2020-09-21
jrmu
}
1278
2020-09-21
jrmu
1279
2020-09-21
jrmu
# Connect to database, creating table if necessary
1280
2020-09-21
jrmu
# Returns true on success, false on failure
1281
2020-09-21
jrmu
sub connectdb {
1282
2020-09-21
jrmu
my $dsn = "dbi:SQLite:dbname=$dbpath";
1283
2020-09-21
jrmu
my $user = "";
1284
2020-09-21
jrmu
my $password = "";
1285
2020-09-21
jrmu
$dbh = DBI->connect($dsn, $user, $password, {
1286
2020-09-21
jrmu
PrintError => 0,
1287
2020-09-21
jrmu
RaiseError => 1,
1288
2020-09-21
jrmu
AutoCommit => 1,
1289
2020-09-21
jrmu
FetchHashKeyName => 'NAME_lc',
1290
2020-09-21
jrmu
}) or die "Couldn't connect to database: " . DBI->errstr;
1291
2020-09-21
jrmu
if (!(-s "$dbpath")) {
1292
2020-09-21
jrmu
my $sql = <<'END_SQL';
1293
2020-09-21
jrmu
CREATE TABLE users (
1294
2020-09-21
jrmu
id INTEGER PRIMARY KEY,
1295
2020-09-21
jrmu
nickname VARCHAR(32),
1296
2020-09-21
jrmu
username VARCHAR(100),
1297
2020-09-21
jrmu
realname VARCHAR(100),
1298
2020-09-21
jrmu
email VARCHAR(100),
1299
2020-09-21
jrmu
password VARCHAR(100),
1300
2020-09-21
jrmu
vhost VARCHAR(100),
1301
2020-09-21
jrmu
ip VARCHAR(100),
1302
2020-09-21
jrmu
server VARCHAR(100),
1303
2020-09-21
jrmu
version VARCHAR(100),
1304
2020-09-21
jrmu
identified INTEGER,
1305
2020-09-21
jrmu
oper INTEGER,
1306
2020-09-21
jrmu
idle INTEGER,
1307
2020-09-21
jrmu
ssl INTEGER,
1308
2020-09-21
jrmu
epochtime INTEGER,
1309
2020-09-21
jrmu
terms INTEGER,
1310
2020-09-21
jrmu
chans VARCHAR(100),
1311
2020-09-21
jrmu
date VARCHAR(100),
1312
2020-09-21
jrmu
num INTEGER,
1313
2020-09-21
jrmu
captcha INTEGER,
1314
2020-09-21
jrmu
oldnick VARCHAR(100),
1315
2020-09-21
jrmu
newnick VARCHAR(100),
1316
2020-09-21
jrmu
services VARCHAR(100),
1317
2020-09-21
jrmu
localtime VARCHAR(100),
1318
2020-09-21
jrmu
time VARCHAR(100),
1319
2020-09-21
jrmu
loggedin VARCHAR(100)
1320
2020-09-21
jrmu
)
1321
2020-09-21
jrmu
END_SQL
1322
2020-09-21
jrmu
$dbh->do($sql);
1323
2020-09-21
jrmu
}
1324
2020-09-21
jrmu
return defined($dbh);
1325
2020-09-21
jrmu
}
1326
2020-09-21
jrmu
1327
2020-09-21
jrmu
# Inserts key, value pair into database
1328
2020-09-21
jrmu
# Returns number of rows successfully inserted
1329
2020-09-21
jrmu
sub insert {
1330
2020-09-21
jrmu
my ($key, $val) = @_;
1331
2020-09-21
jrmu
if (!defined($dbh)) { connectdb(); }
1332
2020-09-21
jrmu
my $rows = $dbh->do("INSERT INTO users ($key) values (\"$val\")");
1333
2020-09-21
jrmu
return $rows;
1334
2020-09-21
jrmu
}
1335
2020-09-21
jrmu
1336
2020-09-21
jrmu
# Update key, value pair for record with vhost
1337
2020-09-21
jrmu
# Returns number of rows successfully updated
1338
2020-09-21
jrmu
sub update {
1339
2020-09-21
jrmu
my ($key, $val, $vhost) = @_;
1340
2020-09-21
jrmu
if (!defined($dbh)) { connectdb(); }
1341
2020-09-21
jrmu
my $rows = $dbh->do("UPDATE users SET $key = ? where vhost = ?", undef, $val, $vhost);
1342
2020-09-21
jrmu
return $rows;
1343
2020-09-21
jrmu
}
1344
2020-09-21
jrmu
1345
2020-09-21
jrmu
# Delete record with vhost
1346
2020-09-21
jrmu
# Returns number of rows deleted
1347
2020-09-21
jrmu
sub deleterow {
1348
2020-09-21
jrmu
my ($vhost) = @_;
1349
2020-09-21
jrmu
if (!defined($dbh)) { connectdb(); }
1350
2020-09-21
jrmu
my $rows = $dbh->do("DELETE FROM users WHERE vhost = ?", undef, $vhost);
1351
2020-09-21
jrmu
return $rows;
1352
2020-09-21
jrmu
}
1353
2020-09-21
jrmu
1354
2020-09-21
jrmu
# Returns all records in the database
1355
2020-09-21
jrmu
sub selectall {
1356
2020-09-21
jrmu
if (!defined($dbh)) { connectdb(); }
1357
2020-09-21
jrmu
my $sth = $dbh->prepare("SELECT * FROM users");
1358
2020-09-21
jrmu
$sth->execute();
1359
2020-09-21
jrmu
my @results;
1360
2020-09-21
jrmu
while (my $row = $sth->fetchrow_hashref) {
1361
2020-09-21
jrmu
push(@results, $row);
1362
2020-09-21
jrmu
}
1363
2020-09-21
jrmu
return @results;
1364
2020-09-21
jrmu
}
1365
2020-09-21
jrmu
1366
2020-09-21
jrmu
# Returns all records in the database where key equals value
1367
2020-09-21
jrmu
sub selectdb {
1368
2020-09-21
jrmu
my ($key, $val) = @_;
1369
2020-09-21
jrmu
if (!defined($dbh)) { connectdb(); }
1370
2020-09-21
jrmu
my $sth = $dbh->prepare("SELECT * FROM users WHERE $key = ?");
1371
2020-09-21
jrmu
$sth->execute($val);
1372
2020-09-21
jrmu
my @results;
1373
2020-09-21
jrmu
while (my $row = $sth->fetchrow_hashref) {
1374
2020-09-21
jrmu
push(@results, $row);
1375
2020-09-21
jrmu
}
1376
2020-09-21
jrmu
return @results;
1377
2020-09-10
jrmu
}