Gestione gruppi proxy

This commit is contained in:
cmaffio
2016-05-17 16:50:51 +02:00
parent 6d7923c5d5
commit d3a75524fa
15 changed files with 256 additions and 41 deletions

View File

@@ -9,7 +9,7 @@ require "$Bin/../script/conntrack.conf";
local $SIG{ALRM} = sub {
my $time = localtime; # scalar context
print LOG "$$ - $time - Exit\n";
# print LOG "$$ - $time - Exit\n";
exit 1;
};
@@ -21,8 +21,8 @@ my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die (
$sts = $dbmysql->prepare("use $DBname");
$sts->execute ();
open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
LOG->autoflush(1);
#open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
#LOG->autoflush(1);
while($limit) {
alarm $timeout;
@@ -35,15 +35,15 @@ while($limit) {
my $ritorno = cerca ($param[1],$param[2], -1);
$limit--;
if ($ritorno) {
print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
# print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
print "DENY\n";
} else {
$ritorno = cerca ($param[1],$param[2], 1);
if ($ritorno) {
print LOG "$param[0] - $param[1] - $param[2] - OK\n";
# print LOG "$param[0] - $param[1] - $param[2] - OK\n";
print "OK\n";
} else {
print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
# print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
# print "DENY\n";
print "\n";
}

View File

@@ -9,7 +9,7 @@ require "$Bin/../script/conntrack.conf";
local $SIG{ALRM} = sub {
my $time = localtime; # scalar context
print LOG "$$ - $time - Exit\n";
# print LOG "$$ - $time - Exit\n";
exit 1;
};
@@ -21,8 +21,8 @@ my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die (
$sts = $dbmysql->prepare("use $DBname");
$sts->execute ();
open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
LOG->autoflush(1);
#open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
#LOG->autoflush(1);
while($limit) {
alarm $timeout;
@@ -35,15 +35,15 @@ while($limit) {
my $ritorno = cerca ($param[1],$param[2], -1);
$limit--;
if ($ritorno) {
print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
# print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
print "DENY\n";
} else {
$ritorno = cerca ($param[1],$param[2], 1);
if ($ritorno) {
print LOG "$param[0] - $param[1] - $param[2] - OK\n";
# print LOG "$param[0] - $param[1] - $param[2] - OK\n";
print "OK\n";
} else {
print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
# print LOG "$param[0] - $param[1] - $param[2] - ERR\n";
print "\n";
}
}

View File

@@ -8,7 +8,7 @@ require "$Bin/../script/conntrack.conf";
local $SIG{ALRM} = sub {
my $time = localtime; # scalar context
print LOG "$$ - $time - Exit\n";
# print LOG "$$ - $time - Exit\n";
exit 1;
};
@@ -20,8 +20,8 @@ my $dbmysql = DBI->connect("DBI:mysql:;host=$DBhost", $DBuser, $DBpass) or die (
$sts = $dbmysql->prepare("use $DBname");
$sts->execute ();
open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
LOG->autoflush(1);
#open LOG, ">> /srv/www/htdocs/pannello_vbc/proxy/squid_acl/squid_pool.log";
#LOG->autoflush(1);
alarm $timeout;
while($limit) {
@@ -29,11 +29,10 @@ while($limit) {
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";
$query = "SELECT id, primo, (tempo*3600)-time_to_sec(timediff(ultimo, primo)) AS rimasto, tempo FROM proxy_utenti WHERE user = '".$param[0]."' AND pass = PASSWORD('".$param[1]."') AND attivo = 1";
$limit--;
alarm $timeout;
} else {
@@ -47,7 +46,22 @@ while($limit) {
if ($ref = $sts->fetchrow_hashref ) {
my $id = $$ref{'id'};
my $query = "UPDATE proxy_utenti SET data = NOW() WHERE id = $id";
my $primo = $$ref{'primo'};
my $rimasto = $$ref{'rimasto'};
my $tempo = $$ref{'tempo'};
my $agg = "";
my $query = "";
if (($tempo > 0) && ($rimasto < 0)){
$agg = "attivo = 0,";
}
if (!$primo) {
$query = "UPDATE proxy_utenti SET $agg primo = NOW(), ultimo = NOW() WHERE id = $id";
} else {
$query = "UPDATE proxy_utenti SET $agg ultimo = NOW() WHERE id = $id";
}
# print LOG "$rimasto -- $query\n";
$sts = $dbmysql->prepare($query);
$sts->execute ();
print "OK\n";