Blame
Date:
Sun Oct 8 22:28:02 2023 UTC
Message:
Now prevents creating accounts that exist in database with a password
001
2023-03-07
jrmu
#!/usr/bin/perl
002
2023-03-07
jrmu
#
003
2023-03-07
jrmu
use strict;
004
2023-03-07
jrmu
#no strict 'refs';
005
2023-03-07
jrmu
use warnings;
006
2023-03-07
jrmu
use Data::Dumper;
007
2023-03-07
jrmu
# Bsd pledge/unveil security modules
008
2023-03-07
jrmu
use OpenBSD::Pledge;
009
2023-03-07
jrmu
use OpenBSD::Unveil;
010
2023-03-07
jrmu
011
2023-03-07
jrmu
# Database modules
012
2023-03-07
jrmu
use DBI;
013
2023-03-07
jrmu
use DBD::SQLite;
014
2023-03-07
jrmu
015
2023-03-07
jrmu
# setup log level constents
016
2023-03-07
jrmu
use constant {
017
2023-03-07
jrmu
NONE => 0,
018
2023-03-07
jrmu
ERRORS => 1,
019
2023-03-07
jrmu
WARNINGS => 2,
020
2023-03-07
jrmu
ALL => 3,
021
2023-03-07
jrmu
};
022
2023-03-07
jrmu
my $verbose = ERRORS;
023
2023-03-07
jrmu
sub debug {
024
2023-03-07
jrmu
my ($level, $msg) = @_;
025
2023-03-07
jrmu
if ($verbose >= $level) { print "$msg\n"; }
026
2023-03-07
jrmu
}
027
2023-03-07
jrmu
028
2023-03-07
jrmu
#
029
2023-03-07
jrmu
use lib './';
030
2023-03-07
jrmu
031
2023-03-07
jrmu
my ($ipTable, $nameTable) = init_ip_xref();
032
2023-03-07
jrmu
033
2023-03-07
jrmu
while (my $username = shift) { #param 1 should be the name of a user to generate a report from.
034
2023-03-07
jrmu
my $dbFile = '/var/www/botnow/botnow.db';
035
2023-03-07
jrmu
my $dbh = connectdb($dbFile);
036
2023-03-07
jrmu
if (!defined($dbh)) {
037
2023-03-07
jrmu
die "failed to connect to $dbFile";
038
2023-03-07
jrmu
}
039
2023-03-07
jrmu
my $stmt=qq{select * from bnc join irc on (bnc.ircid = irc.id) where username is ?};
040
2023-03-07
jrmu
my $sth=$dbh->prepare($stmt);
041
2023-03-07
jrmu
$sth->execute($username) or die "execution failed: $dbh->errstr()";
042
2023-03-07
jrmu
while (my $row=$sth->fetchrow_hashref) {
043
2023-03-07
jrmu
my $dossier =qq{
044
2023-03-07
jrmu
Username: $row->{username}
045
2023-03-07
jrmu
Email Address: $row->{email}
046
2023-03-07
jrmu
$row->{hostmask}
047
2023-03-07
jrmu
$row->{ctcpversion}
048
2023-03-07
jrmu
$row->{ctcptime}
049
2023-03-07
jrmu
Registration Date: $row->{date}
050
2023-03-07
jrmu
};
051
2023-03-07
jrmu
print $dossier;
052
2023-03-07
jrmu
print "Same Email ["
053
2023-03-07
jrmu
. join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where email = ?\,undef,$row->{email})})
054
2023-03-07
jrmu
. "]\n";
055
2023-03-07
jrmu
print "Same Date ["
056
2023-03-07
jrmu
. join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where date = ?\,undef,$row->{date})})
057
2023-03-07
jrmu
. "]\n";
058
2023-03-07
jrmu
print "Same Hostmask ["
059
2023-03-07
jrmu
. join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where hostmask = ?\,undef,$row->{hostmask})})
060
2023-03-07
jrmu
. "]\n";
061
2023-03-07
jrmu
print Dumper($row);
062
2023-03-07
jrmu
print "Frequency of connections from: \n" . Dumper($nameTable->{$username});
063
2023-03-07
jrmu
print "Other Users connecting from: \n";
064
2023-03-07
jrmu
foreach(keys(%{$nameTable->{$username}})) {
065
2023-03-07
jrmu
print "$_ =>[" . join (', ', keys(%{$ipTable->{$_}})) . "]\n";
066
2023-03-07
jrmu
}
067
2023-03-07
jrmu
}
068
2023-03-07
jrmu
}
069
2023-03-07
jrmu
070
2023-03-07
jrmu
071
2023-03-07
jrmu
072
2023-03-07
jrmu
073
2023-03-07
jrmu
exit 0;
074
2023-03-07
jrmu
075
2023-03-07
jrmu
sub connectdb {
076
2023-03-07
jrmu
my $dbpath=shift;
077
2023-03-07
jrmu
my $dsn = "dbi:SQLite:dbname=$dbpath";
078
2023-03-07
jrmu
my $user = "";
079
2023-03-07
jrmu
my $password = "";
080
2023-03-07
jrmu
my $dbh = DBI->connect($dsn, $user, $password, {
081
2023-03-07
jrmu
PrintError => 1,
082
2023-03-07
jrmu
RaiseError => 1,
083
2023-03-07
jrmu
AutoCommit => 1,
084
2023-03-07
jrmu
FetchHashKeyName => 'NAME_lc',
085
2023-03-07
jrmu
}) or die "Couldn't connect to database: " . $DBI::errstr;
086
2023-03-07
jrmu
if (!(-s "$dbpath")) {
087
2023-03-07
jrmu
main::debug(ALL, "Cant locate $dbpath");
088
2023-03-07
jrmu
exit 1;
089
2023-03-07
jrmu
}
090
2023-03-07
jrmu
main::debug(ALL, "connected to $dbpath");
091
2023-03-07
jrmu
return $dbh;
092
2023-03-07
jrmu
}
093
2023-03-07
jrmu
# Read and index the znc log file.
094
2023-03-07
jrmu
sub init_ip_xref {
095
2023-03-07
jrmu
# Get IP addresses
096
2023-03-07
jrmu
my $ip2usernames={};
097
2023-03-07
jrmu
my $usernames2ip={};
098
2023-03-07
jrmu
open my $zncLog, '<', '/home/znc/home/znc/.znc/moddata/adminlog/znc.log' or die "Can't open znc log file";
099
2023-03-07
jrmu
while (my $line = <$zncLog>) {
100
2023-03-07
jrmu
if( $line =~/.*\[(.*)\] connected to ZNC from (.*)/) {
101
2023-03-07
jrmu
my $name=$1;
102
2023-03-07
jrmu
my $ip=$2;
103
2023-03-07
jrmu
if (!defined($ip2usernames->{$ip})) {
104
2023-03-07
jrmu
$ip2usernames->{$ip} = {};
105
2023-03-07
jrmu
}
106
2023-03-07
jrmu
if (!defined($ip2usernames->{$name})) {
107
2023-03-07
jrmu
$ip2usernames->{$ip}->{$name}=0;
108
2023-03-07
jrmu
}
109
2023-03-07
jrmu
$ip2usernames->{$ip}->{$name}++;
110
2023-03-07
jrmu
if (!defined($usernames2ip->{$name})) {
111
2023-03-07
jrmu
$usernames2ip->{$name}={};
112
2023-03-07
jrmu
}
113
2023-03-07
jrmu
if (!defined($usernames2ip->{$name}->{$ip})) {
114
2023-03-07
jrmu
$usernames2ip->{$name}->{$ip}=0;
115
2023-03-07
jrmu
}
116
2023-03-07
jrmu
$usernames2ip->{$name}->{$ip}++;
117
2023-03-07
jrmu
}
118
2023-03-07
jrmu
}
119
2023-03-07
jrmu
close $zncLog;
120
2023-03-07
jrmu
return $ip2usernames,$usernames2ip;
121
2023-03-07
jrmu
}
IRCNow