Subversion Repositories ALCASAR

Rev

Rev 859 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 859 Rev 860
Line 98... Line 98...
98
	break;
98
	break;
99
case 'NF_Off' :
99
case 'NF_Off' :
100
	exec ("sudo /usr/local/sbin/alcasar-nf.sh -off");
100
	exec ("sudo /usr/local/sbin/alcasar-nf.sh -off");
101
	break;
101
	break;
102
case 'new_port' :
102
case 'new_port' :
103
	$_POST['add_proto'] = str_replace (CHR(32),"-",$_POST['add_proto']);
-
 
104
	if ((trim($_POST['add_port']) != "80") and ($_POST['add_port'] != "") and ($_POST['add_proto'] != "") and (is_numeric($_POST['add_port'])))
103
	if ((trim($_POST['add_port']) != "80") and ($_POST['add_port'] != "") and ($_POST['add_proto'] != "") and (is_numeric($_POST['add_port'])))
105
		{
104
		{
-
 
105
		$_POST['add_proto'] = str_replace (CHR(32),"-",$_POST['add_proto']);
106
		$tab=file(SERVICES_LIST);
106
		$tab=file(SERVICES_LIST);
107
		if ($tab)
107
		$insert = true;
-
 
108
		if ($tab) // file isn't empty
108
			{
109
			{
109
			$pointeur=fopen(SERVICES_LIST,"r");
-
 
110
			// test if port doesn't already exist
110
			foreach ($tab as $line)  //test if port doesn't already exist
111
			$insert = true;
-
 
112
			foreach ($tab as $line)
-
 
113
				{
111
				{
114
				$proto_f=explode(" ", $line);
112
				$proto_f=explode(" ", $line);
115
				if (trim($_POST['add_port']) == trim($proto_f[1])) {$insert = false;}
113
				if (trim($_POST['add_port']) == trim($proto_f[1])) {$insert = false;}
116
				}
114
				}
117
			fclose($pointeur);
115
			}
118
			if ($insert == true) 
116
		if ($insert == true) 
119
				{
117
			{
120
				$line = "\n" . "#" . trim($_POST['add_proto']) . " " . trim($_POST['add_port']);
118
			$line = "\n" . "#" . trim($_POST['add_proto']) . " " . trim($_POST['add_port']);
121
				$pointeur=fopen(SERVICES_LIST,"a");
119
			$pointeur=fopen(SERVICES_LIST,"a");
122
				fwrite ($pointeur, $line);
120
			fwrite ($pointeur, $line);
123
				fclose ($pointeur);
121
			fclose ($pointeur);
124
				exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
122
			exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
125
				}
-
 
126
			}
123
			}
127
		}
124
		}
128
	break;
125
	break;
129
case 'new_ip' :
126
case 'new_ip' :
130
	if (trim($_POST['add_ip']) != "") 
127
	if (trim($_POST['add_ip']) != "") 
131
		{
128
		{
-
 
129
		$_POST['add_comment'] = str_replace (CHR(32),"-",$_POST['add_comment']);
132
		$tab=file(IP_BLOCKED);
130
		$tab=file(IP_BLOCKED);
133
		if ($tab)
131
		$insert = true;
-
 
132
		if ($tab) // file isn't empty
134
			{
133
			{
135
			$pointeur=fopen(IP_BLOCKED,"r");
-
 
136
			// test if IP doesn't already exist
134
			foreach ($tab as $line) // test if IP address doesn't already exist
137
			$insert = true;
-
 
138
			foreach ($tab as $line)
-
 
139
				{
135
				{
140
				$IP_f=explode("#", $line);
136
				$IP_f=explode(" ", $line);
141
				if (trim($_POST['add_ip']) == trim($IP_f[0])) {$insert = false;}
137
				if (trim($_POST['add_ip']) == trim(trim($IP_f[0],"#"))) {$insert = false;}
142
				}
-
 
143
			fclose($pointeur);
-
 
144
			if ($insert == true) 
-
 
145
				{
-
 
146
				$line ="\n" . trim($_POST['add_ip']) . " # " . trim($_POST['add_comment']);
-
 
147
				$pointeur=fopen(IP_BLOCKED,"a");
-
 
148
				fwrite ($pointeur, $line);
-
 
149
				fclose ($pointeur);
-
 
150
				exec ("sudo /usr/local/bin/alcasar-file-clean.sh");
-
 
151
				}
138
				}
152
			}
139
			}
-
 
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
			}
153
		}
148
		}
154
	break;
149
	break;
155
case 'change_port' :
150
case 'change_port' :
156
	$tab=file(SERVICES_LIST);
151
	$tab=file(SERVICES_LIST);
157
	if ($tab)
152
	if ($tab)
Line 169... Line 164...
169
					{
164
					{
170
					$name_svc2 = str_replace('del-','',$key);
165
					$name_svc2 = str_replace('del-','',$key);
171
					if ($name_svc1 == $name_svc2)
166
					if ($name_svc1 == $name_svc2)
172
				       		{
167
				       		{
173
						$remove_line = True;
168
						$remove_line = True;
174
						break;
-
 
175
						}
169
						}
176
					}
170
					}
177
				if (strstr($key,'chk-'))
171
				if (strstr($key,'chk-'))
178
					{
172
					{
179
					$name_svc2 = str_replace('chk-','',$key);
173
					$name_svc2 = str_replace('chk-','',$key);
Line 191... Line 185...
191
				fwrite($pointeur,$line);
185
				fwrite($pointeur,$line);
192
				}
186
				}
193
			}
187
			}
194
		fclose($pointeur);
188
		fclose($pointeur);
195
		}
189
		}
196
	exec ("sudo /usr/local/sbin/alcasar-nf.sh -on");
190
	exec ("sudo /usr/local/bin/alcasar-iptables.sh -on");
197
	break;
191
	break;
198
case 'change_ip' :
192
case 'change_ip' :
199
	$tab=file(IP_BLOCKED);
193
	$tab=file(IP_BLOCKED);
200
	if ($tab)
194
	if ($tab)
201
		{
195
		{
Line 206... Line 200...
206
			$ip_f=explode(" ", $ligne);
200
			$ip_f=explode(" ", $ligne);
207
			$ip_blocked1=trim($ip_f[0],"#");
201
			$ip_blocked1=trim($ip_f[0],"#");
208
			$actif = False; $remove_line = false;
202
			$actif = False; $remove_line = false;
209
			foreach ($_POST as $key => $value)
203
			foreach ($_POST as $key => $value)
210
				{
204
				{
-
 
205
				$key = str_replace ("_",".",$key); // dot are replace by '_' in post request
211
				if (strstr($key,'del-'))
206
				if (strstr($key,'del-'))
212
					{
207
					{
213
					$ip_blocked2 = str_replace('del-','',$key);
208
					$ip_blocked2 = str_replace('del-','',$key);
214
					if ($ip_blocked1 == $ip_blocked2)
209
					if ($ip_blocked1 == $ip_blocked2)
215
				       		{
210
				       		{
Line 234... Line 229...
234
				fwrite($pointeur,$line);
229
				fwrite($pointeur,$line);
235
				}
230
				}
236
			}
231
			}
237
		fclose($pointeur);
232
		fclose($pointeur);
238
		}
233
		}
239
	#exec ("sudo /usr/local/bin/alcasar-iptables.sh");
234
	exec ("sudo /usr/local/bin/alcasar-iptables.sh");
240
	break;
235
	break;
241
	}
236
	}
242
# default values
237
# default values
243
if (is_file (CONF_FILE))
238
if (is_file (CONF_FILE))
244
	{
239
	{
Line 299... Line 294...
299
		{
294
		{
300
		if (trim($line) != '') # the line isn't empty
295
		if (trim($line) != '') # the line isn't empty
301
			{
296
			{
302
			$blocked_ip=explode(" ", $line);
297
			$blocked_ip=explode(" ", $line);
303
			$ip_addr=trim($blocked_ip[0],"#");
298
			$ip_addr=trim($blocked_ip[0],"#");
-
 
299
			$comment=trim($blocked_ip[1]);
-
 
300
			if ($comment ==''){$comment=" ";}
304
			echo "<tr><td>$ip_addr<td>$blocked_ip[1]";
301
			echo "<tr><td>$ip_addr<td>$comment";
305
			echo "<td><input type='checkbox' name='chk-$ip_addr'";
302
			echo "<td><input type='checkbox' name='chk-$ip_addr'";
306
			// if the line is commented -> IP adress is not blocked
-
 
307
			if (preg_match('/^#/',$line, $r)) {
303
			if (preg_match('/^#/',$line, $r)) {
308
				echo ">";}
304
				echo ">";}
309
			else {
305
			else {
310
				echo "checked>";}
306
				echo "checked>";}
311
			echo "<td><input type='checkbox' name='del-$ip_addr'>";
307
			echo "<td><input type='checkbox' name='del-$ip_addr'>";