119 lines
2.9 KiB
PHP
Executable File
119 lines
2.9 KiB
PHP
Executable File
<?php
|
|
include_once ("../core/config.php");
|
|
$UTENTE = login();
|
|
$DIRITTI = diritti('Admin');
|
|
?>
|
|
<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'];
|
|
$genera = 0;
|
|
switch ($azione) {
|
|
case "macchina_rm":
|
|
$query = "DELETE FROM condes_macchine WHERE id = $id";
|
|
$testo = "Confermate la rimozione della macchina da quelle disponibili?";
|
|
break;
|
|
case "macchina_up":
|
|
$query = "UPDATE condes_macchine SET attivo = 1 WHERE id = $id";
|
|
$testo = "Confermate l'attivazione della macchina?";
|
|
break;
|
|
case "macchina_down":
|
|
$query = "UPDATE condes_macchine SET attivo = 0 WHERE id = $id";
|
|
$testo = "Confermate la disattivazione della macchina?";
|
|
break;
|
|
|
|
case "regola_rm":
|
|
$query = "DELETE FROM condes_regole WHERE id = $id";
|
|
$testo = "Confermate la rimozione della macchina da quelle disponibili?";
|
|
break;
|
|
case "regola_up":
|
|
$query = "UPDATE condes_regole SET attivo = 1 WHERE id = $id";
|
|
$testo = "Confermate l'attivazione della macchina?";
|
|
break;
|
|
case "regola_down":
|
|
$query = "UPDATE condes_regole SET attivo = 0 WHERE id = $id";
|
|
$testo = "Confermate la disattivazione della macchina?";
|
|
break;
|
|
|
|
default:
|
|
$testo = "Regola non implementata";
|
|
break;
|
|
}
|
|
|
|
if (isset($_GET['ref'])) {
|
|
$ref = pack ('H*', $_GET['ref']);
|
|
mysql_query( $query, $DB_ID );
|
|
if ($genera) genera($DB_ID);
|
|
?>
|
|
<script type="text/javascript">
|
|
document.location.href="<?php print $ref ?>"
|
|
</script>
|
|
<?php } else {
|
|
$ref = unpack ('H*', $_SERVER["HTTP_REFERER"]);
|
|
?>
|
|
<script type="text/javascript">
|
|
var r = confirm("<?php print $testo ?>");
|
|
if (r == true) {
|
|
document.location.href="<?php print $_SERVER['REQUEST_URI']?>&ref=<?php print $ref[1] ?>"
|
|
} else {
|
|
document.location.href="<?php print $_SERVER['HTTP_REFERER']?>"
|
|
}
|
|
</script>
|
|
<?php }
|
|
|
|
}
|
|
}
|
|
?>
|
|
|
|
<?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");
|
|
remote ($DB_ID);
|
|
}
|
|
|
|
function remote ($DB_ID) {
|
|
$query = " SELECT
|
|
host,
|
|
port,
|
|
usr,
|
|
pwd,
|
|
path,
|
|
command
|
|
FROM
|
|
proxy_remote
|
|
WHERE
|
|
attivo = 1
|
|
";
|
|
|
|
$res = mysql_query( $query, $DB_ID );
|
|
while ($dato = mysql_fetch_array ( $res )) {
|
|
$connection = ssh2_connect($dato['host'], $dato['port']);
|
|
ssh2_auth_password($connection, $dato['usr'], $dato['pwd']);
|
|
|
|
ssh2_scp_send($connection, 'squid_acl/listip', $dato['path'].'/listip', 0644);
|
|
$stream = ssh2_exec($connection, $dato['command']);
|
|
}
|
|
}
|
|
?>
|