Gestione conntrack multiprocesso con watchguard
This commit is contained in:
BIN
proxy/.conntrack.pl.swp
Normal file
BIN
proxy/.conntrack.pl.swp
Normal file
Binary file not shown.
@@ -6,7 +6,7 @@ use FindBin qw($Bin);
|
|||||||
|
|
||||||
my $param = shift @ARGV;
|
my $param = shift @ARGV;
|
||||||
|
|
||||||
$verbose = 0;
|
our $verbose = 0;
|
||||||
if ($param eq '-v') {
|
if ($param eq '-v') {
|
||||||
$verbose = 1;
|
$verbose = 1;
|
||||||
}
|
}
|
||||||
@@ -19,9 +19,58 @@ my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die (
|
|||||||
$sts = $dbmysql->prepare("use $DBname");
|
$sts = $dbmysql->prepare("use $DBname");
|
||||||
$sts->execute ();
|
$sts->execute ();
|
||||||
|
|
||||||
open CT, "/usr/sbin/conntrack -E -eNEW,DESTROY -otimestamp,id -p tcp --dport $proxy_PORT |" or die "non va\n";
|
$query = " SELECT
|
||||||
|
id,
|
||||||
|
ip,
|
||||||
|
port
|
||||||
|
FROM
|
||||||
|
proxy_conn
|
||||||
|
WHERE
|
||||||
|
attivo = 1
|
||||||
|
";
|
||||||
|
$sts = $dbmysql->prepare($query);
|
||||||
|
$sts->execute ();
|
||||||
|
|
||||||
while (<CT>) {
|
while ( $ref = $sts->fetchrow_hashref ) {
|
||||||
|
my $id = $$ref{'id'};
|
||||||
|
my $ip = $$ref{'ip'};
|
||||||
|
my $port = $$ref{'port'};
|
||||||
|
|
||||||
|
|
||||||
|
if (!fork) {
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
my $pidi = fork;
|
||||||
|
if (!$pidi) {
|
||||||
|
conntrack ($id, $ip, $port);
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
waitpid $newpidi, WNOHANG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($verbose) {
|
||||||
|
while (1) { sleep 1000; }
|
||||||
|
}
|
||||||
|
exit 1;
|
||||||
|
|
||||||
|
|
||||||
|
sub conntrack {
|
||||||
|
my $sess_id = shift;
|
||||||
|
my $proxy_IP = shift;
|
||||||
|
my $proxy_PORT = shift;
|
||||||
|
|
||||||
|
print "Attivato agente $sess_id su $proxy_IP:$proxy_PORT\n" if ($verbose);
|
||||||
|
|
||||||
|
my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die ($DBI::errstr);
|
||||||
|
$sts = $dbmysql->prepare("use $DBname");
|
||||||
|
$sts->execute ();
|
||||||
|
|
||||||
|
open CT, "/usr/sbin/conntrack -E -eNEW,DESTROY -otimestamp,id -p tcp -d $proxy_IP --dport $proxy_PORT |" or die "non va\n";
|
||||||
|
|
||||||
|
while (<CT>) {
|
||||||
my $riga = $_;
|
my $riga = $_;
|
||||||
# print "$riga";
|
# print "$riga";
|
||||||
|
|
||||||
@@ -38,6 +87,7 @@ while (<CT>) {
|
|||||||
VALUES
|
VALUES
|
||||||
('$remote_IP', $thread_ID, FROM_UNIXTIME($remote_START))
|
('$remote_IP', $thread_ID, FROM_UNIXTIME($remote_START))
|
||||||
";
|
";
|
||||||
|
|
||||||
# print "$query\n";
|
# print "$query\n";
|
||||||
$sts = $dbmysql->prepare($query);
|
$sts = $dbmysql->prepare($query);
|
||||||
$sts->execute ();
|
$sts->execute ();
|
||||||
@@ -46,9 +96,6 @@ while (<CT>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( $riga =~ /^\s*\[(\d+)\.\d+\]\s+\[DESTROY\] tcp\s+\d+ src=(\S+) dst=(\S+) sport=\d+ dport=(\d+) packets=\d+ bytes=(\d+) src=\S+ dst=\S+ sport=\d+ dport=\d+ packets=\d+ bytes=(\d+) \[\w+\] id=(\d+)/) {
|
if ( $riga =~ /^\s*\[(\d+)\.\d+\]\s+\[DESTROY\] tcp\s+\d+ src=(\S+) dst=(\S+) sport=\d+ dport=(\d+) packets=\d+ bytes=(\d+) src=\S+ dst=\S+ sport=\d+ dport=\d+ packets=\d+ bytes=(\d+) \[\w+\] id=(\d+)/) {
|
||||||
# next if ($2 != $proxy_IP);
|
|
||||||
# next if ($3 != $proxy_PORT);
|
|
||||||
|
|
||||||
my $remote_DESTROY = $1;
|
my $remote_DESTROY = $1;
|
||||||
my $remote_IP = $2;
|
my $remote_IP = $2;
|
||||||
my $local_IP = $3;
|
my $local_IP = $3;
|
||||||
@@ -57,7 +104,7 @@ while (<CT>) {
|
|||||||
my $remote_RECEIVE = $6;
|
my $remote_RECEIVE = $6;
|
||||||
my $thread_ID = $7;
|
my $thread_ID = $7;
|
||||||
|
|
||||||
print "IP: $remote_IP - ID: $thread_ID - Invati: $remote_SEND - Ricevuti: $remote_RECEIVE\n" if ($verbose);
|
print "$sess_id - IP: $remote_IP - ID: $thread_ID - Invati: $remote_SEND - Ricevuti: $remote_RECEIVE\n" if ($verbose);
|
||||||
|
|
||||||
my $query = " UPDATE
|
my $query = " UPDATE
|
||||||
proxy_dati
|
proxy_dati
|
||||||
@@ -81,5 +128,7 @@ while (<CT>) {
|
|||||||
$sts = $dbmysql->prepare($query);
|
$sts = $dbmysql->prepare($query);
|
||||||
$sts->execute ();
|
$sts->execute ();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
close CT;
|
||||||
}
|
}
|
||||||
close CT;
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
$proxy_IP = '';
|
our $DBhost = '';
|
||||||
$proxy_PORT = 3128;
|
our $DBname = '';
|
||||||
|
our $DBuser = '';
|
||||||
$DBhost = '';
|
our $DBpass = '';
|
||||||
$DBname = '';
|
|
||||||
$DBuser = '';
|
|
||||||
$DBpass = '';
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user