Project

General

Profile

Download (45.3 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
	if($_POST['statetype'] == "modulate state" or $_POST['statetype'] == "synproxy state") {
233
		if( $_POST['proto'] != "tcp" )
234
			$input_errors[] = "{$_POST['statetype']} is only valid with protocol tcp.";
235
		if(($_POST['statetype'] == "synproxy state") && ($_POST['gateway'] != ""))
236
			$input_errors[] = "{$_POST['statetype']} is only valid if the gateway is set to 'default'.";
237
	}
238
        
239
	if (!(is_specialnet($_POST['srctype']) || ($_POST['srctype'] == "single"))) {
240
		$reqdfields[] = "srcmask";
241
		$reqdfieldsn[] = "Source bit count";
242
	}
243
	if (!(is_specialnet($_POST['dsttype']) || ($_POST['dsttype'] == "single"))) {
244
		$reqdfields[] = "dstmask";
245
		$reqdfieldsn[] = "Destination bit count";
246
	}
247

    
248
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
249

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
435
		write_config();
436
		touch($d_filterconfdirty_path);
437

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

    
446
$pgtitle = array("Firewall","Rules","Edit");
447
$closehead = false;
448

    
449
$page_filename = "firewall_rules_edit.php";
450
include("head.inc");
451

    
452
?>
453

    
454
</head>
455

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

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

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

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

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

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

    
725
					foreach ($ostypes as $ostype => $descr): ?>
726
						<option value="<?=$ostype;?>" <?php if ($ostype == $pconfig['os']) echo "selected"; ?>><?=htmlspecialchars($descr);?></option>
727
<?php				endforeach; ?>
728
				</select>
729
				<br />
730
				Note: this only works for TCP rules
731
			</td>
732
		</tr>
733
		<tr>
734
			<td width="22%" valign="top" class="vncellreq">Destination</td>
735
			<td width="78%" class="vtable">
736
				<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
737
				<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
							<select name="dsttype" class="formselect" onChange="typesel_change()">
747
<?php
748
								$sel = is_specialnet($pconfig['dst']); ?>
749
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
750
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
751
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
752
								<?php if(have_ruleint_access("wan")): ?>
753
								<option value="wanip" <?php if ($pconfig['dst'] == "wanip") { echo "selected"; } ?>>WAN address</option>
754
								<?php endif; ?>
755
								<?php if(have_ruleint_access("lan")): ?>
756
								<option value="lanip" <?php if ($pconfig['dst'] == "lanip") { echo "selected"; } ?>>LAN address</option>
757
								<?php endif; ?>
758
								<?php if(have_ruleint_access("lan")): ?>
759
								<option value="lan" <?php if ($pconfig['dst'] == "lan") { echo "selected"; } ?>>LAN subnet</option>
760
								<?php endif; ?>
761
								<?php if(have_ruleint_access("pptp")): ?>
762
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
763
								<?php endif; ?>
764
								<?php if(have_ruleint_access("pppoe")): ?>
765
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
766
								<?php endif; ?>								
767
								
768

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

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

    
861
                                <input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
862
                                <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>");?>
863
                                </span><p>
864
                                <input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>">
865
                                <br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before on another rule.")?>
866
                                </span> <p>
867
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
868
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
869
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
870
				<select name="max-src-conn-rates" id="max-src-conn-rates">
871
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
872
<?php				for($x=1; $x<255; $x++) {
873
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
874
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
875
					} ?>
876
				</select><br />
877
				Maximum new connections / per second
878
				<p>
879

    
880
				<input name="statetimeout" value="<?php echo $pconfig['statetimeout'] ?>"><br>
881
				State Timeout in seconds
882
				<p />
883

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

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

    
1132
<?php
1133
	$isfirst = 0;
1134
	$aliases = "";
1135
	$addrisfirst = 0;
1136
	$aliasesaddr = "";
1137
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1138
		foreach($config['aliases']['alias'] as $alias_name) {
1139
			if(!stristr($alias_name['address'], ".")) {
1140
				if($isfirst == 1) $aliases .= ",";
1141
				$aliases .= "'" . $alias_name['name'] . "'";
1142
				$isfirst = 1;
1143
			} else {
1144
				if($addrisfirst == 1) $aliasesaddr .= ",";
1145
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1146
				$addrisfirst = 1;
1147
			}
1148
		}
1149
?>
1150

    
1151
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1152
	var customarray=new Array(<?php echo $aliases; ?>);
1153

    
1154
//-->
1155
</script>
1156

    
1157

    
1158
<?php include("fend.inc"); ?>
1159
</body>
1160
</html>
1161

    
(54-54/211)