Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 859 → Rev 860

/web/acc/admin/net_filter.php
100,56 → 100,51
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);
if ($tab)
$insert = true;
if ($tab) // file isn't empty
{
$pointeur=fopen(SERVICES_LIST,"r");
// test if port doesn't already exist
$insert = true;
foreach ($tab as $line)
foreach ($tab as $line) //test if port doesn't already exist
{
$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);
if ($tab)
$insert = true;
if ($tab) // file isn't empty
{
$pointeur=fopen(IP_BLOCKED,"r");
// test if IP doesn't already exist
$insert = true;
foreach ($tab as $line)
foreach ($tab as $line) // test if IP address doesn't already exist
{
$IP_f=explode("#", $line);
if (trim($_POST['add_ip']) == trim($IP_f[0])) {$insert = false;}
$IP_f=explode(" ", $line);
if (trim($_POST['add_ip']) == trim(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' :
171,7 → 166,6
if ($name_svc1 == $name_svc2)
{
$remove_line = True;
break;
}
}
if (strstr($key,'chk-'))
193,7 → 187,7
}
fclose($pointeur);
}
exec ("sudo /usr/local/sbin/alcasar-nf.sh -on");
exec ("sudo /usr/local/bin/alcasar-iptables.sh -on");
break;
case 'change_ip' :
$tab=file(IP_BLOCKED);
208,6 → 202,7
$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);
236,7 → 231,7
}
fclose($pointeur);
}
#exec ("sudo /usr/local/bin/alcasar-iptables.sh");
exec ("sudo /usr/local/bin/alcasar-iptables.sh");
break;
}
# default values
301,9 → 296,10
{
$blocked_ip=explode(" ", $line);
$ip_addr=trim($blocked_ip[0],"#");
echo "<tr><td>$ip_addr<td>$blocked_ip[1]";
$comment=trim($blocked_ip[1]);
if ($comment ==''){$comment="&nbsp;";}
echo "<tr><td>$ip_addr<td>$comment";
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 {