| 2134 | richard | 1 | <!DOCTYPE html "-//W3C//DTD HTML 4.01 Transitional//EN">
 | 
        
           | 1521 | richard | 2 | <HTML><!-- written by Rexy -->
 | 
        
           |  |  | 3 | <HEAD>
 | 
        
           |  |  | 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 | 
        
           |  |  | 5 | <TITLE>Network Filter</TITLE>
 | 
        
           | 2817 | rexy | 6 | <link rel="stylesheet" href="/css/acc.css" type="text/css">
 | 
        
           | 1521 | richard | 7 | </HEAD>
 | 
        
           |  |  | 8 | <body>
 | 
        
           | 3028 | rexy | 9 | <div id="ldoverlay" class="overlay">
 | 
        
           |  |  | 10 | 	<div class="lds-spinner" id="spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
 | 
        
           |  |  | 11 | </div>
 | 
        
           | 1521 | richard | 12 | <?
 | 
        
           |  |  | 13 | # Choice of language
 | 
        
           |  |  | 14 | $Language = 'en';
 | 
        
           |  |  | 15 | if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
 | 
        
           |  |  | 16 |   $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
 | 
        
           |  |  | 17 |   $Language = strtolower(substr(chop($Langue[0]),0,2)); }
 | 
        
           | 2853 | rexy | 18 | if($Language == 'fr') {
 | 
        
           | 1521 | richard | 19 |   $l_remove="Retirer de la liste";
 | 
        
           | 3243 | rexy | 20 |   $l_title_proto = "Filtrage personnalisée de protocoles réseau";
 | 
        
           |  |  | 21 |   $l_comment="Définissez ici la liste personalisée de protocoles réseau autorisés. Vous pouvez ensuite l'attribuer à des utilisateurs (cf. creation/gestion des utilisateurs).";
 | 
        
           | 2134 | richard | 22 |   $l_protocols="Protocoles autorisés";
 | 
        
           | 1521 | richard | 23 |   $l_error_open_file="Erreur d'ouverture du fichier";
 | 
        
           |  |  | 24 |   $l_port="Numéro de port";
 | 
        
           |  |  | 25 |   $l_proto="Nom du protocole";
 | 
        
           | 2134 | richard | 26 |   $l_enabled="Autorisé";
 | 
        
           |  |  | 27 |   $l_add_to_list="Ajouter à la liste";
 | 
        
           | 1521 | richard | 28 |   $l_save="Enregistrer les modifications";
 | 
        
           | 2853 | rexy | 29 | } else if($Language == 'es') {
 | 
        
           |  |  | 30 |   $l_remove="Bloquear";
 | 
        
           | 3243 | rexy | 31 |   $l_title_proto = "Filtrado personalizado de protocolos de red";
 | 
        
           |  |  | 32 |   $l_comment="Aquí puede definir su propia lista de protocolos de red autorizados. Luego, puede asignarlo a un usuario (consulte crear / administrar usuarios)";
 | 
        
           | 2853 | rexy | 33 |   $l_protocols="Autorizar protocolos";
 | 
        
           |  |  | 34 |   $l_error_open_file="Error al abrir el archivo";
 | 
        
           |  |  | 35 |   $l_port="Número de puerto";
 | 
        
           |  |  | 36 |   $l_proto="nombre del protocolo";
 | 
        
           |  |  | 37 |   $l_enabled="Autorizado";
 | 
        
           |  |  | 38 |   $l_add_to_list="Agregar a la lista";
 | 
        
           |  |  | 39 |   $l_save="guardar cambios";
 | 
        
           |  |  | 40 | } else {
 | 
        
           | 1521 | richard | 41 |   $l_remove="Remove from list";
 | 
        
           | 3243 | rexy | 42 |   $l_title_proto = "Custom network protocols filtering";
 | 
        
           |  |  | 43 |   $l_comment="Here, you can define your own list of authorized network protocols. Then, You can assign it to a user (see create/manage users)";
 | 
        
           | 1521 | richard | 44 |   $l_protocols="Authorize protocols";
 | 
        
           |  |  | 45 |   $l_error_open_file="Error opening the file";
 | 
        
           |  |  | 46 |   $l_port="Port number";
 | 
        
           |  |  | 47 |   $l_proto="protocol name";
 | 
        
           |  |  | 48 |   $l_enabled="Authorized";
 | 
        
           |  |  | 49 |   $l_add_to_list="Add to the list";
 | 
        
           |  |  | 50 |   $l_save="Save changes";
 | 
        
           |  |  | 51 | }
 | 
        
           |  |  | 52 | /********************
 | 
        
           |  |  | 53 | *  TEST CONF FILES  *
 | 
        
           |  |  | 54 | *********************/
 | 
        
           | 3245 | rexy | 55 | define ("SERVICES_LIST", "/usr/local/etc/alcasar-custom-allowed-ports");
 | 
        
           | 1521 | richard | 56 | define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
 | 
        
           |  |  | 57 | $conf_files=array(SERVICES_LIST,CONF_FILE);
 | 
        
           |  |  | 58 | foreach ($conf_files as $file){
 | 
        
           |  |  | 59 | if (!file_exists($file)){
 | 
        
           |  |  | 60 | 	exit("Requested file ".$file." isn't present");}
 | 
        
           |  |  | 61 | if (!is_readable($file)){
 | 
        
           |  |  | 62 | 	exit("Can't read the file ".$file);}
 | 
        
           |  |  | 63 | }
 | 
        
           |  |  | 64 | /**********************************
 | 
        
           |  |  | 65 | *	Read ALCASAR CONF_FILE    *
 | 
        
           |  |  | 66 | ***********************************/
 | 
        
           |  |  | 67 | $ouvre=fopen(CONF_FILE,"r");
 | 
        
           |  |  | 68 | if ($ouvre){
 | 
        
           |  |  | 69 | 	while (!feof ($ouvre))
 | 
        
           |  |  | 70 | 	{
 | 
        
           |  |  | 71 | 		$tampon = fgets($ouvre, 4096);
 | 
        
           |  |  | 72 | 		if (strpos($tampon,"=")!==false){
 | 
        
           |  |  | 73 | 			$tmp = explode("=",$tampon);
 | 
        
           |  |  | 74 | 			$conf[$tmp[0]] = $tmp[1];
 | 
        
           |  |  | 75 | 		}
 | 
        
           |  |  | 76 | 	}
 | 
        
           |  |  | 77 | 	fclose($ouvre);
 | 
        
           |  |  | 78 | }
 | 
        
           |  |  | 79 |   | 
        
           |  |  | 80 | if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
 | 
        
           |  |  | 81 | switch ($choix)
 | 
        
           |  |  | 82 | {
 | 
        
           |  |  | 83 | case 'new_port' :
 | 
        
           | 2184 | richard | 84 | 	if (($_POST['add_port'] != "") and ($_POST['add_proto'] != "") and (is_numeric($_POST['add_port'])))
 | 
        
           | 1521 | richard | 85 | 		{
 | 
        
           |  |  | 86 | 		$_POST['add_proto'] = str_replace (CHR(32),"-",$_POST['add_proto']);
 | 
        
           |  |  | 87 | 		$tab=file(SERVICES_LIST);
 | 
        
           |  |  | 88 | 		$insert = true;
 | 
        
           |  |  | 89 | 		if ($tab) // file isn't empty
 | 
        
           |  |  | 90 | 			{
 | 
        
           |  |  | 91 | 			foreach ($tab as $line)  //test if port doesn't already exist
 | 
        
           |  |  | 92 | 				{
 | 
        
           |  |  | 93 | 				$proto_f=explode(" ", $line);
 | 
        
           |  |  | 94 | 				if (trim($_POST['add_port']) == trim($proto_f[1])) {$insert = false;}
 | 
        
           |  |  | 95 | 				}
 | 
        
           |  |  | 96 | 			}
 | 
        
           |  |  | 97 | 		if ($insert == true) 
 | 
        
           |  |  | 98 | 			{
 | 
        
           |  |  | 99 | 			$line = "\n" . "#" . trim($_POST['add_proto']) . " " . trim($_POST['add_port']);
 | 
        
           |  |  | 100 | 			$pointeur=fopen(SERVICES_LIST,"a");
 | 
        
           |  |  | 101 | 			fwrite ($pointeur, $line);
 | 
        
           |  |  | 102 | 			fclose ($pointeur);
 | 
        
           |  |  | 103 | 			exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
 | 
        
           |  |  | 104 | 			}
 | 
        
           |  |  | 105 | 		}
 | 
        
           |  |  | 106 | 	break;
 | 
        
           |  |  | 107 | case 'change_port' :
 | 
        
           |  |  | 108 | 	$tab=file(SERVICES_LIST);
 | 
        
           |  |  | 109 | 	if ($tab)
 | 
        
           |  |  | 110 | 		{
 | 
        
           |  |  | 111 | // authorize/block protocols
 | 
        
           |  |  | 112 | 		$pointeur=fopen(SERVICES_LIST,"w+");
 | 
        
           |  |  | 113 | 		foreach ($tab as $ligne)
 | 
        
           |  |  | 114 | 			{
 | 
        
           |  |  | 115 | 			$proto_f=explode(" ", $ligne);
 | 
        
           |  |  | 116 | 			$name_svc1=trim($proto_f[0],"#");
 | 
        
           |  |  | 117 | 			$actif = False; $remove_line = false;
 | 
        
           |  |  | 118 | 			foreach ($_POST as $key => $value)
 | 
        
           |  |  | 119 | 				{
 | 
        
           |  |  | 120 | 				if (strstr($key,'del-'))
 | 
        
           |  |  | 121 | 					{
 | 
        
           |  |  | 122 | 					$name_svc2 = str_replace('del-','',$key);
 | 
        
           |  |  | 123 | 					if ($name_svc1 == $name_svc2)
 | 
        
           |  |  | 124 | 				       		{
 | 
        
           |  |  | 125 | 						$remove_line = True;
 | 
        
           |  |  | 126 | 						}
 | 
        
           |  |  | 127 | 					}
 | 
        
           |  |  | 128 | 				if (strstr($key,'chk-'))
 | 
        
           |  |  | 129 | 					{
 | 
        
           |  |  | 130 | 					$name_svc2 = str_replace('chk-','',$key);
 | 
        
           |  |  | 131 | 					if ($name_svc1 == $name_svc2)
 | 
        
           |  |  | 132 | 				       		{
 | 
        
           |  |  | 133 | 						$actif = True;
 | 
        
           |  |  | 134 | 						break;
 | 
        
           |  |  | 135 | 						}
 | 
        
           |  |  | 136 | 					}
 | 
        
           |  |  | 137 | 				}
 | 
        
           |  |  | 138 | 			if (! $remove_line)
 | 
        
           |  |  | 139 | 				{
 | 
        
           |  |  | 140 | 				if (! $actif) {	$line="#$name_svc1 $proto_f[1]";}
 | 
        
           |  |  | 141 | 				else { $line="$name_svc1 $proto_f[1]";}
 | 
        
           |  |  | 142 | 				fwrite($pointeur,$line);
 | 
        
           |  |  | 143 | 				}
 | 
        
           |  |  | 144 | 			}
 | 
        
           |  |  | 145 | 		fclose($pointeur);
 | 
        
           |  |  | 146 | 		}
 | 
        
           | 2184 | richard | 147 | 	exec ("sudo /usr/local/bin/alcasar-iptables.sh");
 | 
        
           | 1521 | richard | 148 | 	break;
 | 
        
           |  |  | 149 | 	}
 | 
        
           |  |  | 150 | ?>
 | 
        
           |  |  | 151 | <TABLE width="100%" border=0 cellspacing=0 cellpadding=0>
 | 
        
           |  |  | 152 | <tr><th><?echo "$l_title_proto";?></th></tr>
 | 
        
           |  |  | 153 | <tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
 | 
        
           |  |  | 154 | </table>
 | 
        
           |  |  | 155 | <TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
 | 
        
           | 2134 | richard | 156 | <tr><td colspan="2" valign="middle" align="left">
 | 
        
           |  |  | 157 | <? echo "<CENTER>$l_comment</CENTER>";?>
 | 
        
           |  |  | 158 | <tr><td valign="middle" align="center">
 | 
        
           |  |  | 159 | <form action='protocols_filter.php' method='POST'>
 | 
        
           |  |  | 160 | <table cellspacing=2 cellpadding=3 border=1>
 | 
        
           | 1521 | richard | 161 | <?
 | 
        
           | 2134 | richard | 162 | echo "<tr><th>$l_port<th>$l_proto<th>$l_enabled<th>$l_remove</tr>";
 | 
        
           |  |  | 163 | // Read and compute the protocols list
 | 
        
           |  |  | 164 | $tab=file(SERVICES_LIST);
 | 
        
           |  |  | 165 | if ($tab) # the file isn't empty
 | 
        
           |  |  | 166 | 	{
 | 
        
           |  |  | 167 | 	foreach ($tab as $line)
 | 
        
           |  |  | 168 | 		{
 | 
        
           |  |  | 169 | 		if (trim($line) != '') # the line isn't empty
 | 
        
           |  |  | 170 | 			{
 | 
        
           |  |  | 171 | 			$proto=explode(" ", $line);
 | 
        
           |  |  | 172 | 			$name_svc=trim($proto[0],"#");
 | 
        
           |  |  | 173 | 			echo "<tr><td>$proto[1]<td>$name_svc";
 | 
        
           |  |  | 174 | 			echo "<td><input type='checkbox' name='chk-$name_svc'";
 | 
        
           |  |  | 175 | 			// if the line is commented -> protocol is not allowed
 | 
        
           |  |  | 176 | 			if (preg_match('/^#/',$line, $r)) {
 | 
        
           |  |  | 177 | 				echo ">";}
 | 
        
           |  |  | 178 | 			else {
 | 
        
           |  |  | 179 | 				echo "checked>";}
 | 
        
           |  |  | 180 | 			echo "<td>";
 | 
        
           |  |  | 181 | 			if ($name_svc != "icmp") {
 | 
        
           |  |  | 182 | 				echo "<input type='checkbox' name='del-$name_svc'>";}
 | 
        
           |  |  | 183 | 			else {
 | 
        
           |  |  | 184 | 				echo " ";}		
 | 
        
           |  |  | 185 | 			echo "</tr>";
 | 
        
           |  |  | 186 | 			}
 | 
        
           |  |  | 187 | 		}
 | 
        
           |  |  | 188 | 	}
 | 
        
           | 1521 | richard | 189 | ?>
 | 
        
           | 2134 | richard | 190 | </table>
 | 
        
           |  |  | 191 | <input type='hidden' name='choix' value='change_port'>
 | 
        
           | 3028 | rexy | 192 | <input type='submit' onClick="document.getElementById('ldoverlay').style.display='block';" value='<?echo"$l_save";?>'>
 | 
        
           | 2134 | richard | 193 | </form></td><td valign='middle' align='center'>
 | 
        
           |  |  | 194 | <form action='protocols_filter.php' method='POST'>
 | 
        
           |  |  | 195 | <table cellspacing=2 cellpadding=3 border=1>
 | 
        
           |  |  | 196 | <tr><th><?echo"$l_port<th>$l_proto"?></tr>
 | 
        
           |  |  | 197 | <tr><td><input type='text' name='add_port' size='5'></td>
 | 
        
           |  |  | 198 | <td><input type='text' name='add_proto' size='10'></td>
 | 
        
           |  |  | 199 | <td><input type='hidden' name='choix' value='new_port'>
 | 
        
           | 3028 | rexy | 200 | <input type='submit' onClick="document.getElementById('ldoverlay').style.display='block';" value='<?echo"$l_add_to_list";?>'></td>
 | 
        
           | 2134 | richard | 201 | </tr></table>
 | 
        
           |  |  | 202 | </form>
 | 
        
           |  |  | 203 | </td></tr>
 | 
        
           |  |  | 204 | </TABLE>
 | 
        
           |  |  | 205 | </BODY>
 | 
        
           |  |  | 206 | </HTML>
 | 
        
           | 2006 | raphael.pi | 207 |   |