erste Eintragungen in DB
This commit is contained in:
64
ban2mysql.pl
64
ban2mysql.pl
@@ -6,21 +6,71 @@ use DBI;
|
||||
use Data::Printer;
|
||||
use File::Slurp;
|
||||
|
||||
use Mojo::UserAgent;
|
||||
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
|
||||
$year = $year+1900;
|
||||
|
||||
my $month2int = {
|
||||
'jan' => '01',
|
||||
'feb' => '02',
|
||||
'mar' => '03',
|
||||
'apr' => '04',
|
||||
'may' => '05',
|
||||
'jun' => '06',
|
||||
'jul' => '07',
|
||||
'aug' => '08',
|
||||
'sep' => '09',
|
||||
'oct' => '10',
|
||||
'nov' => '11',
|
||||
'dez' => '12'
|
||||
};
|
||||
|
||||
# Connect to the database.
|
||||
my $dbh = DBI->connect("DBI:MariaDB:database=kram;host=edna",
|
||||
"steffen", "66WXRlvF0UUV",
|
||||
{'RaiseError' => 1});
|
||||
|
||||
my @file = read_file('sys.log');
|
||||
my @file = read_file('sys.log.1');
|
||||
|
||||
my $ua = Mojo::UserAgent->new();
|
||||
|
||||
for my $l ( @file ) {
|
||||
my ( $month, $day, $h, $m, $s, $kat, $src, $dst, $port ) = $l =~ /(.*?) (.*?) (..):(..):(..) 192.*banIP\/...-wan\/drop\/(.*?):.*SRC=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) DST=(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*DPT=(\d+)/;
|
||||
$ua->get("http://ip-api.com/json/$src" => {Accept => '*/*'})->result->body;
|
||||
p $ua;
|
||||
|
||||
my $dt = '';
|
||||
if ( $month ) {
|
||||
p $month;
|
||||
p $src;
|
||||
$month = $month2int->{lc $month};
|
||||
$dt = "$year-$month-$day $h:$m:$s";
|
||||
p $dt;
|
||||
|
||||
my $da = $dbh->selectrow_hashref('SELECT * FROM banip WHERE src = ? and port = ?', undef, $src, $port );
|
||||
if ( $da ) {
|
||||
$dbh->do('UPDATE banip set count = count + 1, updated = ? WHERE src = ? and port = ?', undef, $dt, $src, $port );
|
||||
} else {
|
||||
$dbh->do(
|
||||
'INSERT INTO banip (
|
||||
created,
|
||||
updated,
|
||||
src,
|
||||
dst,
|
||||
port,
|
||||
kat)
|
||||
VALUES (
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?,
|
||||
?)', undef,
|
||||
$dt,
|
||||
$dt,
|
||||
$src,
|
||||
$dst,
|
||||
$port,
|
||||
$kat);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# $dbh->selectall_arrayref($statement);
|
||||
|
||||
Reference in New Issue
Block a user