Subversion Repositories ALCASAR

Rev

Rev 2817 | Rev 2857 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><!-- written by Rexy - 3abtux -->
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>Exceptions</TITLE>
<link rel="stylesheet" href="/css/acc.css" type="text/css">
</HEAD>
<body>
<?
/********************
*  TEST CONF FILES  *
*********************/
$domain_allowed_list="/usr/local/etc/alcasar-uamdomain";
$url_allowed_list="/usr/local/etc/alcasar-uamallowed";
define ("DOMAIN_ALLOWED_LIST", $domain_allowed_list);
define ("IP_ALLOWED_LIST", $url_allowed_list);
$conf_files=array(DOMAIN_ALLOWED_LIST,IP_ALLOWED_LIST);
foreach ($conf_files as $file){
if (!file_exists($file)){
        exit("Requested file ".$file." isn't present");}
if (!is_readable($file)){
        exit("Can't read the file ".$file);}
}
# Choice of language
$Language = 'en';
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
        $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $Language = strtolower(substr(chop($Langue[0]),0,2)); }
if($Language == 'fr'){
        $l_load="Chargement...";
        $l_error_open_file      = "Erreur d'ouverture du fichier";
        $l_trusted_domain       = "Noms de domaine Internet de confiance";
        $l_domain               = "Noms de domaine";
        $l_comment_explain      = "Lien affiché dans la page d'interception";
        $l_comment_explain2     = "Laissez vide si non affiché";
        $l_remove               = "Retirer de la liste";
        $l_trusted_ip           = "adresses IP de confiance";
        $l_trusted_equipments   = "Equipements de consultation de confiance";
        $l_comment              = "Commentaires";
        $l_trusted_domain_explain = "Gérez ici les noms de domaine Internet pouvant être joints sans authentification";
        $l_trusted_equipments_explain   = "Pour qu'un équipement du réseau de consultation puisse accéder à Internet sans être interceptés : créer un utilisateur dont le nom de login est l'@MAC de l'équipement et le mot de passe est 'password'" ;
        $l_trusted_ip_explain   = "Gérez ici les adresses IP de systèmes ou de réseaux pouvant être joints sans authentification";
        $l_submit               = "Enregistrer";
        $l_add_to_list          = "Ajouter à la liste";
        $l_apply                = "Appliquer les changements";
} else if($Language == 'es') {
    $l_load="Cargando...";
        $l_error_open_file      = "Error en la lectura del archivo";
        $l_trusted_domain       = "Sitios de Internet confiables";
        $l_domain               = "Nombres de Dominio";
        $l_comment_explain      = "Enlace mostrado en la página de interceptación";
        $l_comment_explain2     = "Dejar vacío para ocultar el enlace";
        $l_remove               = "Borrar de la lista";
        $l_trusted_ip           = "Direcciones IP confiables";
        $l_trusted_equipments   = "Equipos Autorizados (confiables)";
        $l_comment              = "Comentarios";
        $l_trusted_domain_explain = "Administra los sitios de Internet a los que se acceder sin iniciar sesión";
        $l_trusted_equipments_explain   = "Para permitir que un equipo se conecte a Internet sin interceptarlo, cree un usuario cuyo nombre sea la dirección MAC del dispositivo y la contraseña sea 'password'";
        $l_trusted_ip_explain   = "Administre direcciones IP de sistemas o direcciones IP de redes que pueden unirse sin autenticación";
        $l_submit               = "Enviar";
        $l_add_to_list          = "Agregar a la lista";
        $l_apply                = "Aplicar cambios";
} else {
        $l_load="Loading...";
        $l_error_open_file      = "File open error";
        $l_trusted_domain       = "Trusted Internet domain names";
        $l_domain               = "Domain names";
        $l_comment_explain      = "Link displayed in intercept page";
        $l_comment_explain2     = "Let empty to not display link";
        $l_remove               = "Remove from list";
        $l_trusted_ip           = "Trusted IP addresses";
        $l_trusted_equipments   = "Trusted consultation equipements";
        $l_comment              = "Comments";
        $l_trusted_domain_explain = "Manage Internet domain names that can be joined without authentication";
        $l_trusted_equipments_explain   = "To allow a consultation equipment to connect to Internet without interception, create a user whose name is the MAC address of the device and the password is 'password'";
        $l_trusted_ip_explain   = "Manage systems IP addresses or networks IP addresses that can be joined without authentication";
        $l_submit               = "Submit";
        $l_add_to_list          = "Add to list";
        $l_apply                = "Apply changes";
}
if (isset($_POST['choix'])){ 
        switch ($_POST['choix'])
        {
        case 'new_uamdomain' :
        if (trim($_POST['add_uamdomain']) != "") 
                {
                $tab=file(DOMAIN_ALLOWED_LIST);
                $insert = true;
                if ($tab) // file isn't empty
                        {
                        foreach ($tab as $line) // test if domain address doesn't already exist
                                {
                                $domain=explode("\"", $line);
                                if (strcmp(trim($_POST['add_uamdomain']),$domain[1]) == 0)
                                        {
                                        $insert = false;
                                        break;
                                        }
                                }
                        }
                if ($insert == true) 
                        {
                        $line ="\nuamdomain=\"" . trim($_POST['add_uamdomain']) . "\" #" . trim($_POST['add_domain_comment']);
                        $pointeur=fopen(DOMAIN_ALLOWED_LIST,"a");
                        fwrite ($pointeur, $line);
                        fclose ($pointeur);
                        exec ("sudo /usr/local/bin/alcasar-file-clean.sh"); # Clean & sort conf files. Add uamallowed domains to the dns-blackhole conf
                        sleep (1); # be sure that dnsmasq-blackhole is restarted before killing tun0 ! 
                        exec ("sudo /usr/bin/systemctl restart chilli");
                        }
                }
        break;
        case 'change_uamdomain' :
        $tab=file(DOMAIN_ALLOWED_LIST);
        if ($tab)
                {
                $pointeur=fopen(DOMAIN_ALLOWED_LIST,"w+");
                foreach ($tab as $ligne)
                        {
                        $uamdomain1=explode("\"", $ligne);
                        $remove_line = false;
                        foreach ($_POST as $key => $value)
                                {
                                $key = str_replace ("_",".",$key); // dot are replace by '_' in post request
                                if (strstr($key,'del-'))
                                        {
                                        $uamdomain2 = str_replace('del-','',$key);
                                        if (strcmp($uamdomain1[1],$uamdomain2) == 0)
                                                {
                                                $remove_line = True;
                                                break;
                                                }
                                        }
                                }
                        if (! $remove_line)
                                {
                                fwrite($pointeur,$ligne);
                                }
                        }
                fclose($pointeur);
                }
        exec ("sudo /usr/local/bin/alcasar-file-clean.sh");  # Clean & sort conf files. Add uamallowed domains to the dns-blackhole conf
        sleep (1); # be sure that dnsmasq-blackhole is restarted before killing tun0 ! 
        exec ("sudo /usr/bin/systemctl restart chilli");
        break;
        case 'new_ip' :
                $ipAddr = trim($_POST['add_ip']);
                if (!preg_match('/^([0-9]{1,3}\.){3}([0-9]{1,3})$/', $ipAddr)) {
                        echo '<span style="color: red;">'.'Invalid IP address'.'</span>'; // TODO : need to translate
                } else if (!empty($ipAddr)) {
                        $tab=file(IP_ALLOWED_LIST);
                        $insert = true;
                        if ($tab) { // file isn't empty
                                foreach ($tab as $line) { // test if domain address doesn't already exist
                                        $ip = explode('"', $line);
                                        if (strcmp($ipAddr, $ip[1]) === 0) {
                                                $insert = false;
                                                break;
                                        }
                                }
                        }
                        if ($insert === true)  {
                                $line = "\nuamallowed=\"" . $ipAddr .'" #' . trim($_POST['add_ip_comment']);
                                $pointeur = fopen(IP_ALLOWED_LIST, 'a');
                                fwrite($pointeur, $line);
                                fclose($pointeur);
                                exec('sudo /usr/local/bin/alcasar-file-clean.sh');  # Clean & sort conf files. Add uamallowed domains to the dns-blackhole conf
                                exec('sudo /usr/bin/systemctl restart chilli');
                        }
                }
        break;
        case 'change_ip' :
        $tab=file(IP_ALLOWED_LIST);
        if ($tab)
                {
                $pointeur=fopen(IP_ALLOWED_LIST,"w+");
                foreach ($tab as $ligne)
                        {
                        $ip1=explode("\"", $ligne);
                        $remove_line = false;
                        foreach ($_POST as $key => $value)
                                {
                                $key = str_replace ("_",".",$key); // dot are replace by '_' in post request
                                if (strstr($key,'del-'))
                                        {
                                        $ip2 = str_replace('del-','',$key);
                                        if (strcmp($ip1[1],$ip2) == 0)
                                                {
                                                $remove_line = True;
                                                break;
                                                }
                                        }
                                }
                        if (! $remove_line)
                                {
                                fwrite($pointeur,$ligne);
                                }
                        }
                fclose($pointeur);
                }
        exec ("sudo /usr/local/bin/alcasar-file-clean.sh");  # Clean & sort conf files. Add uamallowed domains to the dns-blackhole conf
        exec ("sudo /usr/bin/systemctl restart chilli");
        break;
        }
}
?>
<TABLE width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><th><?echo "$l_trusted_domain";?></th></tr>
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</table>
<table width="100%" border=1 cellspacing=0 cellpadding=1>
<tr><td colspan=2 align="center">
<?
echo "$l_trusted_domain_explain</td></tr>\n";
echo "<tr><td align='center' valign='middle'>\n";
echo "<FORM action='$_SERVER[PHP_SELF]' method='POST'>\n";
echo "<table cellspacing=2 cellpadding=2 border=1>";
echo "<tr align='center' bgcolor='#d0ddb0'><td>$l_domain<td>$l_comment_explain<td>$l_remove</tr>\n";
// Read the "Domain alowed" file
$tab=file(DOMAIN_ALLOWED_LIST);
if ($tab)  # the file isn't empty
        {
        foreach ($tab as $line)
                {
                if (trim($line) != '') # the line isn't empty
                        {
                        $domain_allowed=explode("#", $line);
                        $uamdomain=trim($domain_allowed[0],"#");
                        $domain=explode("\"", $uamdomain);
                        echo "<tr><td>$domain[1]";
                        echo "<td>";
                        if (isset ($domain_allowed[1])) {
                                echo trim($domain_allowed[1]);}
                        else echo "&nbsp";
                        echo "<td>";
                        echo "<input type='checkbox' name='del-$domain[1]'>";
                        echo "</tr>\n";
                        }
                }
        }
echo "</table>";
if ($tab)
        {
        echo "<input type='hidden' name='choix' value='change_uamdomain'>";
        echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_apply'>";
        }
?>
</form>
</td><td valign='middle' align='center'>
<form action='<?echo"$_SERVER[PHP_SELF]"?>' method='POST'>
<table cellspacing=2 cellpadding=3 border=1>
<tr align='center'><td bgcolor='#d0ddb0'><?echo "$l_domain<td bgcolor='#d0ddb0'>$l_comment_explain";?>
<td></tr>
<tr><td>exemple1 : www.mydomain.com <br>exemple2 : .yourdomain.net
<td>exemple1 : mydomain<br><?echo "$l_comment_explain2";?><td></tr>
<tr><td><input type='text' name='add_uamdomain' size='20'>
<td><input type='text' name='add_domain_comment' size='15'>
<input type='hidden' name='choix' value='new_uamdomain'></td>
<td><input type='submit' onClick="this.disabled=true; this.value='<?echo $l_load;?>';submit();" value='<?echo "$l_add_to_list";?>'>
</tr></table>
</form>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo "$l_trusted_ip" ;?></th></tr>
        <tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</table>
<table width="100%" border=1 cellspacing=0 cellpadding=1>
<tr><td colspan=2 align="center">
<?
echo "$l_trusted_ip_explain</td></tr>\n";
echo "<tr><td align='center' valign='middle'>\n";
echo "<FORM action='$_SERVER[PHP_SELF]' method='POST'>\n";
echo "<table cellspacing=2 cellpadding=2 border=1>";
echo "<tr align='center' bgcolor='#d0ddb0'><td>$l_trusted_ip<td>$l_comment<td>$l_remove</tr>\n";
// Read the "ip alowed" file
$tab=file(IP_ALLOWED_LIST);
if ($tab)  # the file isn't empty
        {
        foreach ($tab as $line)
                {
                if (trim($line) != '') # the line isn't empty
                        {
                        $ip_allowed=explode("#", $line);
                        $ip_a=trim($ip_allowed[0],"#");
                        $ip=explode("\"", $ip_a);
                        echo "<tr><td>$ip[1]";
                        echo "<td>";
                        if (isset($ip_allowed[1]))
                                echo trim($ip_allowed[1]);
                        else echo "&nbsp;";
                        echo "<td><input type='checkbox' name='del-$ip[1]'>";
                        echo "</tr>\n";
                        }
                }
        }
echo "</table>";
if ($tab)
        {
        echo "<input type='hidden' name='choix' value='change_ip'>";
        echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_apply'>";
        }
?>
</form>
</td><td valign='middle' align='center'>
<form action='<?echo "$_SERVER[PHP_SELF]"?>' method='POST'>
<table cellspacing=2 cellpadding=3 border=1>
<tr align='center'><td bgcolor='#d0ddb0'><?echo "$l_trusted_ip<td bgcolor='#d0ddb0'>$l_comment";?>
<td></tr>
<tr><td>exemple1 : 170.25.23.10 <br>exemple2 : 15.20.20.0/16</td>
<td>my_web_server <br>my_dmz<td></tr>
<tr><td><input type='text' name='add_ip' size='20'></td>
<td><input type='text' name='add_ip_comment' size='15'>
<input type='hidden' name='choix' value='new_ip'></td>
<td><input type='submit' onClick="this.disabled=true; this.value='<?echo $l_load;?>';submit();" value='<?echo "$l_add_to_list";?>'></td>
</tr></table>
</form>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo "$l_trusted_equipments";?></th></tr>
        <tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</table>
<table width="100%" border=1 cellspacing=0 cellpadding=1>
<tr><td colspan=2 align="center">
<?echo "$l_trusted_equipments_explain";?>
</td></tr>
</table>
</BODY>
</HTML>