7 # Bsd pledge/unveil security modules
15 # setup log level constents
24 my ($level, $msg) = @_;
25 if ($verbose >= $level) { print "$msg\n"; }
28 # location of local modules
31 # Date string to epock used in init_ip_xref
34 my ($ipTable, $nameTable) = init_ip_xref();
36 while (my $username = shift) { #param 1 should be the name of a user to generate a report from.
37 my $dbFile = '/var/www/botnow/botnow.db';
38 my $dbh = connectdb($dbFile);
40 die "failed to connect to $dbFile";
42 my $stmt=qq{select * from bnc join irc on (bnc.ircid = irc.id) where username is ?};
43 my $sth=$dbh->prepare($stmt);
44 $sth->execute($username) or die "execution failed: $dbh->errstr()";
45 while (my $row=$sth->fetchrow_hashref) {
47 Username: $row->{username}
48 Email Address: $row->{email}
52 Registration Date: $row->{date}
56 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where email = ?\,undef,$row->{email})})
59 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where date = ?\,undef,$row->{date})})
61 print "Same Hostmask ["
62 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where hostmask = ?\,undef,$row->{hostmask})})
65 print "Frequency of connections from: \n" . Dumper($nameTable->{$username});
66 print "Other Users connecting from: \n";
67 foreach my $ip (keys(%{$nameTable->{$username}})) {
68 my $thisLastConnect = @{ $nameTable->{ $row->{username} }->{$ip}->{epoch} }[-1];
70 foreach my $link (keys(%{ $ipTable->{$ip} })) {
71 my $linkLastConnect = @{ $nameTable->{$link}->{$ip}->{epoch} }[-1];
72 if (abs($thisLastConnect - $linkLastConnect) < 300) { # les then 5 min
74 } elsif (abs($thisLastConnect - $linkLastConnect) < 600) { # less then 10 min
92 my $dsn = "dbi:SQLite:dbname=$dbpath";
95 my $dbh = DBI->connect($dsn, $user, $password, {
99 FetchHashKeyName => 'NAME_lc',
100 }) or die "Couldn't connect to database: " . $DBI::errstr;
101 if (!(-s "$dbpath")) {
102 main::debug(ALL, "Cant locate $dbpath");
105 main::debug(ALL, "connected to $dbpath");
108 # Read and index the znc log file.
113 open my $zncLog, '<', '/home/znc/home/znc/.znc/moddata/adminlog/znc.log' or die "Can't open znc log file";
114 while (my $line = <$zncLog>) {
115 if( $line =~/\[(.*)\].*\[(.*)\] connected to ZNC from (.*)/) {
119 if (!defined($ip2usernames->{$ip})) {
120 $ip2usernames->{$ip} = {};
122 if (!defined($ip2usernames->{$name})) {
123 $ip2usernames->{$ip}->{$name}={};
124 $ip2usernames->{$ip}->{$name}->{count}=0;
125 $ip2usernames->{$ip}->{$name}->{timestamps}=[];
126 $ip2usernames->{$ip}->{$name}->{epoch}=[];
129 $ip2usernames->{$ip}->{$name}->{count}++;
130 push (@{$ip2usernames->{$ip}->{$name}->{timestamps}}, $timestamp);
131 push (@{$ip2usernames->{$ip}->{$name}->{epoch}}, str2time($timestamp));
133 if (!defined($usernames2ip->{$name})) {
134 $usernames2ip->{$name}={};
136 if (!defined($usernames2ip->{$name}->{$ip})) {
137 $usernames2ip->{$name}->{$ip}={};
138 $usernames2ip->{$name}->{$ip}->{count}=0;
139 $usernames2ip->{$name}->{$ip}->{timestamps}=[];
140 $usernames2ip->{$name}->{$ip}->{epoch}=[];
142 $usernames2ip->{$name}->{$ip}->{count}++;
143 push (@{$usernames2ip->{$name}->{$ip}->{timestamps}}, $timestamp);
144 push (@{$usernames2ip->{$name}->{$ip}->{epoch}}, str2time($timestamp));
148 return $ip2usernames,$usernames2ip;