Blame
Date:
Sun Dec 27 01:56:09 2020 UTC
Message:
Updated p5-Class-DBI-SQLite-0.11p2
001
2020-10-11
jrmu
#!/usr/bin/perl
002
2020-10-11
jrmu
003
2020-10-11
jrmu
package BNC;
004
2020-10-11
jrmu
005
2020-10-11
jrmu
use strict;
006
2020-10-11
jrmu
use warnings;
007
2020-10-11
jrmu
use OpenBSD::Pledge;
008
2020-10-11
jrmu
use OpenBSD::Unveil;
009
2020-10-11
jrmu
use Data::Dumper;
010
2020-10-11
jrmu
use MIME::Base64;
011
2020-10-20
jrmu
use Digest::SHA qw(sha256_hex);
012
2020-10-11
jrmu
use lib './';
013
2020-11-15
jrmu
require "SQLite.pm";
014
2020-11-15
jrmu
require "Hash.pm";
015
2020-11-15
jrmu
require "DNS.pm";
016
2020-11-15
jrmu
require "Mail.pm";
017
2020-10-11
jrmu
018
2020-11-15
jrmu
my %conf = %main::conf;
019
2020-11-15
jrmu
my $chans = $conf{chans};
020
2020-11-15
jrmu
my $teamchans = $conf{teamchans};
021
2020-11-15
jrmu
my @teamchans = split /[,\s]+/m, $teamchans;
022
2020-11-15
jrmu
my $staff = $conf{staff};
023
2020-11-15
jrmu
my $zncdir = $conf{zncdir};
024
2020-11-15
jrmu
my $znclog = $conf{znclog} || "$zncdir/.znc/moddata/adminlog/znc.log";
025
2020-10-11
jrmu
my $captchaURL = "https://guava.ircnow.org/captcha.php?vhost=";
026
2020-11-15
jrmu
my $hostname = $conf{hostname};
027
2020-11-15
jrmu
my $terms = $conf{terms};
028
2020-10-11
jrmu
my @logs;
029
2020-11-15
jrmu
my $expires = $conf{expires};
030
2020-11-15
jrmu
my $sslport = $conf{sslport};
031
2020-11-15
jrmu
my $plainport = $conf{plainport};
032
2020-11-15
jrmu
my $mailfrom = $conf{mailfrom};
033
2020-11-15
jrmu
my $mailname = $conf{mailname};
034
2020-11-15
jrmu
my $zncconfpath = $conf{zncconfpath} || "$zncdir/.znc/configs/znc.conf";
035
2020-11-15
jrmu
my $znctree = { Node => "root" };
036
2020-11-15
jrmu
037
2020-10-23
jrmu
use constant {
038
2020-10-23
jrmu
NONE => 0,
039
2020-10-23
jrmu
ERRORS => 1,
040
2020-10-23
jrmu
WARNINGS => 2,
041
2020-10-23
jrmu
ALL => 3,
042
2020-10-23
jrmu
};
043
2020-10-23
jrmu
044
2020-11-17
jrmu
`doas chmod g+r /home/znc/home/znc/.znc/configs/znc.conf`;
045
2020-12-25
jrmu
`doas chown -R znc:daemon /home/znc/home/znc/.znc/`;
046
2020-11-15
jrmu
my @zncconf = main::readarray($zncconfpath);
047
2020-12-25
jrmu
$znctree;
048
2020-12-25
jrmu
my @users;
049
2020-12-25
jrmu
foreach my $line (@zncconf) {
050
2020-12-25
jrmu
if ($line =~ /<User (.*)>/) {
051
2020-12-25
jrmu
push(@users, $1);
052
2020-12-25
jrmu
}
053
2020-12-25
jrmu
}
054
2020-12-25
jrmu
#$znctree = parseml($znctree, @zncconf);
055
2020-11-15
jrmu
main::cbind("pub", "-", "bnc", \&mbnc);
056
2020-11-15
jrmu
main::cbind("msg", "-", "bnc", \&mbnc);
057
2020-11-15
jrmu
main::cbind("msg", "-", "regex", \&mregex);
058
2020-11-15
jrmu
main::cbind("msg", "-", "foreach", \&mforeach);
059
2020-11-15
jrmu
main::cbind("msgm", "-", "*", \&mcontrolpanel);
060
2020-11-15
jrmu
main::cbind("msg", "-", "taillog", \&mtaillog);
061
2020-11-15
jrmu
main::cbind("msg", "-", "lastseen", \&mlastseen);
062
2020-11-15
jrmu
063
2020-10-11
jrmu
sub init {
064
2020-10-23
jrmu
#znc.conf file
065
2020-10-23
jrmu
unveil("$zncconfpath", "r") or die "Unable to unveil $!";
066
2020-10-11
jrmu
#dependencies for figlet
067
2020-10-11
jrmu
unveil("/usr/local/bin/figlet", "rx") or die "Unable to unveil $!";
068
2020-10-11
jrmu
unveil("/usr/lib/libc.so.95.1", "r") or die "Unable to unveil $!";
069
2020-10-11
jrmu
unveil("/usr/libexec/ld.so", "r") or die "Unable to unveil $!";
070
2020-11-05
jrmu
unveil("/usr/bin/tail", "rx") or die "Unable to unveil $!";
071
2020-10-11
jrmu
#znc.log file
072
2020-10-11
jrmu
unveil("$znclog", "r") or die "Unable to unveil $!";
073
2020-10-23
jrmu
#print treeget($znctree, "AnonIPLimit")."\n";
074
2020-10-23
jrmu
#print treeget($znctree, "ServerThrottle")."\n";
075
2020-10-23
jrmu
#print treeget($znctree, "ConnectDelay")."\n";
076
2020-10-23
jrmu
#print "treeget\n";
077
2020-10-23
jrmu
#print Dumper \treeget($znctree, "User", "Node");
078
2020-10-23
jrmu
#print Dumper \treeget($znctree, "User", "Network", "Node");
079
2020-10-11
jrmu
}
080
2020-10-11
jrmu
081
2020-10-23
jrmu
# parseml($tree, @lines)
082
2020-10-23
jrmu
# tree is a reference to a hash
083
2020-10-23
jrmu
# returns hash ref of tree
084
2020-10-23
jrmu
sub parseml {
085
2020-10-23
jrmu
my ($tree, @lines) = @_;
086
2020-10-23
jrmu
#if (scalar(@lines) == 0) { return $tree; }
087
2020-10-23
jrmu
while (scalar(@lines) > 0) {
088
2020-10-23
jrmu
my $line = shift(@lines);
089
2020-10-23
jrmu
if ($line =~ /^\s*([^=<>\s]+)\s*=\s*([^=<>]+)\s*$/) {
090
2020-10-23
jrmu
my ($tag, $val) = ($1, $2);
091
2020-10-23
jrmu
$tree->{$tag} = $val;
092
2020-10-23
jrmu
} elsif ($line =~ /^\/\//) { # skip comments
093
2020-10-23
jrmu
} elsif ($line =~ /^\s*$/) { # skip blank lines
094
2020-10-23
jrmu
} elsif ($line =~ /^\s*<([^>\s\/]+)\s*([^>\/]*)>\s*$/) {
095
2020-10-23
jrmu
my ($tag, $val) = ($1, $2);
096
2020-10-23
jrmu
if (!defined($tree->{$tag})) { $tree->{$tag} = []; }
097
2020-10-23
jrmu
my @newlines;
098
2020-10-23
jrmu
while (scalar(@lines) > 0) {
099
2020-10-23
jrmu
my $line = shift(@lines);
100
2020-10-23
jrmu
if ($line =~ /^\s*<\/$tag>\s*$/) {
101
2020-10-23
jrmu
my $subtree = parseml({ Node => $val }, @newlines);
102
2020-10-23
jrmu
push(@{$tree->{$tag}}, $subtree);
103
2020-10-23
jrmu
return parseml($tree, @lines);
104
2020-10-23
jrmu
}
105
2020-10-23
jrmu
push(@newlines, $line);
106
2020-10-23
jrmu
}
107
2020-10-23
jrmu
} else { print "ERROR: $line\n"; }
108
2020-10-23
jrmu
#TODO ERRORS not defined??
109
2020-10-23
jrmu
# } else { main::debug(ERRORS, "ERROR: $line"); }
110
2020-10-20
jrmu
}
111
2020-10-23
jrmu
return $tree;
112
2020-10-23
jrmu
}
113
2020-10-23
jrmu
114
2020-10-23
jrmu
#Returns array of all values
115
2020-10-23
jrmu
#treeget($tree, "User");
116
2020-10-23
jrmu
#treeget($tree, "MaFFia Network");
117
2020-10-23
jrmu
sub treeget {
118
2020-10-23
jrmu
my ($tree, @keys) = @_;
119
2020-10-23
jrmu
my $subtree;
120
2020-10-23
jrmu
my @rest = @keys;
121
2020-10-23
jrmu
my $key = shift(@rest);
122
2020-10-23
jrmu
$subtree = $tree->{$key};
123
2020-10-23
jrmu
if (!defined($subtree)) {
124
2020-10-23
jrmu
return ("Undefined");
125
2020-10-23
jrmu
} elsif (ref($subtree) eq 'HASH') {
126
2020-10-23
jrmu
return treeget($subtree, @rest);
127
2020-10-23
jrmu
} elsif (ref($subtree) eq 'ARRAY') {
128
2020-10-23
jrmu
my @array = @{$subtree};
129
2020-10-23
jrmu
my @ret;
130
2020-10-23
jrmu
foreach my $hashref (@array) {
131
2020-10-23
jrmu
push(@ret, treeget($hashref, @rest));
132
2020-10-11
jrmu
}
133
2020-10-23
jrmu
return @ret;
134
2020-10-23
jrmu
#my @array = @{$subtree};
135
2020-10-23
jrmu
#print Dumper treeget($hashref, @rest);
136
2020-10-23
jrmu
#print Dumper treeget({$key => $subtree}, @rest);
137
2020-10-23
jrmu
#return (treeget($hashref, @rest), treeget({$key => $subtree}, @rest));
138
2020-10-11
jrmu
} else {
139
2020-10-23
jrmu
return ($subtree);
140
2020-10-11
jrmu
}
141
2020-10-11
jrmu
}
142
2020-10-15
jrmu
143
2020-10-15
jrmu
sub mbnc {
144
2020-10-11
jrmu
my ($bot, $nick, $host, $hand, @args) = @_;
145
2020-10-11
jrmu
my ($chan, $text);
146
2020-10-11
jrmu
if (@args == 2) {
147
2020-10-11
jrmu
($chan, $text) = ($args[0], $args[1]);
148
2020-10-11
jrmu
} else { $text = $args[0]; }
149
2020-10-11
jrmu
my $hostmask = "$nick!$host";
150
2020-10-15
jrmu
if (defined($chan) && $chans =~ /$chan/) {
151
2020-10-15
jrmu
main::putserv($bot, "PRIVMSG $chan :$nick: Please check private message");
152
2020-10-15
jrmu
}
153
2020-10-20
jrmu
if ($text =~ /^$/) {
154
2020-10-15
jrmu
main::putserv($bot, "PRIVMSG $nick :Type !help for new instructions");
155
2020-10-15
jrmu
foreach my $chan (@teamchans) {
156
2020-10-15
jrmu
main::putserv($bot, "PRIVMSG $chan :Help *$nick* on ".$bot->{name});
157
2020-10-15
jrmu
}
158
2020-10-20
jrmu
return;
159
2020-10-20
jrmu
} elsif ($staff =~ /$nick/ && $text =~ /^delete\s+([[:ascii:]]+)/) {
160
2020-10-20
jrmu
my $username = $1;
161
2020-10-20
jrmu
if (SQLite::deleterows("bnc", "username", $username)) {
162
2020-10-20
jrmu
main::putserv($bot, "PRIVMSG *controlpanel :deluser $username");
163
2020-10-20
jrmu
foreach my $chan (@teamchans) {
164
2020-10-20
jrmu
main::putserv($bot, "PRIVMSG $chan :$username deleted");
165
2020-10-15
jrmu
}
166
2020-10-20
jrmu
}
167
2020-10-20
jrmu
return;
168
2020-10-23
jrmu
} elsif ($staff =~ /$nick/ && $text =~ /^cloneuser$/i) {
169
2020-10-23
jrmu
main::putserv($bot, "PRIVMSG *controlpanel :deluser cloneuser");
170
2020-10-23
jrmu
sleep 3;
171
2020-10-23
jrmu
main::putserv($bot, "PRIVMSG *controlpanel :get Nick cloneuser");
172
2020-10-20
jrmu
}
173
2020-10-20
jrmu
### TODO: Check duplicate emails ###
174
2020-10-20
jrmu
my @rows = SQLite::selectrows("irc", "hostmask", $hostmask);
175
2020-10-20
jrmu
foreach my $row (@rows) {
176
2020-10-20
jrmu
my $password = SQLite::get("bnc", "ircid", $row->{id}, "password");
177
2020-10-20
jrmu
if (defined($password)) {
178
2020-10-20
jrmu
main::putserv($bot, "PRIVMSG $nick :Sorry, only one account per person. Please contact staff if you need help.");
179
2020-10-20
jrmu
return;
180
2020-10-20
jrmu
}
181
2020-10-20
jrmu
}
182
2020-10-20
jrmu
if ($text =~ /^captcha\s+([[:alnum:]]+)/) {
183
2020-10-20
jrmu
my $text = $1;
184
2020-11-15
jrmu
# TODO avoid using host mask because cloaking can cause problems
185
2020-11-15
jrmu
my $ircid = SQLite::id("irc", "nick", $nick, $expires);
186
2020-10-20
jrmu
my $captcha = SQLite::get("bnc", "ircid", $ircid, "captcha");
187
2020-10-20
jrmu
if ($text ne $captcha) {
188
2020-10-15
jrmu
main::putserv($bot, "PRIVMSG $nick :Wrong captcha. To get a new captcha, type !bnc <username> <email>");
189
2020-10-20
jrmu
return;
190
2020-10-15
jrmu
}
191
2020-10-20
jrmu
my $pass = Hash::newpass();
192
2020-10-20
jrmu
chomp(my $encrypted = `encrypt $pass`);
193
2020-10-20
jrmu
my $username = SQLite::get("bnc", "ircid", $ircid, "username");
194
2020-10-20
jrmu
my $email = SQLite::get("bnc", "ircid", $ircid, "email");
195
2020-10-20
jrmu
my $version = SQLite::get("bnc", "ircid", $ircid, "version");
196
2020-10-20
jrmu
my $bindhost = "$username.$hostname";
197
2020-10-20
jrmu
SQLite::set("bnc", "ircid", $ircid, "password", $encrypted);
198
2020-10-20
jrmu
if (DNS::nextdns($username)) {
199
2020-10-20
jrmu
sleep(2);
200
2020-10-20
jrmu
createbnc($bot, $username, $pass, $bindhost);
201
2020-10-20
jrmu
main::putserv($bot, "PRIVMSG $nick :Check your email!");
202
2020-10-20
jrmu
mailbnc($username, $email, $pass, "bouncer", $version);
203
2020-10-20
jrmu
#www($newnick, $reply, $password, "bouncer");
204
2020-10-20
jrmu
} else {
205
2020-10-11
jrmu
foreach my $chan (@teamchans) {
206
2020-10-20
jrmu
main::putserv($bot, "PRIVMSG $chan :Assigning bindhost $bindhost failed");
207
2020-10-11
jrmu
}
208
2020-10-11
jrmu
}
209
2020-10-20
jrmu
return;
210
2020-10-11
jrmu
} elsif ($text =~ /^([[:alnum:]]+)\s+([[:ascii:]]+)/) {
211
2020-10-11
jrmu
my ($username, $email) = ($1, $2);
212
2020-12-25
jrmu
# my @users = treeget($znctree, "User", "Node");
213
2020-10-23
jrmu
foreach my $user (@users) {
214
2020-10-23
jrmu
if ($user eq $username) {
215
2020-10-23
jrmu
main::putserv($bot, "PRIVMSG $nick :Sorry, username taken. Please contact staff if you need help.");
216
2020-10-23
jrmu
}
217
2020-10-23
jrmu
}
218
2020-10-23
jrmu
#my $captcha = join'', map +(0..9,'a'..'z','A'..'Z')[rand(10+26*2)], 1..4;
219
2020-10-20
jrmu
my $captcha = int(rand(999));
220
2020-10-20
jrmu
my $ircid = int(rand(2147483647));
221
2020-10-20
jrmu
SQLite::set("irc", "id", $ircid, "localtime", time());
222
2020-10-20
jrmu
SQLite::set("irc", "id", $ircid, "date", main::date());
223
2020-10-20
jrmu
SQLite::set("irc", "id", $ircid, "hostmask", $hostmask);
224
2020-10-20
jrmu
SQLite::set("irc", "id", $ircid, "nick", $nick);
225
2020-10-20
jrmu
SQLite::set("bnc", "ircid", $ircid, "username", $username);
226
2020-10-20
jrmu
SQLite::set("bnc", "ircid", $ircid, "email", $email);
227
2020-10-20
jrmu
SQLite::set("bnc", "ircid", $ircid, "captcha", $captcha);
228
2020-10-11
jrmu
main::whois($bot->{sock}, $nick);
229
2020-10-27
jrmu
main::ctcp($bot->{sock}, $nick);
230
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG $nick :".`figlet $captcha`);
231
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG $nick :$captchaURL".encode_base64($captcha));
232
2020-10-15
jrmu
main::putserv($bot, "PRIVMSG $nick :Type !bnc captcha <text>");
233
2020-10-11
jrmu
foreach my $chan (@teamchans) {
234
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG $chan :$nick\'s captcha is $captcha");
235
2020-10-11
jrmu
}
236
2020-10-11
jrmu
} else {
237
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG $nick :Invalid username or email. Type !bnc <username> <email> to try again.");
238
2020-10-11
jrmu
foreach my $chan (@teamchans) {
239
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG $chan :Help *$nick* on ".$bot->{name});
240
2020-10-11
jrmu
}
241
2020-10-11
jrmu
}
242
2020-10-11
jrmu
}
243
2020-10-11
jrmu
244
2020-10-11
jrmu
sub mregex {
245
2020-10-11
jrmu
my ($bot, $nick, $host, $hand, $text) = @_;
246
2020-10-11
jrmu
if ($staff !~ /$nick/) { return; }
247
2020-10-11
jrmu
if ($text =~ /^ips?\s+([-_()|0-9A-Za-z:\.?*\s]{3,})$/) {
248
2020-10-11
jrmu
my $ips = $1; # space-separated list of IPs
249
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG $nick :".regexlist($ips));
250
2020-10-11
jrmu
} elsif ($text =~ /^users?\s+([-_()|0-9A-Za-z:\.?*\s]{3,})$/) {
251
2020-10-11
jrmu
my $users = $1; # space-separated list of usernames
252
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG $nick :".regexlist($users));
253
2020-10-11
jrmu
} elsif ($text =~ /^[-_()|0-9A-Za-z:,\.?*\s]{3,}$/) {
254
2020-10-11
jrmu
my @lines = regex($text);
255
2020-10-11
jrmu
foreach my $l (@lines) { print "$l\n"; }
256
2020-10-11
jrmu
}
257
2020-10-11
jrmu
}
258
2020-10-11
jrmu
sub mforeach {
259
2020-10-11
jrmu
my ($bot, $nick, $host, $hand, $text) = @_;
260
2020-10-15
jrmu
if ($staff !~ /$nick/) { return; }
261
2020-10-11
jrmu
if ($text =~ /^network\s+del\s+([[:graph:]]+)\s+(#[[:graph:]]+)$/) {
262
2020-10-11
jrmu
my ($user, $chan) = ($1, $2);
263
2020-10-11
jrmu
foreach my $n (@main::networks) {
264
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG *controlpanel :delchan $user $n->{name} $chan");
265
2020-10-11
jrmu
}
266
2020-10-11
jrmu
}
267
2020-10-11
jrmu
}
268
2020-10-20
jrmu
269
2020-10-23
jrmu
sub mcontrolpanel {
270
2020-10-23
jrmu
my ($bot, $nick, $host, $hand, @args) = @_;
271
2020-10-23
jrmu
my ($chan, $text);
272
2020-10-23
jrmu
if (@args == 2) {
273
2020-10-23
jrmu
($chan, $text) = ($args[0], $args[1]);
274
2020-10-23
jrmu
} else { $text = $args[0]; }
275
2020-10-23
jrmu
my $hostmask = "$nick!$host";
276
2020-10-23
jrmu
if($hostmask eq '*controlpanel!znc@znc.in') {
277
2020-10-23
jrmu
if ($text =~ /^Error: User \[cloneuser\] does not exist/) {
278
2020-10-23
jrmu
createclone($bot);
279
2020-10-23
jrmu
foreach my $chan (@teamchans) {
280
2020-10-23
jrmu
main::putserv($bot, "PRIVMSG $chan :Cloneuser created");
281
2020-10-23
jrmu
}
282
2020-10-23
jrmu
} elsif ($text =~ /^User (.*) added!$/) {
283
2020-10-23
jrmu
main::debug(ALL, "User $1 created");
284
2020-10-23
jrmu
} elsif ($text =~ /^Password has been changed!$/) {
285
2020-10-23
jrmu
main::debug(ALL, "Password changed");
286
2020-10-23
jrmu
} elsif ($text =~ /^Queued network (.*) of user (.*) for a reconnect.$/) {
287
2020-10-23
jrmu
main::debug(ALL, "$2 now connecting to $1...");
288
2020-10-23
jrmu
} elsif ($text =~ /^Admin = false/) {
289
2020-10-23
jrmu
foreach my $chan (@teamchans) {
290
2020-10-23
jrmu
main::putserv($bot, "PRIVMSG $chan :ERROR: $nick is not admin");
291
2020-10-23
jrmu
}
292
2020-10-23
jrmu
die "ERROR: $nick is not admin";
293
2020-10-23
jrmu
} elsif ($text =~ /^Admin = true/) {
294
2020-10-23
jrmu
main::debug(ALL, "$nick is ZNC admin");
295
2020-10-23
jrmu
} elsif ($text =~ /(.*) = (.*)/) {
296
2020-10-23
jrmu
my ($key, $val) = ($1, $2);
297
2020-10-23
jrmu
main::debug(ALL, "ZNC: $key => $val");
298
2020-10-23
jrmu
} else {
299
2020-11-17
jrmu
main::debug(ERRORS, "Unexpected 290 BNC.pm: $hostmask $text");
300
2020-10-23
jrmu
}
301
2020-10-23
jrmu
}
302
2020-10-23
jrmu
}
303
2020-10-11
jrmu
sub loadlog {
304
2020-10-11
jrmu
open(my $fh, '<', "$znclog") or die "Could not read file 'znc.log' $!";
305
2020-10-11
jrmu
chomp(@logs = <$fh>);
306
2020-10-11
jrmu
close $fh;
307
2020-10-11
jrmu
}
308
2020-10-11
jrmu
309
2020-10-11
jrmu
# return all lines matching a pattern
310
2020-10-11
jrmu
sub regex {
311
2020-10-11
jrmu
my ($pattern) = @_;
312
2020-10-11
jrmu
if (!@logs) { loadlog(); }
313
2020-10-11
jrmu
return grep(/$pattern/, @logs);
314
2020-10-11
jrmu
}
315
2020-10-11
jrmu
316
2020-10-11
jrmu
# given a list of IPs, return matching users
317
2020-10-11
jrmu
# or given a list of users, return matching IPs
318
2020-10-11
jrmu
sub regexlist {
319
2020-10-11
jrmu
my ($items) = @_;
320
2020-10-11
jrmu
my @items = split /[,\s]+/m, $items;
321
2020-10-11
jrmu
my $pattern = "(".join('|', @items).")";
322
2020-10-11
jrmu
if (!@logs) { loadlog(); }
323
2020-10-11
jrmu
my @matches = grep(/$pattern/, @logs);
324
2020-10-11
jrmu
my @results;
325
2020-10-11
jrmu
foreach my $match (@matches) {
326
2020-10-11
jrmu
if ($match =~ /^\[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\] \[([^]\/]+)(\/[^]]+)?\] connected to ZNC from (.*)/) {
327
2020-10-11
jrmu
my ($user, $ip) = ($1, $3);
328
2020-10-11
jrmu
if ($items =~ /[.:]/) { # items are IP addresses
329
2020-10-11
jrmu
push(@results, $user);
330
2020-10-11
jrmu
} else { # items are users
331
2020-10-11
jrmu
push(@results, $ip);
332
2020-10-11
jrmu
}
333
2020-10-11
jrmu
}
334
2020-10-11
jrmu
}
335
2020-10-11
jrmu
my @sorted = sort @results;
336
2020-10-11
jrmu
@results = do { my %seen; grep { !$seen{$_}++ } @sorted }; # uniq
337
2020-10-11
jrmu
return join(' ', @results);
338
2020-10-11
jrmu
}
339
2020-10-11
jrmu
340
2020-10-11
jrmu
sub createclone {
341
2020-10-11
jrmu
my ($bot) = @_;
342
2020-10-11
jrmu
my $socket = $bot->{sock};
343
2020-10-15
jrmu
my $password = Hash::newpass();
344
2020-10-11
jrmu
my $msg = <<"EOF";
345
2020-10-11
jrmu
adduser cloneuser $password
346
2020-10-11
jrmu
set Nick cloneuser cloneuser
347
2020-10-11
jrmu
set Altnick cloneuser cloneuser_
348
2020-10-11
jrmu
set Ident cloneuser cloneuser
349
2020-10-11
jrmu
set RealName cloneuser cloneuser
350
2020-10-11
jrmu
set MaxNetworks cloneuser 1000
351
2020-10-11
jrmu
set ChanBufferSize cloneuser 1000
352
2020-10-11
jrmu
set MaxQueryBuffers cloneuser 1000
353
2020-10-11
jrmu
set QueryBufferSize cloneuser 1000
354
2020-10-11
jrmu
set NoTrafficTimeout cloneuser 600
355
2020-10-11
jrmu
set QuitMsg cloneuser IRCNow and Forever!
356
2020-10-11
jrmu
set RealName cloneuser cloneuser
357
2020-10-11
jrmu
set DenySetBindHost cloneuser true
358
2020-10-11
jrmu
set Timezone cloneuser US/Pacific
359
2020-10-11
jrmu
LoadModule cloneuser controlpanel
360
2020-10-11
jrmu
LoadModule cloneuser chansaver
361
2020-10-11
jrmu
EOF
362
2020-10-11
jrmu
#LoadModule cloneuser buffextras
363
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG *controlpanel :$msg");
364
2020-10-11
jrmu
foreach my $n (@main::networks) {
365
2020-10-11
jrmu
my $net = $n->{name};
366
2020-10-11
jrmu
my $server = $n->{server};
367
2020-10-11
jrmu
my $port = $n->{port};
368
2020-10-11
jrmu
my $trustcerts = $n->{trustcerts};
369
2020-10-11
jrmu
$msg = <<"EOF";
370
2020-10-11
jrmu
addnetwork cloneuser $net
371
2020-10-11
jrmu
addserver cloneuser $net $server $port
372
2020-10-11
jrmu
disconnect cloneuser $net
373
2020-10-11
jrmu
EOF
374
2020-10-11
jrmu
if ($trustcerts) {
375
2020-10-11
jrmu
$msg .= "SetNetwork TrustAllCerts cloneuser $net True\r\n";
376
2020-10-11
jrmu
}
377
2020-10-11
jrmu
my @chans = split /[,\s]+/m, $chans;
378
2020-10-11
jrmu
foreach my $chan (@chans) {
379
2020-10-11
jrmu
$msg .= "addchan cloneuser $net $chan\r\n";
380
2020-10-11
jrmu
}
381
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG *controlpanel :$msg");
382
2020-10-11
jrmu
}
383
2020-10-11
jrmu
}
384
2020-10-11
jrmu
385
2020-10-11
jrmu
sub createbnc {
386
2020-10-11
jrmu
my ($bot, $username, $password, $bindhost) = @_;
387
2020-10-11
jrmu
my $netname = $bot->{name};
388
2020-10-11
jrmu
my $msg = <<"EOF";
389
2020-10-11
jrmu
cloneuser cloneuser $username
390
2020-10-11
jrmu
set Nick $username $username
391
2020-10-11
jrmu
set Altnick $username ${username}_
392
2020-10-11
jrmu
set Ident $username $username
393
2020-10-11
jrmu
set RealName $username $username
394
2020-10-11
jrmu
set Password $username $password
395
2020-10-11
jrmu
set MaxNetworks $username 1000
396
2020-10-11
jrmu
set ChanBufferSize $username 1000
397
2020-10-11
jrmu
set MaxQueryBuffers $username 1000
398
2020-10-11
jrmu
set QueryBufferSize $username 1000
399
2020-10-11
jrmu
set NoTrafficTimeout $username 600
400
2020-10-11
jrmu
set QuitMsg $username IRCNow and Forever!
401
2020-10-11
jrmu
set BindHost $username $bindhost
402
2020-10-11
jrmu
set DCCBindHost $username $bindhost
403
2020-10-11
jrmu
set DenySetBindHost $username true
404
2020-10-11
jrmu
reconnect $username $netname
405
2020-10-11
jrmu
EOF
406
2020-10-11
jrmu
#set Language $username en-US
407
2020-10-11
jrmu
main::putserv($bot, "PRIVMSG *controlpanel :$msg");
408
2020-10-11
jrmu
return 1;
409
2020-10-11
jrmu
}
410
2020-10-20
jrmu
sub mailbnc {
411
2020-10-20
jrmu
my( $username, $email, $password, $service, $version )=@_;
412
2020-10-20
jrmu
my $passhash = sha256_hex("$username");
413
2020-10-20
jrmu
if ($version =~ /mIRC/) {
414
2020-10-20
jrmu
$version = "mIRC";
415
2020-10-20
jrmu
}
416
2020-10-20
jrmu
my $versionhash = encode_base64($version);
417
2020-10-11
jrmu
418
2020-10-20
jrmu
my $body = <<"EOF";
419
2020-10-20
jrmu
You created a bouncer!
420
2020-10-20
jrmu
421
2020-10-20
jrmu
Username: $username
422
2020-10-20
jrmu
Password: $password
423
2020-10-20
jrmu
Server: $hostname
424
2020-10-20
jrmu
Port: $sslport for SSL (secure connection)
425
2020-10-20
jrmu
Port: $plainport for plaintext
426
2020-10-20
jrmu
427
2020-10-20
jrmu
*IMPORTANT*: Verify your email address:
428
2020-10-20
jrmu
429
2020-10-20
jrmu
https://www.$hostname/register.php?id=$passhash&version=$versionhash
430
2020-10-20
jrmu
431
2020-10-20
jrmu
You *MUST* click on the link or your account will be deleted.
432
2020-10-20
jrmu
433
2020-10-20
jrmu
IRCNow
434
2020-10-20
jrmu
EOF
435
2020-10-20
jrmu
Mail::mail($mailfrom, $email, $mailname, "Verify IRCNow Account", $body);
436
2020-10-20
jrmu
}
437
2020-10-20
jrmu
438
2020-11-05
jrmu
sub mtaillog {
439
2020-11-05
jrmu
my ($bot, $nick, $host, $hand, @args) = @_;
440
2020-11-05
jrmu
my ($chan, $text);
441
2020-11-05
jrmu
if (@args == 2) {
442
2020-11-05
jrmu
($chan, $text) = ($args[0], $args[1]);
443
2020-11-05
jrmu
} else { $text = $args[0]; }
444
2020-11-05
jrmu
my $hostmask = "$nick!$host";
445
2020-11-05
jrmu
open(my $fh, "-|", "/usr/bin/tail", "-f", $znclog) or die "could not start tail: $!";
446
2020-11-05
jrmu
while (my $line = <$fh>) {
447
2020-11-05
jrmu
foreach my $chan (@teamchans) {
448
2020-11-05
jrmu
main::putserv($bot, "PRIVMSG $chan :$line");
449
2020-11-05
jrmu
}
450
2020-11-05
jrmu
}
451
2020-11-05
jrmu
}
452
2020-11-05
jrmu
453
2020-11-05
jrmu
sub mlastseen {
454
2020-11-05
jrmu
my ($bot, $nick, $host, $hand, @args) = @_;
455
2020-11-05
jrmu
my ($chan, $text);
456
2020-11-05
jrmu
if (@args == 2) {
457
2020-11-05
jrmu
($chan, $text) = ($args[0], $args[1]);
458
2020-11-05
jrmu
} else { $text = $args[0]; }
459
2020-11-05
jrmu
my $hostmask = "$nick!$host";
460
2020-11-05
jrmu
if (!@logs) { loadlog(); }
461
2020-12-25
jrmu
# my @users = treeget($znctree, "User", "Node");
462
2020-11-05
jrmu
foreach my $user (@users) {
463
2020-11-05
jrmu
my @lines = grep(/^\[\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\] \[$user\] connected to ZNC from [.0-9a-fA-F:]+/, @logs);
464
2020-11-05
jrmu
if (scalar(@lines) == 0) {
465
2020-11-05
jrmu
foreach my $chan (@teamchans) {
466
2020-11-05
jrmu
main::putserv($bot, "PRIVMSG $chan :$user never logged in");
467
2020-11-05
jrmu
}
468
2020-11-05
jrmu
next;
469
2020-11-05
jrmu
}
470
2020-11-05
jrmu
my $recent = pop(@lines);
471
2020-11-05
jrmu
if ($recent =~ /^\[(\d{4}-\d\d-\d\d) \d\d:\d\d:\d\d\] \[$user\] connected to ZNC from [.0-9a-fA-F:]+/) {
472
2020-11-05
jrmu
my $date = $1;
473
2020-11-05
jrmu
foreach my $chan (@teamchans) {
474
2020-11-05
jrmu
main::putserv($bot, "PRIVMSG $chan :$user $date");
475
2020-11-05
jrmu
}
476
2020-11-05
jrmu
}
477
2020-11-05
jrmu
}
478
2020-11-05
jrmu
}
479
2020-10-11
jrmu
#sub resend {
480
2020-10-11
jrmu
# my ($bot, $newnick, $email) = @_;
481
2020-10-11
jrmu
# my $password = newpass();
482
2020-10-11
jrmu
# sendmsg($bot, "*controlpanel", "set Password $newnick $password");
483
2020-10-11
jrmu
# mailverify($newnick, $email, $password, "bouncer");
484
2020-10-11
jrmu
# sendmsg($bot, "$newnick", "Email sent");
485
2020-10-11
jrmu
#}
486
2020-10-11
jrmu
487
2020-10-11
jrmu
# if ($reply =~ /^!resend ([-_0-9a-zA-Z]+) ([-_0-9a-zA-Z]+@[-_0-9a-zA-Z]+\.[-_0-9a-zA-Z]+)$/i) {
488
2020-10-11
jrmu
# my ($newnick, $email) = ($1, $2);
489
2020-10-11
jrmu
# my $password = newpass();
490
2020-10-11
jrmu
# resend($bot, $newnick, $email);
491
2020-10-11
jrmu
# }
492
2020-10-11
jrmu
493
2020-10-11
jrmu
#sub resetznc {
494
2020-10-11
jrmu
#
495
2020-10-11
jrmu
#AnonIPLimit 10000
496
2020-10-11
jrmu
#AuthOnlyViaModule false
497
2020-10-11
jrmu
#ConnectDelay 0
498
2020-10-11
jrmu
#HideVersion true
499
2020-10-11
jrmu
#LoadModule
500
2020-10-11
jrmu
#ServerThrottle
501
2020-10-11
jrmu
#1337 209.141.38.137
502
2020-10-11
jrmu
#31337 209.141.38.137
503
2020-10-11
jrmu
#1337 2605:6400:20:5cc::
504
2020-10-11
jrmu
#31337 2605:6400:20:5cc::
505
2020-10-11
jrmu
#1337 127.0.0.1
506
2020-10-11
jrmu
#1338 127.0.0.1
507
2020-10-11
jrmu
#}
508
2020-10-11
jrmu
#
509
2020-10-11
jrmu
#alias Provides bouncer-side command alias support.
510
2020-10-11
jrmu
#autoreply Reply to queries when you are away
511
2020-10-11
jrmu
#block_motd Block the MOTD from IRC so it's not sent to your client(s).
512
2020-10-11
jrmu
#bouncedcc Bounces DCC transfers through ZNC instead of sending them directly to the user.
513
2020-10-11
jrmu
#clientnotify Notifies you when another IRC client logs into or out of your account. Configurable.
514
2020-10-11
jrmu
#ctcpflood Don't forward CTCP floods to clients
515
2020-10-11
jrmu
#dcc This module allows you to transfer files to and from ZNC
516
2020-10-11
jrmu
#perform Keeps a list of commands to be executed when ZNC connects to IRC.
517
2020-10-11
jrmu
#webadmin Web based administration module.
518
2020-10-11
jrmu
519
2020-10-11
jrmu
520
2020-10-11
jrmu
1; # MUST BE LAST STATEMENT IN FILE