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