Subversion Repositories ALCASAR

Rev

Rev 859 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
318 richard 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<HTML><!-- written by Rexy -->
3
<HEAD>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
<TITLE>Network Filter</TITLE>
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
7
</HEAD>
8
<body>
9
<TABLE width="100%" border=0 cellspacing=0 cellpadding=0>
10
<?
11
# Choice of language
12
$Language = 'en';
13
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
14
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
15
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
16
if($Language == 'fr'){
372 richard 17
  $l_title_antivir = "Antivirus de flux WEB";
364 franck 18
  $l_antivir_on="L'antivirus de flux WEB est actuellement activ&eacute;";
19
  $l_antivir_off="L'antivirus de flux WEB est actuellement désactiv&eacute;";
318 richard 20
  $l_switch_antivir_on="Activer l'antivirus";
364 franck 21
  $l_switch_antivir_off="D&eacute;sactiver l'antivirus";
859 richard 22
  $l_title_ip_block="Filtrage d'adresses IP";
23
  $l_ip_address="Adresses IP (ou addresse de réseau) bloquées";
24
  $l_blocked_ip_address="Adresses IP";
25
  $l_blocked_ip_address_comment="Commentaires";
26
  $l_blocked="Bloquée";
27
  $l_ip_block_explain="Liste des adresses IP (ou adresses IP de réseaux) bloquées";
28
  $l_remove="Retirer de la liste";
791 richard 29
  $l_title_proto = "Filtrage de protocoles r&eacute;seau";
372 richard 30
  $l_netfilter_on="Le filtrage de protocoles r&eacute;seau est actuellement activ&eacute;";
31
  $l_netfilter_off="Le filtrage de protocoles réseau est actuellement désactiv&eacute";
32
  $l_switch_on="Activer le filtrage";
33
  $l_switch_off="D&eacute;sactiver le filtrage";
318 richard 34
  $l_comment_on="&Agrave; l'exclusion du WEB (port 80), les protocoles r&eacute;seau sont interdits.<BR>Choisissez ci-dessous les protocoles que vous autorisez";
364 franck 35
  $l_comment_off="(tous les protocoles réseau sont autoris&eacute;s)";
36
  $l_protocols="Protocoles autoris&eacute;s";
318 richard 37
  $l_error_open_file="Erreur d'ouverture du fichier";
859 richard 38
  $l_port="Numéro de port";
39
  $l_proto="Nom du protocole";
364 franck 40
  $l_enabled="Autoris&eacute;";
318 richard 41
  $l_add_to_list="Ajouter &agrave; la liste";
42
  $l_save_modif="Enregistrer les modifications";
43
}
44
else {
372 richard 45
  $l_title_antivir = "WEB antivirus";
46
  $l_antivir_on="Actually, the WEB antivirus is on";
47
  $l_antivir_off="Actually, the WEB antivirus is off";
318 richard 48
  $l_switch_antivir_on="Switch the antivirus on";
49
  $l_switch_antivir_off="Switch the antivirus off";
859 richard 50
  $l_title_ip_block="IP address filter";
51
  $l_ip_address="IP address (or network IP address)";
52
  $l_blocked_ip_address="IP addresses";
53
  $l_blocked_ip_address_comment="Comments";
54
  $l_blocked="Blocked";
55
  $l_ip_block_explain="List of blocked IP addresses (or network IP adresses)";
56
  $l_remove="Remove from list";
791 richard 57
  $l_title_proto = "Network protocols filter";
372 richard 58
  $l_netfilter_on="Actually, the network protocols filter is enable";
59
  $l_netfilter_off="Actually, the network protocols filter is disable";
60
  $l_switch_on="Switch the Filter on";
61
  $l_switch_off="Switch the Filter off";
318 richard 62
  $l_comment_on="(choose the authorized network protocols)";
859 richard 63
  $l_comment_on="Except for the WEB (port 80), all protocols are blocked.<BR>Choose in the list below, the protocols you want authorize";
318 richard 64
  $l_comment_off="(all the network protocols are allowed for authenticated users)";
65
  $l_protocols="Authorize protocols";
66
  $l_error_open_file="Error opening the file";
859 richard 67
  $l_port="Port number";
68
  $l_proto="protocol name";
69
  $l_enabled="Authorized";
318 richard 70
  $l_add_to_list="Add to the list";
71
  $l_save_modif="Save modifications";
72
}
859 richard 73
/********************
74
*  TEST CONF FILES  *
75
*********************/
76
define ("SERVICES_LIST", "/usr/local/etc/alcasar-services");
77
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
78
define ("IP_BLOCKED", "/usr/local/etc/alcasar-ip-blocked");
79
$conf_files=array(SERVICES_LIST,CONF_FILE,IP_BLOCKED);
80
foreach ($conf_files as $file){
81
if (!file_exists($file)){
82
	exit("Requested file ".$file." isn't present");}
83
if (!is_readable($file)){
84
	exit("Can't read the file ".$file);}
85
}
86
 
318 richard 87
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
88
switch ($choix)
89
{
90
case 'AV_On' :
91
	exec ("sudo /usr/local/sbin/alcasar-havp.sh -on");
92
	break;
93
case 'AV_Off' :
94
	exec ("sudo /usr/local/sbin/alcasar-havp.sh -off");
95
	break;
96
case 'NF_On' :
97
	exec ("sudo /usr/local/sbin/alcasar-nf.sh -on");
98
	break;
99
case 'NF_Off' :
100
	exec ("sudo /usr/local/sbin/alcasar-nf.sh -off");
101
	break;
859 richard 102
case 'new_port' :
318 richard 103
	if ((trim($_POST['add_port']) != "80") and ($_POST['add_port'] != "") and ($_POST['add_proto'] != "") and (is_numeric($_POST['add_port'])))
104
		{
860 richard 105
		$_POST['add_proto'] = str_replace (CHR(32),"-",$_POST['add_proto']);
859 richard 106
		$tab=file(SERVICES_LIST);
860 richard 107
		$insert = true;
108
		if ($tab) // file isn't empty
318 richard 109
			{
860 richard 110
			foreach ($tab as $line)  //test if port doesn't already exist
318 richard 111
				{
859 richard 112
				$proto_f=explode(" ", $line);
318 richard 113
				if (trim($_POST['add_port']) == trim($proto_f[1])) {$insert = false;}
114
				}
115
			}
860 richard 116
		if ($insert == true) 
117
			{
118
			$line = "\n" . "#" . trim($_POST['add_proto']) . " " . trim($_POST['add_port']);
119
			$pointeur=fopen(SERVICES_LIST,"a");
120
			fwrite ($pointeur, $line);
121
			fclose ($pointeur);
122
			exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
123
			}
318 richard 124
		}
125
	break;
859 richard 126
case 'new_ip' :
127
	if (trim($_POST['add_ip']) != "") 
128
		{
860 richard 129
		$_POST['add_comment'] = str_replace (CHR(32),"-",$_POST['add_comment']);
859 richard 130
		$tab=file(IP_BLOCKED);
860 richard 131
		$insert = true;
132
		if ($tab) // file isn't empty
859 richard 133
			{
860 richard 134
			foreach ($tab as $line) // test if IP address doesn't already exist
859 richard 135
				{
860 richard 136
				$IP_f=explode(" ", $line);
137
				if (trim($_POST['add_ip']) == trim(trim($IP_f[0],"#"))) {$insert = false;}
859 richard 138
				}
139
			}
860 richard 140
		if ($insert == true) 
141
			{
142
			$line ="\n" . "#".trim($_POST['add_ip']) . " " . trim($_POST['add_comment']);
143
			$pointeur=fopen(IP_BLOCKED,"a");
144
			fwrite ($pointeur, $line);
145
			fclose ($pointeur);
146
			exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
147
			}
859 richard 148
		}
149
	break;
150
case 'change_port' :
151
	$tab=file(SERVICES_LIST);
318 richard 152
	if ($tab)
153
		{
859 richard 154
// authorize/block protocols
155
		$pointeur=fopen(SERVICES_LIST,"w+");
318 richard 156
		foreach ($tab as $ligne)
157
			{
158
			$proto_f=explode(" ", $ligne);
159
			$name_svc1=trim($proto_f[0],"#");
160
			$actif = False; $remove_line = false;
161
			foreach ($_POST as $key => $value)
162
				{
163
				if (strstr($key,'del-'))
164
					{
165
					$name_svc2 = str_replace('del-','',$key);
166
					if ($name_svc1 == $name_svc2)
167
				       		{
168
						$remove_line = True;
169
						}
170
					}
171
				if (strstr($key,'chk-'))
172
					{
173
					$name_svc2 = str_replace('chk-','',$key);
174
					if ($name_svc1 == $name_svc2)
175
				       		{
176
						$actif = True;
177
						break;
178
						}
179
					}
180
				}
181
			if (! $remove_line)
182
				{
183
				if (! $actif) {	$line="#$name_svc1 $proto_f[1]";}
184
				else { $line="$name_svc1 $proto_f[1]";}
185
				fwrite($pointeur,$line);
186
				}
187
			}
188
		fclose($pointeur);
189
		}
860 richard 190
	exec ("sudo /usr/local/bin/alcasar-iptables.sh -on");
318 richard 191
	break;
859 richard 192
case 'change_ip' :
193
	$tab=file(IP_BLOCKED);
194
	if ($tab)
195
		{
196
// authorize/block IPs 
197
		$pointeur=fopen(IP_BLOCKED,"w+");
198
		foreach ($tab as $ligne)
199
			{
200
			$ip_f=explode(" ", $ligne);
201
			$ip_blocked1=trim($ip_f[0],"#");
202
			$actif = False; $remove_line = false;
203
			foreach ($_POST as $key => $value)
204
				{
860 richard 205
				$key = str_replace ("_",".",$key); // dot are replace by '_' in post request
859 richard 206
				if (strstr($key,'del-'))
207
					{
208
					$ip_blocked2 = str_replace('del-','',$key);
209
					if ($ip_blocked1 == $ip_blocked2)
210
				       		{
211
						$remove_line = True;
212
						break;
213
						}
214
					}
215
				if (strstr($key,'chk-'))
216
					{
217
					$ip_blocked2 = str_replace('chk-','',$key);
218
					if ($ip_blocked1 == $ip_blocked2)
219
				       		{
220
						$actif = True;
221
						break;
222
						}
223
					}
224
				}
225
			if (! $remove_line)
226
				{
227
				if (! $actif) {	$line="#$ip_blocked1 $ip_f[1]";}
228
				else { $line="$ip_blocked1 $ip_f[1]";}
229
				fwrite($pointeur,$line);
230
				}
231
			}
232
		fclose($pointeur);
233
		}
860 richard 234
	exec ("sudo /usr/local/bin/alcasar-iptables.sh");
859 richard 235
	break;
318 richard 236
	}
612 richard 237
# default values
859 richard 238
if (is_file (CONF_FILE))
612 richard 239
	{
859 richard 240
	$tab=file(CONF_FILE);
612 richard 241
	if ($tab)
242
		{
243
		foreach ($tab as $line)
244
			{
245
			$field=explode("=", $line);
246
			if ($field[0] == "PROTOCOLS_FILTERING")	{$PROTOCOLS_FILTERING=trim($field[1]);}
247
			if ($field[0] == "WEB_ANTIVIRUS")	{$WEB_ANTIVIRUS=trim($field[1]);}
248
			}
249
		}
250
	}
251
echo "<tr><th>$l_title_antivir</th></tr>";
318 richard 252
?>
612 richard 253
<tr bgcolor=#FFCC66><td><img src=/images/pix.gif width=1 height=2></td></tr>
254
</TABLE>
318 richard 255
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
256
	<tr><td valign="middle" align="left">
257
<?php
612 richard 258
if ($WEB_ANTIVIRUS == "on")
318 richard 259
	{
260
	echo "<CENTER><H3>$l_antivir_on</H3></CENTER>";
261
 	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
262
	echo "<input type=hidden name='choix' value=\"AV_Off\">";
263
	echo "<input type=submit value=\"$l_switch_antivir_off\">";
264
}
265
else
266
	{
267
	echo "<CENTER><H3>$l_antivir_off</H3></CENTER>";
268
 	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
269
	echo "<input type=hidden name='choix' value=\"AV_On\">";
270
	echo "<input type=submit value=\"$l_switch_antivir_on\">";
271
	}
272
?>
273
</FORM>
274
</td></tr>
372 richard 275
</table>
276
<TABLE width="100%" border=0 cellspacing=0 cellpadding=0>
859 richard 277
<tr><th><?echo "$l_title_ip_block";?></th></tr>
372 richard 278
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
279
</table>
859 richard 280
<table width="100%" border=1 cellspacing=0 cellpadding=1>
281
<tr><td colspan=2 align="center">
282
<?
283
echo "$l_ip_block_explain</td></tr>";
284
echo "<tr><td align='center' valign='middle'>";
285
echo "<FORM action='$_SERVER[PHP_SELF]' method='POST'>";
286
echo "<input type=hidden name='choix' value=\"IP_block_filter\">";
287
echo "<table cellspacing=2 cellpadding=2 border=1>";
288
echo "<tr><th>$l_blocked_ip_address<th>$l_blocked_ip_address_comment<th>$l_blocked<th>$l_remove</tr>";
289
// Read the "IP_block" file
290
$tab=file(IP_BLOCKED);
291
if ($tab)  # the file isn't empty
790 richard 292
	{
859 richard 293
	foreach ($tab as $line)
294
		{
295
		if (trim($line) != '') # the line isn't empty
296
			{
297
			$blocked_ip=explode(" ", $line);
298
			$ip_addr=trim($blocked_ip[0],"#");
860 richard 299
			$comment=trim($blocked_ip[1]);
300
			if ($comment ==''){$comment="&nbsp;";}
301
			echo "<tr><td>$ip_addr<td>$comment";
859 richard 302
			echo "<td><input type='checkbox' name='chk-$ip_addr'";
303
			if (preg_match('/^#/',$line, $r)) {
304
				echo ">";}
305
			else {
306
				echo "checked>";}
307
			echo "<td><input type='checkbox' name='del-$ip_addr'>";
308
			echo "</tr>";
309
			}
310
		}
790 richard 311
	}
312
?>
859 richard 313
</table>
314
<input type='hidden' name='choix' value='change_ip'>
315
<input type='submit' value='<?echo"$l_save_modif";?>'>
316
</form></td><td valign='middle' align='center'>
317
<form action='<?echo"$_SERVER[PHP_SELF]"?>' method='POST'>
318
<table cellspacing=2 cellpadding=3 border=1>
319
<tr><th><?echo"$l_ip_address<th>$l_blocked_ip_address_comment";?>
320
<td></td></tr>
321
<tr><td>exemple1 : 15.25.26.27 <br>exemple2 : 18.20.20.0/24</td><td>exemple1 : CERT alert<br>exemple2 : LAN of zombies</td><td></td></tr>
322
<tr><td><input type='text' name='add_ip' size='17'></td>
323
<td><input type='text' name='add_comment' size='10'></td>
324
<input type='hidden' name='choix' value='new_ip'>
325
<td><input type='submit' value='<?echo"$l_add_to_list";?>'></td>
326
</tr></table>
327
</form>
790 richard 328
</td></tr>
329
</table>
330
<TABLE width="100%" border=0 cellspacing=0 cellpadding=0>
331
<tr><th><?echo "$l_title_proto";?></th></tr>
332
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
333
</table>
334
<TABLE width="100%" border=1 cellspacing=0 cellpadding=0>
859 richard 335
<tr>
318 richard 336
<?
612 richard 337
if ($PROTOCOLS_FILTERING == "on")
318 richard 338
	{
859 richard 339
	echo "<td colspan=\"2\" valign=\"middle\" align=\"left\">";
318 richard 340
	echo "<CENTER><H3>$l_netfilter_on</H3>$l_comment_on</CENTER>";
341
	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
342
	echo "<input type=hidden name='choix' value=\"NF_Off\">";
343
	echo "<input type=submit value=\"$l_switch_off\">";
859 richard 344
	echo "</FORM></td></tr>";
345
	require ('net_filter2.php');
318 richard 346
	}
347
else
348
	{
859 richard 349
	echo "<td valign=\"middle\" align=\"left\">";
318 richard 350
	echo "<CENTER><H3>$l_netfilter_off</H3>$l_comment_off</CENTER>";
351
 	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
352
	echo "<input type=hidden name='choix' value=\"NF_On\">";
353
	echo "<input type=submit value=\"$l_switch_on\">";
859 richard 354
	echo "</FORM></td></tr>";
355
	echo "</table></body></html>";
318 richard 356
	}
357
?>