Subversion Repositories ALCASAR

Rev

Rev 2853 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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