Project

General

Profile

Download (34 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_nat_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

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

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

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*
32
	pfSense_MODULE:	nat
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-firewall-nat-portforward-edit
37
##|*NAME=Firewall: NAT: Port Forward: Edit page
38
##|*DESCR=Allow access to the 'Firewall: NAT: Port Forward: Edit' page.
39
##|*MATCH=firewall_nat_edit.php*
40
##|-PRIV
41

    
42
require("guiconfig.inc");
43
require_once("itemid.inc");
44
require("filter.inc");
45
require("shaper.inc");
46

    
47
$specialsrcdst = explode(" ", "any pptp pppoe l2tp openvpn");
48
$ifdisp = get_configured_interface_with_descr();
49
foreach ($ifdisp as $kif => $kdescr) {
50
	$specialsrcdst[] = "{$kif}";
51
	$specialsrcdst[] = "{$kif}ip";
52
}
53

    
54
if (!is_array($config['nat']['rule'])) {
55
	$config['nat']['rule'] = array();
56
}
57
$a_nat = &$config['nat']['rule'];
58

    
59
$id = $_GET['id'];
60
if (isset($_POST['id']))
61
	$id = $_POST['id'];
62

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

    
68
if (isset($id) && $a_nat[$id]) {
69
	$pconfig['disabled'] = isset($a_nat[$id]['disabled']);
70
	$pconfig['nordr'] = isset($a_nat[$id]['nordr']);
71

    
72
	address_to_pconfig($a_nat[$id]['source'], $pconfig['src'],
73
		$pconfig['srcmask'], $pconfig['srcnot'],
74
		$pconfig['srcbeginport'], $pconfig['srcendport']);
75

    
76
	address_to_pconfig($a_nat[$id]['destination'], $pconfig['dst'],
77
		$pconfig['dstmask'], $pconfig['dstnot'],
78
		$pconfig['dstbeginport'], $pconfig['dstendport']);
79

    
80
	$pconfig['proto'] = $a_nat[$id]['protocol'];
81
	$pconfig['localip'] = $a_nat[$id]['target'];
82
	$pconfig['localbeginport'] = $a_nat[$id]['local-port'];
83
	$pconfig['descr'] = $a_nat[$id]['descr'];
84
	$pconfig['interface'] = $a_nat[$id]['interface'];
85
	$pconfig['associated-rule-id'] = $a_nat[$id]['associated-rule-id'];
86
	$pconfig['nosync'] = isset($a_nat[$id]['nosync']);
87

    
88
	if (!$pconfig['interface'])
89
		$pconfig['interface'] = "wan";
90
} else {
91
	$pconfig['interface'] = "wan";
92
	$pconfig['src'] = "any";
93
	$pconfig['srcbeginport'] = "any";
94
	$pconfig['srcendport'] = "any";
95
}
96

    
97
if (isset($_GET['dup']))
98
	unset($id);
99

    
100
/*  run through $_POST items encoding HTML entties so that the user
101
 *  cannot think he is slick and perform a XSS attack on the unwilling
102
 */
103
foreach ($_POST as $key => $value) {
104
	$temp = $value;
105
	$newpost = htmlentities($temp);
106
	if($newpost <> $temp)
107
		$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";
108
}
109

    
110
if ($_POST) {
111

    
112
	if(strtoupper($_POST['proto']) == "TCP" || strtoupper($_POST['proto']) == "UDP" || strtoupper($_POST['proto']) == "TCP/UDP") {
113
		if ($_POST['srcbeginport_cust'] && !$_POST['srcbeginport'])
114
			$_POST['srcbeginport'] = $_POST['srcbeginport_cust'];
115
		if ($_POST['srcendport_cust'] && !$_POST['srcendport'])
116
			$_POST['srcendport'] = $_POST['srcendport_cust'];
117

    
118
		if ($_POST['srcbeginport'] == "any") {
119
			$_POST['srcbeginport'] = 0;
120
			$_POST['srcendport'] = 0;
121
		} else {
122
			if (!$_POST['srcendport'])
123
				$_POST['srcendport'] = $_POST['srcbeginport'];
124
		}
125
		if ($_POST['srcendport'] == "any")
126
			$_POST['srcendport'] = $_POST['srcbeginport'];
127

    
128
		if ($_POST['dstbeginport_cust'] && !$_POST['dstbeginport'])
129
			$_POST['dstbeginport'] = $_POST['dstbeginport_cust'];
130
		if ($_POST['dstendport_cust'] && !$_POST['dstendport'])
131
			$_POST['dstendport'] = $_POST['dstendport_cust'];
132

    
133
		if ($_POST['dstbeginport'] == "any") {
134
			$_POST['dstbeginport'] = 0;
135
			$_POST['dstendport'] = 0;
136
		} else {
137
			if (!$_POST['dstendport'])
138
				$_POST['dstendport'] = $_POST['dstbeginport'];
139
		}
140
		if ($_POST['dstendport'] == "any")
141
			$_POST['dstendport'] = $_POST['dstbeginport'];
142

    
143
		if ($_POST['localbeginport_cust'] && !$_POST['localbeginport'])
144
			$_POST['localbeginport'] = $_POST['localbeginport_cust'];
145

    
146
		/* Make beginning port end port if not defined and endport is */
147
		if (!$_POST['srcbeginport'] && $_POST['srcendport'])
148
			$_POST['srcbeginport'] = $_POST['srcendport'];
149
		if (!$_POST['dstbeginport'] && $_POST['dstendport'])
150
			$_POST['dstbeginport'] = $_POST['dstendport'];
151
	} else {
152
		$_POST['srcbeginport'] = 0;
153
		$_POST['srcendport'] = 0;
154
		$_POST['dstbeginport'] = 0;
155
		$_POST['dstendport'] = 0;
156
	}
157

    
158
	if (is_specialnet($_POST['srctype'])) {
159
		$_POST['src'] = $_POST['srctype'];
160
		$_POST['srcmask'] = 0;
161
	} else if ($_POST['srctype'] == "single") {
162
		$_POST['srcmask'] = 32;
163
	}
164
	if (is_specialnet($_POST['dsttype'])) {
165
		$_POST['dst'] = $_POST['dsttype'];
166
		$_POST['dstmask'] = 0;
167
	}  else if ($_POST['dsttype'] == "single") {
168
		$_POST['dstmask'] = 32;
169
	}
170

    
171
	unset($input_errors);
172
	$pconfig = $_POST;
173

    
174
	/* input validation */
175
	if(strtoupper($_POST['proto']) == "TCP" or strtoupper($_POST['proto']) == "UDP" or strtoupper($_POST['proto']) == "TCP/UDP") {
176
		$reqdfields = explode(" ", "interface proto dstbeginport dstendport localip localbeginport");
177
		$reqdfieldsn = explode(",", "Interface,Protocol,Destination port from,Destination port to,NAT IP,Local port");
178
	} else {
179
		$reqdfields = explode(" ", "interface proto localip");
180
		$reqdfieldsn = explode(",", "Interface,Protocol,NAT IP");
181
	}
182

    
183
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
184

    
185
	if (!$_POST['srcbeginport']) {
186
		$_POST['srcbeginport'] = 0;
187
		$_POST['srcendport'] = 0;
188
	}
189
	if (!$_POST['dstbeginport']) {
190
		$_POST['dstbeginport'] = 0;
191
		$_POST['dstendport'] = 0;
192
	}
193

    
194
	if (($_POST['localip'] && !is_ipaddroralias($_POST['localip']))) {
195
		$input_errors[] = "\"{$_POST['localip']}\" is not valid NAT IP address or host alias.";
196
	}
197

    
198
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
199
		$input_errors[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
200
	if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
201
		$input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
202
	if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
203
		$input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
204
	if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
205
		$input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
206

    
207
	if ($_POST['localbeginport'] && !is_portoralias($_POST['localbeginport'])) {
208
		$input_errors[] = "{$_POST['localbeginport']} is not a valid local port. It must be a port alias or integer between 1 and 65535.";
209
	}
210

    
211
	/* if user enters an alias and selects "network" then disallow. */
212
	if($_POST['srctype'] == "network") {
213
		if(is_alias($_POST['src']))
214
			$input_errors[] = "You must specify single host or alias for alias entries.";
215
	}
216
	if($_POST['dsttype'] == "network") {
217
		if(is_alias($_POST['dst']))
218
			$input_errors[] = "You must specify single host or alias for alias entries.";
219
	}
220

    
221
	if (!is_specialnet($_POST['srctype'])) {
222
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
223
			$input_errors[] = "{$_POST['src']} is not a valid source IP address or alias.";
224
		}
225
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
226
			$input_errors[] = "A valid source bit count must be specified.";
227
		}
228
	}
229
	if (!is_specialnet($_POST['dsttype'])) {
230
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
231
			$input_errors[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
232
		}
233
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
234
			$input_errors[] = "A valid destination bit count must be specified.";
235
		}
236
	}
237

    
238
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
239
		/* swap */
240
		$tmp = $_POST['srcendport'];
241
		$_POST['srcendport'] = $_POST['srcbeginport'];
242
		$_POST['srcbeginport'] = $tmp;
243
	}
244
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
245
		/* swap */
246
		$tmp = $_POST['dstendport'];
247
		$_POST['dstendport'] = $_POST['dstbeginport'];
248
		$_POST['dstbeginport'] = $tmp;
249
	}
250

    
251
	if (!$input_errors) {
252
		if (($_POST['dstendport'] - $_POST['dstbeginport'] + $_POST['localbeginport']) > 65535)
253
			$input_errors[] = "The target port range must be an integer between 1 and 65535.";
254
	}
255

    
256
	/* check for overlaps */
257
	foreach ($a_nat as $natent) {
258
		if (isset($id) && ($a_nat[$id]) && ($a_nat[$id] === $natent))
259
			continue;
260
		if ($natent['interface'] != $_POST['interface'])
261
			continue;
262
		if ($natent['destination']['address'] != $_POST['dst'])
263
			continue;
264
		if (($natent['proto'] != $_POST['proto']) && ($natent['proto'] != "tcp/udp") && ($_POST['proto'] != "tcp/udp"))
265
			continue;
266

    
267
		list($begp,$endp) = explode("-", $natent['destination']['port']);
268
		if (!$endp)
269
			$endp = $begp;
270

    
271
		if (!(   (($_POST['beginport'] < $begp) && ($_POST['endport'] < $begp))
272
		      || (($_POST['beginport'] > $endp) && ($_POST['endport'] > $endp)))) {
273

    
274
			$input_errors[] = "The destination port range overlaps with an existing entry.";
275
			break;
276
		}
277
	}
278

    
279
	if (!$input_errors) {
280
		$natent = array();
281

    
282
		$natent['disabled'] = isset($_POST['disabled']) ? true:false;
283
		$natent['nordr'] = isset($_POST['nordr']) ? true:false;
284

    
285
		pconfig_to_address($natent['source'], $_POST['src'],
286
			$_POST['srcmask'], $_POST['srcnot'],
287
			$_POST['srcbeginport'], $_POST['srcendport']);
288

    
289
		pconfig_to_address($natent['destination'], $_POST['dst'],
290
			$_POST['dstmask'], $_POST['dstnot'],
291
			$_POST['dstbeginport'], $_POST['dstendport']);
292

    
293
		$natent['protocol'] = $_POST['proto'];
294

    
295
		$natent['target'] = $_POST['localip'];
296
		$natent['local-port'] = $_POST['localbeginport'];
297
		$natent['interface'] = $_POST['interface'];
298
		$natent['descr'] = $_POST['descr'];
299
		$natent['associated-rule-id'] = $_POST['associated-rule-id'];
300

    
301
		if($_POST['filter-rule-association'] == "pass")
302
			$natent['associated-rule-id'] = "pass";
303

    
304
		if($_POST['nosync'] == "yes")
305
			$natent['nosync'] = true;
306
		else
307
			unset($natent['nosync']);
308

    
309
		// If we used to have an associated filter rule, but no-longer should have one
310
		if ($a_nat[$id]>0 && empty($natent['associated-rule-id'])) {
311
			// Delete the previous rule
312
			delete_id($a_nat[$id]['associated-rule-id'], $config['filter']['rule']);
313
			mark_subsystem_dirty('filter');
314
		}
315

    
316
		$need_filter_rule = false;
317
		// Updating a rule with a filter rule associated
318
		if (!empty($natent['associated-rule-id']))
319
			$need_filter_rule = true;
320
		// Create a rule or if we want to create a new one
321
		if( $natent['associated-rule-id']=='new' ) {
322
			$need_filter_rule = true;
323
			unset( $natent['associated-rule-id'] );
324
			$_POST['filter-rule-association']='add-associated';
325
		}
326
		// If creating a new rule, where we want to add the filter rule, associated or not
327
		else if( isset($_POST['filter-rule-association']) &&
328
			($_POST['filter-rule-association']=='add-associated' ||
329
			$_POST['filter-rule-association']=='add-unassociated') )
330
			$need_filter_rule = true;
331

    
332
		// Determine NAT entry ID now, we need it for the firewall rule
333
		if (isset($id) && $a_nat[$id])
334
			$a_nat[$id] = $natent;
335
		else {
336
			if (is_numeric($after))
337
				$id = $after + 1;
338
			else
339
				$id = count($a_nat);
340
		}
341

    
342
		if ($need_filter_rule == true) {
343

    
344
			/* auto-generate a matching firewall rule */
345
			$filterent = array();
346
			unset($filterentid);
347
			// If a rule already exists, load it
348
			if (!empty($natent['associated-rule-id'])) {
349
				$filterentid = get_id($natent['associated-rule-id'], $config['filter']['rule']);
350
				if ($filterentid == false) {
351
					pconfig_to_address($filterent['source'], $_POST['src'],
352
						$_POST['srcmask'], $_POST['srcnot'],
353
						$_POST['srcbeginport'], $_POST['srcendport']);
354
					$filterent['associated-rule-id'] = $natent['associated-rule-id'];
355
				} else
356
					$filterent =& $config['filter']['rule'][$filterentid];
357
			} else
358
				pconfig_to_address($filterent['source'], $_POST['src'],
359
					$_POST['srcmask'], $_POST['srcnot'],
360
					$_POST['srcbeginport'], $_POST['srcendport']);
361

    
362
			// Update interface, protocol and destination
363
			$filterent['interface'] = $_POST['interface'];
364
			$filterent['protocol'] = $_POST['proto'];
365
			$filterent['destination']['address'] = $_POST['localip'];
366

    
367
			$dstpfrom = $_POST['localbeginport'];
368
			$dstpto = $dstpfrom + $_POST['endport'] - $_POST['beginport'];
369

    
370
			if ($dstpfrom == $dstpto)
371
				$filterent['destination']['port'] = $dstpfrom;
372
			else
373
				$filterent['destination']['port'] = $dstpfrom . "-" . $dstpto;
374

    
375
			/*
376
			 * Our firewall filter description may be no longer than
377
			 * 63 characters, so don't let it be.
378
			 */
379
			$filterent['descr'] = substr("NAT " . $_POST['descr'], 0, 62);
380

    
381
			// If this is a new rule, create an ID and add the rule
382
			if( $_POST['filter-rule-association']=='add-associated' ) {
383
				$filterent['associated-rule-id'] = $natent['associated-rule-id'] = get_unique_id();
384
				$config['filter']['rule'][] = $filterent;
385
			}
386

    
387
			mark_subsystem_dirty('filter');
388
		}
389

    
390
		// Update the NAT entry now
391
		if (isset($id) && $a_nat[$id])
392
			$a_nat[$id] = $natent;
393
		else {
394
			if (is_numeric($after))
395
				array_splice($a_nat, $after+1, 0, array($natent));
396
			else
397
				$a_nat[] = $natent;
398
		}
399

    
400
		mark_subsystem_dirty('natconf');
401

    
402
		write_config();
403

    
404
		header("Location: firewall_nat.php");
405
		exit;
406
	}
407
}
408

    
409
$pgtitle = array("Firewall","NAT","Port Forward: Edit");
410
include("head.inc");
411

    
412
?>
413

    
414
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
415
<?php
416
include("fbegin.inc"); ?>
417
<?php if ($input_errors) print_input_errors($input_errors); ?>
418
            <form action="firewall_nat_edit.php" method="post" name="iform" id="iform">
419
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
420
				<tr>
421
					<td colspan="2" valign="top" class="listtopic">Edit NAT entry</td>
422
				</tr>
423
		<tr>
424
			<td width="22%" valign="top" class="vncellreq">Disabled</td>
425
			<td width="78%" class="vtable">
426
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
427
				<strong>Disable this rule</strong><br />
428
				<span class="vexpl">Set this option to disable this rule without removing it from the list.</span>
429
			</td>
430
		</tr>
431
                <tr>
432
                  <td width="22%" valign="top" class="vncell">No RDR (NOT)</td>
433
                  <td width="78%" class="vtable">
434
                    <input type="checkbox" name="nordr"<?php if($pconfig['nordr']) echo " CHECKED"; ?>>
435
                    <span class="vexpl">Enabling this option will disable NATing for the item and stop processing outgoing NAT rules.
436
                    <br>Hint: this option is rarely needed, don't use this unless you know what you're doing.</span>
437
                  </td>
438
                </tr>
439
		<tr>
440
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
441
                  <td width="78%" class="vtable">
442
					<select name="interface" class="formselect">
443
						<?php
444

    
445
						$iflist = get_configured_interface_with_descr(false, true);
446
						foreach ($iflist as $if => $ifdesc)
447
							if(have_ruleint_access($if))
448
								$interfaces[$if] = $ifdesc;
449

    
450
						if ($config['pptpd']['mode'] == "server")
451
							if(have_ruleint_access("pptp"))
452
								$interfaces['pptp'] = "PPTP VPN";
453

    
454
						if ($config['pppoe']['mode'] == "server")
455
							if(have_ruleint_access("pppoe"))
456
								$interfaces['pppoe'] = "PPPoE VPN";
457

    
458
						/* add ipsec interfaces */
459
						if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
460
							if(have_ruleint_access("enc0"))
461
								$interfaces["enc0"] = "IPsec";
462

    
463
						foreach ($interfaces as $iface => $ifacename): ?>
464
						<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
465
						<?=htmlspecialchars($ifacename);?>
466
						</option>
467
						<?php endforeach; ?>
468
					</select><br>
469
                     <span class="vexpl">Choose which interface this rule applies to.<br>
470
                     Hint: in most cases, you'll want to use WAN here.</span></td>
471
                </tr>
472
                <tr>
473
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
474
                  <td width="78%" class="vtable">
475
                    <select name="proto" class="formselect" onChange="proto_change(); check_for_aliases();">
476
                      <?php $protocols = explode(" ", "TCP UDP TCP/UDP GRE ESP"); foreach ($protocols as $proto): ?>
477
                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
478
                      <?php endforeach; ?>
479
                    </select> <br> <span class="vexpl">Choose which IP protocol
480
                    this rule should match.<br>
481
                    Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span></td>
482
                </tr>
483
		<tr id="showadvancedboxsrc" name="showadvancedboxsrc">
484
			<td width="22%" valign="top" class="vncellreq">Source</td>
485
			<td width="78%" class="vtable">
486
				<input type="button" onClick="show_source()" value="Advanced"></input> - Show source address and port range</a>
487
			</td>
488
		</tr>
489
		<tr style="display: none;" id="srctable" name="srctable">
490
			<td width="22%" valign="top" class="vncellreq">Source</td>
491
			<td width="78%" class="vtable">
492
				<input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked"; ?>>
493
				<strong>not</strong>
494
				<br />
495
				Use this option to invert the sense of the match.
496
				<br />
497
				<br />
498
				<table border="0" cellspacing="0" cellpadding="0">
499
					<tr>
500
						<td>Type:&nbsp;&nbsp;</td>
501
						<td>
502
							<select name="srctype" class="formselect" onChange="typesel_change()">
503
<?php
504
								$sel = is_specialnet($pconfig['src']); ?>
505
								<option value="any"     <?php if ($pconfig['src'] == "any") { echo "selected"; } ?>>any</option>
506
								<option value="single"  <?php if (($pconfig['srcmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
507
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
508
								<?php if(have_ruleint_access("pptp")): ?>
509
								<option value="pptp"    <?php if ($pconfig['src'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
510
								<?php endif; ?>
511
								<?php if(have_ruleint_access("pppoe")): ?>
512
								<option value="pppoe"   <?php if ($pconfig['src'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
513
								<?php endif; ?>
514
								 <?php if(have_ruleint_access("l2tp")): ?>
515
                                                                <option value="l2tp"   <?php if ($pconfig['src'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
516
                                                                <?php endif; ?>
517
<?php
518
								foreach ($ifdisp as $ifent => $ifdesc): ?>
519
								<?php if(have_ruleint_access($ifent)): ?>
520
									<option value="<?=$ifent;?>" <?php if ($pconfig['src'] == $ifent) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
521
									<option value="<?=$ifent;?>ip"<?php if ($pconfig['src'] ==  $ifent . "ip") { echo "selected"; } ?>>
522
										<?=$ifdesc?> address
523
									</option>
524
								<?php endif; ?>
525
<?php 							endforeach; ?>
526
							</select>
527
						</td>
528
					</tr>
529
					<tr>
530
						<td>Address:&nbsp;&nbsp;</td>
531
						<td>
532
							<input autocomplete='off' name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>"> /
533
							<select name="srcmask" class="formselect" id="srcmask">
534
<?php						for ($i = 31; $i > 0; $i--): ?>
535
								<option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected"; ?>><?=$i;?></option>
536
<?php 						endfor; ?>
537
							</select>
538
						</td>
539
					</tr>
540
				</table>
541
			</td>
542
		</tr>
543
		<tr style="display:none" id="sprtable" name="sprtable">
544
			<td width="22%" valign="top" class="vncellreq">Source port range</td>
545
			<td width="78%" class="vtable">
546
				<table border="0" cellspacing="0" cellpadding="0">
547
					<tr>
548
						<td>from:&nbsp;&nbsp;</td>
549
						<td>
550
							<select name="srcbeginport" class="formselect" onchange="src_rep_change();ext_change()">
551
								<option value="">(other)</option>
552
								<option value="any" <?php $bfound = 0; if ($pconfig['srcbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
553
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
554
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcbeginport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
555
<?php 							endforeach; ?>
556
							</select>
557
							<input autocomplete='off' class="formfldalias" name="srcbeginport_cust" id="srcbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcbeginport']) echo $pconfig['srcbeginport']; ?>">
558
						</td>
559
					</tr>
560
					<tr>
561
						<td>to:</td>
562
						<td>
563
							<select name="srcendport" class="formselect" onchange="ext_change()">
564
								<option value="">(other)</option>
565
								<option value="any" <?php $bfound = 0; if ($pconfig['srcendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
566
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
567
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['srcendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
568
<?php							endforeach; ?>
569
							</select>
570
							<input autocomplete='off' class="formfldalias" name="srcendport_cust" id="srcendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['srcendport']) echo $pconfig['srcendport']; ?>">
571
						</td>
572
					</tr>
573
				</table>
574
				<br />
575
				<span class="vexpl">Specify the source port or port range for this rule. <b>This is almost never equal to the destination port range (and is usually &quot;any&quot;)</b>. <br /> Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port</span><br/>
576
			</td>
577
		</tr>
578
		<tr>
579
			<td width="22%" valign="top" class="vncellreq">Destination</td>
580
			<td width="78%" class="vtable">
581
				<input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked"; ?>>
582
				<strong>not</strong>
583
					<br />
584
				Use this option to invert the sense of the match.
585
					<br />
586
					<br />
587
				<table border="0" cellspacing="0" cellpadding="0">
588
					<tr>
589
						<td>Type:&nbsp;&nbsp;</td>
590
						<td>
591
							<select name="dsttype" class="formselect" onChange="typesel_change()">
592
<?php
593
								$sel = is_specialnet($pconfig['dst']); ?>
594
								<option value="any" <?php if ($pconfig['dst'] == "any") { echo "selected"; } ?>>any</option>
595
								<option value="single" <?php if (($pconfig['dstmask'] == 32) && !$sel) { echo "selected"; $sel = 1; } ?>>Single host or alias</option>
596
								<option value="network" <?php if (!$sel) echo "selected"; ?>>Network</option>
597
								<?php if(have_ruleint_access("pptp")): ?>
598
								<option value="pptp" <?php if ($pconfig['dst'] == "pptp") { echo "selected"; } ?>>PPTP clients</option>
599
								<?php endif; ?>
600
								<?php if(have_ruleint_access("pppoe")): ?>
601
								<option value="pppoe" <?php if ($pconfig['dst'] == "pppoe") { echo "selected"; } ?>>PPPoE clients</option>
602
								<?php endif; ?>
603
								<?php if(have_ruleint_access("l2tp")): ?>
604
                                                                <option value="l2tp" <?php if ($pconfig['dst'] == "l2tp") { echo "selected"; } ?>>L2TP clients</option>
605
                                                                <?php endif; ?>
606

    
607
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
608
								<?php if(have_ruleint_access($if)): ?>
609
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
610
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
611
										<?=$ifdesc;?> address
612
									</option>
613
								<?php endif; ?>
614
<?php 							endforeach; ?>
615
							</select>
616
						</td>
617
					</tr>
618
					<tr>
619
						<td>Address:&nbsp;&nbsp;</td>
620
						<td>
621
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
622
							/
623
							<select name="dstmask" class="formselect" id="dstmask">
624
<?php
625
							for ($i = 31; $i > 0; $i--): ?>
626
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
627
<?php						endfor; ?>
628
							</select>
629
						</td>
630
					</tr>
631
				</table>
632
			</td>
633
		</tr>
634
		<tr id="dprtr" name="dprtr">
635
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
636
			<td width="78%" class="vtable">
637
				<table border="0" cellspacing="0" cellpadding="0">
638
					<tr>
639
						<td>from:&nbsp;&nbsp;</td>
640
						<td>
641
							<select name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
642
								<option value="">(other)</option>
643
								<option value="any" <?php $bfound = 0; if ($pconfig['dstbeginport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
644
<?php 							foreach ($wkports as $wkport => $wkportdesc): ?>
645
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
646
<?php 							endforeach; ?>
647
							</select>
648
							<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
649
						</td>
650
					</tr>
651
					<tr>
652
						<td>to:</td>
653
						<td>
654
							<select name="dstendport" class="formselect" onchange="ext_change()">
655
								<option value="">(other)</option>
656
								<option value="any" <?php $bfound = 0; if ($pconfig['dstendport'] == "any") { echo "selected"; $bfound = 1; } ?>>any</option>
657
<?php							foreach ($wkports as $wkport => $wkportdesc): ?>
658
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
659
<?php 							endforeach; ?>
660
							</select>
661
							<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
662
						</td>
663
					</tr>
664
				</table>
665
				<br />
666
				<span class="vexpl">
667
					Specify the port or port range for the destination of the packet for this rule.
668
					<br />
669
					Hint: you can leave the <em>'to'</em> field empty if you only want to filter a single port
670
				</span>
671
			</td>
672
		</tr>
673
                <tr>
674
                  <td width="22%" valign="top" class="vncellreq">NAT IP</td>
675
                  <td width="78%" class="vtable">
676
                    <input autocomplete='off' name="localip" type="text" class="formfldalias" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>">
677
                    <br> <span class="vexpl">Enter the internal IP address of
678
                    the server on which you want to map the ports.<br>
679
                    e.g. <em>192.168.1.12</em></span></td>
680
                </tr>
681
                <tr>
682
                  <td width="22%" valign="top" class="vncellreq">Local port</td>
683
                  <td width="78%" class="vtable">
684
                    <select name="localbeginport" class="formselect" onChange="ext_change();check_for_aliases();">
685
                      <option value="">(other)</option>
686
                      <?php $bfound = 0; foreach ($wkports as $wkport => $wkportdesc): ?>
687
                      <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['localbeginport']) {
688
							echo "selected";
689
							$bfound = 1;
690
						}?>>
691
					  <?=htmlspecialchars($wkportdesc);?>
692
					  </option>
693
                      <?php endforeach; ?>
694
                    </select> <input onChange="check_for_aliases();" autocomplete='off' class="formfldalias" name="localbeginport_cust" id="localbeginport_cust" type="text" size="5" value="<?php if (!$bfound) echo $pconfig['localbeginport']; ?>">
695
                    <br>
696
                    <span class="vexpl">Specify the port on the machine with the
697
                    IP address entered above. In case of a port range, specify
698
                    the beginning port of the range (the end port will be calculated
699
                    automatically).<br>
700
                    Hint: this is usually identical to the 'from' port above</span></td>
701
                </tr>
702
                <tr>
703
                  <td width="22%" valign="top" class="vncell">Description</td>
704
                  <td width="78%" class="vtable">
705
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
706
                    <br> <span class="vexpl">You may enter a description here
707
                    for your reference (not parsed).</span></td>
708
                </tr>
709
				<tr>
710
					<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
711
					<td width="78%" class="vtable">
712
						<input type="checkbox" value="yes" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
713
						HINT: This prevents the rule from automatically syncing to other CARP members.
714
					</td>
715
				</tr>
716
				<?php if (isset($id) && $a_nat[$id] && !isset($_GET['dup'])): ?>
717
				<tr>
718
					<td width="22%" valign="top" class="vncell">Filter rule association</td>
719
					<td width="78%" class="vtable">
720
						<select name="associated-rule-id">
721
							<option value="">None</option>
722
							<option value="pass" <?php if($pconfig['associated-rule-id'] == "pass") echo " SELECTED"; ?>>Pass</option>
723
							<?php
724
							$linkedrule = "";
725
							if (is_array($config['filter']['rule'])) {
726
								$filter_id = 0;
727
							      foreach ($config['filter']['rule'] as $filter_rule) {
728
								if (isset($filter_rule['associated-rule-id'])) {
729
									echo "<option value=\"{$filter_rule['associated-rule-id']}\"";
730
									if ($filter_rule['associated-rule-id']==$pconfig['associated-rule-id']) {
731
										echo " SELECTED";
732
										$linkedrule = "<br /><a href=\"firewall_rules_edit.php?id={$filter_id}\">View the filter rule</a><br/>";
733
									}
734
									echo ">". htmlspecialchars('Rule ' . $filter_rule['descr']) . "</option>\n";
735

    
736
								}
737
								if ($filter_rule['interface'] == $pconfig['interface'])
738
									$filter_id++;
739
							      }
740
							}
741
							if (isset($pconfig['associated-rule-id']))
742
								echo "<option value=\"new\">Create new associated filter rule</option>\n";
743
						echo "</select>\n";
744
						echo $linkedrule;
745
						?>
746
					</td>
747
				</tr>
748
				<?php endif; ?>
749
                <?php if ((!(isset($id) && $a_nat[$id])) || (isset($_GET['dup']))): ?>
750
                <tr>
751
                  <td width="22%" valign="top" class="vncell">Filter rule association</td>
752
                  <td width="78%" class="vtable">
753
                    <select name="filter-rule-association" id="filter-rule-association">
754
						<option value="">None</option>
755
						<option value="add-associated" selected="selected">Add associated filter rule</option>
756
						<option value="add-unassociated">Add unassociated filter rule</option>
757
						<option value="pass">Pass</option>
758
					</select>
759
				  </td>
760
                </tr><?php endif; ?>
761
				<tr>
762
                  <td width="22%" valign="top">&nbsp;</td>
763
                  <td width="78%">&nbsp;</td>
764
				</tr>
765
                <tr>
766
                  <td width="22%" valign="top">&nbsp;</td>
767
                  <td width="78%">
768
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
769
                    <?php if (isset($id) && $a_nat[$id]): ?>
770
                    <input name="id" type="hidden" value="<?=$id;?>">
771
                    <?php endif; ?>
772
                  </td>
773
                </tr>
774
              </table>
775
</form>
776
<script language="JavaScript">
777
<!--
778
	ext_change();
779
	typesel_change();
780
	proto_change();
781
//-->
782
</script>
783
<?php
784
$isfirst = 0;
785
$aliases = "";
786
$addrisfirst = 0;
787
$aliasesaddr = "";
788
if($config['aliases']['alias'] <> "")
789
	foreach($config['aliases']['alias'] as $alias_name) {
790
		switch ($alias_name['type']) {
791
                        case "port":
792
                                if($isfirst == 1) $portaliases .= ",";
793
                                $portaliases .= "'" . $alias_name['name'] . "'";
794
                                $isfirst = 1;
795
                                break;
796
                        case "host":
797
                        case "network":
798
                        case "openvpn":
799
                                if($addrisfirst == 1) $aliasesaddr .= ",";
800
                                $aliasesaddr .= "'" . $alias_name['name'] . "'";
801
                                $addrisfirst = 1;
802
                                break;
803
                        default:
804
                                break;
805
		}
806
	}
807
?>
808
<script language="JavaScript">
809
<!--
810
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
811
	var customarray=new Array(<?php echo $portaliases; ?>);
812

    
813
	var oTextbox1 = new AutoSuggestControl(document.getElementById("localip"), new StateSuggestions(addressarray));
814
        var oTextbox2 = new AutoSuggestControl(document.getElementById("beginport_cust"), new StateSuggestions(customarray));
815
        var oTextbox3 = new AutoSuggestControl(document.getElementById("endport_cust"), new StateSuggestions(customarray));
816
        var oTextbox4 = new AutoSuggestControl(document.getElementById("localbeginport_cust"), new StateSuggestions(customarray));
817
//-->
818
</script>
819
<?php include("fend.inc"); ?>
820
</body>
821
</html>
(52-52/216)