Project

General

Profile

Download (45.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules_edit.php
5
	part of pfSense (http://www.pfsense.com)
6
        Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
*/
33

    
34
##|+PRIV
35
##|*IDENT=page-firewall-rules-edit
36
##|*NAME=Firewall: Rules: Edit page
37
##|*DESCR=Allow access to the 'Firewall: Rules: Edit' page.
38
##|*MATCH=firewall_rules_edit.php*
39
##|-PRIV
40

    
41

    
42
require("guiconfig.inc");
43

    
44
$specialsrcdst = explode(" ", "any wanip lanip lan pptp pppoe");
45

    
46
if (!is_array($config['filter']['rule'])) {
47
	$config['filter']['rule'] = array();
48
}
49
filter_rules_sort();
50
$a_filter = &$config['filter']['rule'];
51

    
52
$id = $_GET['id'];
53
if (is_numeric($_POST['id']))
54
	$id = $_POST['id'];
55

    
56
$after = $_GET['after'];
57

    
58
if (isset($_POST['after']))
59
	$after = $_POST['after'];
60

    
61
if (isset($_GET['dup'])) {
62
	$id = $_GET['dup'];
63
	$after = $_GET['dup'];
64
}
65

    
66
if (isset($id) && $a_filter[$id]) {
67
	$pconfig['interface'] = $a_filter[$id]['interface'];
68

    
69
	if (!isset($a_filter[$id]['type']))
70
		$pconfig['type'] = "pass";
71
	else
72
		$pconfig['type'] = $a_filter[$id]['type'];
73

    
74
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
75
		$pconfig['floating'] = $a_filter[$id]['floating'];
76
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") 
77
			$pconfig['interface'] = $a_filter[$id]['interface'];
78
	}
79
	
80
	if (isset($a_filter['floating'])) 
81
		$pconfig['floating'] = "yes";
82

    
83
	if (isset($a_filter[$id]['direction']))
84
                $pconfig['direction'] = $a_filter[$id]['direction'];
85

    
86
	if (isset($a_filter[$id]['protocol']))
87
		$pconfig['proto'] = $a_filter[$id]['protocol'];
88
	else
89
		$pconfig['proto'] = "any";
90

    
91
	if ($a_filter[$id]['protocol'] == "icmp")
92
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
93

    
94
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
95
		$pconfig['srcmask'], $pconfig['srcnot'],
96
		$pconfig['srcbeginport'], $pconfig['srcendport']);
97

    
98
	if($a_filter[$id]['os'] <> "")
99
		$pconfig['os'] = $a_filter[$id]['os'];
100

    
101
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
102
		$pconfig['dstmask'], $pconfig['dstnot'],
103
		$pconfig['dstbeginport'], $pconfig['dstendport']);
104

    
105
	if ($a_filter[$id]['dscp'] <> "")
106
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
107

    
108
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
109
	$pconfig['log'] = isset($a_filter[$id]['log']);
110
	$pconfig['descr'] = $a_filter[$id]['descr'];
111

    
112
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "") 
113
		$pconfig['tag'] = $a_filter[$id]['tag'];
114
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tag'] <> "")
115
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
116
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
117
		$pconfig['quick'] = $a_filter[$id]['quick'];
118

    
119
	/* advanced */
120
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
121
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
122
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
123
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
124

    
125
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
126

    
127
	/* advanced - new connection per second banning*/
128
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
129
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
130

    
131
	/* Multi-WAN next-hop support */
132
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
133
	
134
	/* Shaper support */
135
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
136
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
137
	$pconfig['dnpipe'] = $a_filter[$id]['dnpipe'];
138
	$pconfig['pdnpipe'] = $a_filter[$id]['pdnpipe'];
139

    
140
	//schedule support
141
	$pconfig['sched'] = $a_filter[$id]['sched'];
142

    
143
} else {
144
	/* defaults */
145
	if ($_GET['if'])
146
		$pconfig['interface'] = $_GET['if'];
147
	$pconfig['type'] = "pass";
148
	$pconfig['src'] = "any";
149
	$pconfig['dst'] = "any";
150
}
151
/* Allow the FlotingRules to work */
152
$if = $pconfig['interface'];
153

    
154
if (isset($_GET['dup']))
155
	unset($id);
156

    
157
if ($_POST) {
158

    
159
	if ($_POST['type'] == "reject" && $_POST['proto'] <> "tcp")
160
		$input_errors[] = "Reject type rules only works when the protocol is set to TCP.";
161

    
162
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
163
		$_POST['srcbeginport'] = 0;
164
		$_POST['srcendport'] = 0;
165
		$_POST['dstbeginport'] = 0;
166
		$_POST['dstendport'] = 0;
167
	} else {
168

    
169
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
170
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
171
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
172
			$_POST['srcendport'] = $_POST['srcendport_cust'];
173

    
174
		if ($_POST['srcbeginport'] == "any") {
175
			$_POST['srcbeginport'] = 0;
176
			$_POST['srcendport'] = 0;
177
		} else {
178
			if (!$_POST['srcendport'])
179
				$_POST['srcendport'] = $_POST['srcbeginport'];
180
		}
181
		if ($_POST['srcendport'] == "any")
182
			$_POST['srcendport'] = $_POST['srcbeginport'];
183

    
184
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
185
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
186
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
187
			$_POST['dstendport'] = $_POST['dstendport_cust'];
188

    
189
		if ($_POST['dstbeginport'] == "any") {
190
			$_POST['dstbeginport'] = 0;
191
			$_POST['dstendport'] = 0;
192
		} else {
193
			if (!$_POST['dstendport'])
194
				$_POST['dstendport'] = $_POST['dstbeginport'];
195
		}
196
		if ($_POST['dstendport'] == "any")
197
			$_POST['dstendport'] = $_POST['dstbeginport'];
198
	}
199

    
200
	if (is_specialnet($_POST['srctype'])) {
201
		$_POST['src'] = $_POST['srctype'];
202
		$_POST['srcmask'] = 0;
203
	} else if ($_POST['srctype'] == "single") {
204
		$_POST['srcmask'] = 32;
205
	}
206
	if (is_specialnet($_POST['dsttype'])) {
207
		$_POST['dst'] = $_POST['dsttype'];
208
		$_POST['dstmask'] = 0;
209
	}  else if ($_POST['dsttype'] == "single") {
210
		$_POST['dstmask'] = 32;
211
	}
212

    
213
	unset($input_errors);
214
	$pconfig = $_POST;
215

    
216
	/*  run through $_POST items encoding HTML entties so that the user
217
	 *  cannot think he is slick and perform a XSS attack on the unwilling 
218
	 */
219
	foreach ($_POST as $key => $value) {
220
		$temp = $value;
221
		if (isset($_POST['floating']) && $key == "interface")
222
			continue;
223
		$newpost = htmlentities($temp);
224
		if($newpost <> $temp) 
225
			$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";
226
	}
227

    
228
	/* input validation */
229
	$reqdfields = explode(" ", "type proto src dst");
230
	$reqdfieldsn = explode(",", "Type,Protocol,Source,Destination");
231

    
232

    
233
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
234
		if( $_POST['proto'] != "tcp" )
235
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
236
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
237
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
238
	}
239

    
240

    
241
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
242
		$reqdfields[] = "srcmask";
243
		$reqdfieldsn[] = "Source bit count";
244
	}
245
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
246
		$reqdfields[] = "dstmask";
247
		$reqdfieldsn[] = "Destination bit count";
248
	}
249

    
250
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
251

    
252
	if (!$_POST['srcbeginport']) {
253
		$_POST['srcbeginport'] = 0;
254
		$_POST['srcendport'] = 0;
255
	}
256
	if (!$_POST['dstbeginport']) {
257
		$_POST['dstbeginport'] = 0;
258
		$_POST['dstendport'] = 0;
259
	}
260

    
261
	if (($_POST['srcbeginport'] && !alias_expand($_POST['srcbeginport']) && !is_port($_POST['srcbeginport']))) {
262
		$input_errors[] = "The start source port must be an alias or integer between 1 and 65535.";
263
	}
264
	if (($_POST['srcendport'] && !alias_expand($_POST['srcendport']) && !is_port($_POST['srcendport']))) {
265
		$input_errors[] = "The end source port must be an alias or integer between 1 and 65535.";
266
	}
267
	if (($_POST['dstbeginport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstbeginport']))) {
268
		$input_errors[] = "The start destination port must be an alias or integer between 1 and 65535.";
269
	}
270
	if (($_POST['dstendport'] && !alias_expand($_POST['dstbeginport']) && !is_port($_POST['dstendport']))) {
271
		$input_errors[] = "The end destination port must be an alias or integer between 1 and 65535.";
272
	}
273

    
274
	/* if user enters an alias and selects "network" then disallow. */
275
	if($_POST['srctype'] == "network") {
276
		if(is_alias($_POST['src']))
277
			$input_errors[] = "You must specify single host or alias for alias entries.";
278
	}
279
	if($_POST['dsttype'] == "network") {
280
		if(is_alias($_POST['dst']))
281
			$input_errors[] = "You must specify single host or alias for alias entries.";
282
	}
283

    
284
	if (!is_specialnet($_POST['srctype'])) {
285
		if (($_POST['src'] && !is_ipaddroranyalias($_POST['src']))) {
286
			$input_errors[] = "A valid source IP address or alias must be specified.";
287
		}
288
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
289
			$input_errors[] = "A valid source bit count must be specified.";
290
		}
291
	}
292
	if (!is_specialnet($_POST['dsttype'])) {
293
		if (($_POST['dst'] && !is_ipaddroranyalias($_POST['dst']))) {
294
			$input_errors[] = "A valid destination IP address or alias must be specified.";
295
		}
296
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
297
			$input_errors[] = "A valid destination bit count must be specified.";
298
		}
299
	}
300

    
301
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
302
		/* swap */
303
		$tmp = $_POST['srcendport'];
304
		$_POST['srcendport'] = $_POST['srcbeginport'];
305
		$_POST['srcbeginport'] = $tmp;
306
	}
307
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
308
		/* swap */
309
		$tmp = $_POST['dstendport'];
310
		$_POST['dstendport'] = $_POST['dstbeginport'];
311
		$_POST['dstbeginport'] = $tmp;
312
	}
313
	if ($_POST['os'])
314
		if( $_POST['proto'] != "tcp" )
315
			$input_errors[] = "OS detection is only valid with protocol tcp.";
316

    
317
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
318
		if ($_POST['defaultqueue'] == "none" )
319
			$input_errors[] = "You have to select a queue when you select an acknowledge queue too.";
320
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
321
			$input_errors[] = "Acknokledge queue and Queue cannot be the same.";		
322
	}
323
	if ($_POST['pdnpipe'] && $_POST['pdnpipe'] != "none") {
324
		if ($_POST['dnpipe'] == "none" )
325
			$input_errors[] = "You must select a queue for the In direction before selecting one for Out too.";
326
		else if ($_POST['pdnpipe'] == $_POST['dnpipe'])
327
			$input_errors[] = "In and Out Queue cannot be the same.";
328
		else if ($pdnpipe[0] == "?" && $dnpipe[0] <> "?")
329
			$input_errors[] = "You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.";
330
		else if ($dnpipe[0] == "?" && $pdnpipe[0] <> "?")
331
			$input_errors[] = "You cannot select one queue and one virtual interface for IN and Out. both must be from the same type.";
332
	}
333

    
334
	if (!$input_errors) {
335
		$filterent = array();
336
		$filterent['type'] = $_POST['type'];
337
		if (isset($_POST['interface'] ))
338
			$filterent['interface'] = $_POST['interface'];
339

    
340
		if ($if == "FloatingRules" || isset($_POST['floating'])) {
341
			if (isset($_POST['tag']))
342
				$filterent['tag'] = $_POST['tag'];
343
			if (isset($_POST['tagged']))
344
            			$filterent['tagged'] = $_POST['tagged'];
345
			$filterent['direction'] = $_POST['direction'];
346
			if (isset($_POST['quick']) && $_POST['quick'] <> "")
347
				$filterent['quick'] = $_POST['quick'];
348
			$filterent['floating'] = "yes";
349
			if (isset($_POST['interface']) && count($_POST['interface']) > 0)  {
350
					$filterent['interface'] = implode(",", $_POST['interface']);
351
			}
352
		}
353

    
354
		/* Advanced options */
355
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
356
		$filterent['max-src-states'] = $_POST['max-src-states'];
357
		$filterent['statetimeout'] = $_POST['statetimeout'];
358
		$filterent['statetype'] = $_POST['statetype'];
359
		$filterent['os'] = $_POST['os'];
360

    
361
		/* Nosync directive - do not xmlrpc sync this item */
362
		if($_POST['nosync'] <> "")
363
			$filterent['nosync'] = true;
364
		else
365
			unset($filterent['nosync']);
366

    
367
		/* unless both values are provided, unset the values - ticket #650 */
368
		if($_POST['max-src-conn-rate'] <> "" and $_POST['max-src-conn-rates'] <> "") {
369
			$filterent['max-src-conn-rate'] = $_POST['max-src-conn-rate'];
370
			$filterent['max-src-conn-rates'] = $_POST['max-src-conn-rates'];
371
		} else {
372
			unset($filterent['max-src-conn-rate']);
373
			unset($filterent['max-src-conn-rates']);
374
		}
375

    
376
		if ($_POST['proto'] != "any")
377
			$filterent['protocol'] = $_POST['proto'];
378
		else
379
			unset($filterent['protocol']);
380

    
381
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
382
			$filterent['icmptype'] = $_POST['icmptype'];
383
		else
384
			unset($filterent['icmptype']);
385

    
386
		pconfig_to_address($filterent['source'], $_POST['src'],
387
			$_POST['srcmask'], $_POST['srcnot'],
388
			$_POST['srcbeginport'], $_POST['srcendport']);
389

    
390
		pconfig_to_address($filterent['destination'], $_POST['dst'],
391
			$_POST['dstmask'], $_POST['dstnot'],
392
			$_POST['dstbeginport'], $_POST['dstendport']);
393

    
394
                if ($_POST['disabled'])
395
                        $filterent['disabled'] = true;
396
                else
397
                        unset($filterent['disabled']);
398
		
399
		if ($_POST['dscp'])
400
			$filterent['dscp'] = $_POST['dscp'];
401

    
402
                if ($_POST['log'])
403
                        $filterent['log'] = true;
404
                else
405
                        unset($filterent['log']);
406
		strncpy($filterent['descr'], $_POST['descr'], 52);
407

    
408
		if ($_POST['gateway'] != "") {
409
			$filterent['gateway'] = $_POST['gateway'];
410
		}
411
		
412
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
413
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
414
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
415
				$filterent['ackqueue'] = $_POST['ackqueue'];
416
		}
417

    
418
		if (isset($_POST['dnpipe']) && $_POST['dnpipe'] != "none") {
419
			$filterent['dnpipe'] = $_POST['dnpipe'];
420
			if (isset($_POST['pdnpipe']) && $_POST['pdnpipe'] != "none")
421
				$filterent['pdnpipe'] = $_POST['pdnpipe'];
422
		}
423

    
424
		if ($_POST['sched'] != "") {
425
			$filterent['sched'] = $_POST['sched'];
426
		}
427

    
428
		if (isset($id) && $a_filter[$id])
429
			$a_filter[$id] = $filterent;
430
		else {
431
			if (is_numeric($after))
432
				array_splice($a_filter, $after+1, 0, array($filterent));
433
			else
434
				$a_filter[] = $filterent;
435
		}
436

    
437
		write_config();
438
		touch($d_filterconfdirty_path);
439

    
440
		if (isset($_POST['floating']))
441
			header("Location: firewall_rules.php?if=FloatingRules");
442
		else
443
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
444
		exit;
445
	}
446
}
447

    
448
$pgtitle = array("Firewall","Rules","Edit");
449
$closehead = false;
450

    
451
$page_filename = "firewall_rules_edit.php";
452
include("head.inc");
453

    
454
?>
455

    
456
</head>
457

    
458
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
459
<?php include("fbegin.inc"); ?>
460
<?php if ($input_errors) print_input_errors($input_errors); ?>
461

    
462
<form action="firewall_rules_edit.php" method="post" name="iform" id="iform">
463
	<table width="100%" border="0" cellpadding="6" cellspacing="0">
464
		<tr>
465
			<td colspan="2" valign="top" class="listtopic">Edit Firewall rule</td>
466
		</tr>	
467
    	<tr>
468
			<td width="22%" valign="top" class="vncellreq">Action</td>
469
			<td width="78%" class="vtable">
470
				<select name="type" class="formselect">
471
					<?php $types = explode(" ", "Pass Block Reject"); foreach ($types as $type): ?>
472
					<option value="<?=strtolower($type);?>" <?php if (strtolower($type) == strtolower($pconfig['type'])) echo "selected"; ?>>
473
					<?=htmlspecialchars($type);?>
474
					</option>
475
					<?php endforeach; ?>
476
				</select>
477
				<br/>
478
				<span class="vexpl">
479
					Choose what to do with packets that match the criteria specified below. <br/>
480
					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. Reject only works when the protocol is set to either TCP or UDP (but not &quot;TCP/UDP&quot;) below.
481
				</span>
482
			</td>
483
		</tr>
484
		<tr>
485
			<td width="22%" valign="top" class="vncellreq">Disabled</td>
486
			<td width="78%" class="vtable">
487
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
488
				<strong>Disable this rule</strong><br />
489
				<span class="vexpl">Set this option to disable this rule without removing it from the list.</span>
490
			</td>
491
		</tr>
492
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
493
		<tr>
494
                        <td width="22%" valign="top" class="vncellreq"><?=gettext("Quick");?></td>
495
                        <td width="78%" class="vtable">
496
                                <input name="quick" type="checkbox" id="quick" value="yes" <?php if ($pconfig['quick']) echo "checked=\"checked\""; ?> />
497
                                <strong><?=gettext("Apply the action immediately on match.");?></strong><br />
498
                                <span class="vexpl"><?=gettext("Set this option if you need to apply this action to traffic that matches this rule immediately.");?></span>
499
                        </td>
500
                </tr>
501
<? endif; ?>
502
		<tr>
503
			<td width="22%" valign="top" class="vncellreq">Interface</td>
504
			<td width="78%" class="vtable">
505
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
506
				<select name="interface[]" multiple="true" class="formselect" size="3">
507
<? else: ?>
508
				<select name="interface" class="formselect">
509
<?php
510
   endif;
511
				$ifdescs = get_configured_interface_with_descr();
512

    
513
				foreach ($ifdescs as $ifent => $ifdesc)
514
        				if(have_ruleint_access($ifent))
515
                				$interfaces[$ifent] = $ifdesc;
516

    
517
					if ($config['pptpd']['mode'] == "server")
518
						if(have_ruleint_access("pptp")) 
519
							$interfaces['pptp'] = "PPTP VPN";
520
					
521
					if ($config['pppoe']['mode'] == "server")
522
						if(have_ruleint_access("pppoe")) 
523
							$interfaces['pppoe'] = "PPPoE VPN";
524
					
525
					/* add ipsec interfaces */
526
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
527
						if(have_ruleint_access("enc0")) 
528
							$interfaces["enc0"] = "IPsec";
529
		
530
					/* add openvpn/tun interfaces */
531
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
532
       					$interfaces["openvpn"] = "OpenVPN";
533

    
534
					foreach ($interfaces as $iface => $ifacename): ?>
535
						<option value="<?=$iface;?>" <?php if ($pconfig['interface'] <> "" && stristr($pconfig['interface'], $iface)) echo "selected"; ?>><?=gettext($ifacename);?></option>
536
<?php 				endforeach; ?>
537
				</select>
538
				<br />
539
				<span class="vexpl">Choose on which interface packets must come in to match this rule.</span>
540
			</td>
541
		</tr>
542
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
543
                <tr>
544
                        <td width="22%" valign="top" class="vncellreq"><?=gettext("Direction");?></td>
545
                        <td width="78%" class="vtable">
546
                                 <select name="direction" class="formselect">
547
                                  <?php      $directions = array('any', 'in', 'out');
548
                                        foreach ($directions as $direction): ?>
549
                                                <option value="<?=$direction;?>"
550
                                                <?php if ($direction == $pconfig['direction']): ?>
551
                                                        selected="selected" 
552
						<?php endif; ?>
553
                                                ><?=$direction;?></option>
554
                  	                <?php endforeach; ?>      
555
                                </select>
556
                		<input type="hidden" id="floating" name="floating" value="floating">
557
                        </td>
558
                <tr>
559
<?php endif; ?>
560
		<tr>
561
			<td width="22%" valign="top" class="vncellreq">Protocol</td>
562
			<td width="78%" class="vtable">
563
				<select name="proto" class="formselect" onchange="proto_change()">
564
<?php
565
				$protocols = explode(" ", "TCP UDP TCP/UDP ICMP ESP AH GRE IGMP any carp pfsync");
566
				foreach ($protocols as $proto): ?>
567
					<option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
568
<?php 			endforeach; ?>
569
				</select>
570
				<br />
571
				<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>
572
			</td>
573
		</tr>
574
		<tr id="icmpbox" name="icmpbox">
575
			<td valign="top" class="vncell">ICMP type</td>
576
			<td class="vtable">
577
				<select name="icmptype" class="formselect">
578
<?php
579
				$icmptypes = array(
580
				"" => "any",
581
				"echorep" => "Echo reply",
582
				"unreach" => "Destination unreachable",
583
				"squench" => "Source quench",
584
				"redir" => "Redirect",
585
				"althost" => "Alternate Host",
586
				"echoreq" => "Echo",
587
				"routeradv" => "Router advertisement",
588
				"routersol" => "Router solicitation",
589
				"timex" => "Time exceeded",
590
				"paramprob" => "Invalid IP header",
591
				"timereq" => "Timestamp",
592
				"timerep" => "Timestamp reply",
593
				"inforeq" => "Information request",
594
				"inforep" => "Information reply",
595
				"maskreq" => "Address mask request",
596
				"maskrep" => "Address mask reply"
597
				);
598

    
599
				foreach ($icmptypes as $icmptype => $descr): ?>
600
					<option value="<?=$icmptype;?>" <?php if ($icmptype == $pconfig['icmptype']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
601
<?php 			endforeach; ?>
602
			</select>
603
			<br />
604
			<span class="vexpl">If you selected ICMP for the protocol above, you may specify an ICMP type here.</span>
605
		</td>
606
		</tr>
607
		<tr>
608
			<td width="22%" valign="top" class="vncellreq">Source</td>
609
			<td width="78%" class="vtable">
610
				<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
611
				<strong>not</strong>
612
				<br />
613
				Use this option to invert the sense of the match.
614
				<br />
615
				<br />
616
				<table border="0" cellspacing="0" cellpadding="0">
617
					<tr>
618
						<td>Type:&nbsp;&nbsp;</td>
619
						<td>
620
							<select name="srctype" class="formselect" onChange="typesel_change()">
621
<?php
622
								$sel = is_specialnet($pconfig['src']); ?>
623
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
624
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
625
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
626
								<?php if(have_ruleint_access("wan")): ?>
627
								<option value="wanip" 	<?php if ($pconfig['src'] == "wanip") { echo "selected"; } ?>>WAN address</option>
628
								<?php endif; ?>
629
								<?php if(have_ruleint_access("lan")): ?>
630
								<option value="lanip" 	<?php if ($pconfig['src'] == "lanip") { echo "selected"; } ?>>LAN address</option>
631
								<?php endif; ?>
632
								<?php if(have_ruleint_access("lan")): ?>
633
								<option value="lan"     <?php if ($pconfig['src'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
634
								<?php endif; ?>
635
								<?php if(have_ruleint_access("pptp")): ?>
636
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
637
								<?php endif; ?>
638
								<?php if(have_ruleint_access("pppoe")): ?>
639
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
640
								<?php endif; ?>								
641
<?php
642
								$ifdisp = get_configured_interface_with_descr();
643
								foreach ($ifdisp as $ifent => $ifdesc): ?>
644
								<?php if(have_ruleint_access($ifent)): ?>
645
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
646
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
647
										<?=$ifdesc?> address
648
									</option>
649
								<?php endif; ?>
650
<?php 							endforeach; ?>
651
							</select>
652
						</td>
653
					</tr>
654
					<tr>
655
						<td>Address:&nbsp;&nbsp;</td>
656
						<td>
657
							<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
658
							<select name="srcmask" class="formselect" id="srcmask">
659
<?php						for ($i = 31; $i > 0; $i--): ?>
660
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
661
<?php 						endfor; ?>
662
							</select>
663
						</td>
664
					</tr>
665
				</table>
666
				<div id="showadvancedboxspr">
667
					<p>
668
					<input type="button" onClick="show_source_port_range()" value="Advanced"></input> - Show source port range</a>
669
				</div>
670
			</td>
671
		</tr>
672
		<tr style="display:none" id="sprtable" name="sprtable">
673
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
674
			<td width="78%" class="vtable">
675
				<table border="0" cellspacing="0" cellpadding="0">
676
					<tr>
677
						<td>from:&nbsp;&nbsp;</td>
678
						<td>
679
							<select name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
680
								<option value="">(other)</option>
681
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
682
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
683
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
684
<?php 							endforeach; ?>
685
							</select>
686
							<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
687
						</td>
688
					</tr>
689
					<tr>
690
						<td>to:</td>
691
						<td>
692
							<select name="srcendport" class="formselect" onchange="ext_change()">
693
								<option value="">(other)</option>
694
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
695
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
696
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
697
<?php							endforeach; ?>
698
							</select>
699
							<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
700
						</td>
701
					</tr>
702
				</table>
703
				<br />
704
				<span class="vexpl">Specify the port or port range for the source of the packet for this rule. This is usually not equal to the destination port range (and is often &quot;any&quot;). <br /> Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port</span><br/>
705
				<span class="vexpl"><B>NOTE:</B> You will not need to enter anything here in 99.99999% of the circumstances.  If you're unsure, do not enter anything here!</span>
706
			</td>
707
		</tr>
708
		<tr>
709
			<td width="22%" valign="top" class="vncell">Source OS</td>
710
			<td width="78%" class="vtable">OS Type:&nbsp;
711
				<select name="os" id="os" class="formselect">
712
<?php
713
		           $ostypes = array(
714
						 "" => "any",
715
		                 "AIX" => "AIX",
716
		                 "Linux" => "Linux",
717
		                 "FreeBSD" => "FreeBSD",
718
		                 "NetBSD" => "NetBSD",
719
		                 "OpenBSD" => "OpenBSD",
720
		                 "Solaris" => "Solaris",
721
		                 "MacOS" => "MacOS",
722
		                 "Windows" => "Windows",
723
		                 "Novell" => "Novell",
724
		                 "NMAP" => "NMAP"
725
		           );
726

    
727
					foreach ($ostypes as $ostype => $descr): ?>
728
						<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
729
<?php				endforeach; ?>
730
				</select>
731
				<br />
732
				Note: this only works for TCP rules
733
			</td>
734
		</tr>
735
		<tr>
736
			<td width="22%" valign="top" class="vncellreq">Destination</td>
737
			<td width="78%" class="vtable">
738
				<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
739
				<strong>not</strong>
740
					<br />
741
				Use this option to invert the sense of the match.
742
					<br />
743
					<br />
744
				<table border="0" cellspacing="0" cellpadding="0">
745
					<tr>
746
						<td>Type:&nbsp;&nbsp;</td>
747
						<td>
748
							<select name="dsttype" class="formselect" onChange="typesel_change()">
749
<?php
750
								$sel = is_specialnet($pconfig['dst']); ?>
751
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
752
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
753
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
754
								<?php if(have_ruleint_access("wan")): ?>
755
								<option value="wanip" <?php if ($pconfig['dst'] == "wanip") { echo "selected"; } ?>>WAN address</option>
756
								<?php endif; ?>
757
								<?php if(have_ruleint_access("lan")): ?>
758
								<option value="lanip" <?php if ($pconfig['dst'] == "lanip") { echo "selected"; } ?>>LAN address</option>
759
								<?php endif; ?>
760
								<?php if(have_ruleint_access("lan")): ?>
761
								<option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
762
								<?php endif; ?>
763
								<?php if(have_ruleint_access("pptp")): ?>
764
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
765
								<?php endif; ?>
766
								<?php if(have_ruleint_access("pppoe")): ?>
767
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
768
								<?php endif; ?>								
769
								
770

    
771
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
772
								<?php if(have_ruleint_access($if)): ?>
773
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
774
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
775
										<?=$ifdesc;?> address
776
									</option>
777
								<?php endif; ?>
778
<?php 							endforeach; ?>
779
							</select>
780
						</td>
781
					</tr>
782
					<tr>
783
						<td>Address:&nbsp;&nbsp;</td>
784
						<td>
785
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
786
							/
787
							<select name="dstmask" class="formselect" id="dstmask">
788
<?php
789
							for ($i = 31; $i > 0; $i--): ?>
790
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
791
<?php						endfor; ?>
792
							</select>
793
						</td>
794
					</tr>
795
				</table>
796

    
797
			</td>
798
		</tr>
799
		<tr id="dprtr" name="dprtr">
800
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
801
			<td width="78%" class="vtable">
802
				<table border="0" cellspacing="0" cellpadding="0">
803
					<tr>
804
						<td>from:&nbsp;&nbsp;</td>
805
						<td>
806
							<select name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
807
								<option value="">(other)</option>
808
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
809
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
810
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
811
<?php 							endforeach; ?>
812
							</select>
813
							<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
814
						</td>
815
					</tr>
816
					<tr>
817
						<td>to:</td>
818
						<td>
819
							<select name="dstendport" class="formselect" onchange="ext_change()">
820
								<option value="">(other)</option>
821
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
822
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
823
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
824
<?php 							endforeach; ?>
825
							</select>
826
							<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
827
						</td>
828
					</tr>
829
				</table>
830
				<br />
831
				<span class="vexpl">
832
					Specify the port or port range for the destination of the packet for this rule.
833
						<br />
834
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
835
				</span>
836
			</td>
837
		</tr>
838
                <tr>
839
                        <td width="22%" valign="top" class="vncellreq">Diffserv Code Point</td>
840
                        <td width="78%" class="vtable">
841
                                <input name="dscp" id="dscp" value="<?=htmlspecialchars($pconfig['dscp']);?>">
842
                                        <br />
843
                                <span class="vexpl">Valid values are: af11, af12, af13, af21, af22, af23, af31, af32, af33, af41, af42, af43, EF, 1-64, 0x04-0xfc.</span>
844
                        </td>
845
                </tr>
846
		<tr>
847
			<td width="22%" valign="top" class="vncellreq">Log</td>
848
			<td width="78%" class="vtable">
849
				<input name="log" type="checkbox" id="log" value="yes" <?php if ($pconfig['log']) echo "checked"; ?>>
850
				<strong>Log packets that are handled by this rule</strong>
851
					<br />
852
				<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>
853
			</td>
854
		</tr>
855
		<tr>
856
			<td width="22%" valign="top" class="vncell">Advanced Options</td>
857
			<td width="78%" class="vtable">
858
			<div id="aoadv" name="aoadv">
859
				<input type="button" onClick="show_aodiv();" value="Advanced"> - Show advanced options
860
			</div>
861
			<div id="aodivmain" name="aodivmain" style="display:none">
862
<?php if ($if == "FloatingRules" || isset($pconfig['floating'])): ?>
863

    
864
                                <input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
865
                                <br /><span class="vexpl"><?=gettext("You can mark a packet matching this rule and
866
use this mark to match on other rules. It is called <b>Policy filtering</b>");?>
867
                                </span><p>
868
<?php endif; ?>
869
                                <input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>"
870
>
871
                                <br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before
872
on another rule.")?>
873
                                </span> <p>
874

    
875
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
876
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
877
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
878
				<select name="max-src-conn-rates" id="max-src-conn-rates">
879
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
880
<?php				for($x=1; $x<255; $x++) {
881
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
882
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
883
					} ?>
884
				</select><br />
885
				Maximum new connections / per second
886
				<p>
887

    
888
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
889
				State Timeout in seconds
890
				<p />
891

    
892
				<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
893
			  </div>
894
			</td>
895
		</tr>
896
		<tr>
897
			<td width="22%" valign="top" class="vncell">State Type</td>
898
			<td width="78%" class="vtable">
899
				<div id="showadvstatebox">
900
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show state</a>
901
				</div>
902
				<div id="showstateadv" style="display:none">
903
					<select name="statetype">
904
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
905
						<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
906
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
907
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
908
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
909
					<p>
910
					<table width="90%">
911
						<tr><td width="25%"><ul><li>keep state</li></td><td>Works with all IP protocols.</ul></td></tr>
912
						<tr><td width="25%"><ul><li>modulate state</li></td><td>Works only with TCP. {$g['product_name']} will generate strong Initial Sequence Numbers (ISNs) for packets matching this rule.</li></ul></td></tr>
913
						<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>
914
						<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>
915
					</table>
916
					</p>
917
			  </div>
918
			</td>
919
		</tr>
920
		<tr>
921
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
922
			<td width="78%" class="vtable">
923
				<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
924
				HINT: This prevents the rule from automatically syncing to other carp members.
925
			</td>
926
		</tr>
927
		<?php
928
			//build list of schedules
929
			$schedules = array();
930
			$schedules[] = "none";//leave none to leave rule enabled all the time
931
			if(is_array($config['schedules']['schedule'])) {
932
				foreach ($config['schedules']['schedule'] as $schedule) {
933
					if ($schedule['name'] <> "")
934
						$schedules[] = $schedule['name'];
935
				}
936
			}
937
		?>
938
		<tr>
939
			<td width="22%" valign="top" class="vncell">Schedule</td>
940
			<td width="78%" class="vtable">
941
				<select name='sched'>
942
<?php
943
				foreach($schedules as $schedule) {
944
					if($schedule == $pconfig['sched']) {
945
						$selected = " SELECTED";
946
					} else {
947
						$selected = "";
948
					}
949
					if ($schedule == "none") {
950
						echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
951
					} else {
952
						echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
953
					}
954
				}?>
955
				</select>
956
				<p>Leave as 'none' to leave the rule enabled all the time.</p>
957
				<strong>NOTE:  schedule logic can be a bit different.  Click <a target="_new" href='firewall_rules_schedule_logic.php'>here</a> for more information.</strong>
958
			</td>
959
		</tr>
960
		
961
<?php
962
			/* build a list of gateways */
963
			$gateways = array();
964
			$gateways[] = "default"; // default to don't use this feature :)
965
			if (is_array($config['gateways']['gateway_item'])) {
966
				foreach($config['gateways']['gateway_item'] as $gw_item) {
967
				if($gw_item['gateway'] <> "")
968
					$gateways[] = $gw_item['name'];
969
				}
970
			}
971
			
972
?>
973
		<tr>
974
			<td width="22%" valign="top" class="vncell">Gateway</td>
975
			<td width="78%" class="vtable">
976
				<select name='gateway'>
977
<?php
978
				foreach($gateways as $gw) {
979
					if($gw == "") 
980
						continue;
981
					if($gw == $pconfig['gateway']) {
982
						$selected = " SELECTED";
983
					} else {
984
						$selected = "";
985
					}
986
					if ($gw == "default") {
987
						echo "<option value=\"\" {$selected}>{$gw}</option>\n";
988
					} else {
989
						$gwip = lookup_gateway_ip_by_name($gw);
990
						echo "<option value=\"{$gw}\" {$selected}>{$gw} - {$gwip}</option>\n";
991
					}
992
				}
993
				/* add gateway groups to the list */
994
				if (is_array($config['gateways']['gateway_group'])) {
995
					foreach($config['gateways']['gateway_group'] as $gw_group) {
996
						if($gw_group['name'] == "")
997
							continue;
998
						if($pconfig['gateway'] == $gw_group['name']) {
999
							echo "<option value=\"{$gw_group['name']}\" SELECTED>{$gw_group['name']}</option>\n";
1000
						} else {
1001
							echo "<option value=\"{$gw_group['name']}\">{$gw_group['name']}</option>\n";
1002
						}
1003
					}
1004
				}
1005
				$iflist = get_configured_interface_with_descr();
1006
				foreach ($iflist as $ifent => $ifdesc) {
1007
					if (in_array($config['interfaces'][$ifent]['ipaddr'],
1008
						 array("dhcp", "pppoe", "pptp"))) {
1009
						if ($pconfig['gateway'] == $ifent) {
1010
							$selected = " SELECTED";
1011
						} else {
1012
							$selected = "";
1013
						}
1014
						if($ifdesc <> "") 
1015
							echo "<option value=\"{$ifent}\" {$selected}>".strtoupper($if)." - {$ifdesc}</option>\n";
1016
					}
1017
				}
1018
?>
1019
				</select>
1020
				<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
1021
			</td>
1022
		</tr>
1023
		<tr>
1024
			<td width="22%" valign="top" class="vncell">In/Out</td>
1025
			<td width="78%" class="vtable">
1026
			<select name="dnpipe">
1027
<?php
1028
		read_dummynet_config(); /* XXX: */
1029
		$dnqlist =& get_unique_dnqueue_list();
1030
		if (!is_array($dnqlist))
1031
			$dnqlist = array();
1032
		echo "<option value=\"none\"";
1033
		if (!$dnqselected) echo " SELECTED";
1034
		echo " >none</option>";
1035
		foreach ($dnqlist as $dnq => $dnqkey) {
1036
			if($dnq == "")
1037
				continue;
1038
			echo "<option value=\"$dnqkey\"";
1039
			if ($dnqkey == $pconfig['dnpipe']) {
1040
				$dnqselected = 1;
1041
				echo " SELECTED";
1042
			}
1043
			echo ">{$dnq}</option>"; 
1044
		}
1045
?>
1046
			</select> / 			
1047
			<select name="pdnpipe">
1048
<?php
1049
		$dnqselected = 0;
1050
		echo "<option value=\"none\"";
1051
		if (!$dnqselected) echo " SELECTED";
1052
		echo " >none</option>";
1053
		foreach ($dnqlist as $dnq => $dnqkey) {
1054
			if($dnq == "")
1055
				continue;
1056
			echo "<option value=\"$dnqkey\"";
1057
			if ($dnqkey == $pconfig['pdnpipe']) {
1058
				$dnqselected = 1;
1059
				echo " SELECTED";
1060
			}
1061
			echo ">{$dnq}</option>"; 
1062
		}
1063
?>
1064
			</select>
1065
				<br />
1066
				<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>
1067
			</td>
1068
		</tr>
1069

    
1070
		<tr>
1071
			<td width="22%" valign="top" class="vncell">Ackqueue/Queue</td>
1072
			<td width="78%" class="vtable">
1073
			<select name="ackqueue">
1074
<?php
1075
		read_altq_config(); /* XXX: */
1076
		$qlist =& get_unique_queue_list();
1077
		if (!is_array($qlist))
1078
			$qlist = array();
1079
		echo "<option value=\"none\"";
1080
		if (!$qselected) echo " SELECTED";
1081
		echo " >none</option>";
1082
		foreach ($qlist as $q => $qkey) {
1083
			if($q == "")
1084
				continue;
1085
			echo "<option value=\"$q\"";
1086
			if ($q == $pconfig['ackqueue']) {
1087
				$qselected = 1;
1088
				echo " SELECTED";
1089
			}
1090
			echo ">{$q}</option>"; 
1091
		}
1092
?>
1093
			</select> / 			
1094
			<select name="defaultqueue">
1095
<?php
1096
		$qselected = 0;
1097
		echo "<option value=\"none\"";
1098
		if (!$qselected) echo " SELECTED";
1099
		echo " >none</option>";
1100
		foreach ($qlist as $q => $qkey) {
1101
			if($q == "")
1102
				continue;
1103
			echo "<option value=\"$q\"";
1104
			if ($q == $pconfig['defaultqueue']) {
1105
				$qselected = 1;
1106
				echo " SELECTED";
1107
			}
1108
			echo ">{$q}</option>"; 
1109
		}
1110
?>
1111
			</select>
1112
				<br />
1113
				<span class="vexpl">Choose the Acknowledge Queue only if you have selected Queue.</span>
1114
			</td>
1115
		</tr>
1116
		<tr>
1117
			<td width="22%" valign="top" class="vncell">Description</td>
1118
			<td width="78%" class="vtable">
1119
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
1120
				<br />
1121
				<span class="vexpl">You may enter a description here for your reference (not parsed).</span>
1122
			</td>
1123
		</tr>
1124
		<tr>
1125
			<td width="22%" valign="top">&nbsp;</td>
1126
			<td width="78%">
1127
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
1128
<?php			if (isset($id) && $a_filter[$id]): ?>
1129
					<input name="id" type="hidden" value="<?=$id;?>">
1130
<?php 			endif; ?>
1131
				<input name="after" type="hidden" value="<?=$after;?>">
1132
			</td>
1133
		</tr>
1134
	</table>
1135
</form>
1136
<script language="JavaScript">
1137
<!--
1138
	ext_change();
1139
	typesel_change();
1140
	proto_change();
1141

    
1142
<?php
1143
	$isfirst = 0;
1144
	$aliases = "";
1145
	$addrisfirst = 0;
1146
	$aliasesaddr = "";
1147
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1148
		foreach($config['aliases']['alias'] as $alias_name) {
1149
			if(!stristr($alias_name['address'], ".")) {
1150
				if($isfirst == 1) $aliases .= ",";
1151
				$aliases .= "'" . $alias_name['name'] . "'";
1152
				$isfirst = 1;
1153
			} else {
1154
				if($addrisfirst == 1) $aliasesaddr .= ",";
1155
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1156
				$addrisfirst = 1;
1157
			}
1158
		}
1159
?>
1160

    
1161
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1162
	var customarray=new Array(<?php echo $aliases; ?>);
1163

    
1164
//-->
1165
</script>
1166

    
1167

    
1168
<?php include("fend.inc"); ?>
1169
</body>
1170
</html>
1171

    
(52-52/211)