Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
1521 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>ALCASAR Whitelist filtering</TITLE>
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
7
</HEAD>
8
<body>
9
<?
10
function form_filter ($form_content)
11
{
12
// réencodage iso + format unix + rc fin de ligne (ouf...)
13
	$list = str_replace("\r\n", "\n", utf8_decode($form_content));
14
	if (strlen($list) != 0){
15
		if ($list[strlen($list)-1] != "\n") { $list[strlen($list)]="\n";} ;} ;
16
	return $list;
17
}
18
function form_filter_ip($form_content, $color)
19
{
20
	//# reconstruction des ip
21
	$list = explode("\n", form_filter($form_content));
22
	$new_list = "";
23
	foreach($list as &$value)
24
	{
25
		if(preg_match('/([0-9]{1,3}.){3}[0-9]{1,3}/', $value))
26
		{
27
			$new_list = $new_list.$value."\n";
28
		}
29
	}
30
	if($color == "white")
31
	{
32
		return preg_replace("/(.*)\n/", "add whitelist_ip_allowed $1\n", $new_list);
33
	}
34
	else
35
	{
36
		return preg_replace("/(.*)\n/", "add blacklist_ip_blocked $1\n", $new_list);
37
	}
38
}
39
function echo_file ($filename)
40
	{
41
	if (file_exists($filename))
42
		{
43
		if (filesize($filename) != 0)
44
			{
45
			$pointeur=fopen($filename,"r");
46
			$tampon = fread($pointeur, filesize($filename));
47
			fclose($pointeur);
48
			echo $tampon;
49
			}
50
		}
51
	else
52
		{
53
		echo "$filename doesn't exist";
54
		}
55
	}
56
function echo_ip_file ($filename)
57
{
58
	exec("cat $filename | cut -d ' ' -f3", $resultat);
59
	for($i=0; $i<exec("wc -l $filename"); $i++)
60
	{
61
		echo $resultat[$i]."\n";
62
	}
63
}
64
# Choice of language
65
$Language = 'en';
66
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
67
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
68
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
69
if($Language == 'fr'){
70
  $l_wl="Liste blanche";
71
  $l_list_version="Version de la liste : ";
72
  $l_wl_categories="Sélectionnez les catégories à autoriser";
73
  $l_allowed_dns="Noms de domaine autorisés";
74
  $l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
75
  $l_add_to_wl="Noms de domaine ou IP ajoutés à la liste blanche";
76
  $l_forbidden_ip_explain="Entrez une IP par ligne (exemple : 123.123.123.123)<br/>ou une adresse de réseau (exemple : 123.123.0.0/16)";
1614 franck 77
  $l_allowed_ip="IP autorisées";
1521 richard 78
  $l_record="Enregistrer les modifications";
79
  $l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
80
  $l_error_open_file="Erreur d'ouverture du fichier";
81
  $l_submit="Envoyer";
82
  $l_nb_ip="Nombre d'IP";
83
  $l_nb_domain_names="Nombre de noms de domaine";
84
  $l_nbDomainNames="Noms de domaine :";
85
  $l_nbUrl="Url :";
86
  $l_nbIp="Ip :";
87
}
88
else {
89
  $l_wl="WhiteList";
90
  $l_list_version="List version : ";
91
  $l_wl_categories="Select the categories to allow";
92
  $l_allowed_dns="Allowed domain names";
93
  $l_one_dns="Enter one domain name per row (example : .domain.org)";
94
  $l_add_to_wl="Domain names or IP to add to whitelist";
95
  $l_forbidden_ip_explain="Enter one IP per row (example : 123.123.123.123)<br/>or a network address (example : 123.123.0.0/16)";
96
  $l_allowed_ip="Allowed IP";
97
  $l_record="Save changes";
98
  $l_wait="Once validated, 10 seconds are necessary to compute your modifications";
99
  $l_error_open_file="Error opening file";
100
  $l_submit="Submit";
101
  $l_nb_ip="Number of IP";
102
  $l_nb_domain_names="Number of domain names";
103
  $l_nbDomainNames="Domain names :";
104
  $l_nbUrl="Url :";
105
  $l_nbIp="Ip :";
106
}
107
$dir_etc="/usr/local/etc/";
108
$dir_dg="/etc/dansguardian/lists/";
109
$file_wl_ip="/usr/local/share/ossi-ip-wl";
110
$wl_categories=$dir_etc."alcasar-wl-categories";
111
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
112
$conf_file=$dir_etc."alcasar.conf";
113
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
114
switch ($choix)
115
{
116
case 'MAJ_cat_wl' :
117
	$tab=file($wl_categories_enabled);	
118
	if ($tab)
119
		{
120
		$pointeur=fopen($wl_categories_enabled, "w+");
121
		foreach ($_POST as $key => $value)
122
			{
123
			if (strstr($key,'chk-'))
124
				{	
125
				$line=str_replace('chk-','',$key)."\n";
126
				fwrite($pointeur,$line);
127
				}
128
			}
129
		fclose($pointeur);
130
		}
131
	else {echo "$l_error_open_file $wl_categories_enabled";}
132
	$fichier=fopen($dir_dg."blacklists/ossi/domains_wl","w+");
133
	fputs($fichier, form_filter($_POST['OSSI_wl_domains']));
134
	fclose($fichier);
135
	unset($_POST['OSSI_wl_domains']);
136
	$fichier=fopen($file_wl_ip, "w+");
137
	fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
138
	fclose($fichier);
139
	unset($_POST['OSSI_wl_ip']);
140
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --reload");
141
	break;
142
}
143
?>
144
<table width="100%" border="0" cellspacing="0" cellpadding="0">
145
	<tr><th><?php echo $l_wl; ?></th></tr>
146
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
147
</table>
148
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
149
<tr><td valign="middle" align="left" colspan=10>
150
<FORM action='wl_filter.php' method=POST>
151
<input type='hidden' name='choix' value='MAJ_cat_wl'>
152
<?php
153
echo "<center>";
154
$nbDomainNames = exec ("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
155
$nbUrl = 0;
156
$nbIp = 0;
157
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
158
echo "$l_wl_categories</center></td></tr>";
159
//on lit et on interprete le fichier de catégories
160
$cols=1; 
161
if (file_exists($wl_categories))
162
	{
163
	$pointeur=fopen($wl_categories,"r");
164
	while (!feof ($pointeur))
165
		{
166
		$ligne=fgets($pointeur, 4096);
167
		if ($ligne)
168
			{
169
			if ($cols == 1) { echo "<tr>";}
170
			$categorie=trim(basename($ligne));
171
			echo "<td><a href='bl_categories_help.php?liste=wl&cat=$categorie' target='cat_help' onclick=window.open('bl_categories_help.php','cat_help','width=600,height=450,toolbar=no,scrollbars=yes,resizable=yes') title='categories help page'>$categorie</a><br>";
172
			echo "<input type='checkbox' name='chk-$categorie'";
173
			// si la ligne est commentée -> categorie non selectionnée
174
			if (preg_match('/^#/',$ligne, $r)) { echo ">";}
175
			else { echo "checked>"; }
176
			echo "</td>";
177
			$cols++;
178
			if ($cols > 10) {
179
				echo "</tr>";
180
				$cols=1; }
181
			}
182
		}
183
	fclose($pointeur);
184
	}
185
else	{
186
	echo "$l_error_open_file $wl_categories";
187
	}
188
echo "<tr><td valign='middle' align='left' colspan=10>";
189
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
190
echo "<tr><td width=50% colspan=5 align=center>";
191
echo "<H3>$l_allowed_dns</H3>$l_one_dns<BR>";
192
echo "<textarea name='OSSI_wl_domains' rows=3 cols=40>";
193
echo_file ($dir_dg."blacklists/ossi/domains_wl");
194
echo "</textarea></td>";
195
echo "<td width=50% colspan=5 align=center>";
196
echo "<H3>$l_allowed_ip</H3>$l_forbidden_ip_explain<BR>";
197
echo "<textarea name='OSSI_wl_ip' rows=3 cols=40>";
198
echo_ip_file ($file_wl_ip);
199
echo "</textarea></td></tr><tr><td colspan=10>";
200
echo "<input type='submit' value='$l_record'></form></td></tr>";
201
?>
202
</TABLE><br/>
203
</BODY>
204
</HTML>