Project

General

Profile

Download (56.7 KB) Statistics
| Branch: | Tag: | Revision:
1 5ba18897 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4 bdb7d6e7 Scott Ullrich
	firewall_rules_edit.php
5 e4cabb75 Scott Ullrich
	part of pfSense (http://www.pfsense.com)
6
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7 5ba18897 Scott Ullrich
8 e4cabb75 Scott Ullrich
	originally part of m0n0wall (http://m0n0.ch/wall)
9 bdb7d6e7 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 5ba18897 Scott Ullrich
12 bdb7d6e7 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 5ba18897 Scott Ullrich
15 bdb7d6e7 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 5ba18897 Scott Ullrich
18 bdb7d6e7 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21 5ba18897 Scott Ullrich
22 bdb7d6e7 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32 5b237745 Scott Ullrich
*/
33 7ac5a4cb Scott Ullrich
/*
34
	pfSense_MODULE:	filter
35
*/
36 5b237745 Scott Ullrich
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-firewall-rules-edit
39
##|*NAME=Firewall: Rules: Edit page
40
##|*DESCR=Allow access to the 'Firewall: Rules: Edit' page.
41
##|*MATCH=firewall_rules_edit.php*
42
##|-PRIV
43
44 5b237745 Scott Ullrich
require("guiconfig.inc");
45 1a03cf69 Scott Ullrich
require("filter.inc");
46
require("shaper.inc");
47 5b237745 Scott Ullrich
48 1e578a7f Ermal Lu?i
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
49 3331a640 Ermal Lu?i
$ifdisp = get_configured_interface_with_descr();
50 679d21bb Ermal Lu?i
foreach ($ifdisp as $kif => $kdescr) {
51 3331a640 Ermal Lu?i
	$specialsrcdst[] = "{$kif}";
52
	$specialsrcdst[] = "{$kif}ip";
53 679d21bb Ermal Lu?i
}
54 5b237745 Scott Ullrich
55
if (!is_array($config['filter']['rule'])) {
56
	$config['filter']['rule'] = array();
57
}
58
filter_rules_sort();
59
$a_filter = &$config['filter']['rule'];
60
61
$id = $_GET['id'];
62
if (is_numeric($_POST['id']))
63
	$id = $_POST['id'];
64 5ba18897 Scott Ullrich
65 5b237745 Scott Ullrich
$after = $_GET['after'];
66
67
if (isset($_POST['after']))
68
	$after = $_POST['after'];
69
70
if (isset($_GET['dup'])) {
71
	$id = $_GET['dup'];
72
	$after = $_GET['dup'];
73
}
74
75
if (isset($id) && $a_filter[$id]) {
76
	$pconfig['interface'] = $a_filter[$id]['interface'];
77 5ba18897 Scott Ullrich
78 b9e28d57 unknown
	if (isset($a_filter[$id]['id']))
79
		$pconfig['ruleid'] = $a_filter[$id]['id'];
80
81 5b237745 Scott Ullrich
	if (!isset($a_filter[$id]['type']))
82
		$pconfig['type'] = "pass";
83
	else
84
		$pconfig['type'] = $a_filter[$id]['type'];
85 5ba18897 Scott Ullrich
86 4633edc2 Ermal Luçi
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
87 661aed33 Ermal Luçi
		$pconfig['floating'] = $a_filter[$id]['floating'];
88
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") 
89
			$pconfig['interface'] = $a_filter[$id]['interface'];
90
	}
91
	
92
	if (isset($a_filter['floating'])) 
93
		$pconfig['floating'] = "yes";
94
95
	if (isset($a_filter[$id]['direction']))
96
                $pconfig['direction'] = $a_filter[$id]['direction'];
97
98 5b237745 Scott Ullrich
	if (isset($a_filter[$id]['protocol']))
99
		$pconfig['proto'] = $a_filter[$id]['protocol'];
100
	else
101
		$pconfig['proto'] = "any";
102 5ba18897 Scott Ullrich
103 5b237745 Scott Ullrich
	if ($a_filter[$id]['protocol'] == "icmp")
104
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
105 5ba18897 Scott Ullrich
106 5b237745 Scott Ullrich
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
107
		$pconfig['srcmask'], $pconfig['srcnot'],
108
		$pconfig['srcbeginport'], $pconfig['srcendport']);
109 5ba18897 Scott Ullrich
110 8be60f21 Scott Ullrich
	if($a_filter[$id]['os'] <> "")
111
		$pconfig['os'] = $a_filter[$id]['os'];
112 e33c8694 Bill Marquette
113 5b237745 Scott Ullrich
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
114
		$pconfig['dstmask'], $pconfig['dstnot'],
115
		$pconfig['dstbeginport'], $pconfig['dstendport']);
116
117 c5fc1b2e Ermal Luçi
	if ($a_filter[$id]['dscp'] <> "")
118
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
119
120 5b237745 Scott Ullrich
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
121
	$pconfig['log'] = isset($a_filter[$id]['log']);
122
	$pconfig['descr'] = $a_filter[$id]['descr'];
123 8c84fe43 Scott Ullrich
124 b8ed2a11 Ermal
	if (isset($a_filter[$id]['tcpflags_any']))
125
		$pconfig['tcpflags_any'] = true;
126
	else {
127
		if (isset($a_filter[$id]['tcpflags1']) && $a_filter[$id]['tcpflags1'] <> "") 
128
			$pconfig['tcpflags1'] = $a_filter[$id]['tcpflags1'];
129
		if (isset($a_filter[$id]['tcpflags2']) && $a_filter[$id]['tcpflags2'] <> "") 
130
			$pconfig['tcpflags2'] = $a_filter[$id]['tcpflags2'];
131
	}
132
133 5c1f5584 Ermal Luçi
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "") 
134 661aed33 Ermal Luçi
		$pconfig['tag'] = $a_filter[$id]['tag'];
135 b6494651 Ermal Lu?i
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tagged'] <> "")
136 661aed33 Ermal Luçi
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
137
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
138
		$pconfig['quick'] = $a_filter[$id]['quick'];
139 775ccea3 Ermal Luci
	if (isset($a_filter[$id]['allowopts']))
140
		$pconfig['allowopts'] = true;
141 19757916 Ermal Lu?i
	if (isset($a_filter[$id]['disablereplyto']))
142
		$pconfig['disablereplyto'] = true;
143 661aed33 Ermal Luçi
144 ed08ef3e Scott Ullrich
	/* advanced */
145 a56b2fa0 pierrepomes
	$pconfig['max'] = $a_filter[$id]['max'];
146 f1c49ff4 Scott Ullrich
	$pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
147 26dd6a54 pierrepomes
	$pconfig['max-src-conn'] = $a_filter[$id]['max-src-conn'];
148 f1c49ff4 Scott Ullrich
	$pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
149
	$pconfig['statetype'] = $a_filter[$id]['statetype'];
150 5ba18897 Scott Ullrich
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
151 8c84fe43 Scott Ullrich
152 f1c49ff4 Scott Ullrich
	/* advanced - nosync */
153 8c84fe43 Scott Ullrich
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
154 10f21e70 Scott Ullrich
155 ed08ef3e Scott Ullrich
	/* advanced - new connection per second banning*/
156
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
157
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
158 5ba18897 Scott Ullrich
159 e5980370 Scott Ullrich
	/* Multi-WAN next-hop support */
160 c98ddde2 Bill Marquette
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
161 615b27bc Scott Dale
	
162 197bfe96 Ermal Luçi
	/* Shaper support */
163
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
164
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
165 a5fd67e1 Ermal Luçi
	$pconfig['dnpipe'] = $a_filter[$id]['dnpipe'];
166
	$pconfig['pdnpipe'] = $a_filter[$id]['pdnpipe'];
167 7e50413c Ermal Luçi
	$pconfig['l7container'] = $a_filter[$id]['l7container'];
168 197bfe96 Ermal Luçi
169 615b27bc Scott Dale
	//schedule support
170
	$pconfig['sched'] = $a_filter[$id]['sched'];
171 9b16b834 Ermal Lu?i
	$pconfig['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
172 c98ddde2 Bill Marquette
173 5b237745 Scott Ullrich
} else {
174
	/* defaults */
175 a23d7248 Scott Ullrich
	if ($_GET['if'])
176
		$pconfig['interface'] = $_GET['if'];
177 5b237745 Scott Ullrich
	$pconfig['type'] = "pass";
178
	$pconfig['src'] = "any";
179
	$pconfig['dst'] = "any";
180
}
181 72320b88 Ermal Luçi
/* Allow the FlotingRules to work */
182
$if = $pconfig['interface'];
183 5b237745 Scott Ullrich
184
if (isset($_GET['dup']))
185
	unset($id);
186
187
if ($_POST) {
188 87f0be87 Chris Buechler
189
	if ($_POST['type'] == "reject" && $_POST['proto'] <> "tcp")
190
		$input_errors[] = "Reject type rules only works when the protocol is set to TCP.";
191 28f9e493 Scott Ullrich
192 5b237745 Scott Ullrich
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
193
		$_POST['srcbeginport'] = 0;
194
		$_POST['srcendport'] = 0;
195
		$_POST['dstbeginport'] = 0;
196
		$_POST['dstendport'] = 0;
197
	} else {
198 5ba18897 Scott Ullrich
199 5b237745 Scott Ullrich
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
200
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
201
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
202
			$_POST['srcendport'] = $_POST['srcendport_cust'];
203 5ba18897 Scott Ullrich
204 5b237745 Scott Ullrich
		if ($_POST['srcbeginport'] == "any") {
205
			$_POST['srcbeginport'] = 0;
206
			$_POST['srcendport'] = 0;
207 5ba18897 Scott Ullrich
		} else {
208 5b237745 Scott Ullrich
			if (!$_POST['srcendport'])
209
				$_POST['srcendport'] = $_POST['srcbeginport'];
210
		}
211
		if ($_POST['srcendport'] == "any")
212
			$_POST['srcendport'] = $_POST['srcbeginport'];
213 5ba18897 Scott Ullrich
214 5b237745 Scott Ullrich
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
215
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
216
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
217
			$_POST['dstendport'] = $_POST['dstendport_cust'];
218 5ba18897 Scott Ullrich
219 5b237745 Scott Ullrich
		if ($_POST['dstbeginport'] == "any") {
220
			$_POST['dstbeginport'] = 0;
221
			$_POST['dstendport'] = 0;
222 5ba18897 Scott Ullrich
		} else {
223 5b237745 Scott Ullrich
			if (!$_POST['dstendport'])
224
				$_POST['dstendport'] = $_POST['dstbeginport'];
225
		}
226
		if ($_POST['dstendport'] == "any")
227 5ba18897 Scott Ullrich
			$_POST['dstendport'] = $_POST['dstbeginport'];
228 5b237745 Scott Ullrich
	}
229 5ba18897 Scott Ullrich
230 5b237745 Scott Ullrich
	if (is_specialnet($_POST['srctype'])) {
231
		$_POST['src'] = $_POST['srctype'];
232
		$_POST['srcmask'] = 0;
233
	} else if ($_POST['srctype'] == "single") {
234
		$_POST['srcmask'] = 32;
235
	}
236
	if (is_specialnet($_POST['dsttype'])) {
237
		$_POST['dst'] = $_POST['dsttype'];
238
		$_POST['dstmask'] = 0;
239
	}  else if ($_POST['dsttype'] == "single") {
240
		$_POST['dstmask'] = 32;
241
	}
242 5ba18897 Scott Ullrich
243 5b237745 Scott Ullrich
	unset($input_errors);
244
	$pconfig = $_POST;
245
246 ef2a753c Scott Ullrich
	/*  run through $_POST items encoding HTML entties so that the user
247
	 *  cannot think he is slick and perform a XSS attack on the unwilling 
248
	 */
249 21eff66f Scott Ullrich
	foreach ($_POST as $key => $value) {
250 08825acc smos
		$temp = str_replace(">", "", $value);
251
			
252 661aed33 Ermal Luçi
		if (isset($_POST['floating']) && $key == "interface")
253
			continue;
254 21eff66f Scott Ullrich
		$newpost = htmlentities($temp);
255 5157927f Scott Ullrich
		if($newpost <> $temp)   	 
256
			$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";		
257 ef2a753c Scott Ullrich
	}
258
259 5b237745 Scott Ullrich
	/* input validation */
260 1122a892 Erik Fonnesbeck
	$reqdfields = explode(" ", "type proto");
261
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
262
		$redqfields[] = "src";
263 473d0ff0 pierrepomes
		$redqfields[] = "dst";
264 1122a892 Erik Fonnesbeck
	}
265
	$reqdfieldsn = explode(",", "Type,Protocol");
266
	if ( isset($a_filter[$id]['associated-rule-id'])===false ) {
267
		$reqdfieldsn[] = "Source";
268 473d0ff0 pierrepomes
		$reqdfieldsn[] = "Destination";
269 1122a892 Erik Fonnesbeck
	}
270 5b237745 Scott Ullrich
271 452ade89 Bill Marquette
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
272 c22767b1 Bill Marquette
		if( $_POST['proto'] != "tcp" )
273
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
274 452ade89 Bill Marquette
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
275
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
276
	}
277 10f7933f Chris Buechler
        
278 1122a892 Erik Fonnesbeck
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
279
	(!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) ) {
280 5b237745 Scott Ullrich
		$reqdfields[] = "srcmask";
281
		$reqdfieldsn[] = "Source bit count";
282
	}
283 9b16b834 Ermal Lu?i
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
284 473d0ff0 pierrepomes
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
285 5b237745 Scott Ullrich
		$reqdfields[] = "dstmask";
286
		$reqdfieldsn[] = "Destination bit count";
287
	}
288 5ba18897 Scott Ullrich
289 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
290 5ba18897 Scott Ullrich
291 5b237745 Scott Ullrich
	if (!$_POST['srcbeginport']) {
292
		$_POST['srcbeginport'] = 0;
293
		$_POST['srcendport'] = 0;
294
	}
295
	if (!$_POST['dstbeginport']) {
296
		$_POST['dstbeginport'] = 0;
297
		$_POST['dstendport'] = 0;
298
	}
299 5ba18897 Scott Ullrich
300 9b45f821 Ermal Lu?i
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
301
                $input_errors[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
302
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
303
                $input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
304
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
305
                $input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
306
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
307
                $input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
308 5ba18897 Scott Ullrich
309 0e5ddcd9 Scott Ullrich
	/* if user enters an alias and selects "network" then disallow. */
310
	if($_POST['srctype'] == "network") {
311
		if(is_alias($_POST['src']))
312
			$input_errors[] = "You must specify single host or alias for alias entries.";
313
	}
314
	if($_POST['dsttype'] == "network") {
315
		if(is_alias($_POST['dst']))
316
			$input_errors[] = "You must specify single host or alias for alias entries.";
317
	}
318
319 5b237745 Scott Ullrich
	if (!is_specialnet($_POST['srctype'])) {
320 1e578a7f Ermal Lu?i
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
321 9b45f821 Ermal Lu?i
			$input_errors[] = "{$_POST['src']} is not a valid source IP address or alias.";
322 5b237745 Scott Ullrich
		}
323
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
324
			$input_errors[] = "A valid source bit count must be specified.";
325
		}
326
	}
327
	if (!is_specialnet($_POST['dsttype'])) {
328 1e578a7f Ermal Lu?i
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
329 9b45f821 Ermal Lu?i
			$input_errors[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
330 5b237745 Scott Ullrich
		}
331
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
332
			$input_errors[] = "A valid destination bit count must be specified.";
333
		}
334
	}
335 5ba18897 Scott Ullrich
336 5b237745 Scott Ullrich
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
337
		/* swap */
338
		$tmp = $_POST['srcendport'];
339
		$_POST['srcendport'] = $_POST['srcbeginport'];
340
		$_POST['srcbeginport'] = $tmp;
341
	}
342
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
343
		/* swap */
344
		$tmp = $_POST['dstendport'];
345
		$_POST['dstendport'] = $_POST['dstbeginport'];
346
		$_POST['dstbeginport'] = $tmp;
347
	}
348 e33c8694 Bill Marquette
	if ($_POST['os'])
349
		if( $_POST['proto'] != "tcp" )
350
			$input_errors[] = "OS detection is only valid with protocol tcp.";
351 5b237745 Scott Ullrich
352 197bfe96 Ermal Luçi
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
353
		if ($_POST['defaultqueue'] == "none" )
354
			$input_errors[] = "You have to select a queue when you select an acknowledge queue too.";
355
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
356 aa8cdf52 Scott Ullrich
			$input_errors[] = "Acknowledge queue and Queue cannot be the same.";		
357 197bfe96 Ermal Luçi
	}
358 a5fd67e1 Ermal Luçi
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
359
		if ($_POST['dnpipe'] == "none" )
360
			$input_errors[] = "You must select a queue for the In direction before selecting one for Out too.";
361
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
362
			$input_errors[] = "In and Out Queue cannot be the same.";
363
		else if ($pdnpipe[0] == "?" && $dnpipe[0] <> "?")
364
			$input_errors[] = "You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.";
365
		else if ($dnpipe[0] == "?" && $pdnpipe[0] <> "?")
366
			$input_errors[] = "You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.";
367
	}
368 b9e28d57 unknown
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
369
		$input_errors[] = 'ID must be an integer';
370 7e50413c Ermal Luçi
	if($_POST['l7container'] && $_POST['l7container'] != "none") {
371
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
372 8b69a3e1 Chris Buechler
			$input_errors[] = "You can only select a layer7 container for TCP and/or UDP protocols";
373 3b184ca5 Ermal Lu?i
		if ($_POST['type'] <> "pass")
374
			$input_errors[] = "You can only select a layer7 container for Pass type rules.";
375 7e50413c Ermal Luçi
	}
376 197bfe96 Ermal Luçi
377 b8ed2a11 Ermal
	if (!$_POST['tcpflags_any']) {
378
		$settcpflags = array();
379
		$outoftcpflags = array();
380
		foreach ($tcpflags as $tcpflag) {
381
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
382
				$settcpflags[] = $tcpflag;
383
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
384
				$outoftcpflags[] = $tcpflag;
385
		}
386
		if (empty($outoftcpflags) && !empty($settcpflags))
387
			$input_errors[] = "If you specify TCP flags that should be set you should specify out of which flags as well.";
388
	}
389
390 5b237745 Scott Ullrich
	if (!$input_errors) {
391
		$filterent = array();
392 b9e28d57 unknown
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
393 5b237745 Scott Ullrich
		$filterent['type'] = $_POST['type'];
394 661aed33 Ermal Luçi
		if (isset($_POST['interface'] ))
395
			$filterent['interface'] = $_POST['interface'];
396
397 b8ed2a11 Ermal
		if ($_POST['tcpflags_any']) {
398
			$filterent['tcpflags_any'] = true;
399
		} else {
400
			$settcpflags = array();
401
			$outoftcpflags = array();
402
			foreach ($tcpflags as $tcpflag) {
403
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
404
					$settcpflags[] = $tcpflag;
405
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
406
					$outoftcpflags[] = $tcpflag;
407
			}
408
			if (!empty($outoftcpflags)) {
409
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
410
				if (!empty($settcpflags))
411
					$filterent['tcpflags1'] = join(",", $settcpflags);
412
			}
413
		}
414
415 661aed33 Ermal Luçi
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
416
			if (isset($_POST['tag']))
417
				$filterent['tag'] = $_POST['tag'];
418
			if (isset($_POST['tagged']))
419 f1602cc4 sullrich
				$filterent['tagged'] = $_POST['tagged'];
420 661aed33 Ermal Luçi
			$filterent['direction'] = $_POST['direction'];
421
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
422
				$filterent['quick'] = $_POST['quick'];
423
			$filterent['floating'] = "yes";
424
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
425 f1602cc4 sullrich
				$filterent['interface'] = implode(",", $_POST['interface']);
426 661aed33 Ermal Luçi
			}
427
		}
428 d59874c1 Scott Ullrich
429 bdb7d6e7 Scott Ullrich
		/* Advanced options */
430 775ccea3 Ermal Luci
		if ($_POST['allowopts'] == "yes")
431
			$filterent['allowopts'] = true;
432
		else
433
			unset($filterent['allowopts']);
434 19757916 Ermal Lu?i
		if ($_POST['disablereplyto'] == "yes")
435
			$filterent['disablereplyto'] = true;
436
		else
437
			unset($filterent['disablereplyto']);
438 a56b2fa0 pierrepomes
		$filterent['max'] = $_POST['max'];
439 bdb7d6e7 Scott Ullrich
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
440 26dd6a54 pierrepomes
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
441 bdb7d6e7 Scott Ullrich
		$filterent['max-src-states'] = $_POST['max-src-states'];
442 5ba18897 Scott Ullrich
		$filterent['statetimeout'] = $_POST['statetimeout'];
443 fa9af164 Scott Ullrich
		$filterent['statetype'] = $_POST['statetype'];
444 e33c8694 Bill Marquette
		$filterent['os'] = $_POST['os'];
445 10f21e70 Scott Ullrich
446
		/* Nosync directive - do not xmlrpc sync this item */
447 8c84fe43 Scott Ullrich
		if($_POST['nosync'] <> "")
448 10f21e70 Scott Ullrich
			$filterent['nosync'] = true;
449
		else
450
			unset($filterent['nosync']);
451
452 3f00c1dc Scott Ullrich
		/* unless both values are provided, unset the values - ticket #650 */
453
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
454
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
455
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
456
		} else {
457
			unset($filterent['max-src-conn-rate']);
458
			unset($filterent['max-src-conn-rates']);
459
		}
460 5ba18897 Scott Ullrich
461 5b237745 Scott Ullrich
		if ($_POST['proto'] != "any")
462
			$filterent['protocol'] = $_POST['proto'];
463
		else
464
			unset($filterent['protocol']);
465 5ba18897 Scott Ullrich
466 5b237745 Scott Ullrich
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
467
			$filterent['icmptype'] = $_POST['icmptype'];
468
		else
469
			unset($filterent['icmptype']);
470 5ba18897 Scott Ullrich
471 5b237745 Scott Ullrich
		pconfig_to_address($filterent['source'], $_POST['src'],
472
			$_POST['srcmask'], $_POST['srcnot'],
473
			$_POST['srcbeginport'], $_POST['srcendport']);
474 5ba18897 Scott Ullrich
475 5b237745 Scott Ullrich
		pconfig_to_address($filterent['destination'], $_POST['dst'],
476
			$_POST['dstmask'], $_POST['dstnot'],
477
			$_POST['dstbeginport'], $_POST['dstendport']);
478 5ba18897 Scott Ullrich
479 f1602cc4 sullrich
		if ($_POST['disabled'])
480
			$filterent['disabled'] = true;
481
		else
482
			unset($filterent['disabled']);
483
484 c5fc1b2e Ermal Luçi
		if ($_POST['dscp'])
485
			$filterent['dscp'] = $_POST['dscp'];
486
487 f1602cc4 sullrich
		if ($_POST['log'])
488
			$filterent['log'] = true;
489
		else
490
			unset($filterent['log']);
491 c68fc1e7 Bill Marquette
		strncpy($filterent['descr'], $_POST['descr'], 52);
492 5ba18897 Scott Ullrich
493 c98ddde2 Bill Marquette
		if ($_POST['gateway'] != "") {
494
			$filterent['gateway'] = $_POST['gateway'];
495
		}
496 197bfe96 Ermal Luçi
		
497
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
498
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
499
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
500
				$filterent['ackqueue'] = $_POST['ackqueue'];
501
		}
502 c98ddde2 Bill Marquette
503 a5fd67e1 Ermal Luçi
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
504
			$filterent['dnpipe'] = $_POST['dnpipe'];
505
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
506
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
507
		}
508
509 7e50413c Ermal Luçi
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
510
			$filterent['l7container'] = $_POST['l7container'];
511
		}
512
		
513 615b27bc Scott Dale
		if ($_POST['sched'] != "") {
514
			$filterent['sched'] = $_POST['sched'];
515
		}
516
517 1122a892 Erik Fonnesbeck
		// If we have an associated nat rule, make sure the source and destination doesn't change
518 9b16b834 Ermal Lu?i
		if( isset($a_filter[$id]['associated-rule-id']) ) {
519 1122a892 Erik Fonnesbeck
			$filterent['source'] = $a_filter[$id]['source'];
520 473d0ff0 pierrepomes
			$filterent['destination'] = $a_filter[$id]['destination'];
521 9b16b834 Ermal Lu?i
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
522 473d0ff0 pierrepomes
		}
523
524 5b237745 Scott Ullrich
		if (isset($id) && $a_filter[$id])
525
			$a_filter[$id] = $filterent;
526
		else {
527
			if (is_numeric($after))
528
				array_splice($a_filter, $after+1, 0, array($filterent));
529
			else
530
				$a_filter[] = $filterent;
531
		}
532 f4e2a352 Scott Ullrich
533 5b237745 Scott Ullrich
		write_config();
534 a368a026 Ermal Lu?i
		mark_subsystem_dirty('filter');
535 5ba18897 Scott Ullrich
536 661aed33 Ermal Luçi
		if (isset($_POST['floating']))
537
			header("Location: firewall_rules.php?if=FloatingRules");
538
		else
539
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
540 5b237745 Scott Ullrich
		exit;
541
	}
542 c60824d2 Scott Ullrich
}
543
544 37c53a0d Ermal Lu?i
read_altq_config(); /* XXX: */
545
$qlist =& get_unique_queue_list();
546
read_dummynet_config(); /* XXX: */
547
$dnqlist =& get_unique_dnqueue_list();
548
read_layer7_config();
549
$l7clist =& get_l7_unique_list();
550
551 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Rules","Edit");
552 3cceb5d5 jim-p
$statusurl = "status_filter_reload.php";
553
$logurl = "diag_logs_filter.php";
554
555 a1357fe0 Bill Marquette
$closehead = false;
556 8ab3e9ed Erik Kristensen
557
$page_filename = "firewall_rules_edit.php";
558 da7ae7ef Bill Marquette
include("head.inc");
559 c60824d2 Scott Ullrich
560 5b237745 Scott Ullrich
?>
561 da7ae7ef Bill Marquette
562 5b237745 Scott Ullrich
</head>
563
564
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
565
<?php include("fbegin.inc"); ?>
566
<?php if ($input_errors) print_input_errors($input_errors); ?>
567 8ab3e9ed Erik Kristensen
568
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
569 6eac9b90 Scott Ullrich
<input type='hidden' name="ruleid" value="<?=(isset($pconfig['ruleid'])&&$pconfig['ruleid']>0)?htmlspecialchars($pconfig['ruleid']):''?>">
570
571 8ab3e9ed Erik Kristensen
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
572 e091cb45 Scott Ullrich
		<tr>
573
			<td colspan="2" valign="top" class="listtopic">Edit Firewall rule</td>
574
		</tr>	
575 8ab3e9ed Erik Kristensen
    	<tr>
576
			<td width="22%" valign="top" class="vncellreq">Action</td>
577
			<td width="78%" class="vtable">
578 b5c78501 Seth Mos
				<select name="type" class="formselect">
579 8ab3e9ed Erik Kristensen
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
580
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
581
					<?=htmlspecialchars($type);?>
582
					</option>
583
					<?php endforeach; ?>
584 8c84fe43 Scott Ullrich
				</select>
585 8ab3e9ed Erik Kristensen
				<br/>
586
				<span class="vexpl">
587
					Choose what to do with packets that match the criteria specified below. <br/>
588 e91baab8 Chris Buechler
					Hint: the difference between block and reject is that with reject, a packet (TCP RST or ICMP port unreachable for UDP) is returned to the sender, whereas with block the packet is dropped silently. In either case, the original packet is discarded. 
589 8ab3e9ed Erik Kristensen
				</span>
590
			</td>
591
		</tr>
592
		<tr>
593
			<td width="22%" valign="top" class="vncellreq">Disabled</td>
594
			<td width="78%" class="vtable">
595
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
596
				<strong>Disable this rule</strong><br />
597
				<span class="vexpl">Set this option to disable this rule without removing it from the list.</span>
598
			</td>
599
		</tr>
600 661aed33 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
601
		<tr>
602 f1602cc4 sullrich
			<td width="22%" valign="top" class="vncellreq">
603
				<?=gettext("Quick");?>
604
			</td>
605
			<td width="78%" class="vtable">
606
				<input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
607
				<strong><?=gettext("Apply the action immediately on match.");?></strong><br />
608
				<span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
609
			</td>
610
		</tr>
611 661aed33 Ermal Luçi
<? endif; ?>
612 8ab3e9ed Erik Kristensen
		<tr>
613
			<td width="22%" valign="top" class="vncellreq">Interface</td>
614
			<td width="78%" class="vtable">
615 4633edc2 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
616 8e6ac824 Ermal Luçi
				<select name="interface[]" multiple="true" class="formselect" size="3">
617 661aed33 Ermal Luçi
<? else: ?>
618 b5c78501 Seth Mos
				<select name="interface" class="formselect">
619 8ab3e9ed Erik Kristensen
<?php
620 661aed33 Ermal Luçi
   endif;
621 a7782099 Ermal Lu?i
				/* add group interfaces */
622 f1602cc4 sullrich
				if (is_array($config['ifgroups']['ifgroupentry']))
623 a7782099 Ermal Lu?i
					foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
624
						if (have_ruleint_access($ifgen['ifname']))
625
							$interfaces[$ifgen['ifname']] = $ifgen['ifname'];
626 b7391125 Ermal Luçi
				$ifdescs = get_configured_interface_with_descr();
627 5335811d Ermal Luçi
				foreach ($ifdescs as $ifent => $ifdesc)
628
        				if(have_ruleint_access($ifent))
629 f1602cc4 sullrich
							$interfaces[$ifent] = $ifdesc;
630 617f8d25 Ermal Lu?i
					if ($config['l2tp']['mode'] == "server")
631 f1602cc4 sullrich
						if(have_ruleint_access("l2tp"))
632
							$interfaces['l2tp'] = "L2TP VPN";
633 b6742927 Scott Ullrich
					if ($config['pptpd']['mode'] == "server")
634
						if(have_ruleint_access("pptp")) 
635
							$interfaces['pptp'] = "PPTP VPN";
636
					
637
					if ($config['pppoe']['mode'] == "server")
638
						if(have_ruleint_access("pppoe")) 
639
							$interfaces['pppoe'] = "PPPoE VPN";
640
					/* add ipsec interfaces */
641
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
642
						if(have_ruleint_access("enc0")) 
643 0f266b2e Chris Buechler
							$interfaces["enc0"] = "IPsec";
644 bfb60ac8 Ermal Luçi
					/* add openvpn/tun interfaces */
645 d799787e Matthew Grooms
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
646
       					$interfaces["openvpn"] = "OpenVPN";
647 8ab3e9ed Erik Kristensen
					foreach ($interfaces as $iface => $ifacename): ?>
648 c013d3f5 Chris Buechler
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && (strcasecmp($pconfig['interface'], $iface) == 0)) echo "selected"; ?>><?=gettext($ifacename);?></option>
649 8ab3e9ed Erik Kristensen
<?php 				endforeach; ?>
650 8c84fe43 Scott Ullrich
				</select>
651 8ab3e9ed Erik Kristensen
				<br />
652
				<span class="vexpl">Choose on which interface packets must come in to match this rule.</span>
653
			</td>
654
		</tr>
655 661aed33 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
656 f1602cc4 sullrich
		<tr>
657
			<td width="22%" valign="top" class="vncellreq">
658
				<?=gettext("Direction");?>
659
			</td>
660
			<td width="78%" class="vtable">
661
				<select name="direction" class="formselect">
662
					<?php      $directions = array('any', 'in', 'out');
663
				foreach ($directions as $direction): ?>
664
				<option value="<?=$direction;?>"
665
					<?php if ($direction == $pconfig['direction']): ?>
666
						selected="selected" 
667
					<?php endif; ?>
668
					><?=$direction;?></option>
669
				<?php endforeach; ?>      
670
				</select>
671
				<input type="hidden" id="floating" name="floating" value="floating">
672
			</td>
673
		<tr>
674 661aed33 Ermal Luçi
<?php endif; ?>
675 8ab3e9ed Erik Kristensen
		<tr>
676
			<td width="22%" valign="top" class="vncellreq">Protocol</td>
677
			<td width="78%" class="vtable">
678 b5c78501 Seth Mos
				<select name="proto" class="formselect" onchange="proto_change()">
679 8ab3e9ed Erik Kristensen
<?php
680 87f0be87 Chris Buechler
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP any carp pfsync");
681 8ab3e9ed Erik Kristensen
				foreach ($protocols as $proto): ?>
682
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
683
<?php 			endforeach; ?>
684
				</select>
685
				<br />
686
				<span class="vexpl">Choose which IP protocol this rule should match. <br /> Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span>
687
			</td>
688
		</tr>
689 3de8af0e Scott Ullrich
		<tr id="icmpbox" name="icmpbox">
690 8ab3e9ed Erik Kristensen
			<td valign="top" class="vncell">ICMP type</td>
691
			<td class="vtable">
692 b5c78501 Seth Mos
				<select name="icmptype" class="formselect">
693 8ab3e9ed Erik Kristensen
<?php
694
				$icmptypes = array(
695
				"" => "any",
696
				"echorep" => "Echo reply",
697
				"unreach" => "Destination unreachable",
698
				"squench" => "Source quench",
699
				"redir" => "Redirect",
700
				"althost" => "Alternate Host",
701
				"echoreq" => "Echo",
702
				"routeradv" => "Router advertisement",
703
				"routersol" => "Router solicitation",
704
				"timex" => "Time exceeded",
705
				"paramprob" => "Invalid IP header",
706
				"timereq" => "Timestamp",
707
				"timerep" => "Timestamp reply",
708
				"inforeq" => "Information request",
709
				"inforep" => "Information reply",
710
				"maskreq" => "Address mask request",
711
				"maskrep" => "Address mask reply"
712
				);
713
714
				foreach ($icmptypes as $icmptype => $descr): ?>
715
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
716
<?php 			endforeach; ?>
717
			</select>
718
			<br />
719
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
720
		</td>
721
		</tr>
722
		<tr>
723
			<td width="22%" valign="top" class="vncellreq">Source</td>
724
			<td width="78%" class="vtable">
725 383654fc Vinicius Coque
				<?php $edit_disabled=false; ?>
726
				<?php if( isset($pconfig['associated-rule-id']) ): ?>
727
					<span class="red"><strong>NOTE: </strong></span> This is associated to a NAT rule.<br />
728
					You cannot edit the source and destination of associated filter rules.<br />
729
					<br />
730 bae53989 Renato Botelho
					<?php
731 383654fc Vinicius Coque
						$edit_disabled=true;
732
						if (is_array($config['nat']['rule'])) {
733 bae53989 Renato Botelho
							foreach( $config['nat']['rule'] as $index => $nat_rule ) {
734 1122a892 Erik Fonnesbeck
								if( isset($nat_rule['associated-rule-id']) && $nat_rule['associated-rule-id']==$pconfig['associated-rule-id'] ) {
735
									echo "<a href=\"firewall_nat_edit.php?id={$index}\">View the NAT rule</a><br>";
736 bae53989 Renato Botelho
									break;
737 383654fc Vinicius Coque
								}
738 bae53989 Renato Botelho
							}
739 383654fc Vinicius Coque
						}
740
					?>
741
					<br />
742
					<script type="text/javascript">
743
					editenabled = 0;
744
					</script>
745
				<?php endif; ?>
746
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
747 8ab3e9ed Erik Kristensen
				<strong>not</strong>
748
				<br />
749
				Use this option to invert the sense of the match.
750
				<br />
751
				<br />
752
				<table border="0" cellspacing="0" cellpadding="0">
753
					<tr>
754
						<td>Type:&nbsp;&nbsp;</td>
755
						<td>
756 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srctype" class="formselect" onChange="typesel_change()">
757 87f0be87 Chris Buechler
<?php
758
								$sel = is_specialnet($pconfig['src']); ?>
759 8ab3e9ed Erik Kristensen
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
760 87f0be87 Chris Buechler
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
761
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
762 99ea4439 Scott Ullrich
								<?php if(have_ruleint_access("pptp")): ?>
763 8ab3e9ed Erik Kristensen
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
764 99ea4439 Scott Ullrich
								<?php endif; ?>
765
								<?php if(have_ruleint_access("pppoe")): ?>
766 8c84fe43 Scott Ullrich
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
767 99ea4439 Scott Ullrich
								<?php endif; ?>								
768 8a6bc505 Ermal Lu?i
								 <?php if(have_ruleint_access("l2tp")): ?>
769
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
770
                                                                <?php endif; ?>
771 8ab3e9ed Erik Kristensen
<?php
772 5335811d Ermal Luçi
								foreach ($ifdisp as $ifent => $ifdesc): ?>
773
								<?php if(have_ruleint_access($ifent)): ?>
774
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
775
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
776 b7391125 Ermal Luçi
										<?=$ifdesc?> address
777 e30a5970 Scott Ullrich
									</option>
778 99ea4439 Scott Ullrich
								<?php endif; ?>
779 b7391125 Ermal Luçi
<?php 							endforeach; ?>
780 8ab3e9ed Erik Kristensen
							</select>
781
						</td>
782
					</tr>
783
					<tr>
784
						<td>Address:&nbsp;&nbsp;</td>
785
						<td>
786 383654fc Vinicius Coque
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
787
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcmask" class="formselect" id="srcmask">
788 8ab3e9ed Erik Kristensen
<?php						for ($i = 31; $i > 0; $i--): ?>
789
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
790
<?php 						endfor; ?>
791
							</select>
792 bdb7d6e7 Scott Ullrich
						</td>
793 8ab3e9ed Erik Kristensen
					</tr>
794
				</table>
795 22abf2ef Scott Ullrich
				<div id="showadvancedboxspr">
796
					<p>
797 383654fc Vinicius Coque
					<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> type="button" onClick="show_source_port_range()" value="Advanced"></input> - Show source port range</a>
798 22abf2ef Scott Ullrich
				</div>
799 8ab3e9ed Erik Kristensen
			</td>
800 e33c8694 Bill Marquette
		</tr>
801 3de8af0e Scott Ullrich
		<tr style="display:none" id="sprtable" name="sprtable">
802 8ab3e9ed Erik Kristensen
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
803
			<td width="78%" class="vtable">
804
				<table border="0" cellspacing="0" cellpadding="0">
805
					<tr>
806
						<td>from:&nbsp;&nbsp;</td>
807
						<td>
808 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
809 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
810
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
811
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
812
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
813
<?php 							endforeach; ?>
814 8c84fe43 Scott Ullrich
							</select>
815 383654fc Vinicius Coque
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
816 8ab3e9ed Erik Kristensen
						</td>
817
					</tr>
818
					<tr>
819
						<td>to:</td>
820
						<td>
821 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcendport" class="formselect" onchange="ext_change()">
822 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
823
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
824
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
825
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
826
<?php							endforeach; ?>
827 8c84fe43 Scott Ullrich
							</select>
828 383654fc Vinicius Coque
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
829 8ab3e9ed Erik Kristensen
						</td>
830
					</tr>
831
				</table>
832
				<br />
833 3e3582a9 Erik Fonnesbeck
				<span class="vexpl"><?=gettext("Specify the source port or port range for this rule. <b>This is usually <em>random</em> and almost never equal to the destination port range (and should usually be &quot;any&quot;).</b> <br /> Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port.");?></span><br/>
834 8ab3e9ed Erik Kristensen
			</td>
835 8c84fe43 Scott Ullrich
		</tr>
836 8ab3e9ed Erik Kristensen
		<tr>
837
			<td width="22%" valign="top" class="vncellreq">Destination</td>
838
			<td width="78%" class="vtable">
839 383654fc Vinicius Coque
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
840 8ab3e9ed Erik Kristensen
				<strong>not</strong>
841
					<br />
842
				Use this option to invert the sense of the match.
843
					<br />
844
					<br />
845
				<table border="0" cellspacing="0" cellpadding="0">
846
					<tr>
847
						<td>Type:&nbsp;&nbsp;</td>
848
						<td>
849 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dsttype" class="formselect" onChange="typesel_change()">
850 87f0be87 Chris Buechler
<?php
851
								$sel = is_specialnet($pconfig['dst']); ?>
852 8ab3e9ed Erik Kristensen
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
853 87f0be87 Chris Buechler
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
854
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
855 99ea4439 Scott Ullrich
								<?php if(have_ruleint_access("pptp")): ?>
856 8ab3e9ed Erik Kristensen
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
857 99ea4439 Scott Ullrich
								<?php endif; ?>
858
								<?php if(have_ruleint_access("pppoe")): ?>
859 8ab3e9ed Erik Kristensen
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
860 99ea4439 Scott Ullrich
								<?php endif; ?>								
861 3331a640 Ermal Lu?i
								<?php if(have_ruleint_access("l2tp")): ?>
862
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
863
                                                                <?php endif; ?>
864 b7391125 Ermal Luçi
865
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
866
								<?php if(have_ruleint_access($if)): ?>
867
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
868
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
869
										<?=$ifdesc;?> address
870 cbff71a1 Scott Ullrich
									</option>
871 99ea4439 Scott Ullrich
								<?php endif; ?>
872 b7391125 Ermal Luçi
<?php 							endforeach; ?>
873 8ab3e9ed Erik Kristensen
							</select>
874
						</td>
875
					</tr>
876
					<tr>
877
						<td>Address:&nbsp;&nbsp;</td>
878
						<td>
879 383654fc Vinicius Coque
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
880 8ab3e9ed Erik Kristensen
							/
881 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstmask" class="formselect" id="dstmask">
882 8ab3e9ed Erik Kristensen
<?php
883
							for ($i = 31; $i > 0; $i--): ?>
884
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
885
<?php						endfor; ?>
886
							</select>
887
						</td>
888
					</tr>
889
				</table>
890
			</td>
891
		</tr>
892 3de8af0e Scott Ullrich
		<tr id="dprtr" name="dprtr">
893 8ab3e9ed Erik Kristensen
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
894
			<td width="78%" class="vtable">
895
				<table border="0" cellspacing="0" cellpadding="0">
896
					<tr>
897
						<td>from:&nbsp;&nbsp;</td>
898
						<td>
899 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
900 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
901
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
902
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
903
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
904
<?php 							endforeach; ?>
905
							</select>
906 383654fc Vinicius Coque
							<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
907 8ab3e9ed Erik Kristensen
						</td>
908
					</tr>
909
					<tr>
910
						<td>to:</td>
911
						<td>
912 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstendport" class="formselect" onchange="ext_change()">
913 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
914
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
915
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
916
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
917
<?php 							endforeach; ?>
918 8c84fe43 Scott Ullrich
							</select>
919 383654fc Vinicius Coque
								<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
920 8ab3e9ed Erik Kristensen
						</td>
921
					</tr>
922
				</table>
923
				<br />
924
				<span class="vexpl">
925
					Specify the port or port range for the destination of the packet for this rule.
926 adb633a0 sullrich
					<br />
927 8ab3e9ed Erik Kristensen
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
928
				</span>
929
			</td>
930
		</tr>
931
		<tr>
932
			<td width="22%" valign="top" class="vncellreq">Log</td>
933
			<td width="78%" class="vtable">
934
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
935
				<strong>Log packets that are handled by this rule</strong>
936 adb633a0 sullrich
				<br />
937 8ab3e9ed Erik Kristensen
				<span class="vexpl">Hint: the firewall has limited local log space. Don't turn on logging for everything. If you want to do a lot of logging, consider using a remote syslog server (see the <a href="diag_logs_settings.php">Diagnostics: System logs: Settings</a> page).</span>
938
			</td>
939
		</tr>
940 151eb2a9 sullrich
		<tr>
941
			<td width="22%" valign="top" class="vncell">Description</td>
942
			<td width="78%" class="vtable">
943
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
944
				<br />
945
				<span class="vexpl">You may enter a description here for your reference.</span>
946
			</td>
947
		</tr>
948
		<tr>
949
			<td width="22%" valign="top">&nbsp;</td>
950
			<td width="78%">
951
				&nbsp;<br>&nbsp;
952
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
953
<?php			if (isset($id) && $a_filter[$id]): ?>
954
					<input name="id" type="hidden" value="<?=$id;?>">
955
<?php 			endif; ?>
956
				<input name="after" type="hidden" value="<?=$after;?>">
957
			</td>
958
		</tr>
959
		<tr>
960
			<td>&nbsp;</td>
961
		</tr>
962
		<tr>
963
			<td colspan="2" valign="top" class="listtopic">Advanced features</td>
964
		</tr>	
965 f1602cc4 sullrich
		<tr>
966
			<td width="22%" valign="top" class="vncell">Source OS</td>
967 e265d9f5 sullrich
			<td width="78%" class="vtable">
968 8ba13f00 Ermal
				<div id="showadvsourceosbox" <? if ($pconfig['os']) echo "style='display:none'"; ?>>
969 adb633a0 sullrich
					<input type="button" onClick="show_advanced_sourceos()" value="Advanced"></input> - Show advanced option</a>
970
				</div>
971 8ba13f00 Ermal
				<div id="showsourceosadv" <? if (empty($pconfig['os'])) echo "style='display:none'"; ?>>
972 e265d9f5 sullrich
					OS Type:&nbsp;
973 adb633a0 sullrich
					<select name="os" id="os" class="formselect">
974 f1602cc4 sullrich
<?php
975 adb633a0 sullrich
						$ostypes = array(
976
							 "" => "any",
977
							"AIX" => "AIX",
978
							"Linux" => "Linux",
979
							"FreeBSD" => "FreeBSD",
980
							"NetBSD" => "NetBSD",
981
							"OpenBSD" => "OpenBSD",
982
							"Solaris" => "Solaris",
983
							"MacOS" => "MacOS",
984
							"Windows" => "Windows",
985
							"Novell" => "Novell",
986
							"NMAP" => "NMAP"
987
			           );
988
						foreach ($ostypes as $ostype => $descr): ?>
989
							<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
990
<?php
991
					endforeach; 
992
?>
993
					</select>
994
					<br />
995
					Note: this only works for TCP rules
996
				</div>
997 f1602cc4 sullrich
			</td>
998
		</tr>
999 30c4ae8a sullrich
		<tr>
1000
			<td width="22%" valign="top" class="vncell">Diffserv Code Point</td>
1001
			<td width="78%" class="vtable">
1002 8ba13f00 Ermal
				<div id="dsadv" name="dsadv" <? if ($pconfig['dscp']) echo "style='display:none'"; ?>>
1003 75c34cbb sullrich
					<input type="button" onClick="show_dsdiv();" value="Advanced"> - Show advanced option
1004 30c4ae8a sullrich
				</div>
1005 8ba13f00 Ermal
				<div id="dsdivmain" name="dsdivmain" <? if (empty($pconfig['dscp'])) echo "style='display:none'"; ?>>
1006 30c4ae8a sullrich
					<select name="dscp" id="dscp">
1007
						<option value=""></option>
1008
						<?php foreach($firewall_rules_dscp_types as $frdt): ?>
1009
							<option value="<?=$frdt?>"<?php if($pconfig['dscp'] == $frdt) echo " SELECTED"; ?>><?=$frdt?></option>
1010
						<?php endforeach; ?>
1011
					</select>
1012
				</div>
1013
			</td>
1014
		</tr>
1015 661aed33 Ermal Luçi
		<tr>
1016 e6db3f58 Ermal Luçi
			<td width="22%" valign="top" class="vncell">Advanced Options</td>
1017
			<td width="78%" class="vtable">
1018
			<div id="aoadv" name="aoadv">
1019 75c34cbb sullrich
				<input type="button" onClick="show_aodiv();" value="Advanced"> - Show advanced option
1020 e6db3f58 Ermal Luçi
			</div>
1021
			<div id="aodivmain" name="aodivmain" style="display:none">
1022 f1602cc4 sullrich
				<input type="checkbox" id="allowopts" value="yes" name="allowopts"<?php if($pconfig['allowopts'] == true) echo " checked"; ?>>
1023 a29dc11b Chris Buechler
				<br/><span class="vexpl"><?=gettext("This allows packets with IP options to pass. Otherwise they are blocked by default. This is usually only seen with multicast traffic.");?>
1024 f1602cc4 sullrich
				</span><p>
1025 19757916 Ermal Lu?i
				<input type="checkbox" id="disablereplyto" value="yes" name="disablereplyto"<?php if($pconfig['disablereplyto'] == true) echo " checked"; ?>>
1026
				<br/><span class="vexpl"><?=gettext("This will disable auto generated reply-to for this rule.");?>
1027
				</span><p>
1028 f1602cc4 sullrich
				<input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
1029 a29dc11b Chris Buechler
				<br /><span class="vexpl"><?=gettext("You can mark a packet matching this rule and use this mark to match on other NAT/filter rules. It is called <b>Policy filtering</b>");?>
1030 775ccea3 Ermal Luci
				</span><p>
1031 f1602cc4 sullrich
				<input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>">
1032
				<br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
1033
				</span> <p>
1034 a56b2fa0 pierrepomes
				<input name="max" id="max" value="<?php echo $pconfig['max'] ?>"><br> Maximum state entries this rule can create<p>
1035 29adf437 Chris Buechler
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Maximum number of unique source hosts<p>
1036
				<input name="max-src-conn" id="max-src-conn" value="<?php echo $pconfig['max-src-conn'] ?>"><br> Maximum number of established connections per host<p>	 
1037 8ab3e9ed Erik Kristensen
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
1038
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
1039
				<select name="max-src-conn-rates" id="max-src-conn-rates">
1040
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
1041
<?php				for($x=1; $x<255; $x++) {
1042
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
1043
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
1044
					} ?>
1045 47042140 Scott Ullrich
				</select><br />
1046 29adf437 Chris Buechler
				Maximum new connections / per second(s)
1047 47042140 Scott Ullrich
				<p>
1048
1049
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
1050 3906617b Scott Ullrich
				State Timeout in seconds
1051 47042140 Scott Ullrich
				<p />
1052
1053 29adf437 Chris Buechler
				<p><strong>NOTE: Leave fields blank to disable that feature.</strong>
1054 197b2a47 Scott Ullrich
			  </div>
1055 8ab3e9ed Erik Kristensen
			</td>
1056
		</tr>
1057 b8ed2a11 Ermal
		<tr id="tcpflags" name="tcpflags"> 
1058
			<td width="22%" valign="top" class="vncell">TCP flags</td>
1059
			<td width="78%" class="vtable">
1060 8ba13f00 Ermal
			<div id="showtcpflagsbox" <? if ($pconfig['tcpflags_any'] || $pconfig['tcpflags1'] || $pconfig['tcpflags2']) echo "style='display:none'"; ?>>
1061 b8ed2a11 Ermal
                        	<input type="button" onClick="show_advanced_tcpflags()" value="Advanced"></input> - Show advanced option</a>
1062
                        </div>
1063 8ba13f00 Ermal
                        <div id="showtcpflagsadv" <? if (empty($pconfig['tcpflags_any']) && empty($pconfig['tcpflags1']) && empty($pconfig['tcpflags2'])) echo "style='display:none'"; ?>>
1064 b8ed2a11 Ermal
			<div id="tcpheader" name="tcpheader">
1065
			<center>
1066
			<table border="0" cellspacing="0" cellpadding="0">
1067
			<?php 
1068
				$setflags = explode(",", $pconfig['tcpflags1']);
1069
				$outofflags = explode(",", $pconfig['tcpflags2']);
1070
				$header = "<td width='40' nowrap></td>";
1071
				$tcpflags1 = "<td width='40' nowrap>set</td>";
1072
				$tcpflags2 = "<td width='40' nowrap>out of</td>";
1073
				foreach ($tcpflags as $tcpflag) {
1074
					$header .= "<td  width='40' nowrap><strong>" . strtoupper($tcpflag) . "</strong></td>\n";
1075
					$tcpflags1 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags1_{$tcpflag}' value='on' ";
1076
					if (array_search($tcpflag, $setflags) !== false)
1077
						$tcpflags1 .= "checked";
1078
					$tcpflags1 .= "></td>\n";
1079
					$tcpflags2 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags2_{$tcpflag}' value='on' ";
1080
					if (array_search($tcpflag, $outofflags) !== false)
1081
						$tcpflags2 .= "checked";
1082
					$tcpflags2 .= "></td>\n";
1083
				}
1084
				echo "<tr id='tcpheader' name='tcpheader'>{$header}</tr>\n";
1085
				echo "<tr id='tcpflags1' name='tcpflags1'>{$tcpflags1}</tr>\n";
1086
				echo "<tr id='tcpflags2' name='tcpflags2'>{$tcpflags2}</tr>\n";
1087
			?>
1088
			</table>
1089
			<center>
1090
			</div>
1091
			<br/><center>
1092
			<input onClick='tcpflags_anyclick(this);' type='checkbox' name='tcpflags_any' value='on' <?php if ($pconfig['tcpflags_any']) echo "checked"; ?>><strong>Any flags.</strong><br/></center>
1093
			<br/>
1094
			<span class="vexpl">Use this to choose TCP flags that must 
1095
			be set or cleared for this rule to match.</span>
1096
			</div>
1097
			</td>
1098
		</tr>
1099 8ab3e9ed Erik Kristensen
		<tr>
1100
			<td width="22%" valign="top" class="vncell">State Type</td>
1101
			<td width="78%" class="vtable">
1102 8ba13f00 Ermal
				<div id="showadvstatebox" <? if (!empty($pconfig['statetype']) && $pconfig['statetype'] != "keep state") echo "style='display:none'"; ?>>
1103 75c34cbb sullrich
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show advanced option</a>
1104 f6970b2f Scott Ullrich
				</div>
1105 8ba13f00 Ermal
				<div id="showstateadv" <? if (empty($pconfig['statetype']) || $pconfig['statetype'] == "keep state") echo "style='display:none'"; ?>>
1106 f6970b2f Scott Ullrich
					<select name="statetype">
1107
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
1108 b8ed2a11 Ermal
						<option value="sloppy state" <?php if($pconfig['statetype'] == "sloppy state") echo "selected"; ?>>sloppy state</option>
1109 f6970b2f Scott Ullrich
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
1110
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
1111
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
1112
					<p>
1113
					<table width="90%">
1114 c62ff4e7 Chris Buechler
						<tr><td width="25%"><ul><li>keep state</li></td><td>Works with all IP protocols.</ul></td></tr>
1115 b8ed2a11 Ermal
						<tr><td width="25%"><ul><li>sloppy state</li></td><td>Works with all IP protocols.</ul></td></tr>
1116 8eb08ba7 Chris Buechler
						<tr><td width="25%"><ul><li>synproxy state</li></td><td>Proxies incoming TCP connections to help protect servers from spoofed TCP SYN floods. This option includes the functionality of keep state and modulate state combined.</ul></td></tr>
1117
						<tr><td width="25%"><ul><li>none</li></td><td>Do not use state mechanisms to keep track.  This is only useful if you're doing advanced queueing in certain situations.  Please check the documentation.</ul></td></tr>
1118 f6970b2f Scott Ullrich
					</table>
1119
					</p>
1120
			  </div>
1121 8ab3e9ed Erik Kristensen
			</td>
1122
		</tr>
1123 10f21e70 Scott Ullrich
		<tr>
1124
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
1125
			<td width="78%" class="vtable">
1126 8ba13f00 Ermal
				<div id="showadvnoxmlrpcsyncbox" <? if ($pconfig['nosync']) echo "style='display:none'"; ?>>
1127 75c34cbb sullrich
					<input type="button" onClick="show_advanced_noxmlrpc()" value="Advanced"></input> - Show advanced option</a>
1128 0239d8ee sullrich
				</div>
1129 8ba13f00 Ermal
				<div id="shownoxmlrpcadv" <? if (empty($pconfig['nosync'])) echo "style='display:none'"; ?>>
1130 0239d8ee sullrich
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
1131 a29dc11b Chris Buechler
					HINT: This prevents the rule from automatically syncing to other CARP members.
1132 0239d8ee sullrich
				</div>
1133 10f21e70 Scott Ullrich
			</td>
1134 8c84fe43 Scott Ullrich
		</tr>
1135 615b27bc Scott Dale
		<?php
1136
			//build list of schedules
1137
			$schedules = array();
1138
			$schedules[] = "none";//leave none to leave rule enabled all the time
1139 a60fd0cb Scott Ullrich
			if(is_array($config['schedules']['schedule'])) {
1140
				foreach ($config['schedules']['schedule'] as $schedule) {
1141
					if ($schedule['name'] <> "")
1142
						$schedules[] = $schedule['name'];
1143
				}
1144
			}
1145 615b27bc Scott Dale
		?>
1146
		<tr>
1147
			<td width="22%" valign="top" class="vncell">Schedule</td>
1148
			<td width="78%" class="vtable">
1149 8ba13f00 Ermal
				<div id="showadvschedulebox" <? if (!empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1150 75c34cbb sullrich
					<input type="button" onClick="show_advanced_schedule()" value="Advanced"></input> - Show advanced option</a>
1151 0239d8ee sullrich
				</div>
1152 8ba13f00 Ermal
				<div id="showscheduleadv" <? if (empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1153 0239d8ee sullrich
					<select name='sched'>
1154 615b27bc Scott Dale
<?php
1155 0239d8ee sullrich
					foreach($schedules as $schedule) {
1156
						if($schedule == $pconfig['sched']) {
1157
							$selected = " SELECTED";
1158
						} else {
1159
							$selected = "";
1160
						}
1161
						if ($schedule == "none") {
1162
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1163
						} else {
1164
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1165
						}
1166 615b27bc Scott Dale
					}
1167 0239d8ee sullrich
?>
1168
					</select>
1169
					<p>Leave as 'none' to leave the rule enabled all the time.</p>
1170
				</div>
1171 615b27bc Scott Dale
			</td>
1172
		</tr>
1173 82628210 Scott Ullrich
		<tr>
1174 8ab3e9ed Erik Kristensen
			<td width="22%" valign="top" class="vncell">Gateway</td>
1175
			<td width="78%" class="vtable">
1176 8ba13f00 Ermal
				<div id="showadvgatewaybox" <? if (!empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1177 75c34cbb sullrich
					<input type="button" onClick="show_advanced_gateway()" value="Advanced"></input> - Show advanced option</a>
1178 0239d8ee sullrich
				</div>
1179 8ba13f00 Ermal
				<div id="showgatewayadv" <? if (empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1180 0239d8ee sullrich
					<select name='gateway'>
1181 1b38ac36 Ermal
					<option value="" >default</option>
1182 8ab3e9ed Erik Kristensen
<?php
1183 1b38ac36 Ermal
					/* build a list of gateways */
1184
					$gateways = return_gateways_array();
1185 106804a2 Chris Buechler
					// add statically configured gateways to list
1186 1b38ac36 Ermal
					foreach($gateways as $gwname => $gw) {
1187 0239d8ee sullrich
						if($gw == "") 
1188 0581660c Scott Ullrich
							continue;
1189 1b38ac36 Ermal
						if($gwname == $pconfig['gateway']) {
1190 4443d4d6 Scott Ullrich
							$selected = " SELECTED";
1191 1fda0968 Scott Ullrich
						} else {
1192
							$selected = "";
1193
						}
1194 1b38ac36 Ermal
						echo "<option value=\"{$gwname}\" {$selected}>{$gw['name']} - {$gw['gateway']}</option>\n";
1195 106804a2 Chris Buechler
					}
1196 0239d8ee sullrich
					/* add gateway groups to the list */
1197
					if (is_array($config['gateways']['gateway_group'])) {
1198
						foreach($config['gateways']['gateway_group'] as $gw_group) {
1199
							if($gw_group['name'] == "")
1200
								continue;
1201
							if($pconfig['gateway'] == $gw_group['name']) {
1202
								echo "<option value=\"{$gw_group['name']}\" SELECTED>{$gw_group['name']}</option>\n";
1203
							} else {
1204
								echo "<option value=\"{$gw_group['name']}\">{$gw_group['name']}</option>\n";
1205
							}
1206
						}
1207
					}
1208 8ab3e9ed Erik Kristensen
?>
1209 0239d8ee sullrich
					</select>
1210
					<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
1211
				</div>
1212 8ab3e9ed Erik Kristensen
			</td>
1213
		</tr>
1214 a5fd67e1 Ermal Luçi
		<tr>
1215
			<td width="22%" valign="top" class="vncell">In/Out</td>
1216
			<td width="78%" class="vtable">
1217 8ba13f00 Ermal
				<div id="showadvinoutbox" <? if (!empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1218 75c34cbb sullrich
					<input type="button" onClick="show_advanced_inout()" value="Advanced"></input> - Show advanced option</a>
1219 4c263f57 sullrich
				</div>
1220 8ba13f00 Ermal
				<div id="showinoutadv" <? if (empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1221 4c263f57 sullrich
					<select name="dnpipe">
1222 a5fd67e1 Ermal Luçi
<?php
1223
		if (!is_array($dnqlist))
1224
			$dnqlist = array();
1225
		echo "<option value=\"none\"";
1226
		if (!$dnqselected) echo " SELECTED";
1227
		echo " >none</option>";
1228
		foreach ($dnqlist as $dnq => $dnqkey) {
1229
			if($dnq == "")
1230
				continue;
1231
			echo "<option value=\"$dnqkey\"";
1232
			if ($dnqkey == $pconfig['dnpipe']) {
1233
				$dnqselected = 1;
1234
				echo " SELECTED";
1235
			}
1236
			echo ">{$dnq}</option>"; 
1237
		}
1238
?>
1239
			</select> / 			
1240
			<select name="pdnpipe">
1241
<?php
1242
		$dnqselected = 0;
1243
		echo "<option value=\"none\"";
1244
		if (!$dnqselected) echo " SELECTED";
1245
		echo " >none</option>";
1246
		foreach ($dnqlist as $dnq => $dnqkey) {
1247
			if($dnq == "")
1248
				continue;
1249
			echo "<option value=\"$dnqkey\"";
1250
			if ($dnqkey == $pconfig['pdnpipe']) {
1251
				$dnqselected = 1;
1252
				echo " SELECTED";
1253
			}
1254
			echo ">{$dnq}</option>"; 
1255
		}
1256
?>
1257 4c263f57 sullrich
				</select>
1258 a5fd67e1 Ermal Luçi
				<br />
1259
				<span class="vexpl">Choose the Out queue/Virtual interface only if you have selected In too. <br/> The Out selection is applied to traffic going out the interface the rule is created, In is the incoming one. <br/> If you are creating a rule on the Floating tab if the direction is In then the same rules apply, if the direction is out the selections are reverted Out is for incoming and In is for outgoing and if you do not select any direction use only the In since the Out selection does not make sense in there to prevent oddities.</span>
1260 4c263f57 sullrich
				</div>
1261 a5fd67e1 Ermal Luçi
			</td>
1262
		</tr>
1263
1264 197bfe96 Ermal Luçi
		<tr>
1265
			<td width="22%" valign="top" class="vncell">Ackqueue/Queue</td>
1266
			<td width="78%" class="vtable">
1267 8ba13f00 Ermal
			<div id="showadvackqueuebox" <? if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1268 75c34cbb sullrich
				<input type="button" onClick="show_advanced_ackqueue()" value="Advanced"></input> - Show advanced option</a>
1269 0239d8ee sullrich
			</div>
1270 8ba13f00 Ermal
			<div id="showackqueueadv" <? if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1271 0239d8ee sullrich
				<select name="ackqueue">
1272 197bfe96 Ermal Luçi
<?php
1273 0239d8ee sullrich
			if (!is_array($qlist))
1274
				$qlist = array();
1275
			echo "<option value=\"none\"";
1276
			if (!$qselected) echo " SELECTED";
1277
			echo " >none</option>";
1278
			foreach ($qlist as $q => $qkey) {
1279
				if($q == "")
1280
					continue;
1281
				echo "<option value=\"$q\"";
1282
				if ($q == $pconfig['ackqueue']) {
1283
					$qselected = 1;
1284
					echo " SELECTED";
1285
				}
1286
				echo ">{$q}</option>"; 
1287 197bfe96 Ermal Luçi
			}
1288
?>
1289 0239d8ee sullrich
				</select> / 			
1290
				<select name="defaultqueue">
1291 197bfe96 Ermal Luçi
<?php
1292 0239d8ee sullrich
			$qselected = 0;
1293
			echo "<option value=\"none\"";
1294
			if (!$qselected) echo " SELECTED";
1295
			echo " >none</option>";
1296
			foreach ($qlist as $q => $qkey) {
1297
				if($q == "")
1298
					continue;
1299
				echo "<option value=\"$q\"";
1300
				if ($q == $pconfig['defaultqueue']) {
1301
					$qselected = 1;
1302
					echo " SELECTED";
1303
				}
1304
				echo ">{$q}</option>"; 
1305 197bfe96 Ermal Luçi
			}
1306
?>
1307 0239d8ee sullrich
				</select>
1308
					<br />
1309
					<span class="vexpl">Choose the Acknowledge Queue only if you have selected Queue.</span>
1310
				</td>
1311
			</tr>
1312
			<tr>
1313
				<td width="22%" valign="top" class="vncell">Layer7</td>
1314
				<td width="78%" class="vtable">
1315 8ba13f00 Ermal
					<div id="showadvlayer7box" <? if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1316 75c34cbb sullrich
						<input type="button" onClick="show_advanced_layer7()" value="Advanced"></input> - Show advanced option</a>
1317 4c263f57 sullrich
					</div>
1318 8ba13f00 Ermal
					<div id="showlayer7adv" <? if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1319 0239d8ee sullrich
				<select name="l7container">
1320 7e50413c Ermal Luçi
<?php
1321 0239d8ee sullrich
					if (!is_array($l7clist))
1322 06e2a55d thompsa
						$l7clist = array();
1323 0239d8ee sullrich
					echo "<option value=\"none\"";
1324
					echo " >none</option>";
1325
					foreach ($l7clist as $l7ckey) {
1326
						echo "<option value=\"{$l7ckey}\"";
1327
						if ($l7ckey == $pconfig['l7container']) {
1328
							echo " SELECTED";
1329
						}
1330
						echo ">{$l7ckey}</option>"; 
1331
					}
1332 7e50413c Ermal Luçi
?>
1333 0239d8ee sullrich
				</select>			
1334 7e50413c Ermal Luçi
				<br/>
1335 0239d8ee sullrich
				<span class="vexpl">
1336
					Choose a Layer7 container to apply application protocol inspection rules.
1337 a29dc11b Chris Buechler
					These are valid for TCP and UDP protocols only.
1338 0239d8ee sullrich
				</span>
1339
			  </div>
1340 7e50413c Ermal Luçi
			</td>
1341
		</tr>
1342 8ab3e9ed Erik Kristensen
		<tr>
1343
			<td width="22%" valign="top">&nbsp;</td>
1344
			<td width="78%">
1345 151eb2a9 sullrich
				&nbsp;<br>&nbsp;
1346 8ab3e9ed Erik Kristensen
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
1347
<?php			if (isset($id) && $a_filter[$id]): ?>
1348
					<input name="id" type="hidden" value="<?=$id;?>">
1349
<?php 			endif; ?>
1350
				<input name="after" type="hidden" value="<?=$after;?>">
1351
			</td>
1352 82628210 Scott Ullrich
		</tr>
1353 8ab3e9ed Erik Kristensen
	</table>
1354 5b237745 Scott Ullrich
</form>
1355
<script language="JavaScript">
1356
<!--
1357 8ab3e9ed Erik Kristensen
	ext_change();
1358
	typesel_change();
1359
	proto_change();
1360 19757279 Scott Ullrich
1361
<?php
1362 8ab3e9ed Erik Kristensen
	$isfirst = 0;
1363
	$aliases = "";
1364
	$addrisfirst = 0;
1365
	$aliasesaddr = "";
1366
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1367
		foreach($config['aliases']['alias'] as $alias_name) {
1368 72cb5baf Ermal Lu?i
			switch ($alias_name['type']) {
1369
			case "port":
1370
				if($isfirst == 1) $portaliases .= ",";
1371
				$portaliases .= "'" . $alias_name['name'] . "'";
1372 8ab3e9ed Erik Kristensen
				$isfirst = 1;
1373 72cb5baf Ermal Lu?i
				break;
1374
			case "host":
1375
			case "network":
1376
			case "openvpn":
1377 c7de8be4 jim-p
			case "urltable":
1378 8ab3e9ed Erik Kristensen
				if($addrisfirst == 1) $aliasesaddr .= ",";
1379
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1380
				$addrisfirst = 1;
1381 72cb5baf Ermal Lu?i
				break;
1382
			default:
1383
				break;
1384 8ab3e9ed Erik Kristensen
			}
1385 092ac49d Scott Ullrich
		}
1386 19757279 Scott Ullrich
?>
1387
1388 8ab3e9ed Erik Kristensen
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1389 72cb5baf Ermal Lu?i
	var customarray=new Array(<?php echo $portaliases; ?>);
1390 19757279 Scott Ullrich
1391 9eb60dcc Ermal Lu?i
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1392
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1393
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1394
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1395
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1396
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1397 5b237745 Scott Ullrich
//-->
1398
</script>
1399
<?php include("fend.inc"); ?>
1400
</body>
1401 9b45f821 Ermal Lu?i
</html>