Project

General

Profile

Download (43.5 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
require("guiconfig.inc");
35

    
36
$specialsrcdst = explode(" ", "any wanip lanip lan pptp pppoe");
37

    
38
if (!is_array($config['filter']['rule'])) {
39
	$config['filter']['rule'] = array();
40
}
41
filter_rules_sort();
42
$a_filter = &$config['filter']['rule'];
43

    
44
$id = $_GET['id'];
45
if (is_numeric($_POST['id']))
46
	$id = $_POST['id'];
47

    
48
$after = $_GET['after'];
49

    
50
if (isset($_POST['after']))
51
	$after = $_POST['after'];
52

    
53
if (isset($_GET['dup'])) {
54
	$id = $_GET['dup'];
55
	$after = $_GET['dup'];
56
}
57

    
58
if($id > -1) {
59
	$if = $a_filter[$id]['interface'];
60
	$security_url = "firewall_rules_edit.php?if=". strtolower($if);
61
	if (!isSystemAdmin($HTTP_SERVER_VARS['AUTH_USER'])) {
62
		log_error("Checking for {$security_url}");
63
		if(!in_array($security_url, $allowed)) {
64
			// User does not have access
65
	//		echo "displaying error {$security_url}"; print_r($allowed);
66
			echo display_error_form("401", "Unauthorized. You do not have access to edit rules on the interface {$if}");
67
			exit;
68
		}
69
	}
70
}
71

    
72
if (isset($id) && $a_filter[$id]) {
73
	$pconfig['interface'] = $a_filter[$id]['interface'];
74

    
75
	if (!isset($a_filter[$id]['type']))
76
		$pconfig['type'] = "pass";
77
	else
78
		$pconfig['type'] = $a_filter[$id]['type'];
79

    
80
	if (isset($a_filter[$id]['floating']) || $if == "FloatingRules") {
81
		$pconfig['floating'] = $a_filter[$id]['floating'];
82
		if (isset($a_filter[$id]['interface']) && $a_filter[$id]['interface'] <> "") 
83
			$pconfig['interface'] = $a_filter[$id]['interface'];
84
	}
85
	
86
	if (isset($a_filter['floating'])) 
87
		$pconfig['floating'] = "yes";
88

    
89
	if (isset($a_filter[$id]['direction']))
90
                $pconfig['direction'] = $a_filter[$id]['direction'];
91

    
92
	if (isset($a_filter[$id]['protocol']))
93
		$pconfig['proto'] = $a_filter[$id]['protocol'];
94
	else
95
		$pconfig['proto'] = "any";
96

    
97
	if ($a_filter[$id]['protocol'] == "icmp")
98
		$pconfig['icmptype'] = $a_filter[$id]['icmptype'];
99

    
100
	address_to_pconfig($a_filter[$id]['source'], $pconfig['src'],
101
		$pconfig['srcmask'], $pconfig['srcnot'],
102
		$pconfig['srcbeginport'], $pconfig['srcendport']);
103

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

    
107
	address_to_pconfig($a_filter[$id]['destination'], $pconfig['dst'],
108
		$pconfig['dstmask'], $pconfig['dstnot'],
109
		$pconfig['dstbeginport'], $pconfig['dstendport']);
110

    
111
	if ($a_filter[$id]['dscp'] <> "")
112
		$pconfig['dscp'] = $a_filter[$id]['dscp'];
113

    
114
	$pconfig['disabled'] = isset($a_filter[$id]['disabled']);
115
	$pconfig['log'] = isset($a_filter[$id]['log']);
116
	$pconfig['descr'] = $a_filter[$id]['descr'];
117

    
118
	if (isset($a_filter[$id]['tag']) && $a_filter[$id]['tag'] <> "") 
119
		$pconfig['tag'] = $a_filter[$id]['tag'];
120
	if (isset($a_filter[$id]['tagged']) && $a_filter[$id]['tag'] <> "")
121
        	$pconfig['tagged'] = $a_filter[$id]['tagged'];
122
	if (isset($a_filter[$id]['quick']) && $a_filter[$id]['quick'])
123
		$pconfig['quick'] = $a_filter[$id]['quick'];
124

    
125
	/* advanced */
126
        $pconfig['max-src-nodes'] = $a_filter[$id]['max-src-nodes'];
127
        $pconfig['max-src-states'] = $a_filter[$id]['max-src-states'];
128
        $pconfig['statetype'] = $a_filter[$id]['statetype'];
129
	$pconfig['statetimeout'] = $a_filter[$id]['statetimeout'];
130

    
131
	$pconfig['nosync'] = isset($a_filter[$id]['nosync']);
132

    
133
	/* advanced - new connection per second banning*/
134
	$pconfig['max-src-conn-rate'] = $a_filter[$id]['max-src-conn-rate'];
135
	$pconfig['max-src-conn-rates'] = $a_filter[$id]['max-src-conn-rates'];
136

    
137
	/* Multi-WAN next-hop support */
138
	$pconfig['gateway'] = $a_filter[$id]['gateway'];
139
	
140
	/* Shaper support */
141
	$pconfig['defaultqueue'] = $a_filter[$id]['defaultqueue'];
142
	$pconfig['ackqueue'] = $a_filter[$id]['ackqueue'];
143

    
144
	//schedule support
145
	$pconfig['sched'] = $a_filter[$id]['sched'];
146

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

    
158
if (isset($_GET['dup']))
159
	unset($id);
160

    
161
if ($_POST) {
162

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

    
166
	if (($_POST['proto'] != "tcp") && ($_POST['proto'] != "udp") && ($_POST['proto'] != "tcp/udp")) {
167
		$_POST['srcbeginport'] = 0;
168
		$_POST['srcendport'] = 0;
169
		$_POST['dstbeginport'] = 0;
170
		$_POST['dstendport'] = 0;
171
	} else {
172

    
173
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
174
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
175
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
176
			$_POST['srcendport'] = $_POST['srcendport_cust'];
177

    
178
		if ($_POST['srcbeginport'] == "any") {
179
			$_POST['srcbeginport'] = 0;
180
			$_POST['srcendport'] = 0;
181
		} else {
182
			if (!$_POST['srcendport'])
183
				$_POST['srcendport'] = $_POST['srcbeginport'];
184
		}
185
		if ($_POST['srcendport'] == "any")
186
			$_POST['srcendport'] = $_POST['srcbeginport'];
187

    
188
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
189
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
190
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
191
			$_POST['dstendport'] = $_POST['dstendport_cust'];
192

    
193
		if ($_POST['dstbeginport'] == "any") {
194
			$_POST['dstbeginport'] = 0;
195
			$_POST['dstendport'] = 0;
196
		} else {
197
			if (!$_POST['dstendport'])
198
				$_POST['dstendport'] = $_POST['dstbeginport'];
199
		}
200
		if ($_POST['dstendport'] == "any")
201
			$_POST['dstendport'] = $_POST['dstbeginport'];
202
	}
203

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

    
217
	unset($input_errors);
218
	$pconfig = $_POST;
219

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

    
232
	/* input validation */
233
	$reqdfields = explode(" ", "type proto src dst");
234
	$reqdfieldsn = explode(",", "Type,Protocol,Source,Destination");
235

    
236

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

    
244

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

    
254
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
255

    
256
	if (!$_POST['srcbeginport']) {
257
		$_POST['srcbeginport'] = 0;
258
		$_POST['srcendport'] = 0;
259
	}
260
	if (!$_POST['dstbeginport']) {
261
		$_POST['dstbeginport'] = 0;
262
		$_POST['dstendport'] = 0;
263
	}
264

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

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

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

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

    
321
	if ($_POST['ackqueue'] && $_POST['ackqueue'] != "none") {
322
		if ($_POST['defaultqueue'] == "none" )
323
			$input_errors[] = "You have to select a queue when you select an acknowledge queue too.";
324
		else if ($_POST['ackqueue'] == $_POST['defaultqueue'])
325
			$input_errors[] = "Acknokledge queue and Queue cannot be the same.";		
326
	}
327

    
328
	if (!$input_errors) {
329
		$filterent = array();
330
		$filterent['type'] = $_POST['type'];
331
		if (isset($_POST['interface'] ))
332
			$filterent['interface'] = $_POST['interface'];
333

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

    
348
		/* Advanced options */
349
		$filterent['max-src-nodes'] = $_POST['max-src-nodes'];
350
		$filterent['max-src-states'] = $_POST['max-src-states'];
351
		$filterent['statetimeout'] = $_POST['statetimeout'];
352
		$filterent['statetype'] = $_POST['statetype'];
353
		$filterent['os'] = $_POST['os'];
354

    
355
		/* Nosync directive - do not xmlrpc sync this item */
356
		if($_POST['nosync'] <> "")
357
			$filterent['nosync'] = true;
358
		else
359
			unset($filterent['nosync']);
360

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

    
370
		if ($_POST['proto'] != "any")
371
			$filterent['protocol'] = $_POST['proto'];
372
		else
373
			unset($filterent['protocol']);
374

    
375
		if ($_POST['proto'] == "icmp" && $_POST['icmptype'])
376
			$filterent['icmptype'] = $_POST['icmptype'];
377
		else
378
			unset($filterent['icmptype']);
379

    
380
		pconfig_to_address($filterent['source'], $_POST['src'],
381
			$_POST['srcmask'], $_POST['srcnot'],
382
			$_POST['srcbeginport'], $_POST['srcendport']);
383

    
384
		pconfig_to_address($filterent['destination'], $_POST['dst'],
385
			$_POST['dstmask'], $_POST['dstnot'],
386
			$_POST['dstbeginport'], $_POST['dstendport']);
387

    
388
                if ($_POST['disabled'])
389
                        $filterent['disabled'] = true;
390
                else
391
                        unset($filterent['disabled']);
392
		
393
		if ($_POST['dscp'])
394
			$filterent['dscp'] = $_POST['dscp'];
395

    
396
                if ($_POST['log'])
397
                        $filterent['log'] = true;
398
                else
399
                        unset($filterent['log']);
400
		strncpy($filterent['descr'], $_POST['descr'], 52);
401

    
402
		if ($_POST['gateway'] != "") {
403
			$filterent['gateway'] = $_POST['gateway'];
404
		}
405
		
406
		if (isset($_POST['defaultqueue']) && $_POST['defaultqueue'] != "none") {
407
			$filterent['defaultqueue'] = $_POST['defaultqueue'];
408
			if (isset($_POST['ackqueue']) && $_POST['ackqueue'] != "none")
409
				$filterent['ackqueue'] = $_POST['ackqueue'];
410
		}
411

    
412
		if ($_POST['sched'] != "") {
413
			$filterent['sched'] = $_POST['sched'];
414
		}
415

    
416
		if (isset($id) && $a_filter[$id])
417
			$a_filter[$id] = $filterent;
418
		else {
419
			if (is_numeric($after))
420
				array_splice($a_filter, $after+1, 0, array($filterent));
421
			else
422
				$a_filter[] = $filterent;
423
		}
424

    
425
		write_config();
426
		touch($d_filterconfdirty_path);
427

    
428
		if (isset($_POST['floating']))
429
			header("Location: firewall_rules.php?if=FloatingRules");
430
		else
431
			header("Location: firewall_rules.php?if=" . $_POST['interface']);
432
		exit;
433
	}
434
}
435

    
436
$pgtitle = array("Firewall","Rules","Edit");
437
$closehead = false;
438

    
439
$page_filename = "firewall_rules_edit.php";
440
include("head.inc");
441

    
442
?>
443

    
444
</head>
445

    
446
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
447
<?php include("fbegin.inc"); ?>
448
<?php if ($input_errors) print_input_errors($input_errors); ?>
449

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

    
498
				foreach ($ifdescs as $ifent => $ifdesc)
499
        				if(have_ruleint_access($ifent))
500
                				$interfaces[$ifent] = $ifdesc;
501

    
502
					if ($config['pptpd']['mode'] == "server")
503
						if(have_ruleint_access("pptp")) 
504
							$interfaces['pptp'] = "PPTP VPN";
505
					
506
					if ($config['pppoe']['mode'] == "server")
507
						if(have_ruleint_access("pppoe")) 
508
							$interfaces['pppoe'] = "PPPoE VPN";
509
					
510
					/* add ipsec interfaces */
511
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
512
						if(have_ruleint_access("enc0")) 
513
							$interfaces["enc0"] = "IPsec";
514
		
515
					/* add openvpn/tun interfaces */
516
					if  ($config['installedpackages']["openvpnserver"] || $config['installedpackages']["openvpnclient"]) {
517
					        if (is_array($config['installedpackages']["openvpnserver"]['config']) ||
518
                					is_array($config['installedpackages']["openvpnclient"]['config']))
519
        					$interfaces["openvpn"] = "OpenVPN";
520
					}
521

    
522

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

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

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

    
759
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
760
								<?php if(have_ruleint_access($if)): ?>
761
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
762
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
763
										<?=$ifdesc;?> address
764
									</option>
765
								<?php endif; ?>
766
<?php 							endforeach; ?>
767
							</select>
768
						</td>
769
					</tr>
770
					<tr>
771
						<td>Address:&nbsp;&nbsp;</td>
772
						<td>
773
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
774
							/
775
							<select name="dstmask" class="formselect" id="dstmask">
776
<?php
777
							for ($i = 31; $i > 0; $i--): ?>
778
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
779
<?php						endfor; ?>
780
							</select>
781
						</td>
782
					</tr>
783
				</table>
784

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

    
853
                                <input name="tag" id="tag" value="<?=htmlspecialchars($pconfig['tag']);?>">
854
                                <br /><span class="vexpl"><?=gettext("You can mark a packet matching this rule and
855
use this mark to match on other rules. It is called <b>Policy filtering</b>");?>
856
                                </span><p>
857
<?php endif; ?>
858
                                <input name="tagged" id="tagged" value="<?=htmlspecialchars($pconfig['tagged']);?>"
859
>
860
                                <br /><span class="vexpl"><?=gettext("You can match packet on a mark placed before
861
on another rule.")?>
862
                                </span> <p>
863

    
864
				<input name="max-src-nodes" id="max-src-nodes" value="<?php echo $pconfig['max-src-nodes'] ?>"><br> Simultaneous client connection limit<p>
865
				<input name="max-src-states" id="max-src-states" value="<?php echo $pconfig['max-src-states'] ?>"><br> Maximum state entries per host<p>
866
				<input name="max-src-conn-rate" id="max-src-conn-rate" value="<?php echo $pconfig['max-src-conn-rate'] ?>"> /
867
				<select name="max-src-conn-rates" id="max-src-conn-rates">
868
					<option value=""<?php if(intval($pconfig['max-src-conn-rates']) < 1) echo " selected"; ?>></option>
869
<?php				for($x=1; $x<255; $x++) {
870
						if($x == $pconfig['max-src-conn-rates']) $selected = " selected"; else $selected = "";
871
						echo "<option value=\"{$x}\"{$selected}>{$x}</option>\n";
872
					} ?>
873
				</select><br />
874
				Maximum new connections / per second
875
				<p>
876

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

    
881
				<p><strong>NOTE: Leave these fields blank to disable this feature.</strong>
882
			  </div>
883
			</td>
884
		</tr>
885
		<tr>
886
			<td width="22%" valign="top" class="vncell">State Type</td>
887
			<td width="78%" class="vtable">
888
				<div id="showadvstatebox">
889
					<input type="button" onClick="show_advanced_state()" value="Advanced"></input> - Show state</a>
890
				</div>
891
				<div id="showstateadv" style="display:none">
892
					<select name="statetype">
893
						<option value="keep state" <?php if(!isset($pconfig['statetype']) or $pconfig['statetype'] == "keep state") echo "selected"; ?>>keep state</option>
894
						<option value="modulate state" <?php if($pconfig['statetype'] == "modulate state")  echo "selected"; ?>>modulate state</option>
895
						<option value="synproxy state"<?php if($pconfig['statetype'] == "synproxy state")  echo "selected"; ?>>synproxy state</option>
896
						<option value="none"<?php if($pconfig['statetype'] == "none") echo "selected"; ?>>none</option>
897
					</select><br>HINT: Select which type of state tracking mechanism you would like to use.  If in doubt, use keep state.
898
					<p>
899
					<table width="90%">
900
						<tr><td width="25%"><ul><li>keep state</li></td><td>Works with all IP protocols.</ul></td></tr>
901
						<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>
902
						<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>
903
						<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>
904
					</table>
905
					</p>
906
			  </div>
907
			</td>
908
		</tr>
909
		<tr>
910
			<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
911
			<td width="78%" class="vtable">
912
				<input type="checkbox" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
913
				HINT: This prevents the rule from automatically syncing to other carp members.
914
			</td>
915
		</tr>
916
		<?php
917
			//build list of schedules
918
			$schedules = array();
919
			$schedules[] = "none";//leave none to leave rule enabled all the time
920
			if(is_array($config['schedules']['schedule'])) {
921
				foreach ($config['schedules']['schedule'] as $schedule) {
922
					if ($schedule['name'] <> "")
923
						$schedules[] = $schedule['name'];
924
				}
925
			}
926
		?>
927
		<tr>
928
			<td width="22%" valign="top" class="vncell">Schedule</td>
929
			<td width="78%" class="vtable">
930
				<select name='sched'>
931
<?php
932
				foreach($schedules as $schedule) {
933
					if($schedule == $pconfig['sched']) {
934
						$selected = " SELECTED";
935
					} else {
936
						$selected = "";
937
					}
938
					if ($schedule == "none") {
939
						echo "<option value=\"\" {$selected}>{$schedule}</option>\n";
940
					} else {
941
						echo "<option value=\"{$schedule}\" {$selected}>{$schedule}</option>\n";
942
					}
943
				}?>
944
				</select>
945
				<p>Leave as 'none' to leave the rule enabled all the time.</p>
946
				<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>
947
			</td>
948
		</tr>
949
		
950
<?php
951
			/* build a list of gateways */
952
			$gateways = array();
953
			$gateways[] = "default"; // default to don't use this feature :)
954
			if (is_array($config['gateways']['gateway_item'])) {
955
				foreach($config['gateways']['gateway_item'] as $gw_item) {
956
				if($gw_item['gateway'] <> "")
957
					$gateways[] = $gw_item['name'];
958
				}
959
			}
960
			
961
?>
962
		<tr>
963
			<td width="22%" valign="top" class="vncell">Gateway</td>
964
			<td width="78%" class="vtable">
965
				<select name='gateway'>
966
<?php
967
				foreach($gateways as $gw) {
968
					if($gw == "") 
969
						continue;
970
					if($gw == $pconfig['gateway']) {
971
						$selected = " SELECTED";
972
					} else {
973
						$selected = "";
974
					}
975
					if ($gw == "default") {
976
						echo "<option value=\"\" {$selected}>{$gw}</option>\n";
977
					} else {
978
						$gwip = lookup_gateway_ip_by_name($gw);
979
						echo "<option value=\"{$gw}\" {$selected}>{$gw} - {$gwip}</option>\n";
980
					}
981
				}
982
				/* add gateway groups to the list */
983
				if (is_array($config['gateways']['gateway_group'])) {
984
					foreach($config['gateways']['gateway_group'] as $gw_group) {
985
						if($gw_group['name'] == "")
986
							continue;
987
						if($pconfig['gateway'] == $gw_group['name']) {
988
							echo "<option value=\"{$gw_group['name']}\" SELECTED>{$gw_group['name']}</option>\n";
989
						} else {
990
							echo "<option value=\"{$gw_group['name']}\">{$gw_group['name']}</option>\n";
991
						}
992
					}
993
				}
994
				$iflist = get_configured_interface_with_descr();
995
				foreach ($iflist as $ifent => $ifdesc) {
996
					if($config['interfaces'][$ifent]['ipaddr'] == "dhcp") {
997
						if ($pconfig['gateway'] == $ifent) {
998
							$selected = " SELECTED";
999
						} else {
1000
							$selected = "";
1001
						}
1002
						if($ifdesc <> "") 
1003
							echo "<option value=\"{$ifent}\" {$selected}>".strtoupper($if)." - {$ifdesc}</option>\n";
1004
					}
1005
				}
1006
?>
1007
				</select>
1008
				<p><strong>Leave as 'default' to use the system routing table.  Or choose a gateway to utilize policy based routing.</strong></p>
1009
			</td>
1010
		</tr>
1011
		<tr>
1012
			<td width="22%" valign="top" class="vncell">Ackqueue/Queue</td>
1013
			<td width="78%" class="vtable">
1014
			<select name="ackqueue">
1015
<?php
1016
		read_altq_config(); /* XXX: */
1017
		$qlist =& get_unique_queue_list();
1018
		if (!is_array($qlist))
1019
			$qlist = array();
1020
		foreach ($qlist as $q => $qkey) {
1021
			echo "<option value=\"$q\"";
1022
			if ($q == $pconfig['ackqueue']) {
1023
				$qselected = 1;
1024
				echo " SELECTED";
1025
			}
1026
			echo ">{$q}</option>"; 
1027
		}
1028
		echo "<option value=\"none\"";
1029
		if (!$qselected) echo " SELECTED";
1030
		echo " >none</option>";
1031
?>
1032
			</select> / 			
1033
			<select name="defaultqueue">
1034
<?php
1035
		$qselected = 0;
1036
		foreach ($qlist as $q => $qkey) {
1037
			echo "<option value=\"$q\"";
1038
			if ($q == $pconfig['defaultqueue']) {
1039
				$qselected = 1;
1040
				echo " SELECTED";
1041
			}
1042
			echo ">{$q}</option>"; 
1043
		}
1044
		echo "<option value=\"none\"";
1045
		if (!$qselected) echo " SELECTED";
1046
		echo " >none</option>";
1047
?>
1048
			</select>
1049
				<br />
1050
				<span class="vexpl">Choose the Acknowledge Queue only if you have selected Queue.</span>
1051
			</td>
1052
		</tr>
1053
		<tr>
1054
			<td width="22%" valign="top" class="vncell">Description</td>
1055
			<td width="78%" class="vtable">
1056
				<input name="descr" type="text" class="formfld unknown" id="descr" size="52" maxlength="52" value="<?=htmlspecialchars($pconfig['descr']);?>">
1057
				<br />
1058
				<span class="vexpl">You may enter a description here for your reference (not parsed).</span>
1059
			</td>
1060
		</tr>
1061
		<tr>
1062
			<td width="22%" valign="top">&nbsp;</td>
1063
			<td width="78%">
1064
				<input name="Submit" type="submit" class="formbtn" value="Save">  <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
1065
<?php			if (isset($id) && $a_filter[$id]): ?>
1066
					<input name="id" type="hidden" value="<?=$id;?>">
1067
<?php 			endif; ?>
1068
				<input name="after" type="hidden" value="<?=$after;?>">
1069
			</td>
1070
		</tr>
1071
	</table>
1072
</form>
1073
<script language="JavaScript">
1074
<!--
1075
	ext_change();
1076
	typesel_change();
1077
	proto_change();
1078

    
1079
<?php
1080
	$isfirst = 0;
1081
	$aliases = "";
1082
	$addrisfirst = 0;
1083
	$aliasesaddr = "";
1084
	if($config['aliases']['alias'] <> "" and is_array($config['aliases']['alias']))
1085
		foreach($config['aliases']['alias'] as $alias_name) {
1086
			if(!stristr($alias_name['address'], ".")) {
1087
				if($isfirst == 1) $aliases .= ",";
1088
				$aliases .= "'" . $alias_name['name'] . "'";
1089
				$isfirst = 1;
1090
			} else {
1091
				if($addrisfirst == 1) $aliasesaddr .= ",";
1092
				$aliasesaddr .= "'" . $alias_name['name'] . "'";
1093
				$addrisfirst = 1;
1094
			}
1095
		}
1096
?>
1097

    
1098
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
1099
	var customarray=new Array(<?php echo $aliases; ?>);
1100

    
1101
//-->
1102
</script>
1103

    
1104

    
1105
<?php include("fend.inc"); ?>
1106
</body>
1107
</html>
1108

    
(51-51/197)