Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 860 → Rev 859

/web/acc/admin/net_filter.php
100,51 → 100,56
exec ("sudo /usr/local/sbin/alcasar-nf.sh -off");
break;
case 'new_port' :
$_POST['add_proto'] = str_replace (CHR(32),"-",$_POST['add_proto']);
if ((trim($_POST['add_port']) != "80") and ($_POST['add_port'] != "") and ($_POST['add_proto'] != "") and (is_numeric($_POST['add_port'])))
{
$_POST['add_proto'] = str_replace (CHR(32),"-",$_POST['add_proto']);
$tab=file(SERVICES_LIST);
$insert = true;
if ($tab) // file isn't empty
if ($tab)
{
foreach ($tab as $line) //test if port doesn't already exist
$pointeur=fopen(SERVICES_LIST,"r");
// test if port doesn't already exist
$insert = true;
foreach ($tab as $line)
{
$proto_f=explode(" ", $line);
if (trim($_POST['add_port']) == trim($proto_f[1])) {$insert = false;}
}
fclose($pointeur);
if ($insert == true)
{
$line = "\n" . "#" . trim($_POST['add_proto']) . " " . trim($_POST['add_port']);
$pointeur=fopen(SERVICES_LIST,"a");
fwrite ($pointeur, $line);
fclose ($pointeur);
exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
}
}
if ($insert == true)
{
$line = "\n" . "#" . trim($_POST['add_proto']) . " " . trim($_POST['add_port']);
$pointeur=fopen(SERVICES_LIST,"a");
fwrite ($pointeur, $line);
fclose ($pointeur);
exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
}
}
break;
case 'new_ip' :
if (trim($_POST['add_ip']) != "")
{
$_POST['add_comment'] = str_replace (CHR(32),"-",$_POST['add_comment']);
$tab=file(IP_BLOCKED);
$insert = true;
if ($tab) // file isn't empty
if ($tab)
{
foreach ($tab as $line) // test if IP address doesn't already exist
$pointeur=fopen(IP_BLOCKED,"r");
// test if IP doesn't already exist
$insert = true;
foreach ($tab as $line)
{
$IP_f=explode(" ", $line);
if (trim($_POST['add_ip']) == trim(trim($IP_f[0],"#"))) {$insert = false;}
$IP_f=explode("#", $line);
if (trim($_POST['add_ip']) == trim($IP_f[0])) {$insert = false;}
}
fclose($pointeur);
if ($insert == true)
{
$line ="\n" . trim($_POST['add_ip']) . " # " . trim($_POST['add_comment']);
$pointeur=fopen(IP_BLOCKED,"a");
fwrite ($pointeur, $line);
fclose ($pointeur);
exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
}
}
if ($insert == true)
{
$line ="\n" . "#".trim($_POST['add_ip']) . " " . trim($_POST['add_comment']);
$pointeur=fopen(IP_BLOCKED,"a");
fwrite ($pointeur, $line);
fclose ($pointeur);
exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
}
}
break;
case 'change_port' :
166,6 → 171,7
if ($name_svc1 == $name_svc2)
{
$remove_line = True;
break;
}
}
if (strstr($key,'chk-'))
187,7 → 193,7
}
fclose($pointeur);
}
exec ("sudo /usr/local/bin/alcasar-iptables.sh -on");
exec ("sudo /usr/local/sbin/alcasar-nf.sh -on");
break;
case 'change_ip' :
$tab=file(IP_BLOCKED);
202,7 → 208,6
$actif = False; $remove_line = false;
foreach ($_POST as $key => $value)
{
$key = str_replace ("_",".",$key); // dot are replace by '_' in post request
if (strstr($key,'del-'))
{
$ip_blocked2 = str_replace('del-','',$key);
231,7 → 236,7
}
fclose($pointeur);
}
exec ("sudo /usr/local/bin/alcasar-iptables.sh");
#exec ("sudo /usr/local/bin/alcasar-iptables.sh");
break;
}
# default values
296,10 → 301,9
{
$blocked_ip=explode(" ", $line);
$ip_addr=trim($blocked_ip[0],"#");
$comment=trim($blocked_ip[1]);
if ($comment ==''){$comment=" ";}
echo "<tr><td>$ip_addr<td>$comment";
echo "<tr><td>$ip_addr<td>$blocked_ip[1]";
echo "<td><input type='checkbox' name='chk-$ip_addr'";
// if the line is commented -> IP adress is not blocked
if (preg_match('/^#/',$line, $r)) {
echo ">";}
else {