Project

General

Profile

Download (56.4 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
		$temp = $value;
251 661aed33 Ermal Luçi
		if (isset($_POST['floating']) && $key == "interface")
252
			continue;
253 21eff66f Scott Ullrich
		$newpost = htmlentities($temp);
254 5157927f Scott Ullrich
		if($newpost <> $temp)   	 
255
			$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";		
256 ef2a753c Scott Ullrich
	}
257
258 5b237745 Scott Ullrich
	/* input validation */
259 473d0ff0 pierrepomes
	$reqdfields = explode(" ", "type proto src");
260 9b16b834 Ermal Lu?i
	if ( isset($a_filter[$id]['associated-rule-id'])===false )
261 473d0ff0 pierrepomes
		$redqfields[] = "dst";
262
	$reqdfieldsn = explode(",", "Type,Protocol,Source");
263 9b16b834 Ermal Lu?i
	if ( isset($a_filter[$id]['associated-rule-id'])===false )
264 473d0ff0 pierrepomes
		$reqdfieldsn[] = "Destination";
265 5b237745 Scott Ullrich
266 452ade89 Bill Marquette
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
267 c22767b1 Bill Marquette
		if( $_POST['proto'] != "tcp" )
268
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
269 452ade89 Bill Marquette
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
270
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
271
	}
272 10f7933f Chris Buechler
        
273 5b237745 Scott Ullrich
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
274
		$reqdfields[] = "srcmask";
275
		$reqdfieldsn[] = "Source bit count";
276
	}
277 9b16b834 Ermal Lu?i
	if ( isset($a_filter[$id]['associated-rule-id'])===false &&
278 473d0ff0 pierrepomes
	(!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) ) {
279 5b237745 Scott Ullrich
		$reqdfields[] = "dstmask";
280
		$reqdfieldsn[] = "Destination bit count";
281
	}
282 5ba18897 Scott Ullrich
283 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
284 5ba18897 Scott Ullrich
285 5b237745 Scott Ullrich
	if (!$_POST['srcbeginport']) {
286
		$_POST['srcbeginport'] = 0;
287
		$_POST['srcendport'] = 0;
288
	}
289
	if (!$_POST['dstbeginport']) {
290
		$_POST['dstbeginport'] = 0;
291
		$_POST['dstendport'] = 0;
292
	}
293 5ba18897 Scott Ullrich
294 9b45f821 Ermal Lu?i
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
295
                $input_errors[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
296
        if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
297
                $input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
298
        if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
299
                $input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
300
        if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
301
                $input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
302 5ba18897 Scott Ullrich
303 0e5ddcd9 Scott Ullrich
	/* if user enters an alias and selects "network" then disallow. */
304
	if($_POST['srctype'] == "network") {
305
		if(is_alias($_POST['src']))
306
			$input_errors[] = "You must specify single host or alias for alias entries.";
307
	}
308
	if($_POST['dsttype'] == "network") {
309
		if(is_alias($_POST['dst']))
310
			$input_errors[] = "You must specify single host or alias for alias entries.";
311
	}
312
313 5b237745 Scott Ullrich
	if (!is_specialnet($_POST['srctype'])) {
314 1e578a7f Ermal Lu?i
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
315 9b45f821 Ermal Lu?i
			$input_errors[] = "{$_POST['src']} is not a valid source IP address or alias.";
316 5b237745 Scott Ullrich
		}
317
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
318
			$input_errors[] = "A valid source bit count must be specified.";
319
		}
320
	}
321
	if (!is_specialnet($_POST['dsttype'])) {
322 1e578a7f Ermal Lu?i
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
323 9b45f821 Ermal Lu?i
			$input_errors[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
324 5b237745 Scott Ullrich
		}
325
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
326
			$input_errors[] = "A valid destination bit count must be specified.";
327
		}
328
	}
329 5ba18897 Scott Ullrich
330 5b237745 Scott Ullrich
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
331
		/* swap */
332
		$tmp = $_POST['srcendport'];
333
		$_POST['srcendport'] = $_POST['srcbeginport'];
334
		$_POST['srcbeginport'] = $tmp;
335
	}
336
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
337
		/* swap */
338
		$tmp = $_POST['dstendport'];
339
		$_POST['dstendport'] = $_POST['dstbeginport'];
340
		$_POST['dstbeginport'] = $tmp;
341
	}
342 e33c8694 Bill Marquette
	if ($_POST['os'])
343
		if( $_POST['proto'] != "tcp" )
344
			$input_errors[] = "OS detection is only valid with protocol tcp.";
345 5b237745 Scott Ullrich
346 197bfe96 Ermal Luçi
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
347
		if ($_POST['defaultqueue'] == "none" )
348
			$input_errors[] = "You have to select a queue when you select an acknowledge queue too.";
349
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
350 aa8cdf52 Scott Ullrich
			$input_errors[] = "Acknowledge queue and Queue cannot be the same.";		
351 197bfe96 Ermal Luçi
	}
352 a5fd67e1 Ermal Luçi
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
353
		if ($_POST['dnpipe'] == "none" )
354
			$input_errors[] = "You must select a queue for the In direction before selecting one for Out too.";
355
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
356
			$input_errors[] = "In and Out Queue cannot be the same.";
357
		else if ($pdnpipe[0] == "?" && $dnpipe[0] <> "?")
358
			$input_errors[] = "You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.";
359
		else if ($dnpipe[0] == "?" && $pdnpipe[0] <> "?")
360
			$input_errors[] = "You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.";
361
	}
362 b9e28d57 unknown
	if( !empty($_POST['ruleid']) && !ctype_digit($_POST['ruleid']))
363
		$input_errors[] = 'ID must be an integer';
364 7e50413c Ermal Luçi
	if($_POST['l7container'] && $_POST['l7container'] != "none") {
365
		if(!($_POST['proto'] == "tcp" || $_POST['proto'] == "udp" || $_POST['proto'] == "tcp/udp"))
366 8b69a3e1 Chris Buechler
			$input_errors[] = "You can only select a layer7 container for TCP and/or UDP protocols";
367 3b184ca5 Ermal Lu?i
		if ($_POST['type'] <> "pass")
368
			$input_errors[] = "You can only select a layer7 container for Pass type rules.";
369 7e50413c Ermal Luçi
	}
370 197bfe96 Ermal Luçi
371 b8ed2a11 Ermal
	if (!$_POST['tcpflags_any']) {
372
		$settcpflags = array();
373
		$outoftcpflags = array();
374
		foreach ($tcpflags as $tcpflag) {
375
			if ($_POST['tcpflags1_' . $tcpflag] == "on")
376
				$settcpflags[] = $tcpflag;
377
			if ($_POST['tcpflags2_' . $tcpflag] == "on")
378
				$outoftcpflags[] = $tcpflag;
379
		}
380
		if (empty($outoftcpflags) && !empty($settcpflags))
381
			$input_errors[] = "If you specify TCP flags that should be set you should specify out of which flags as well.";
382
	}
383
384 5b237745 Scott Ullrich
	if (!$input_errors) {
385
		$filterent = array();
386 b9e28d57 unknown
		$filterent['id'] = $_POST['ruleid']>0?$_POST['ruleid']:'';
387 5b237745 Scott Ullrich
		$filterent['type'] = $_POST['type'];
388 661aed33 Ermal Luçi
		if (isset($_POST['interface'] ))
389
			$filterent['interface'] = $_POST['interface'];
390
391 b8ed2a11 Ermal
		if ($_POST['tcpflags_any']) {
392
			$filterent['tcpflags_any'] = true;
393
		} else {
394
			$settcpflags = array();
395
			$outoftcpflags = array();
396
			foreach ($tcpflags as $tcpflag) {
397
				if ($_POST['tcpflags1_' . $tcpflag] == "on")
398
					$settcpflags[] = $tcpflag;
399
				if ($_POST['tcpflags2_' . $tcpflag] == "on")
400
					$outoftcpflags[] = $tcpflag;
401
			}
402
			if (!empty($outoftcpflags)) {
403
				$filterent['tcpflags2'] = join(",", $outoftcpflags);
404
				if (!empty($settcpflags))
405
					$filterent['tcpflags1'] = join(",", $settcpflags);
406
			}
407
		}
408
409 661aed33 Ermal Luçi
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
410
			if (isset($_POST['tag']))
411
				$filterent['tag'] = $_POST['tag'];
412
			if (isset($_POST['tagged']))
413 f1602cc4 sullrich
				$filterent['tagged'] = $_POST['tagged'];
414 661aed33 Ermal Luçi
			$filterent['direction'] = $_POST['direction'];
415
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
416
				$filterent['quick'] = $_POST['quick'];
417
			$filterent['floating'] = "yes";
418
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
419 f1602cc4 sullrich
				$filterent['interface'] = implode(",", $_POST['interface']);
420 661aed33 Ermal Luçi
			}
421
		}
422 d59874c1 Scott Ullrich
423 bdb7d6e7 Scott Ullrich
		/* Advanced options */
424 775ccea3 Ermal Luci
		if ($_POST['allowopts'] == "yes")
425
			$filterent['allowopts'] = true;
426
		else
427
			unset($filterent['allowopts']);
428 19757916 Ermal Lu?i
		if ($_POST['disablereplyto'] == "yes")
429
			$filterent['disablereplyto'] = true;
430
		else
431
			unset($filterent['disablereplyto']);
432 a56b2fa0 pierrepomes
		$filterent['max'] = $_POST['max'];
433 bdb7d6e7 Scott Ullrich
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
434 26dd6a54 pierrepomes
		$filterent['max-src-conn'] = $_POST['max-src-conn'];
435 bdb7d6e7 Scott Ullrich
		$filterent['max-src-states'] = $_POST['max-src-states'];
436 5ba18897 Scott Ullrich
		$filterent['statetimeout'] = $_POST['statetimeout'];
437 fa9af164 Scott Ullrich
		$filterent['statetype'] = $_POST['statetype'];
438 e33c8694 Bill Marquette
		$filterent['os'] = $_POST['os'];
439 10f21e70 Scott Ullrich
440
		/* Nosync directive - do not xmlrpc sync this item */
441 8c84fe43 Scott Ullrich
		if($_POST['nosync'] <> "")
442 10f21e70 Scott Ullrich
			$filterent['nosync'] = true;
443
		else
444
			unset($filterent['nosync']);
445
446 3f00c1dc Scott Ullrich
		/* unless both values are provided, unset the values - ticket #650 */
447
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
448
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
449
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
450
		} else {
451
			unset($filterent['max-src-conn-rate']);
452
			unset($filterent['max-src-conn-rates']);
453
		}
454 5ba18897 Scott Ullrich
455 5b237745 Scott Ullrich
		if ($_POST['proto'] != "any")
456
			$filterent['protocol'] = $_POST['proto'];
457
		else
458
			unset($filterent['protocol']);
459 5ba18897 Scott Ullrich
460 5b237745 Scott Ullrich
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
461
			$filterent['icmptype'] = $_POST['icmptype'];
462
		else
463
			unset($filterent['icmptype']);
464 5ba18897 Scott Ullrich
465 5b237745 Scott Ullrich
		pconfig_to_address($filterent['source'], $_POST['src'],
466
			$_POST['srcmask'], $_POST['srcnot'],
467
			$_POST['srcbeginport'], $_POST['srcendport']);
468 5ba18897 Scott Ullrich
469 5b237745 Scott Ullrich
		pconfig_to_address($filterent['destination'], $_POST['dst'],
470
			$_POST['dstmask'], $_POST['dstnot'],
471
			$_POST['dstbeginport'], $_POST['dstendport']);
472 5ba18897 Scott Ullrich
473 f1602cc4 sullrich
		if ($_POST['disabled'])
474
			$filterent['disabled'] = true;
475
		else
476
			unset($filterent['disabled']);
477
478 c5fc1b2e Ermal Luçi
		if ($_POST['dscp'])
479
			$filterent['dscp'] = $_POST['dscp'];
480
481 f1602cc4 sullrich
		if ($_POST['log'])
482
			$filterent['log'] = true;
483
		else
484
			unset($filterent['log']);
485 c68fc1e7 Bill Marquette
		strncpy($filterent['descr'], $_POST['descr'], 52);
486 5ba18897 Scott Ullrich
487 c98ddde2 Bill Marquette
		if ($_POST['gateway'] != "") {
488
			$filterent['gateway'] = $_POST['gateway'];
489
		}
490 197bfe96 Ermal Luçi
		
491
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
492
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
493
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
494
				$filterent['ackqueue'] = $_POST['ackqueue'];
495
		}
496 c98ddde2 Bill Marquette
497 a5fd67e1 Ermal Luçi
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
498
			$filterent['dnpipe'] = $_POST['dnpipe'];
499
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
500
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
501
		}
502
503 7e50413c Ermal Luçi
		if (isset($_POST['l7container']) && $_POST['l7container'] != "none") {
504
			$filterent['l7container'] = $_POST['l7container'];
505
		}
506
		
507 615b27bc Scott Dale
		if ($_POST['sched'] != "") {
508
			$filterent['sched'] = $_POST['sched'];
509
		}
510
511 473d0ff0 pierrepomes
		// If we have an associated nat rule, make sure the destination doesn't change
512 9b16b834 Ermal Lu?i
		if( isset($a_filter[$id]['associated-rule-id']) ) {
513 473d0ff0 pierrepomes
			$filterent['destination'] = $a_filter[$id]['destination'];
514 9b16b834 Ermal Lu?i
			$filterent['associated-rule-id'] = $a_filter[$id]['associated-rule-id'];
515 473d0ff0 pierrepomes
		}
516
517 5b237745 Scott Ullrich
		if (isset($id) && $a_filter[$id])
518
			$a_filter[$id] = $filterent;
519
		else {
520
			if (is_numeric($after))
521
				array_splice($a_filter, $after+1, 0, array($filterent));
522
			else
523
				$a_filter[] = $filterent;
524
		}
525 f4e2a352 Scott Ullrich
526 5b237745 Scott Ullrich
		write_config();
527 a368a026 Ermal Lu?i
		mark_subsystem_dirty('filter');
528 5ba18897 Scott Ullrich
529 661aed33 Ermal Luçi
		if (isset($_POST['floating']))
530
			header("Location: firewall_rules.php?if=FloatingRules");
531
		else
532
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
533 5b237745 Scott Ullrich
		exit;
534
	}
535 c60824d2 Scott Ullrich
}
536
537 37c53a0d Ermal Lu?i
read_altq_config(); /* XXX: */
538
$qlist =& get_unique_queue_list();
539
read_dummynet_config(); /* XXX: */
540
$dnqlist =& get_unique_dnqueue_list();
541
read_layer7_config();
542
$l7clist =& get_l7_unique_list();
543
544 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Rules","Edit");
545 a1357fe0 Bill Marquette
$closehead = false;
546 8ab3e9ed Erik Kristensen
547
$page_filename = "firewall_rules_edit.php";
548 da7ae7ef Bill Marquette
include("head.inc");
549 c60824d2 Scott Ullrich
550 5b237745 Scott Ullrich
?>
551 da7ae7ef Bill Marquette
552 5b237745 Scott Ullrich
</head>
553
554
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
555
<?php include("fbegin.inc"); ?>
556
<?php if ($input_errors) print_input_errors($input_errors); ?>
557 8ab3e9ed Erik Kristensen
558
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
559 6eac9b90 Scott Ullrich
<input type='hidden' name="ruleid" value="<?=(isset($pconfig['ruleid'])&&$pconfig['ruleid']>0)?htmlspecialchars($pconfig['ruleid']):''?>">
560
561 8ab3e9ed Erik Kristensen
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
562 e091cb45 Scott Ullrich
		<tr>
563
			<td colspan="2" valign="top" class="listtopic">Edit Firewall rule</td>
564
		</tr>	
565 8ab3e9ed Erik Kristensen
    	<tr>
566
			<td width="22%" valign="top" class="vncellreq">Action</td>
567
			<td width="78%" class="vtable">
568 b5c78501 Seth Mos
				<select name="type" class="formselect">
569 8ab3e9ed Erik Kristensen
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
570
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
571
					<?=htmlspecialchars($type);?>
572
					</option>
573
					<?php endforeach; ?>
574 8c84fe43 Scott Ullrich
				</select>
575 8ab3e9ed Erik Kristensen
				<br/>
576
				<span class="vexpl">
577
					Choose what to do with packets that match the criteria specified below. <br/>
578 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. 
579 8ab3e9ed Erik Kristensen
				</span>
580
			</td>
581
		</tr>
582
		<tr>
583
			<td width="22%" valign="top" class="vncellreq">Disabled</td>
584
			<td width="78%" class="vtable">
585
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
586
				<strong>Disable this rule</strong><br />
587
				<span class="vexpl">Set this option to disable this rule without removing it from the list.</span>
588
			</td>
589
		</tr>
590 661aed33 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
591
		<tr>
592 f1602cc4 sullrich
			<td width="22%" valign="top" class="vncellreq">
593
				<?=gettext("Quick");?>
594
			</td>
595
			<td width="78%" class="vtable">
596
				<input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
597
				<strong><?=gettext("Apply the action immediately on match.");?></strong><br />
598
				<span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
599
			</td>
600
		</tr>
601 661aed33 Ermal Luçi
<? endif; ?>
602 8ab3e9ed Erik Kristensen
		<tr>
603
			<td width="22%" valign="top" class="vncellreq">Interface</td>
604
			<td width="78%" class="vtable">
605 4633edc2 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
606 8e6ac824 Ermal Luçi
				<select name="interface[]" multiple="true" class="formselect" size="3">
607 661aed33 Ermal Luçi
<? else: ?>
608 b5c78501 Seth Mos
				<select name="interface" class="formselect">
609 8ab3e9ed Erik Kristensen
<?php
610 661aed33 Ermal Luçi
   endif;
611 a7782099 Ermal Lu?i
				/* add group interfaces */
612 f1602cc4 sullrich
				if (is_array($config['ifgroups']['ifgroupentry']))
613 a7782099 Ermal Lu?i
					foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
614
						if (have_ruleint_access($ifgen['ifname']))
615
							$interfaces[$ifgen['ifname']] = $ifgen['ifname'];
616 b7391125 Ermal Luçi
				$ifdescs = get_configured_interface_with_descr();
617 5335811d Ermal Luçi
				foreach ($ifdescs as $ifent => $ifdesc)
618
        				if(have_ruleint_access($ifent))
619 f1602cc4 sullrich
							$interfaces[$ifent] = $ifdesc;
620 617f8d25 Ermal Lu?i
					if ($config['l2tp']['mode'] == "server")
621 f1602cc4 sullrich
						if(have_ruleint_access("l2tp"))
622
							$interfaces['l2tp'] = "L2TP VPN";
623 b6742927 Scott Ullrich
					if ($config['pptpd']['mode'] == "server")
624
						if(have_ruleint_access("pptp")) 
625
							$interfaces['pptp'] = "PPTP VPN";
626
					
627
					if ($config['pppoe']['mode'] == "server")
628
						if(have_ruleint_access("pppoe")) 
629
							$interfaces['pppoe'] = "PPPoE VPN";
630
					/* add ipsec interfaces */
631
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
632
						if(have_ruleint_access("enc0")) 
633 0f266b2e Chris Buechler
							$interfaces["enc0"] = "IPsec";
634 bfb60ac8 Ermal Luçi
					/* add openvpn/tun interfaces */
635 d799787e Matthew Grooms
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
636
       					$interfaces["openvpn"] = "OpenVPN";
637 8ab3e9ed Erik Kristensen
					foreach ($interfaces as $iface => $ifacename): ?>
638 c013d3f5 Chris Buechler
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && (strcasecmp($pconfig['interface'], $iface) == 0)) echo "selected"; ?>><?=gettext($ifacename);?></option>
639 8ab3e9ed Erik Kristensen
<?php 				endforeach; ?>
640 8c84fe43 Scott Ullrich
				</select>
641 8ab3e9ed Erik Kristensen
				<br />
642
				<span class="vexpl">Choose on which interface packets must come in to match this rule.</span>
643
			</td>
644
		</tr>
645 661aed33 Ermal Luçi
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
646 f1602cc4 sullrich
		<tr>
647
			<td width="22%" valign="top" class="vncellreq">
648
				<?=gettext("Direction");?>
649
			</td>
650
			<td width="78%" class="vtable">
651
				<select name="direction" class="formselect">
652
					<?php      $directions = array('any', 'in', 'out');
653
				foreach ($directions as $direction): ?>
654
				<option value="<?=$direction;?>"
655
					<?php if ($direction == $pconfig['direction']): ?>
656
						selected="selected" 
657
					<?php endif; ?>
658
					><?=$direction;?></option>
659
				<?php endforeach; ?>      
660
				</select>
661
				<input type="hidden" id="floating" name="floating" value="floating">
662
			</td>
663
		<tr>
664 661aed33 Ermal Luçi
<?php endif; ?>
665 8ab3e9ed Erik Kristensen
		<tr>
666
			<td width="22%" valign="top" class="vncellreq">Protocol</td>
667
			<td width="78%" class="vtable">
668 b5c78501 Seth Mos
				<select name="proto" class="formselect" onchange="proto_change()">
669 8ab3e9ed Erik Kristensen
<?php
670 87f0be87 Chris Buechler
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP any carp pfsync");
671 8ab3e9ed Erik Kristensen
				foreach ($protocols as $proto): ?>
672
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
673
<?php 			endforeach; ?>
674
				</select>
675
				<br />
676
				<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>
677
			</td>
678
		</tr>
679 3de8af0e Scott Ullrich
		<tr id="icmpbox" name="icmpbox">
680 8ab3e9ed Erik Kristensen
			<td valign="top" class="vncell">ICMP type</td>
681
			<td class="vtable">
682 b5c78501 Seth Mos
				<select name="icmptype" class="formselect">
683 8ab3e9ed Erik Kristensen
<?php
684
				$icmptypes = array(
685
				"" => "any",
686
				"echorep" => "Echo reply",
687
				"unreach" => "Destination unreachable",
688
				"squench" => "Source quench",
689
				"redir" => "Redirect",
690
				"althost" => "Alternate Host",
691
				"echoreq" => "Echo",
692
				"routeradv" => "Router advertisement",
693
				"routersol" => "Router solicitation",
694
				"timex" => "Time exceeded",
695
				"paramprob" => "Invalid IP header",
696
				"timereq" => "Timestamp",
697
				"timerep" => "Timestamp reply",
698
				"inforeq" => "Information request",
699
				"inforep" => "Information reply",
700
				"maskreq" => "Address mask request",
701
				"maskrep" => "Address mask reply"
702
				);
703
704
				foreach ($icmptypes as $icmptype => $descr): ?>
705
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
706
<?php 			endforeach; ?>
707
			</select>
708
			<br />
709
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
710
		</td>
711
		</tr>
712
		<tr>
713
			<td width="22%" valign="top" class="vncellreq">Source</td>
714
			<td width="78%" class="vtable">
715 383654fc Vinicius Coque
				<?php $edit_disabled=false; ?>
716
				<?php if( isset($pconfig['associated-rule-id']) ): ?>
717
					<span class="red"><strong>NOTE: </strong></span> This is associated to a NAT rule.<br />
718
					You cannot edit the source and destination of associated filter rules.<br />
719
					<br />
720 bae53989 Renato Botelho
					<?php
721 383654fc Vinicius Coque
						$edit_disabled=true;
722
						if (is_array($config['nat']['rule'])) {
723 bae53989 Renato Botelho
							foreach( $config['nat']['rule'] as $index => $nat_rule ) {
724
								if( $nat_rule['associated-rule-id']==$pconfig['associated-rule-id']) {
725
									echo "<a href=\"firewall_nat_edit.php?id={$nat_rule[$index]}\">View the NAT rule</a><br>";
726
									break;
727 383654fc Vinicius Coque
								}
728 bae53989 Renato Botelho
							}
729 383654fc Vinicius Coque
						}
730
					?>
731
					<br />
732
					<script type="text/javascript">
733
					editenabled = 0;
734
					</script>
735
				<?php endif; ?>
736
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
737 8ab3e9ed Erik Kristensen
				<strong>not</strong>
738
				<br />
739
				Use this option to invert the sense of the match.
740
				<br />
741
				<br />
742
				<table border="0" cellspacing="0" cellpadding="0">
743
					<tr>
744
						<td>Type:&nbsp;&nbsp;</td>
745
						<td>
746 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srctype" class="formselect" onChange="typesel_change()">
747 87f0be87 Chris Buechler
<?php
748
								$sel = is_specialnet($pconfig['src']); ?>
749 8ab3e9ed Erik Kristensen
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
750 87f0be87 Chris Buechler
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
751
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
752 99ea4439 Scott Ullrich
								<?php if(have_ruleint_access("pptp")): ?>
753 8ab3e9ed Erik Kristensen
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
754 99ea4439 Scott Ullrich
								<?php endif; ?>
755
								<?php if(have_ruleint_access("pppoe")): ?>
756 8c84fe43 Scott Ullrich
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
757 99ea4439 Scott Ullrich
								<?php endif; ?>								
758 8a6bc505 Ermal Lu?i
								 <?php if(have_ruleint_access("l2tp")): ?>
759
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
760
                                                                <?php endif; ?>
761 8ab3e9ed Erik Kristensen
<?php
762 5335811d Ermal Luçi
								foreach ($ifdisp as $ifent => $ifdesc): ?>
763
								<?php if(have_ruleint_access($ifent)): ?>
764
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
765
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
766 b7391125 Ermal Luçi
										<?=$ifdesc?> address
767 e30a5970 Scott Ullrich
									</option>
768 99ea4439 Scott Ullrich
								<?php endif; ?>
769 b7391125 Ermal Luçi
<?php 							endforeach; ?>
770 8ab3e9ed Erik Kristensen
							</select>
771
						</td>
772
					</tr>
773
					<tr>
774
						<td>Address:&nbsp;&nbsp;</td>
775
						<td>
776 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']);?>"> /
777
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcmask" class="formselect" id="srcmask">
778 8ab3e9ed Erik Kristensen
<?php						for ($i = 31; $i > 0; $i--): ?>
779
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
780
<?php 						endfor; ?>
781
							</select>
782 bdb7d6e7 Scott Ullrich
						</td>
783 8ab3e9ed Erik Kristensen
					</tr>
784
				</table>
785 22abf2ef Scott Ullrich
				<div id="showadvancedboxspr">
786
					<p>
787 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>
788 22abf2ef Scott Ullrich
				</div>
789 8ab3e9ed Erik Kristensen
			</td>
790 e33c8694 Bill Marquette
		</tr>
791 3de8af0e Scott Ullrich
		<tr style="display:none" id="sprtable" name="sprtable">
792 8ab3e9ed Erik Kristensen
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
793
			<td width="78%" class="vtable">
794
				<table border="0" cellspacing="0" cellpadding="0">
795
					<tr>
796
						<td>from:&nbsp;&nbsp;</td>
797
						<td>
798 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
799 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
800
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
801
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
802
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
803
<?php 							endforeach; ?>
804 8c84fe43 Scott Ullrich
							</select>
805 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']; ?>">
806 8ab3e9ed Erik Kristensen
						</td>
807
					</tr>
808
					<tr>
809
						<td>to:</td>
810
						<td>
811 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="srcendport" class="formselect" onchange="ext_change()">
812 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
813
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
814
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
815
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
816
<?php							endforeach; ?>
817 8c84fe43 Scott Ullrich
							</select>
818 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']; ?>">
819 8ab3e9ed Erik Kristensen
						</td>
820
					</tr>
821
				</table>
822
				<br />
823 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/>
824 8ab3e9ed Erik Kristensen
			</td>
825 8c84fe43 Scott Ullrich
		</tr>
826 8ab3e9ed Erik Kristensen
		<tr>
827
			<td width="22%" valign="top" class="vncellreq">Destination</td>
828
			<td width="78%" class="vtable">
829 383654fc Vinicius Coque
				<input<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
830 8ab3e9ed Erik Kristensen
				<strong>not</strong>
831
					<br />
832
				Use this option to invert the sense of the match.
833
					<br />
834
					<br />
835
				<table border="0" cellspacing="0" cellpadding="0">
836
					<tr>
837
						<td>Type:&nbsp;&nbsp;</td>
838
						<td>
839 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dsttype" class="formselect" onChange="typesel_change()">
840 87f0be87 Chris Buechler
<?php
841
								$sel = is_specialnet($pconfig['dst']); ?>
842 8ab3e9ed Erik Kristensen
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
843 87f0be87 Chris Buechler
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
844
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
845 99ea4439 Scott Ullrich
								<?php if(have_ruleint_access("pptp")): ?>
846 8ab3e9ed Erik Kristensen
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
847 99ea4439 Scott Ullrich
								<?php endif; ?>
848
								<?php if(have_ruleint_access("pppoe")): ?>
849 8ab3e9ed Erik Kristensen
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
850 99ea4439 Scott Ullrich
								<?php endif; ?>								
851 3331a640 Ermal Lu?i
								<?php if(have_ruleint_access("l2tp")): ?>
852
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
853
                                                                <?php endif; ?>
854 b7391125 Ermal Luçi
855
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
856
								<?php if(have_ruleint_access($if)): ?>
857
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
858
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
859
										<?=$ifdesc;?> address
860 cbff71a1 Scott Ullrich
									</option>
861 99ea4439 Scott Ullrich
								<?php endif; ?>
862 b7391125 Ermal Luçi
<?php 							endforeach; ?>
863 8ab3e9ed Erik Kristensen
							</select>
864
						</td>
865
					</tr>
866
					<tr>
867
						<td>Address:&nbsp;&nbsp;</td>
868
						<td>
869 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']);?>">
870 8ab3e9ed Erik Kristensen
							/
871 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstmask" class="formselect" id="dstmask">
872 8ab3e9ed Erik Kristensen
<?php
873
							for ($i = 31; $i > 0; $i--): ?>
874
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
875
<?php						endfor; ?>
876
							</select>
877
						</td>
878
					</tr>
879
				</table>
880
			</td>
881
		</tr>
882 3de8af0e Scott Ullrich
		<tr id="dprtr" name="dprtr">
883 8ab3e9ed Erik Kristensen
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
884
			<td width="78%" class="vtable">
885
				<table border="0" cellspacing="0" cellpadding="0">
886
					<tr>
887
						<td>from:&nbsp;&nbsp;</td>
888
						<td>
889 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
890 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
891
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
892
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
893
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
894
<?php 							endforeach; ?>
895
							</select>
896 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']; ?>">
897 8ab3e9ed Erik Kristensen
						</td>
898
					</tr>
899
					<tr>
900
						<td>to:</td>
901
						<td>
902 383654fc Vinicius Coque
							<select<?php echo ($edit_disabled===true?' DISABLED':''); ?> name="dstendport" class="formselect" onchange="ext_change()">
903 8ab3e9ed Erik Kristensen
								<option value="">(other)</option>
904
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
905
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
906
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
907
<?php 							endforeach; ?>
908 8c84fe43 Scott Ullrich
							</select>
909 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']; ?>">
910 8ab3e9ed Erik Kristensen
						</td>
911
					</tr>
912
				</table>
913
				<br />
914
				<span class="vexpl">
915
					Specify the port or port range for the destination of the packet for this rule.
916 adb633a0 sullrich
					<br />
917 8ab3e9ed Erik Kristensen
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
918
				</span>
919
			</td>
920
		</tr>
921
		<tr>
922
			<td width="22%" valign="top" class="vncellreq">Log</td>
923
			<td width="78%" class="vtable">
924
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
925
				<strong>Log packets that are handled by this rule</strong>
926 adb633a0 sullrich
				<br />
927 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>
928
			</td>
929
		</tr>
930 151eb2a9 sullrich
		<tr>
931
			<td width="22%" valign="top" class="vncell">Description</td>
932
			<td width="78%" class="vtable">
933
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
934
				<br />
935
				<span class="vexpl">You may enter a description here for your reference.</span>
936
			</td>
937
		</tr>
938
		<tr>
939
			<td width="22%" valign="top">&nbsp;</td>
940
			<td width="78%">
941
				&nbsp;<br>&nbsp;
942
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
943
<?php			if (isset($id) && $a_filter[$id]): ?>
944
					<input name="id" type="hidden" value="<?=$id;?>">
945
<?php 			endif; ?>
946
				<input name="after" type="hidden" value="<?=$after;?>">
947
			</td>
948
		</tr>
949
		<tr>
950
			<td>&nbsp;</td>
951
		</tr>
952
		<tr>
953
			<td colspan="2" valign="top" class="listtopic">Advanced features</td>
954
		</tr>	
955 f1602cc4 sullrich
		<tr>
956
			<td width="22%" valign="top" class="vncell">Source OS</td>
957 e265d9f5 sullrich
			<td width="78%" class="vtable">
958 8ba13f00 Ermal
				<div id="showadvsourceosbox" <? if ($pconfig['os']) echo "style='display:none'"; ?>>
959 adb633a0 sullrich
					<input type="button" onClick="show_advanced_sourceos()" value="Advanced"></input> - Show advanced option</a>
960
				</div>
961 8ba13f00 Ermal
				<div id="showsourceosadv" <? if (empty($pconfig['os'])) echo "style='display:none'"; ?>>
962 e265d9f5 sullrich
					OS Type:&nbsp;
963 adb633a0 sullrich
					<select name="os" id="os" class="formselect">
964 f1602cc4 sullrich
<?php
965 adb633a0 sullrich
						$ostypes = array(
966
							 "" => "any",
967
							"AIX" => "AIX",
968
							"Linux" => "Linux",
969
							"FreeBSD" => "FreeBSD",
970
							"NetBSD" => "NetBSD",
971
							"OpenBSD" => "OpenBSD",
972
							"Solaris" => "Solaris",
973
							"MacOS" => "MacOS",
974
							"Windows" => "Windows",
975
							"Novell" => "Novell",
976
							"NMAP" => "NMAP"
977
			           );
978
						foreach ($ostypes as $ostype => $descr): ?>
979
							<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
980
<?php
981
					endforeach; 
982
?>
983
					</select>
984
					<br />
985
					Note: this only works for TCP rules
986
				</div>
987 f1602cc4 sullrich
			</td>
988
		</tr>
989 30c4ae8a sullrich
		<tr>
990
			<td width="22%" valign="top" class="vncell">Diffserv Code Point</td>
991
			<td width="78%" class="vtable">
992 8ba13f00 Ermal
				<div id="dsadv" name="dsadv" <? if ($pconfig['dscp']) echo "style='display:none'"; ?>>
993 75c34cbb sullrich
					<input type="button" onClick="show_dsdiv();" value="Advanced"> - Show advanced option
994 30c4ae8a sullrich
				</div>
995 8ba13f00 Ermal
				<div id="dsdivmain" name="dsdivmain" <? if (empty($pconfig['dscp'])) echo "style='display:none'"; ?>>
996 30c4ae8a sullrich
					<select name="dscp" id="dscp">
997
						<option value=""></option>
998
						<?php foreach($firewall_rules_dscp_types as $frdt): ?>
999
							<option value="<?=$frdt?>"<?php if($pconfig['dscp'] == $frdt) echo " SELECTED"; ?>><?=$frdt?></option>
1000
						<?php endforeach; ?>
1001
					</select>
1002
				</div>
1003
			</td>
1004
		</tr>
1005 661aed33 Ermal Luçi
		<tr>
1006 e6db3f58 Ermal Luçi
			<td width="22%" valign="top" class="vncell">Advanced Options</td>
1007
			<td width="78%" class="vtable">
1008
			<div id="aoadv" name="aoadv">
1009 75c34cbb sullrich
				<input type="button" onClick="show_aodiv();" value="Advanced"> - Show advanced option
1010 e6db3f58 Ermal Luçi
			</div>
1011
			<div id="aodivmain" name="aodivmain" style="display:none">
1012 f1602cc4 sullrich
				<input type="checkbox" id="allowopts" value="yes" name="allowopts"<?php if($pconfig['allowopts'] == true) echo " checked"; ?>>
1013 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.");?>
1014 f1602cc4 sullrich
				</span><p>
1015 19757916 Ermal Lu?i
				<input type="checkbox" id="disablereplyto" value="yes" name="disablereplyto"<?php if($pconfig['disablereplyto'] == true) echo " checked"; ?>>
1016
				<br/><span class="vexpl"><?=gettext("This will disable auto generated reply-to for this rule.");?>
1017
				</span><p>
1018 f1602cc4 sullrich
				<input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
1019 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>");?>
1020 775ccea3 Ermal Luci
				</span><p>
1021 f1602cc4 sullrich
				<input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>">
1022
				<br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
1023
				</span> <p>
1024 a56b2fa0 pierrepomes
				<input name="max" id="max" value="<?php echo $pconfig['max'] ?>"><br> Maximum state entries this rule can create<p>
1025 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>
1026
				<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>	 
1027 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>
1028
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
1029
				<select name="max-src-conn-rates" id="max-src-conn-rates">
1030
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
1031
<?php				for($x=1; $x<255; $x++) {
1032
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
1033
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
1034
					} ?>
1035 47042140 Scott Ullrich
				</select><br />
1036 29adf437 Chris Buechler
				Maximum new connections / per second(s)
1037 47042140 Scott Ullrich
				<p>
1038
1039
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
1040 3906617b Scott Ullrich
				State Timeout in seconds
1041 47042140 Scott Ullrich
				<p />
1042
1043 29adf437 Chris Buechler
				<p><strong>NOTE: Leave fields blank to disable that feature.</strong>
1044 197b2a47 Scott Ullrich
			  </div>
1045 8ab3e9ed Erik Kristensen
			</td>
1046
		</tr>
1047 b8ed2a11 Ermal
		<tr id="tcpflags" name="tcpflags"> 
1048
			<td width="22%" valign="top" class="vncell">TCP flags</td>
1049
			<td width="78%" class="vtable">
1050 8ba13f00 Ermal
			<div id="showtcpflagsbox" <? if ($pconfig['tcpflags_any'] || $pconfig['tcpflags1'] || $pconfig['tcpflags2']) echo "style='display:none'"; ?>>
1051 b8ed2a11 Ermal
                        	<input type="button" onClick="show_advanced_tcpflags()" value="Advanced"></input> - Show advanced option</a>
1052
                        </div>
1053 8ba13f00 Ermal
                        <div id="showtcpflagsadv" <? if (empty($pconfig['tcpflags_any']) && empty($pconfig['tcpflags1']) && empty($pconfig['tcpflags2'])) echo "style='display:none'"; ?>>
1054 b8ed2a11 Ermal
			<div id="tcpheader" name="tcpheader">
1055
			<center>
1056
			<table border="0" cellspacing="0" cellpadding="0">
1057
			<?php 
1058
				$setflags = explode(",", $pconfig['tcpflags1']);
1059
				$outofflags = explode(",", $pconfig['tcpflags2']);
1060
				$header = "<td width='40' nowrap></td>";
1061
				$tcpflags1 = "<td width='40' nowrap>set</td>";
1062
				$tcpflags2 = "<td width='40' nowrap>out of</td>";
1063
				foreach ($tcpflags as $tcpflag) {
1064
					$header .= "<td  width='40' nowrap><strong>" . strtoupper($tcpflag) . "</strong></td>\n";
1065
					$tcpflags1 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags1_{$tcpflag}' value='on' ";
1066
					if (array_search($tcpflag, $setflags) !== false)
1067
						$tcpflags1 .= "checked";
1068
					$tcpflags1 .= "></td>\n";
1069
					$tcpflags2 .= "<td  width='40' nowrap> <input type='checkbox' name='tcpflags2_{$tcpflag}' value='on' ";
1070
					if (array_search($tcpflag, $outofflags) !== false)
1071
						$tcpflags2 .= "checked";
1072
					$tcpflags2 .= "></td>\n";
1073
				}
1074
				echo "<tr id='tcpheader' name='tcpheader'>{$header}</tr>\n";
1075
				echo "<tr id='tcpflags1' name='tcpflags1'>{$tcpflags1}</tr>\n";
1076
				echo "<tr id='tcpflags2' name='tcpflags2'>{$tcpflags2}</tr>\n";
1077
			?>
1078
			</table>
1079
			<center>
1080
			</div>
1081
			<br/><center>
1082
			<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>
1083
			<br/>
1084
			<span class="vexpl">Use this to choose TCP flags that must 
1085
			be set or cleared for this rule to match.</span>
1086
			</div>
1087
			</td>
1088
		</tr>
1089 8ab3e9ed Erik Kristensen
		<tr>
1090
			<td width="22%" valign="top" class="vncell">State Type</td>
1091
			<td width="78%" class="vtable">
1092 8ba13f00 Ermal
				<div id="showadvstatebox" <? if (!empty($pconfig['statetype']) && $pconfig['statetype'] != "keep state") echo "style='display:none'"; ?>>
1093 75c34cbb sullrich
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show advanced option</a>
1094 f6970b2f Scott Ullrich
				</div>
1095 8ba13f00 Ermal
				<div id="showstateadv" <? if (empty($pconfig['statetype']) || $pconfig['statetype'] == "keep state") echo "style='display:none'"; ?>>
1096 f6970b2f Scott Ullrich
					<select name="statetype">
1097
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
1098 b8ed2a11 Ermal
						<option value="sloppy state" <?php if($pconfig['statetype'] == "sloppy state") echo "selected"; ?>>sloppy state</option>
1099 f6970b2f Scott Ullrich
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
1100
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
1101
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
1102
					<p>
1103
					<table width="90%">
1104 c62ff4e7 Chris Buechler
						<tr><td width="25%"><ul><li>keep state</li></td><td>Works with all IP protocols.</ul></td></tr>
1105 b8ed2a11 Ermal
						<tr><td width="25%"><ul><li>sloppy state</li></td><td>Works with all IP protocols.</ul></td></tr>
1106 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>
1107
						<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>
1108 f6970b2f Scott Ullrich
					</table>
1109
					</p>
1110
			  </div>
1111 8ab3e9ed Erik Kristensen
			</td>
1112
		</tr>
1113 10f21e70 Scott Ullrich
		<tr>
1114
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
1115
			<td width="78%" class="vtable">
1116 8ba13f00 Ermal
				<div id="showadvnoxmlrpcsyncbox" <? if ($pconfig['nosync']) echo "style='display:none'"; ?>>
1117 75c34cbb sullrich
					<input type="button" onClick="show_advanced_noxmlrpc()" value="Advanced"></input> - Show advanced option</a>
1118 0239d8ee sullrich
				</div>
1119 8ba13f00 Ermal
				<div id="shownoxmlrpcadv" <? if (empty($pconfig['nosync'])) echo "style='display:none'"; ?>>
1120 0239d8ee sullrich
					<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
1121 a29dc11b Chris Buechler
					HINT: This prevents the rule from automatically syncing to other CARP members.
1122 0239d8ee sullrich
				</div>
1123 10f21e70 Scott Ullrich
			</td>
1124 8c84fe43 Scott Ullrich
		</tr>
1125 615b27bc Scott Dale
		<?php
1126
			//build list of schedules
1127
			$schedules = array();
1128
			$schedules[] = "none";//leave none to leave rule enabled all the time
1129 a60fd0cb Scott Ullrich
			if(is_array($config['schedules']['schedule'])) {
1130
				foreach ($config['schedules']['schedule'] as $schedule) {
1131
					if ($schedule['name'] <> "")
1132
						$schedules[] = $schedule['name'];
1133
				}
1134
			}
1135 615b27bc Scott Dale
		?>
1136
		<tr>
1137
			<td width="22%" valign="top" class="vncell">Schedule</td>
1138
			<td width="78%" class="vtable">
1139 8ba13f00 Ermal
				<div id="showadvschedulebox" <? if (!empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1140 75c34cbb sullrich
					<input type="button" onClick="show_advanced_schedule()" value="Advanced"></input> - Show advanced option</a>
1141 0239d8ee sullrich
				</div>
1142 8ba13f00 Ermal
				<div id="showscheduleadv" <? if (empty($pconfig['sched'])) echo "style='display:none'"; ?>>
1143 0239d8ee sullrich
					<select name='sched'>
1144 615b27bc Scott Dale
<?php
1145 0239d8ee sullrich
					foreach($schedules as $schedule) {
1146
						if($schedule == $pconfig['sched']) {
1147
							$selected = " SELECTED";
1148
						} else {
1149
							$selected = "";
1150
						}
1151
						if ($schedule == "none") {
1152
							echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
1153
						} else {
1154
							echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
1155
						}
1156 615b27bc Scott Dale
					}
1157 0239d8ee sullrich
?>
1158
					</select>
1159
					<p>Leave as 'none' to leave the rule enabled all the time.</p>
1160
				</div>
1161 615b27bc Scott Dale
			</td>
1162
		</tr>
1163 82628210 Scott Ullrich
		<tr>
1164 8ab3e9ed Erik Kristensen
			<td width="22%" valign="top" class="vncell">Gateway</td>
1165
			<td width="78%" class="vtable">
1166 8ba13f00 Ermal
				<div id="showadvgatewaybox" <? if (!empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1167 75c34cbb sullrich
					<input type="button" onClick="show_advanced_gateway()" value="Advanced"></input> - Show advanced option</a>
1168 0239d8ee sullrich
				</div>
1169 8ba13f00 Ermal
				<div id="showgatewayadv" <? if (empty($pconfig['gateway'])) echo "style='display:none'"; ?>>
1170 0239d8ee sullrich
					<select name='gateway'>
1171 1b38ac36 Ermal
					<option value="" >default</option>
1172 8ab3e9ed Erik Kristensen
<?php
1173 1b38ac36 Ermal
					/* build a list of gateways */
1174
					$gateways = return_gateways_array();
1175 106804a2 Chris Buechler
					// add statically configured gateways to list
1176 1b38ac36 Ermal
					foreach($gateways as $gwname => $gw) {
1177 0239d8ee sullrich
						if($gw == "") 
1178 0581660c Scott Ullrich
							continue;
1179 1b38ac36 Ermal
						if($gwname == $pconfig['gateway']) {
1180 4443d4d6 Scott Ullrich
							$selected = " SELECTED";
1181 1fda0968 Scott Ullrich
						} else {
1182
							$selected = "";
1183
						}
1184 1b38ac36 Ermal
						echo "<option value=\"{$gwname}\" {$selected}>{$gw['name']} - {$gw['gateway']}</option>\n";
1185 106804a2 Chris Buechler
					}
1186 0239d8ee sullrich
					/* add gateway groups to the list */
1187
					if (is_array($config['gateways']['gateway_group'])) {
1188
						foreach($config['gateways']['gateway_group'] as $gw_group) {
1189
							if($gw_group['name'] == "")
1190
								continue;
1191
							if($pconfig['gateway'] == $gw_group['name']) {
1192
								echo "<option value=\"{$gw_group['name']}\" SELECTED>{$gw_group['name']}</option>\n";
1193
							} else {
1194
								echo "<option value=\"{$gw_group['name']}\">{$gw_group['name']}</option>\n";
1195
							}
1196
						}
1197
					}
1198 8ab3e9ed Erik Kristensen
?>
1199 0239d8ee sullrich
					</select>
1200
					<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
1201
				</div>
1202 8ab3e9ed Erik Kristensen
			</td>
1203
		</tr>
1204 a5fd67e1 Ermal Luçi
		<tr>
1205
			<td width="22%" valign="top" class="vncell">In/Out</td>
1206
			<td width="78%" class="vtable">
1207 8ba13f00 Ermal
				<div id="showadvinoutbox" <? if (!empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1208 75c34cbb sullrich
					<input type="button" onClick="show_advanced_inout()" value="Advanced"></input> - Show advanced option</a>
1209 4c263f57 sullrich
				</div>
1210 8ba13f00 Ermal
				<div id="showinoutadv" <? if (empty($pconfig['dnpipe'])) echo "style='display:none'"; ?>>
1211 4c263f57 sullrich
					<select name="dnpipe">
1212 a5fd67e1 Ermal Luçi
<?php
1213
		if (!is_array($dnqlist))
1214
			$dnqlist = array();
1215
		echo "<option value=\"none\"";
1216
		if (!$dnqselected) echo " SELECTED";
1217
		echo " >none</option>";
1218
		foreach ($dnqlist as $dnq => $dnqkey) {
1219
			if($dnq == "")
1220
				continue;
1221
			echo "<option value=\"$dnqkey\"";
1222
			if ($dnqkey == $pconfig['dnpipe']) {
1223
				$dnqselected = 1;
1224
				echo " SELECTED";
1225
			}
1226
			echo ">{$dnq}</option>"; 
1227
		}
1228
?>
1229
			</select> / 			
1230
			<select name="pdnpipe">
1231
<?php
1232
		$dnqselected = 0;
1233
		echo "<option value=\"none\"";
1234
		if (!$dnqselected) echo " SELECTED";
1235
		echo " >none</option>";
1236
		foreach ($dnqlist as $dnq => $dnqkey) {
1237
			if($dnq == "")
1238
				continue;
1239
			echo "<option value=\"$dnqkey\"";
1240
			if ($dnqkey == $pconfig['pdnpipe']) {
1241
				$dnqselected = 1;
1242
				echo " SELECTED";
1243
			}
1244
			echo ">{$dnq}</option>"; 
1245
		}
1246
?>
1247 4c263f57 sullrich
				</select>
1248 a5fd67e1 Ermal Luçi
				<br />
1249
				<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>
1250 4c263f57 sullrich
				</div>
1251 a5fd67e1 Ermal Luçi
			</td>
1252
		</tr>
1253
1254 197bfe96 Ermal Luçi
		<tr>
1255
			<td width="22%" valign="top" class="vncell">Ackqueue/Queue</td>
1256
			<td width="78%" class="vtable">
1257 8ba13f00 Ermal
			<div id="showadvackqueuebox" <? if (!empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1258 75c34cbb sullrich
				<input type="button" onClick="show_advanced_ackqueue()" value="Advanced"></input> - Show advanced option</a>
1259 0239d8ee sullrich
			</div>
1260 8ba13f00 Ermal
			<div id="showackqueueadv" <? if (empty($pconfig['defaultqueue'])) echo "style='display:none'"; ?>>
1261 0239d8ee sullrich
				<select name="ackqueue">
1262 197bfe96 Ermal Luçi
<?php
1263 0239d8ee sullrich
			if (!is_array($qlist))
1264
				$qlist = array();
1265
			echo "<option value=\"none\"";
1266
			if (!$qselected) echo " SELECTED";
1267
			echo " >none</option>";
1268
			foreach ($qlist as $q => $qkey) {
1269
				if($q == "")
1270
					continue;
1271
				echo "<option value=\"$q\"";
1272
				if ($q == $pconfig['ackqueue']) {
1273
					$qselected = 1;
1274
					echo " SELECTED";
1275
				}
1276
				echo ">{$q}</option>"; 
1277 197bfe96 Ermal Luçi
			}
1278
?>
1279 0239d8ee sullrich
				</select> / 			
1280
				<select name="defaultqueue">
1281 197bfe96 Ermal Luçi
<?php
1282 0239d8ee sullrich
			$qselected = 0;
1283
			echo "<option value=\"none\"";
1284
			if (!$qselected) echo " SELECTED";
1285
			echo " >none</option>";
1286
			foreach ($qlist as $q => $qkey) {
1287
				if($q == "")
1288
					continue;
1289
				echo "<option value=\"$q\"";
1290
				if ($q == $pconfig['defaultqueue']) {
1291
					$qselected = 1;
1292
					echo " SELECTED";
1293
				}
1294
				echo ">{$q}</option>"; 
1295 197bfe96 Ermal Luçi
			}
1296
?>
1297 0239d8ee sullrich
				</select>
1298
					<br />
1299
					<span class="vexpl">Choose the Acknowledge Queue only if you have selected Queue.</span>
1300
				</td>
1301
			</tr>
1302
			<tr>
1303
				<td width="22%" valign="top" class="vncell">Layer7</td>
1304
				<td width="78%" class="vtable">
1305 8ba13f00 Ermal
					<div id="showadvlayer7box" <? if (!empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1306 75c34cbb sullrich
						<input type="button" onClick="show_advanced_layer7()" value="Advanced"></input> - Show advanced option</a>
1307 4c263f57 sullrich
					</div>
1308 8ba13f00 Ermal
					<div id="showlayer7adv" <? if (empty($pconfig['l7container'])) echo "style='display:none'"; ?>>
1309 0239d8ee sullrich
				<select name="l7container">
1310 7e50413c Ermal Luçi
<?php
1311 0239d8ee sullrich
					if (!is_array($l7clist))
1312 06e2a55d thompsa
						$l7clist = array();
1313 0239d8ee sullrich
					echo "<option value=\"none\"";
1314
					echo " >none</option>";
1315
					foreach ($l7clist as $l7ckey) {
1316
						echo "<option value=\"{$l7ckey}\"";
1317
						if ($l7ckey == $pconfig['l7container']) {
1318
							echo " SELECTED";
1319
						}
1320
						echo ">{$l7ckey}</option>"; 
1321
					}
1322 7e50413c Ermal Luçi
?>
1323 0239d8ee sullrich
				</select>			
1324 7e50413c Ermal Luçi
				<br/>
1325 0239d8ee sullrich
				<span class="vexpl">
1326
					Choose a Layer7 container to apply application protocol inspection rules.
1327 a29dc11b Chris Buechler
					These are valid for TCP and UDP protocols only.
1328 0239d8ee sullrich
				</span>
1329
			  </div>
1330 7e50413c Ermal Luçi
			</td>
1331
		</tr>
1332 8ab3e9ed Erik Kristensen
		<tr>
1333
			<td width="22%" valign="top">&nbsp;</td>
1334
			<td width="78%">
1335 151eb2a9 sullrich
				&nbsp;<br>&nbsp;
1336 8ab3e9ed Erik Kristensen
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
1337
<?php			if (isset($id) && $a_filter[$id]): ?>
1338
					<input name="id" type="hidden" value="<?=$id;?>">
1339
<?php 			endif; ?>
1340
				<input name="after" type="hidden" value="<?=$after;?>">
1341
			</td>
1342 82628210 Scott Ullrich
		</tr>
1343 8ab3e9ed Erik Kristensen
	</table>
1344 5b237745 Scott Ullrich
</form>
1345
<script language="JavaScript">
1346
<!--
1347 8ab3e9ed Erik Kristensen
	ext_change();
1348
	typesel_change();
1349
	proto_change();
1350 19757279 Scott Ullrich
1351
<?php
1352 8ab3e9ed Erik Kristensen
	$isfirst = 0;
1353
	$aliases = "";
1354
	$addrisfirst = 0;
1355
	$aliasesaddr = "";
1356
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1357
		foreach($config['aliases']['alias'] as $alias_name) {
1358 72cb5baf Ermal Lu?i
			switch ($alias_name['type']) {
1359
			case "port":
1360
				if($isfirst == 1) $portaliases .= ",";
1361
				$portaliases .= "'" . $alias_name['name'] . "'";
1362 8ab3e9ed Erik Kristensen
				$isfirst = 1;
1363 72cb5baf Ermal Lu?i
				break;
1364
			case "host":
1365
			case "network":
1366
			case "openvpn":
1367 c7de8be4 jim-p
			case "urltable":
1368 8ab3e9ed Erik Kristensen
				if($addrisfirst == 1) $aliasesaddr .= ",";
1369
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1370
				$addrisfirst = 1;
1371 72cb5baf Ermal Lu?i
				break;
1372
			default:
1373
				break;
1374 8ab3e9ed Erik Kristensen
			}
1375 092ac49d Scott Ullrich
		}
1376 19757279 Scott Ullrich
?>
1377
1378 8ab3e9ed Erik Kristensen
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1379 72cb5baf Ermal Lu?i
	var customarray=new Array(<?php echo $portaliases; ?>);
1380 19757279 Scott Ullrich
1381 9eb60dcc Ermal Lu?i
	var oTextbox1 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
1382
        var oTextbox2 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
1383
        var oTextbox3 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
1384
        var oTextbox4 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
1385
        var oTextbox5 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
1386
        var oTextbox6 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
1387 5b237745 Scott Ullrich
//-->
1388
</script>
1389
<?php include("fend.inc"); ?>
1390
</body>
1391 9b45f821 Ermal Lu?i
</html>