Aggiunto sistema partizionamento DB per ottimizzare l'accesso ai dati
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
proxy/conntrack.conf
|
||||
core/config.php
|
||||
squid_pool.log
|
||||
|
||||
@@ -505,6 +505,4 @@ function byteConvert($bytes) {
|
||||
return sprintf('%.2f '.$s[$e], ($bytes/pow(1024, $e)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -25,20 +25,25 @@ $res = mysql_query( $query, $DB_ID );
|
||||
$valori = mysql_fetch_array ( $res );
|
||||
$max = $valori['max'];
|
||||
|
||||
|
||||
/*
|
||||
$ric = $valori['ricevuti'];
|
||||
$inv = $valori['inviati'];
|
||||
*/
|
||||
|
||||
$query = "SELECT ip, ricevuti, inviati FROM proxy_speed ORDER BY ricevuti desc , inviati desc";
|
||||
$query = "SELECT proxy_speed.ip, proxy_speed.ricevuti, proxy_speed.inviati, proxy_pool.attivo FROM proxy_speed JOIN proxy_pool ON proxy_speed.ip = proxy_pool.ip ORDER BY ricevuti desc , inviati desc";
|
||||
$res = mysql_query( $query, $DB_ID );
|
||||
while ($dato = mysql_fetch_array ( $res )) {
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td rowspan=2 class="col3btn"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente attivo" TITLE="Utente attivo"> </td>
|
||||
<td rowspan=2 class="col3btn"><a href="ip.php?ip=<?php print $dato['ip'] ?>"><img src="<?php print $CONF['base_url'] ?>/img/modify.gif" width="20" height="20" border="0" ALT="Dettaglio" TITLE="Dettaglio"></a></td>
|
||||
<?php
|
||||
if ($dato['attivo']) {
|
||||
?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=libera&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Utente limitato" TITLE="Utente limitato"></a></td>
|
||||
<?php } else { ?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=limita&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente non limitato" TITLE="Utente non limitato"></a></td>
|
||||
<?php } ?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_ip.php?ip=<?php print $dato['ip'] ?>"><img src="<?php print $CONF['base_url'] ?>/img/modify.gif" width="20" height="20" border="0" ALT="Dettaglio" TITLE="Dettaglio"></a></td>
|
||||
<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
|
||||
<td rowspan=2 class="colip"><?php print $dato['ip'] ?></td>
|
||||
|
||||
62
proxy/pool_gest.php
Executable file
62
proxy/pool_gest.php
Executable file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
include_once ("../core/config.php");
|
||||
$UTENTE = login();
|
||||
$DIRITTI = diritti(1);
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
function confirmation(testo) {
|
||||
alert(testo)
|
||||
document.location.href='main.php'
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
|
||||
<?php
|
||||
if (isset($_GET['ip'])) {
|
||||
$ip = $_GET['ip'];
|
||||
if (isset($_GET['azione'])) {
|
||||
$azione = $_GET['azione'];
|
||||
switch ($azione) {
|
||||
case "limita":
|
||||
$query = "INSERT INTO proxy_pool (ip, pool, attivo) VALUES ('$ip', 1, 1) ON DUPLICATE KEY UPDATE attivo = 1";
|
||||
mysql_query( $query, $DB_ID );
|
||||
$testo = "Utente $ip inserito in pool di limitazione banda";
|
||||
genera($DB_ID);
|
||||
break;
|
||||
case "libera":
|
||||
$query = "INSERT INTO proxy_pool (ip, pool, attivo) VALUES ('$ip', 1, 0) ON DUPLICATE KEY UPDATE attivo = 0";
|
||||
mysql_query( $query, $DB_ID );
|
||||
$testo = "Utente $ip rimosso dal pool di limitazione banda";
|
||||
genera($DB_ID);
|
||||
break;
|
||||
default:
|
||||
$testo = "Regola non implementata";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
confirmation ('<?php print "$testo" ?>');
|
||||
document.location.href='<?php print $_SERVER['HTTP_REFERER']?>'
|
||||
</script>
|
||||
|
||||
<?php
|
||||
function genera ($DB_ID) {
|
||||
$file = 'squid_acl/listip';
|
||||
$fp = fopen($file, 'w');
|
||||
|
||||
$query = "SELECT ip FROM proxy_pool WHERE attivo = 1 AND pool = 1";
|
||||
$res = mysql_query( $query, $DB_ID );
|
||||
while ($dato = mysql_fetch_array ( $res )) {
|
||||
fwrite($fp, $dato['ip']."\n");
|
||||
}
|
||||
fclose($fp);
|
||||
exec ("sudo /opt/squid/sbin/squid -k reconfigure");
|
||||
// sudo /opt/squid/sbin/squid -k reconfigure
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -36,17 +36,22 @@ if (isset($_POST['tempo'])) {
|
||||
<?php
|
||||
|
||||
$query = " SELECT
|
||||
ip,
|
||||
MIN(data_destroy) AS first,
|
||||
MAX(data_destroy) AS last,
|
||||
SUM(inviati) AS inviati,
|
||||
SUM(ricevuti) AS ricevuti
|
||||
proxy_pool.attivo,
|
||||
proxy_dati.ip,
|
||||
MIN(proxy_dati.data_destroy) AS first,
|
||||
MAX(proxy_dati.data_destroy) AS last,
|
||||
SUM(proxy_dati.inviati) AS inviati,
|
||||
SUM(proxy_dati.ricevuti) AS ricevuti
|
||||
FROM
|
||||
proxy_dati
|
||||
JOIN
|
||||
proxy_pool
|
||||
ON
|
||||
proxy_dati.ip = proxy_pool.ip
|
||||
WHERE
|
||||
ip = '$ip'
|
||||
proxy_dati.ip = '$ip'
|
||||
AND
|
||||
data_destroy >= DATE_SUB(NOW(), INTERVAL 1 $tempo)
|
||||
proxy_dati.data_destroy >= DATE_SUB(NOW(), INTERVAL 1 $tempo)
|
||||
";
|
||||
|
||||
$res = mysql_query( $query, $DB_ID );
|
||||
@@ -54,8 +59,13 @@ $dato = mysql_fetch_array ( $res );
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td rowspan=2 class="col3btn"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente attivo" TITLE="Utente attivo"> </td>
|
||||
|
||||
<?php
|
||||
if ($dato['attivo']) {
|
||||
?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=libera&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Utente limitato" TITLE="Utente limitato"></a></td>
|
||||
<?php } else { ?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=limita&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente non limitato" TITLE="Utente non limitato"></a></td>
|
||||
<?php } ?>
|
||||
<td rowspan=2 class="colip"><?php print $dato['ip'] ?></td>
|
||||
|
||||
<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
@@ -35,13 +35,18 @@ $valori = mysql_fetch_array ( $res );
|
||||
$max = $valori['max'];
|
||||
|
||||
$query = " SELECT
|
||||
ip,
|
||||
MIN(data_destroy) AS first,
|
||||
MAX(data_destroy) AS last,
|
||||
SUM(inviati) AS inviati,
|
||||
SUM(ricevuti) AS ricevuti
|
||||
proxy_pool.attivo,
|
||||
proxy_dati.ip,
|
||||
MIN(proxy_dati.data_destroy) AS first,
|
||||
MAX(proxy_dati.data_destroy) AS last,
|
||||
SUM(proxy_dati.inviati) AS inviati,
|
||||
SUM(proxy_dati.ricevuti) AS ricevuti
|
||||
FROM
|
||||
proxy_dati
|
||||
JOIN
|
||||
proxy_pool
|
||||
ON
|
||||
proxy_dati.ip = proxy_pool.ip
|
||||
WHERE
|
||||
data_destroy >= DATE_SUB(NOW(), INTERVAL 1 $tempo)
|
||||
GROUP BY
|
||||
@@ -55,8 +60,14 @@ while ($dato = mysql_fetch_array ( $res )) {
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td rowspan=2 class="col3btn"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente attivo" TITLE="Utente attivo"> </td>
|
||||
<td rowspan=2 class="col3btn"><a href="ip.php?ip=<?php print $dato['ip'] ?>"><img src="<?php print $CONF['base_url'] ?>/img/modify.gif" width="20" height="20" border="0" ALT="Dettaglio" TITLE="Dettaglio"></a></td>
|
||||
<?php
|
||||
if ($dato['attivo']) {
|
||||
?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=libera&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Utente limitato" TITLE="Utente limitato"></a></td>
|
||||
<?php } else { ?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_gest.php?azione=limita&ip=<?php print $dato['ip']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente non limitato" TITLE="Utente non limitato"></a></td>
|
||||
<?php } ?>
|
||||
<td rowspan=2 class="col3btn"><a href="pool_ip.php?ip=<?php print $dato['ip'] ?>"><img src="<?php print $CONF['base_url'] ?>/img/modify.gif" width="20" height="20" border="0" ALT="Dettaglio" TITLE="Dettaglio"></a></td>
|
||||
<td rowspan=2 class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
|
||||
<td rowspan=2 class="colip"><?php print $dato['ip'] ?></td>
|
||||
6
proxy/script/conntrack.conf
Normal file
6
proxy/script/conntrack.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
our $DBhost = '127.0.0.1';
|
||||
our $DBname = 'pannello_vbc';
|
||||
our $DBuser = 'pannello_proxy';
|
||||
our $DBpass = 'CuQlM1lfF4VZDCIP';
|
||||
|
||||
return 1;
|
||||
@@ -24,6 +24,15 @@ my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die (
|
||||
$sts = $dbmysql->prepare("use $DBname");
|
||||
$sts->execute ();
|
||||
|
||||
$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,
|
||||
@@ -109,6 +118,14 @@ sub conntrack {
|
||||
$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) VALUE ('$remote_IP', 1, 0)";
|
||||
$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+)/) {
|
||||
@@ -136,7 +153,7 @@ sub conntrack {
|
||||
AND
|
||||
ip = '$remote_IP'
|
||||
AND
|
||||
data_destroy IS NULL
|
||||
data_destroy = '1970-01-01 00:00:00'
|
||||
";
|
||||
|
||||
$sem1->down();
|
||||
@@ -164,6 +181,7 @@ sub database {
|
||||
|
||||
my $sts = $dbmysql->prepare($queryDB);
|
||||
$sts->execute ();
|
||||
|
||||
$sts->finish;
|
||||
$sem1->up();
|
||||
}
|
||||
0
proxy/squid_acl/listip
Normal file
0
proxy/squid_acl/listip
Normal file
58
proxy/squid_acl/squid_auth.pl
Executable file
58
proxy/squid_acl/squid_auth.pl
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/perl
|
||||
$|=1;
|
||||
|
||||
use DBI;
|
||||
use FindBin qw($Bin);
|
||||
|
||||
require "$Bin/../script/conntrack.conf";
|
||||
|
||||
local $SIG{ALRM} = sub {
|
||||
my $time = localtime; # scalar context
|
||||
print LOG "$$ - $time - Exit\n";
|
||||
exit 1;
|
||||
};
|
||||
|
||||
srand($$);
|
||||
$timeout = 60 * (int(rand(5))+61);
|
||||
$limit = 50;
|
||||
|
||||
my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die ($DBI::errstr);
|
||||
$sts = $dbmysql->prepare("use $DBname");
|
||||
$sts->execute ();
|
||||
|
||||
open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
|
||||
LOG->autoflush(1);
|
||||
|
||||
alarm $timeout;
|
||||
while($limit) {
|
||||
my $query = "";
|
||||
my $input = <>;
|
||||
chop $input;
|
||||
|
||||
# my ($acl, $ip) = split / /, $input;
|
||||
my @param = split / /, $input;
|
||||
|
||||
if ($param[0] ne "") {
|
||||
$query = "SELECT id FROM proxy_utenti WHERE user = '".$param[0]."' AND pass = PASSWORD('".$param[1]."') AND attivo = 1";
|
||||
$limit--;
|
||||
alarm $timeout;
|
||||
} else {
|
||||
$limit = 0;
|
||||
}
|
||||
|
||||
next if ($query eq "");
|
||||
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
|
||||
if ($ref = $sts->fetchrow_hashref ) {
|
||||
my $id = $$ref{'id'};
|
||||
my $query = "UPDATE proxy_utenti SET data = NOW() WHERE id = $id";
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
print "OK\n";
|
||||
} else {
|
||||
print "ERR\n";
|
||||
}
|
||||
}
|
||||
exit;
|
||||
69
proxy/squid_acl/squid_pool.pl
Executable file
69
proxy/squid_acl/squid_pool.pl
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/perl
|
||||
$|=1;
|
||||
|
||||
use DBI;
|
||||
use Switch;
|
||||
use FindBin qw($Bin);
|
||||
|
||||
require "$Bin/../script/conntrack.conf";
|
||||
|
||||
local $SIG{ALRM} = sub {
|
||||
my $time = localtime; # scalar context
|
||||
print LOG "$$ - $time - Exit\n";
|
||||
exit 1;
|
||||
};
|
||||
|
||||
srand($$);
|
||||
$timeout = 60 * (int(rand(5))+61);
|
||||
$limit = 50;
|
||||
|
||||
my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die ($DBI::errstr);
|
||||
$sts = $dbmysql->prepare("use $DBname");
|
||||
$sts->execute ();
|
||||
|
||||
open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
|
||||
LOG->autoflush(1);
|
||||
|
||||
alarm $timeout;
|
||||
while($limit) {
|
||||
my $query = "";
|
||||
my $input = <>;
|
||||
chop $input;
|
||||
|
||||
# my ($acl, $ip) = split / /, $input;
|
||||
my @param = split / /, $input;
|
||||
|
||||
switch ($param[0]) {
|
||||
case "permessi" {
|
||||
$query = "SELECT id FROM proxy_src WHERE ip = '".$param[1]."' AND attivo = 1";
|
||||
@reply = ("OK\n", "ERR\n");
|
||||
my $time = localtime; # scalar context
|
||||
print LOG "$$ - $time - $limit - $input -\n";
|
||||
$limit--;
|
||||
alarm $timeout;
|
||||
}
|
||||
case "utenti" {
|
||||
$query = "SELECT id FROM proxy_utenti WHERE user = '".$param[1]."' AND pass = PASSWORD('".$param[2]."') AND attivo = 1";
|
||||
@reply = ("OK\n", "ERR\n");
|
||||
my $time = localtime; # scalar context
|
||||
print LOG "$$ - $time - $limit - $input -\n";
|
||||
$limit--;
|
||||
alarm $timeout;
|
||||
}
|
||||
else {
|
||||
$limit = 0;
|
||||
}
|
||||
}
|
||||
|
||||
next if ($query eq "");
|
||||
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
|
||||
if ($ref = $sts->fetchrow_hashref ) {
|
||||
print $reply[0];
|
||||
} else {
|
||||
print $reply[1];
|
||||
}
|
||||
}
|
||||
exit;
|
||||
66
proxy/users_edit.php
Executable file
66
proxy/users_edit.php
Executable file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
include_once ("../core/config.php");
|
||||
$UTENTE = login();
|
||||
$DIRITTI = diritti(1);
|
||||
view_top();
|
||||
|
||||
if (isset($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
} else {
|
||||
|
||||
}
|
||||
?>
|
||||
<table cellpadding="0" cellspacing="0" border="1" width="90%">
|
||||
<?php
|
||||
$query = " SELECT
|
||||
id,
|
||||
user,
|
||||
fullname,
|
||||
attivo,
|
||||
data,
|
||||
ip
|
||||
FROM
|
||||
proxy_utenti
|
||||
WHERE
|
||||
id = $id
|
||||
";
|
||||
|
||||
$res = mysql_query( $query, $DB_ID );
|
||||
while ($dato = mysql_fetch_array ( $res )) {
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<?php
|
||||
if ($dato['attivo']) {
|
||||
?>
|
||||
<td class="col3btn"><a href="users_gest.php?azione=blocca&id=<?php print $dato['id']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente Attivo" TITLE="Utente Attivo"></a></td>
|
||||
<?php } else { ?>
|
||||
<td class="col3btn"><a href="users_gest.php?azione=abilita&id=<?php print $dato['id']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Utente non Attivo" TITLE="Utente non Attivo"></a></td>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="colip"><?php print $dato['user'] ?></td>
|
||||
|
||||
<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
<td class="colip"><?php print $dato['fullname'] ?></td>
|
||||
|
||||
<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
<td class="colip"><?php print $dato['data'] ?></td>
|
||||
|
||||
<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
<td class="colip"><?php print $dato['ip'] ?></td>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td class="spaziov" colspan=13><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>
|
||||
|
||||
<?php
|
||||
} ?>
|
||||
</table>
|
||||
<img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="20" alt="">
|
||||
<?php view_footer(); ?>
|
||||
43
proxy/users_gest.php
Executable file
43
proxy/users_gest.php
Executable file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
include_once ("../core/config.php");
|
||||
$UTENTE = login();
|
||||
$DIRITTI = diritti(1);
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
function confirmation(testo) {
|
||||
alert(testo)
|
||||
document.location.href='main.php'
|
||||
}
|
||||
//-->
|
||||
</script>
|
||||
|
||||
<?php
|
||||
if (isset($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
if (isset($_GET['azione'])) {
|
||||
$azione = $_GET['azione'];
|
||||
switch ($azione) {
|
||||
case "abilita":
|
||||
$query = "UPDATE proxy_utenti SET attivo = 1 WHERE id = $id";
|
||||
mysql_query( $query, $DB_ID );
|
||||
$testo = "Utente Abilitato";
|
||||
break;
|
||||
case "blocca":
|
||||
$query = "UPDATE proxy_utenti SET attivo = 0 WHERE id = $id";
|
||||
mysql_query( $query, $DB_ID );
|
||||
$testo = "Utente Disabilitato";
|
||||
break;
|
||||
default:
|
||||
$testo = "Regola non implementata";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
confirmation ('<?php print "$testo" ?>');
|
||||
document.location.href='<?php print $_SERVER['HTTP_REFERER']?>'
|
||||
</script>
|
||||
57
proxy/users_lista.php
Executable file
57
proxy/users_lista.php
Executable file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
include_once ("../core/config.php");
|
||||
$UTENTE = login();
|
||||
$DIRITTI = diritti(1);
|
||||
view_top();
|
||||
?>
|
||||
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="90%">
|
||||
<?php
|
||||
$query = " SELECT
|
||||
id,
|
||||
user,
|
||||
fullname,
|
||||
attivo,
|
||||
data,
|
||||
ip
|
||||
FROM
|
||||
proxy_utenti
|
||||
ORDER BY
|
||||
user
|
||||
";
|
||||
|
||||
$res = mysql_query( $query, $DB_ID );
|
||||
while ($dato = mysql_fetch_array ( $res )) {
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<?php
|
||||
if ($dato['attivo']) {
|
||||
?>
|
||||
<td class="col3btn"><a href="users_gest.php?azione=blocca&id=<?php print $dato['id']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/attivo.gif" ALT="Utente Attivo" TITLE="Utente Attivo"></a></td>
|
||||
<?php } else { ?>
|
||||
<td class="col3btn"><a href="users_gest.php?azione=abilita&id=<?php print $dato['id']?>"><img border=0 src="<?php print $CONF['base_url'] ?>/img/non_attivo.gif" ALT="Utente non Attivo" TITLE="Utente non Attivo"></a></td>
|
||||
<?php } ?>
|
||||
<td class="col3btn"><a href="users_edit.php?id=<?php print $dato['id'] ?>"><img src="<?php print $CONF['base_url'] ?>/img/modify.gif" width="20" height="20" border="0" ALT="Dettaglio" TITLE="Dettaglio"></a></td>
|
||||
<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
|
||||
<td class="colip"><?php print $dato['user'] ?></td>
|
||||
|
||||
<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
<td class="colip"><?php print $dato['fullname'] ?></td>
|
||||
|
||||
<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
<td class="colip"><?php print $dato['data'] ?></td>
|
||||
|
||||
<td class="spazioh"><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td>
|
||||
<td class="colip"><?php print $dato['ip'] ?></td>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td class="spaziov" colspan=13><img src="<?php print $CONF['base_url'] ?>/img/spazio.gif"></td></tr>
|
||||
|
||||
<?php
|
||||
} ?>
|
||||
</table>
|
||||
<img src="<?php print $CONF['base_url'] ?>/img/spazio.gif" width="1" height="20" alt="">
|
||||
<?php view_footer(); ?>
|
||||
3
script/dumpDB.sh
Executable file
3
script/dumpDB.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
/usr/bin/mysqldump -u dump -pIZcKUBofwoVgTl3C pannello_vbc > pannello_vbc.sql
|
||||
564
script/pannello_vbc.sql
Normal file
564
script/pannello_vbc.sql
Normal file
File diff suppressed because one or more lines are too long
@@ -9,55 +9,154 @@ use Time::Local;
|
||||
|
||||
our $messaggi = 0;
|
||||
while( $_ = shift @ARGV ) {
|
||||
$messaggi = 1 if /^\-v$/;
|
||||
our $messaggi = 1 if /^\-v$/;
|
||||
$start = 1 if /^\-i$/;
|
||||
}
|
||||
|
||||
my $tabella = "proxy_dati";
|
||||
my $campo = "data_destroy";
|
||||
|
||||
open CONFFILE, "< $Bin/../core/config.php" or die ("Manca file di configurazione\n");
|
||||
while (<CONFFILE>) {
|
||||
if(/^\$db_data_server = "(\S+)"/ ) {
|
||||
$db_host = $1;
|
||||
our $db_host = $1;
|
||||
}
|
||||
if(/^\$db_data_name = "(\S+)"/ ) {
|
||||
$db_name = $1;
|
||||
our $db_name = $1;
|
||||
}
|
||||
if(/^\$db_data_user = "(\S+)"/ ) {
|
||||
$db_user = $1;
|
||||
our $db_user = $1;
|
||||
}
|
||||
if(/^\$db_data_pwd = "(\S+)"/ ) {
|
||||
$db_pass = $1;
|
||||
our $db_pass = $1;
|
||||
}
|
||||
}
|
||||
close CONFFILE;
|
||||
|
||||
printf "Inizio attivita' %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
my $dbmysql = DBI->connect("DBI:mysql:;host=$db_host", "$db_user", "$db_pass") or die ($DBI::errstr);
|
||||
$sts = $dbmysql->prepare("use $db_name");
|
||||
$sts->execute ();
|
||||
|
||||
$part = "ALTER TABLE dati_traffico PARTITION BY RANGE ( dataunix ) (\n";
|
||||
|
||||
#$query = "SELECT DATE_FORMAT(data, \"%Y%m%d\") AS giorno, DATE_FORMAT(data, \"%Y-%m-%d\") AS giorno2 FROM dati_traffico GROUP BY giorno ORDER BY giorno";
|
||||
$query = "SELECT DATE_FORMAT(data, \"%Y%m%d\") AS giorno, DATE_FORMAT(data, \"%Y\") AS a, DATE_FORMAT(data, \"%m\") AS m, DATE_FORMAT(data, \"%d\") AS g FROM dati_traffico GROUP BY giorno ORDER BY giorno";
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
while (my $dato = $sts->fetchrow_hashref) {
|
||||
my $giorno = $$dato{'giorno'};
|
||||
my $a = $$dato{'a'};
|
||||
my $m = $$dato{'m'};
|
||||
my $g = $$dato{'g'};
|
||||
# my $giorno2 = $$dato{'giorno2'};
|
||||
# print "$giorno\n";
|
||||
my $timest = timelocal (59, 59, 23, $g, $m-1, $a);
|
||||
# $part .= "PARTITION p$giorno VALUES LESS THAN ( UNIX_TIMESTAMP('$giorno2 23:59:59') ),\n";
|
||||
$part .= "PARTITION p$giorno VALUES LESS THAN ( $timest ),\n";
|
||||
if ($start) {
|
||||
inizializza($dbmysql, $tabella, $campo);
|
||||
exit;
|
||||
}
|
||||
$part .= "PARTITION p99999999 VALUES LESS THAN (MAXVALUE)\n";
|
||||
$part .= ");\n";
|
||||
|
||||
print $part;
|
||||
aggiorna($dbmysql, $tabella, $campo);
|
||||
exit;
|
||||
|
||||
printf "Inizio partizionamento %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
$sts = $dbmysql->prepare($part);
|
||||
$sts->execute ();
|
||||
|
||||
printf "Termine attivita' %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
sub inizializza {
|
||||
|
||||
my $dbmysql = shift;
|
||||
my $tabella = shift;
|
||||
my $campo = shift;
|
||||
|
||||
printf "Inizio attivita' %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
|
||||
$part = "ALTER TABLE $tabella PARTITION BY RANGE COLUMNS ( $campo ) (\n";
|
||||
|
||||
$query = " SELECT
|
||||
DATE_FORMAT($campo, \"%Y%m%d\") AS giorno,
|
||||
DATE_FORMAT($campo, \"%Y-%m-%d 23:59:59\") AS partenza
|
||||
FROM
|
||||
$tabella
|
||||
GROUP BY
|
||||
giorno
|
||||
ORDER BY
|
||||
giorno
|
||||
";
|
||||
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
while (my $dato = $sts->fetchrow_hashref) {
|
||||
my $giorno = $$dato{'giorno'};
|
||||
my $partenza = $$dato{'partenza'};
|
||||
$part .= "\tPARTITION p$giorno VALUES LESS THAN ( '$partenza' ),\n";
|
||||
}
|
||||
$part .= "\tPARTITION p99999999 VALUES LESS THAN (MAXVALUE)\n";
|
||||
$part .= ");\n";
|
||||
|
||||
print $part if ($messaggi);
|
||||
|
||||
printf "Inizio partizionamento %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
$sts = $dbmysql->prepare($part);
|
||||
$sts->execute ();
|
||||
|
||||
printf "Termine attivita' %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
}
|
||||
|
||||
sub aggiorna {
|
||||
|
||||
my $dbmysql = shift;
|
||||
my $tabella = shift;
|
||||
my $campo = shift;
|
||||
|
||||
printf "Inizio attivita' %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
|
||||
$query = "SHOW CREATE TABLE $tabella";
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
|
||||
my @row = $sts->fetchrow_array();
|
||||
my @risp = split '\n', $row[1];
|
||||
|
||||
my $ultimo = "";
|
||||
foreach $riga (@risp) {
|
||||
if ($riga =~ /^[\(\s]?PARTITION p(\d+) VALUES LESS THAN \(\'(\S+) (\S+)\'\) .*$/) {
|
||||
|
||||
next if ($1 eq '19700101');
|
||||
$ultimo = $2;
|
||||
my $diff = diffgg ($2);
|
||||
|
||||
if ($diff > 365) {
|
||||
my $query = "ALTER TABLE $tabella DROP PARTITION p$1";
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (diffgg($ultimo) > -5) {
|
||||
my $prequery = "ALTER TABLE $tabella REORGANIZE PARTITION p99999999 INTO (\n";
|
||||
my $postquery = "PARTITION p99999999 VALUES LESS THAN (MAXVALUE))\n";
|
||||
my $inquery = "";
|
||||
|
||||
while (diffgg($ultimo) > -5) {
|
||||
$ultimo = addgg ($ultimo);
|
||||
my @tmp0 = split / /, $ultimo;
|
||||
my @tmp = split /-/, $tmp0[0];
|
||||
my $p = $tmp[0].$tmp[1].$tmp[2];
|
||||
$inquery .= "PARTITION p$p VALUES LESS THAN ('$ultimo'),\n";
|
||||
}
|
||||
$query = "$prequery$inquery$postquery";
|
||||
$sts = $dbmysql->prepare($query);
|
||||
$sts->execute ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
printf "Termine attivita' %s\n",strftime('%d-%m-%Y %H:%M:%S',localtime) if ($messaggi);
|
||||
}
|
||||
|
||||
sub diffgg {
|
||||
my $data = shift;
|
||||
|
||||
my @today = localtime();
|
||||
my $time = timelocal(@today);
|
||||
|
||||
my @part = split /-/, $data;
|
||||
my @tempo = (59, 59, 23, $part[2], $part[1]-1, $part[0]-1900);
|
||||
my $tempo = timelocal(@tempo);
|
||||
|
||||
return int(($time - $tempo) / 86400);
|
||||
}
|
||||
|
||||
sub addgg {
|
||||
my $data = shift;
|
||||
|
||||
my @part = split /-/, $data;
|
||||
my @tempo = (59, 59, 23, $part[2], $part[1]-1, $part[0]-1900);
|
||||
my $tempo = timelocal(@tempo) + 86400;
|
||||
return strftime('%Y-%m-%d %H:%M:%S',localtime($tempo))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user