7 # Bsd pledge/unveil security modules
15 # setup log level constents
24 my ($level, $msg) = @_;
25 if ($verbose >= $level) { print "$msg\n"; }
31 my ($ipTable, $nameTable) = init_ip_xref();
33 while (my $username = shift) { #param 1 should be the name of a user to generate a report from.
34 my $dbFile = '/var/www/botnow/botnow.db';
35 my $dbh = connectdb($dbFile);
37 die "failed to connect to $dbFile";
39 my $stmt=qq{select * from bnc join irc on (bnc.ircid = irc.id) where username is ?};
40 my $sth=$dbh->prepare($stmt);
41 $sth->execute($username) or die "execution failed: $dbh->errstr()";
42 while (my $row=$sth->fetchrow_hashref) {
44 Username: $row->{username}
45 Email Address: $row->{email}
49 Registration Date: $row->{date}
53 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where email = ?\,undef,$row->{email})})
56 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where date = ?\,undef,$row->{date})})
58 print "Same Hostmask ["
59 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where hostmask = ?\,undef,$row->{hostmask})})
62 print "Frequency of connections from: \n" . Dumper($nameTable->{$username});
63 print "Other Users connecting from: \n";
64 foreach(keys(%{$nameTable->{$username}})) {
65 print "$_ =>[" . join (', ', keys(%{$ipTable->{$_}})) . "]\n";
77 my $dsn = "dbi:SQLite:dbname=$dbpath";
80 my $dbh = DBI->connect($dsn, $user, $password, {
84 FetchHashKeyName => 'NAME_lc',
85 }) or die "Couldn't connect to database: " . $DBI::errstr;
86 if (!(-s "$dbpath")) {
87 main::debug(ALL, "Cant locate $dbpath");
90 main::debug(ALL, "connected to $dbpath");
93 # Read and index the znc log file.
98 open my $zncLog, '<', '/home/znc/home/znc/.znc/moddata/adminlog/znc.log' or die "Can't open znc log file";
99 while (my $line = <$zncLog>) {
100 if( $line =~/.*\[(.*)\] connected to ZNC from (.*)/) {
103 if (!defined($ip2usernames->{$ip})) {
104 $ip2usernames->{$ip} = {};
106 if (!defined($ip2usernames->{$name})) {
107 $ip2usernames->{$ip}->{$name}=0;
109 $ip2usernames->{$ip}->{$name}++;
110 if (!defined($usernames2ip->{$name})) {
111 $usernames2ip->{$name}={};
113 if (!defined($usernames2ip->{$name}->{$ip})) {
114 $usernames2ip->{$name}->{$ip}=0;
116 $usernames2ip->{$name}->{$ip}++;
120 return $ip2usernames,$usernames2ip;