Subversion Repositories ALCASAR

Rev

Rev 2817 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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