Subversion Repositories ALCASAR

Rev

Rev 504 | Rev 606 | 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/style.css" type="text/css">
</HEAD>
<body>
<?
$mac_allowed_list="/usr/local/etc/alcasar-macallowed";
# 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_error_open_file = "Erreur d'ouverture du fichier";
  $l_trusted_sites = "Sites Internet de confiance";
  $l_trusted_sites_explain1 = "Entrez ici les noms de site ou d'URLs Internet pouvant &ecirc;tre joints sans authentification";
  $l_trusted_sites_explain2 = "Entrez un nom par ligne";
  $l_trusted_sites_list = "Liste de sites Internet de confiance";
  $l_trusted_urls_list = "Liste d'URLs Internet de confiance";
  $l_trusted_mac = "&Eacute;quipements de confiance";
  $l_trusted_mac_explain = "Entrez ici les adresses MAC des &eacute;quipements autorisés à joindre Internet sans authentification";
  $l_trusted_mac_list = "Liste des adresses MAC de confiance";
  $l_trusted_mac_address = "Adresses MAC autorisées";
  $l_trusted_mac_info = "Information équipement";
  $l_trusted_mac_del = "Supprimer de la liste";
  $l_submit = "Enregistrer";
  $l_submit2 = "Appliquer";
  $l_add_to_list = "Ajouter";
}
else {
  $l_error_open_file = "File open error";
  $l_trusted_sites = "Trusted Internet sites";
  $l_trusted_sites_explain1 = "Enter name of Internet sites or URLS that could be joined without authentication";
  $l_trusted_sites_explain2 = "Enter one name per line";
  $l_trusted_sites_list = "Trusted Internet sites list";
  $l_trusted_urls_list = "Trusted Internet URLs list";
  $l_trusted_mac = "Trusted Equipments";
  $l_trusted_mac_explain = "Enter MAC address of equipments that could contact Internet without authentication";
  $l_trusted_mac_list = "Trusted MAC addresses list";
  $l_trusted_mac_address = "Allowed MAC adress"; 
  $l_trusted_mac_info = "Equipment information";
  $l_trusted_mac_del = "Delete from list";
  $l_submit = "Submit";
  $l_submit2 = "Apply";
  $l_add_to_list = "Add";
}
if (isset($_POST['choix'])){ 
        switch ($_POST['choix'])
        {
        case 'MAJ_UAMALLOWED' :
                $nb_domain=0;
                $tab_domains = explode ("\n", $_POST['trusted_domains']);
                $fichier=fopen("/usr/local/etc/alcasar-uamdomain","w+");
                fputs ($fichier, "uamdomain=\"");
                foreach ($tab_domains as $domain ){
                        $tr_domain=trim($domain);
                        $nb_domain++;
                        if ($tr_domain != ""){
                                if ($nb_domain>1) fputs ($fichier, ",".$tr_domain);
                                else fputs ($fichier, $tr_domain);
                                }
                        }       
                fputs($fichier, "\"");
                fclose($fichier);
                unset($_POST['trusted_domains']);
                unset($nb_domain);
                $nb_url=0;
                $tab_urls = explode ("\n", $_POST['trusted_urls']);
                $fichier=fopen("/usr/local/etc/alcasar-uamallowed","w+");
                fputs ($fichier, "uamallowed=\"");
                foreach ($tab_urls as $url ){
                        $tr_url=trim($url);
                        $nb_url++;
                        if ($tr_url != ""){
                                if ($nb_url>1) fputs ($fichier, ",".$tr_url);
                                else fputs ($fichier, $tr_url);
                                }
                        }
                fputs($fichier, "\"");
                fclose($fichier);
                unset($_POST['trusted_urls']);
                unset($nb_url);
                exec ("sudo service chilli restart");
                unset ($_POST['choix']);
                break;
case 'new_mac' :
        if (trim($_POST['add_mac']) != "")
                {
                if (is_file ($mac_allowed_list)) # le fichier existe
                        {
                        $tab=file($mac_allowed_list);
                        $insert = true;
                        if ($tab)  # le fichier n'est pas vide
                                {
                                foreach ($tab as $line)  # on teste si l'adresse mac n'est pas déjà présente
                                        {
                                        $field=explode("#", $line);
                                        $mac_addr=trim($field[0],"macallowed=");
                                        if (trim($_POST['add_mac']) == trim ($mac_addr))
                                                {
                                                $insert = false;;
                                                break;
                                                }
                                        }
                                }
                        if ($insert == true) 
                                {
                                $line = "macallowed=" . trim($_POST['add_mac']) . " #" . trim($_POST['add_comment']) . "\n";
                                $pointeur=fopen($mac_allowed_list,"a");
                                fwrite ($pointeur, $line);
                                fclose ($pointeur);
                                exec ("sudo service chilli restart");
                                }
                        }
                else {echo "$l_error_open_file $mac_allowed_list";}
                }
        break;
case 'del_mac' :
        $tab=file($mac_allowed_list);
        if ($tab)
                {
                $pointeur=fopen($mac_allowed_list,"w+");
                foreach ($tab as $line)
                        {
                        $field=explode("#", $line);
                        $mac_addr=trim(trim($field[0],"macallowed="));
                        $remove_line = false;
                        foreach ($_POST as $key => $value)
                                {
                                if ($mac_addr == $key)
                                        {
                                        $remove_line = True;
                                        break;
                                        }
                                }
                        if (! $remove_line) {fwrite($pointeur,$line);}
                        }
                fclose($pointeur);
                exec ("sudo service chilli restart");
                }
        else {echo "$l_error_open_file $mac_allowed_list";}
        break;
        }       
}
?>
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_trusted_sites ;?></th></tr>
        <tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</TABLE>
<TABLE width="100%" border=0 cellspacing=0 cellpadding=1>
        <tr bgcolor="#666666"><td>
        <TABLE width="100%" border=0 cellspacing=0 cellpadding=2>
                <tr><td valign="middle" align="left">
                <center><?php
                echo "$l_trusted_sites_explain1 <BR>";
                echo "$l_trusted_sites_explain2" ;
                echo "<FORM action='$_SERVER[PHP_SELF]' method='POST'>";?>
                <TABLE cellspacing=2 cellpadding=3 border=1>
                <tr><td width=50% height=100% align=center>
                        <H3><?php echo $l_trusted_sites_list ;?></H3>
                        exemple1 : www.domain1.org<BR>
                        exemple2 : domain2.net<BR>
                        <?php
                                echo "<textarea name='trusted_domains' rows=5 cols=40>";
                                $trusted_domains_file="/usr/local/etc/alcasar-uamdomain";
                                $ouvre=fopen($trusted_domains_file,"r");
                                if ($ouvre)
                                        {
                                        while (!feof ($ouvre))
                                                {
                                                $tampon = fgets($ouvre, 4096);
                                                $domain_list_l = substr($tampon,10);
                                                $domain_list = trim ($domain_list_l,"\"\n\t ");
                                                $tab_domains = explode (",", $domain_list);
                                                foreach ($tab_domains as $domain ){
                                                        if ($domain) { echo $domain."\n";}
                                                        }
                                                }
                                        }
                                else    {
                                        echo "failed to open $trusted_domains_file";
                                        }
                                fclose($ouvre);
                                echo "</textarea>";
                        ?>
                </td>
                <td  width=50% height=100% align=center>
                        <H3><?php echo $l_trusted_urls_list ;?></H3>
                        exemple1 : www.domain3.net/admin/index.htm<BR>
                        exemple2 : domain4.org/~polux/index.html<BR>
                        <?php
                                echo "<textarea name='trusted_urls' rows=5 cols=40>";
                                $trusted_urls_file="/usr/local/etc/alcasar-uamallowed";
                                $ouvre=fopen($trusted_urls_file,"r");
                                if ($ouvre)
                                        {
                                        while (!feof ($ouvre))
                                                {
                                                $tampon = fgets($ouvre, 4096);
                                                $url_list_l = substr($tampon,11);
                                                $url_list = trim ($url_list_l,"\"\n\t ");
                                                $tab_urls = explode (",", $url_list);
                                                foreach ($tab_urls as $url ){
                                                        if ($url) echo $url."\n";
                                                        }
                                                }
                                        }
                                else    {
                                        echo "failed to open $trusted_urls_file";
                                        }
                                fclose($ouvre);
                                echo "</textarea>";
                        ?>
                </td></tr>
                </TABLE>
                <input type='hidden' name='choix' value='MAJ_UAMALLOWED'>
                <input type='submit' value='<?php echo $l_submit ;?>'>
                </FORM>
        </td></tr>
        </TABLE>
</TABLE>
<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_trusted_mac ;?></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_mac_explain</td></tr>";
echo "<tr><td align='center' valign='middle'>";
echo "<FORM action='$_SERVER[PHP_SELF]' method='POST'>";
echo "<table cellspacing=2 cellpadding=3 border=1>";
echo "<tr><th>$l_trusted_mac_address<th>$l_trusted_mac_info<th>$l_trusted_mac_del</tr>";
// On lit et on affiche le fichier d'exception
$display_form = true;
if (is_file ($mac_allowed_list))
        {
        $tab=file($mac_allowed_list);
        if ($tab)  # le fichier n'est pas vide
                {
                foreach ($tab as $line)
                        {
                        $field=explode("#", $line);
                        $mac_addr=trim(trim($field[0],"macallowed="));
                        $mac_info=trim($field[1],"#");
                        echo "<tr><td>$mac_addr";
                        echo "<td>$mac_info";
                        echo "<td><input type='checkbox' name='$mac_addr'>";
                        echo "</tr>";
                        }
                }
        else { $display_form = false;}
        }
else    {
        echo "$l_error_open_file $mac_allowed_list";
        $display_form = false;
        }
echo "</table>";
if ($display_form)
        {
        echo "<input type='hidden' name='choix' value='del_mac'>";
        echo "<input type='submit' value='$l_submit2'>";
        }
echo "</form></td><td valign='middle' align='center'>";
echo "<FORM action='$_SERVER[PHP_SELF]' method='POST'>";
echo "<table cellspacing=2 cellpadding=3 border=1>";
echo "<tr><th>$l_trusted_mac_address<th>$l_trusted_mac_info";
?>
<td></td></tr>
<tr><td>exemple : 12-2f-36-a4-df-43</td><td>exemple : PC of the boss</td><td></td></tr>
<tr><td><input type='text' name='add_mac' size='17'></td>
<td><input type='text' name='add_comment' size='10'></td>
<input type='hidden' name='choix' value='new_mac'>
<td><input type='submit' value='<?echo"$l_add_to_list";?>'></td>
</tr></table>
</form>
</td></tr>
</table>
</BODY>
</HTML>