diff --git a/DBDiff/condex.sql b/DBDiff/condex.sql
index 23b7e8c..1df925a 100644
--- a/DBDiff/condex.sql
+++ b/DBDiff/condex.sql
@@ -25,23 +25,16 @@ CREATE TABLE `condes_regole` (
`permanente` BOOLEAN NOT NULL ,
`data` DATETIME NOT NULL ,
`attivo` BOOLEAN NOT NULL ,
+ `stato` int(11) DEFAULT 0 ,
+ `modifica` DATETIME NOT NULL ,
PRIMARY KEY (`id`)
) ENGINE = InnoDB;
-CREATE TABLE `condes_stato` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT,
- `id_condes_regole` bigint(20) NOT NULL,
- `id_proxy_acl_ip` bigint(20) NOT NULL,
- `permanente` tinyint(1) NOT NULL,
- `data` datetime NOT NULL,
- `attivo` tinyint(1) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8
-
CREATE TABLE `condes_logs` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`id_utenti` bigint(20) NOT NULL,
`id_condes_regole` bigint(20) NOT NULL,
+ `stato` int(11) NOT NULL,
`data` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
diff --git a/condes/condes_logs.php b/condes/condes_logs.php
new file mode 100755
index 0000000..93a755c
--- /dev/null
+++ b/condes/condes_logs.php
@@ -0,0 +1,162 @@
+ 0) {
+ $idutente = $_POST['idutente'];
+ $queryutente = "AND utenti.id = $idutente";
+} else {
+ $idutente = 0;
+ $queryutente = "";
+}
+
+if (isset($_POST['idip']) && $_POST['idip'] > 0) {
+ $idip = $_POST['idip'];
+ $queryip = "AND proxy_pool.id = $idip";
+} else {
+ $idip = 0;
+ $queryip = "";
+}
+
+$stato = array ("Disattivo", "Attivo", "Permanente");
+
+$query_user = " SELECT
+ utenti.id,
+ utenti.utente
+ FROM
+ utenti
+ JOIN
+ permessi
+ ON
+ permessi.id_utenti = utenti.id
+ WHERE
+ permessi.id_moduli = ".$MODULO['id']."
+ ORDER BY
+ utente
+";
+$res_user = mysql_query( $query_user, $DB_ID );
+
+$query_ip = " SELECT
+ condes_macchine.id_proxy_pool AS id,
+ proxy_pool.nome,
+ proxy_pool.ip
+ FROM
+ condes_macchine
+ JOIN
+ proxy_pool
+ ON
+ condes_macchine.id_proxy_pool = proxy_pool.id
+ ORDER BY
+ -proxy_pool.nome DESC,
+ INET_ATON(proxy_pool.ip) ASC
+";
+$res_ip = mysql_query( $query_ip, $DB_ID );
+
+?>
+
+
+
diff --git a/condes/index.php b/condes/index.php
index 016d9eb..6296e7e 100644
--- a/condes/index.php
+++ b/condes/index.php
@@ -7,50 +7,70 @@ view_top();
if (isset($_POST['utente'])) {
$utente = $_POST['utente'];
- print "-- $utente --
";
-
+ $old = $new = array();
foreach ($_POST as $id => $valore) {
- if ($id == "utente") continue;
- print "---- $id => $valore
";
+ if (preg_match ("/^new-(\d+)/", $id, $ris)) $new[$ris[1]] = $valore;
+ if (preg_match ("/^old-(\d+)/", $id, $ris)) $old[$ris[1]] = $valore;
+ }
- $query = " SELECT
- proxy_acl_ip.id
+ foreach ($new as $id => $valore) {
+ if ($new[$id] == $old[$id]) continue;
+
+ if ($valore >1)
+ $stato = 1;
+ else
+ $stato = $valore;
+
+ $query = " SELECT
+ condes_regole.id_condes_macchine,
+ condes_regole.id_proxy_acl_list,
+ condes_macchine.id_proxy_pool
FROM
condes_regole
JOIN
condes_macchine
ON
- condes_regole.id_condes_macchine = condes_macchine.id
- JOIN
- proxy_acl_ip
- ON
- proxy_acl_ip.idacllist = condes_regole.id_proxy_acl_list
- AND
- proxy_acl_ip.idpool = condes_macchine.id_proxy_pool
+ condes_regole.id_condes_macchine = condes_macchine.id
WHERE
condes_regole.id = $id
";
-
$res = mysql_query( $query, $DB_ID );
$dato = mysql_fetch_array ( $res );
- print_r ($dato);
- print "
";
+ $query = " UPDATE
+ condes_regole
+ SET
+ stato = $valore,
+ modifica = NOW()
+ WHERE
+ id_condes_macchine = ".$dato['id_condes_macchine']."
+ AND
+ id_proxy_acl_list = ".$dato['id_proxy_acl_list'];
+ $res = mysql_query( $query, $DB_ID );
+
+ $query = " INSERT INTO
+ proxy_acl_ip
+ SET
+ idacllist = ".$dato['id_proxy_acl_list'].",
+ idpool = ".$dato['id_proxy_pool'].",
+ stato = $stato,
+ data = NOW()
+ ON DUPLICATE KEY UPDATE
+ stato = $stato,
+ data = NOW()
+ ";
+ $res = mysql_query( $query, $DB_ID );
+
+ $query = " INSERT INTO
+ condes_logs
+ SET
+ id_utenti = ".$UTENTE['id'].",
+ id_condes_regole = $id,
+ stato = $valore,
+ data = NOW()
+ ";
+ $res = mysql_query( $query, $DB_ID );
}
-
-
-
- $query = " INSERT INTO
- condes_regole
- SET
- id_utenti = $id_utenti,
- id_condes_macchine = $id_macchine,
- id_proxy_acl_list = $id_acl,
- permanente = $perm,
- data = NOW(),
- attivo = 1
- ";
-// $res = mysql_query( $query, $DB_ID );
}
$tabella = new html (0,"90%",array(15,2,20,2,15,2,5,0));
@@ -67,6 +87,7 @@ $tabella->riga ();
$query = " SELECT
condes_regole.id,
+ condes_regole.stato,
proxy_pool.nome,
proxy_pool.ip,
proxy_acl_list.nome AS acl,
@@ -103,11 +124,12 @@ while ($dato = mysql_fetch_array ( $res )) {
?>
|
- |
@@ -118,7 +140,6 @@ while ($dato = mysql_fetch_array ( $res )) {
 |
Perm |
 |
-
|
diff --git a/condes/script/condes.conf b/condes/script/condes.conf
new file mode 100644
index 0000000..875246a
--- /dev/null
+++ b/condes/script/condes.conf
@@ -0,0 +1,6 @@
+our $DBhost = '127.0.0.1';
+our $DBname = 'pannello_vbc';
+our $DBuser = 'pannello_proxy';
+our $DBpass = 'CuQlM1lfF4VZDCIP';
+
+return 1;
diff --git a/condes/script/condes.pl b/condes/script/condes.pl
new file mode 100755
index 0000000..72304f9
--- /dev/null
+++ b/condes/script/condes.pl
@@ -0,0 +1,289 @@
+#!/usr/bin/perl
+$|=1;
+
+use DBI;
+use FindBin qw($Bin);
+use threads;
+use threads::shared;
+use Thread::Semaphore;
+
+my $param = shift @ARGV;
+
+our $verbose = 0;
+if ($param eq '-v') {
+ $verbose = 1;
+} elsif ($param eq '-vv') {
+ $verbose = 2;
+}
+
+require "$Bin/condes.conf";
+
+my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die ($DBI::errstr);
+$sts = $dbmysql->prepare("use $DBname");
+$sts->execute ();
+
+$query = " SELECT
+ condes_regole.id_condes_macchine,
+ condes_regole.id_proxy_acl_list,
+ condes_macchine.id_proxy_pool
+ FROM
+ condes_regole
+ JOIN
+ condes_macchine
+ ON
+ condes_regole.id_condes_macchine = condes_macchine.id
+ WHERE
+ condes_regole.stato = 1
+";
+
+$query = " UPDATE
+ condes_regole
+ SET
+ stato = $valore,
+ modifica = NOW()
+ WHERE
+ id_condes_macchine = ".$dato['id_condes_macchine']."
+ AND
+ id_proxy_acl_list = ".$dato['id_proxy_acl_list'];
+
+$query = " INSERT INTO
+ proxy_acl_ip
+ SET
+ idacllist = ".$dato['id_proxy_acl_list'].",
+ idpool = ".$dato['id_proxy_pool'].",
+ stato = $stato,
+ data = NOW()
+ ON DUPLICATE KEY UPDATE
+ stato = $stato,
+ data = NOW()
+";
+
+$query = " INSERT INTO
+ condes_logs
+ SET
+ id_utenti = 000,
+ id_condes_regole = $id,
+ stato = $valore,
+ data = NOW()
+";
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+$query = " SELECT
+
+
+
+
+
+";
+
+
+
+
+
+
+
+$sts = $dbmysql->prepare($query);
+$sts->execute ();
+$ref = $sts->fetchrow_hashref;
+our $limit_thread = $$ref{'valore'};
+
+$query = "SELECT ip FROM proxy_pool GROUP BY ip";
+$sts = $dbmysql->prepare($query);
+$sts->execute ();
+
+our @listaip = ();
+while ( $ref = $sts->fetchrow_hashref ) {
+ push @listaip, $$ref{'ip'};
+}
+
+$query = " SELECT
+ id,
+ ip,
+ nome,
+ port
+ FROM
+ proxy_conn
+ WHERE
+ attivo = 1
+ ";
+$sts = $dbmysql->prepare($query);
+$sts->execute ();
+
+$queryDB = "";
+share ($queryDB);
+$sem1 = Thread::Semaphore->new(1);
+$sem2 = Thread::Semaphore->new(0);
+
+my %proc;
+# Generazione figli per DB
+$proc{'database'} = threads->create(\&database);
+# Generazione figli per cattura pacchetti
+while ( $ref = $sts->fetchrow_hashref ) {
+ my $id = $$ref{'id'};
+ my $ip = $$ref{'ip'};
+ my $port = $$ref{'port'};
+ my $nome = $$ref{'nome'};
+ $proc{$nome} = threads->create(\&conntrack, $id, $ip, $port);
+ print "Attivato processo $nome\n" if ($verbose);
+}
+
+while (1) {
+ sleep 30;
+
+ foreach my $variabile (keys %proc) {
+ $puntatore = $proc{$variabile};
+ if(!$puntatore or !$puntatore->is_running ) {
+ print "Rilevato termine processo $variabile\n" if ($verbose);
+ delete $proc{$variabile};
+ #$puntatore->join();
+
+ if ($variabile eq "database") {
+ $proc{'database'} = threads->create(\&database);
+ } else {
+ $query = "SELECT id, ip, port FROM proxy_conn WHERE nome = '$variabile'";
+ $sts = $dbmysql->prepare($query);
+ $sts->execute ();
+ $ref = $sts->fetchrow_hashref;
+ my $id = $$ref{'id'};
+ my $ip = $$ref{'ip'};
+ my $port = $$ref{'port'};
+ $proc{$variabile} = threads->create(\&conntrack, $id, $ip, $port);
+ }
+ }
+ }
+}
+exit;
+
+sub conntrack {
+ my $sess_id = shift;
+ my $proxy_IP = shift;
+ my $proxy_PORT = shift;
+
+ $SIG{INT} = \&end;
+
+ my $conta = 0;
+
+ print "Attivato agente $sess_id su $proxy_IP:$proxy_PORT\n" if ($verbose);
+
+ my $proc_id = open CT, "/usr/sbin/conntrack -E -eNEW,DESTROY -otimestamp,id -p tcp -d $proxy_IP --dport $proxy_PORT 2>/dev/null |" or die "non va\n";
+
+ while () {
+ my $riga = $_;
+
+ if ( $riga =~ /^\s*\[(\d+)\.\d+\]\s+\[NEW\] tcp\s+\d+ \d+ \S*\s*src=(\S+) dst=(\S+) sport=\d+ dport=(\d+)\s+\[\w+\] src=\S+ dst=\S+ sport=\d+ dport=\d+ id=(\d+)/ ) {
+ my $remote_START = $1;
+ my $remote_IP = $2;
+ my $local_IP = $3;
+ my $local_PORT = $4;
+ my $thread_ID = $5;
+
+ my $query = " INSERT INTO
+ proxy_dati
+ (ip, thread, data_new)
+ VALUES
+ ('$remote_IP', $thread_ID, FROM_UNIXTIME($remote_START))
+ ";
+
+ $sem1->down();
+ $queryDB = $query;
+ $sem2->up();
+ print "Invio query INSERT\n" if ($verbose > 1);
+
+ if (!grep( /^$remote_IP$/, @listaip )) {
+ $sem1->down();
+ $queryDB = "INSERT INTO proxy_pool (ip,pool,attivo,ins) VALUE ('$remote_IP', 1, 0,now())";
+ $sem2->up();
+ push @listaip, $remote_IP;
+ print "Invio query INSERT in proxy_pool\n" if ($verbose > 1);
+ }
+ }
+
+ 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+)/) {
+ my $remote_DESTROY = $1;
+ my $remote_IP = $2;
+ my $local_IP = $3;
+ my $local_PORT = $4;
+ my $remote_SEND = $5;
+ my $remote_RECEIVE = $6;
+ my $thread_ID = $7;
+
+ $conta++;
+ printf ("$conta/$limit_thread - $sess_id - IP: %-15s - ID: %-12s - Inviati: %10d - Ricevuti: %10d\n", $remote_IP, $thread_ID, $remote_SEND, $remote_RECEIVE) if ($verbose);
+
+ my $query = " UPDATE
+ proxy_dati
+ SET
+ data_destroy = FROM_UNIXTIME($remote_DESTROY),
+ inviati = $remote_SEND,
+ ricevuti = $remote_RECEIVE,
+ tempo = TIMESTAMPDIFF(SECOND, data_new, FROM_UNIXTIME($remote_DESTROY)),
+ vel_inv = $remote_SEND / TIMESTAMPDIFF(SECOND, data_new, FROM_UNIXTIME($remote_DESTROY)),
+ vel_ric = $remote_RECEIVE / TIMESTAMPDIFF(SECOND, data_new, FROM_UNIXTIME($remote_DESTROY))
+ WHERE
+ thread = $thread_ID
+ AND
+ ip = '$remote_IP'
+ AND
+ data_destroy = '1970-01-01 00:00:00'
+ ";
+
+ $sem1->down();
+ $queryDB = $query;
+ $sem2->up();
+ print "Invio query UPDATE\n" if ($verbose > 1);
+ }
+ if ($conta >= $limit_thread) {
+ last;
+# kill 9, $proc_id;
+# return
+ }
+ }
+ kill 9, $proc_id;
+ return;
+}
+
+sub database {
+ print "Attivato thread DB\n" if ($verbose);
+
+ $dbmysql = DBConn ();
+
+ while (1) {
+ print "DB in attesa\n" if ($verbose > 1);
+ $sem2->down();
+ print "Query arrivata\n" if ($verbose > 1);
+
+ if ( not $dbmysql->ping ) {
+ $dbmysql = DBConn ();
+ }
+
+ my $sts = $dbmysql->prepare($queryDB);
+ $sts->execute ();
+
+ $sts->finish;
+ $sem1->up();
+ }
+}
+
+sub DBConn {
+ print "Connessione DB\n" if ($verbose > 1);
+ my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass, {PrintError => 0, RaiseError => 0, AutoCommit =>1, mysql_auto_reconnect=>1} ) or die ($DBI::errstr);
+ $sts = $dbmysql->prepare("use $DBname");
+ $sts->execute ();
+
+ return $dbmysql;
+}