1 # Original author is izzyb@planetofnix.com
8 # Bsd pledge/unveil security modules
16 # setup log level constents
25 my ($level, $msg) = @_;
26 if ($verbose >= $level) { print "$msg\n"; }
29 # location of local modules
32 # Date string to epock used in init_ip_xref
35 my ($ipTable, $nameTable) = init_ip_xref();
37 while (my $username = shift) { #param 1 should be the name of a user to generate a report from.
38 my $dbFile = '/var/www/botnow/botnow.db';
39 my $dbh = connectdb($dbFile);
41 die "failed to connect to $dbFile";
43 my $stmt=qq{select * from bnc join irc on (bnc.ircid = irc.id) where username is ?};
44 my $sth=$dbh->prepare($stmt);
45 $sth->execute($username) or die "execution failed: $dbh->errstr()";
46 while (my $row=$sth->fetchrow_hashref) {
48 Username: $row->{username}
49 Email Address: $row->{email}
53 Registration Date: $row->{date}
57 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where email = ?\,undef,$row->{email})})
60 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where date = ?\,undef,$row->{date})})
62 print "Same Hostmask ["
63 . join(', ', @{$dbh->selectcol_arrayref(qq\Select username from bnc join irc on (bnc.ircid = irc.id) where hostmask = ?\,undef,$row->{hostmask})})
66 print "Frequency of connections from: \n" . Dumper($nameTable->{$username});
67 print "Other Users connecting from: \n";
68 foreach my $ip (keys(%{$nameTable->{$username}})) {
69 my $thisLastConnect = @{ $nameTable->{ $row->{username} }->{$ip}->{epoch} }[-1];
71 foreach my $link (keys(%{ $ipTable->{$ip} })) {
72 my $linkLastConnect = @{ $nameTable->{$link}->{$ip}->{epoch} }[-1];
73 if (abs($thisLastConnect - $linkLastConnect) < 300) { # les then 5 min
75 } elsif (abs($thisLastConnect - $linkLastConnect) < 600) { # less then 10 min
93 my $dsn = "dbi:SQLite:dbname=$dbpath";
96 my $dbh = DBI->connect($dsn, $user, $password, {
100 FetchHashKeyName => 'NAME_lc',
101 }) or die "Couldn't connect to database: " . $DBI::errstr;
102 if (!(-s "$dbpath")) {
103 main::debug(ALL, "Cant locate $dbpath");
106 main::debug(ALL, "connected to $dbpath");
109 # Read and index the znc log file.
114 open my $zncLog, '<', '/home/znc/home/znc/.znc/moddata/adminlog/znc.log' or die "Can't open znc log file";
115 while (my $line = <$zncLog>) {
116 if( $line =~/\[(.*)\].*\[(.*)\] connected to ZNC from (.*)/) {
120 if (!defined($ip2usernames->{$ip})) {
121 $ip2usernames->{$ip} = {};
123 if (!defined($ip2usernames->{$name})) {
124 $ip2usernames->{$ip}->{$name}={};
125 $ip2usernames->{$ip}->{$name}->{count}=0;
126 $ip2usernames->{$ip}->{$name}->{timestamps}=[];
127 $ip2usernames->{$ip}->{$name}->{epoch}=[];
130 $ip2usernames->{$ip}->{$name}->{count}++;
131 push (@{$ip2usernames->{$ip}->{$name}->{timestamps}}, $timestamp);
132 push (@{$ip2usernames->{$ip}->{$name}->{epoch}}, str2time($timestamp));
134 if (!defined($usernames2ip->{$name})) {
135 $usernames2ip->{$name}={};
137 if (!defined($usernames2ip->{$name}->{$ip})) {
138 $usernames2ip->{$name}->{$ip}={};
139 $usernames2ip->{$name}->{$ip}->{count}=0;
140 $usernames2ip->{$name}->{$ip}->{timestamps}=[];
141 $usernames2ip->{$name}->{$ip}->{epoch}=[];
143 $usernames2ip->{$name}->{$ip}->{count}++;
144 push (@{$usernames2ip->{$name}->{$ip}->{timestamps}}, $timestamp);
145 push (@{$usernames2ip->{$name}->{$ip}->{epoch}}, str2time($timestamp));
149 return $ip2usernames,$usernames2ip;