Project

General

Profile

Download (37.1 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
	$pconfig['natreflection'] = $a_nat[$id]['natreflection'];
88

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

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

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

    
111
if ($_POST) {
112

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

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

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

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

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

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

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

    
176
	unset($input_errors);
177
	$pconfig = $_POST;
178

    
179
	/* input validation */
180
	if(strtoupper($_POST['proto']) == "TCP" or strtoupper($_POST['proto']) == "UDP" or strtoupper($_POST['proto']) == "TCP/UDP") {
181
		$reqdfields = explode(" ", "interface proto dstbeginport dstendport localip");
182
		$reqdfieldsn = explode(",", "Interface,Protocol,Destination port from,Destination port to,NAT IP");
183
	} else {
184
		$reqdfields = explode(" ", "interface proto localip");
185
		$reqdfieldsn = explode(",", "Interface,Protocol,NAT IP");
186
	}
187

    
188
	if ($_POST['srctype'] == "single" || $_POST['srctype'] == "network") {
189
		$reqdfields[] = "src";
190
		$reqdfieldsn[] = "Source address";
191
	}
192
	if ($_POST['dsttype'] == "single" || $_POST['dsttype'] == "network") {
193
		$reqdfields[] = "dst";
194
		$reqdfieldsn[] = "Destination address";
195
	}
196

    
197
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
198

    
199
	if (!$_POST['srcbeginport']) {
200
		$_POST['srcbeginport'] = 0;
201
		$_POST['srcendport'] = 0;
202
	}
203
	if (!$_POST['dstbeginport']) {
204
		$_POST['dstbeginport'] = 0;
205
		$_POST['dstendport'] = 0;
206
	}
207

    
208
	if (($_POST['localip'] && !is_ipaddroralias($_POST['localip']))) {
209
		$input_errors[] = "\"{$_POST['localip']}\" is not valid NAT IP address or host alias.";
210
	}
211

    
212
	if ($_POST['srcbeginport'] && !is_portoralias($_POST['srcbeginport']))
213
		$input_errors[] = "{$_POST['srcbeginport']} is not a valid start source port. It must be a port alias or integer between 1 and 65535.";
214
	if ($_POST['srcendport'] && !is_portoralias($_POST['srcendport']))
215
		$input_errors[] = "{$_POST['srcendport']} is not a valid end source port. It must be a port alias or integer between 1 and 65535.";
216
	if ($_POST['dstbeginport'] && !is_portoralias($_POST['dstbeginport']))
217
		$input_errors[] = "{$_POST['dstbeginport']} is not a valid start destination port. It must be a port alias or integer between 1 and 65535.";
218
	if ($_POST['dstendport'] && !is_portoralias($_POST['dstendport']))
219
		$input_errors[] = "{$_POST['dstendport']} is not a valid end destination port. It must be a port alias or integer between 1 and 65535.";
220

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

    
225
	/* if user enters an alias and selects "network" then disallow. */
226
	if( ($_POST['srctype'] == "network" && is_alias($_POST['src']) ) 
227
	 || ($_POST['dsttype'] == "network" && is_alias($_POST['dst']) ) ) {
228
		$input_errors[] = "You must specify single host or alias for alias entries.";
229
	}
230

    
231
	if (!is_specialnet($_POST['srctype'])) {
232
		if (($_POST['src'] && !is_ipaddroralias($_POST['src']))) {
233
			$input_errors[] = "{$_POST['src']} is not a valid source IP address or alias.";
234
		}
235
		if (($_POST['srcmask'] && !is_numericint($_POST['srcmask']))) {
236
			$input_errors[] = "A valid source bit count must be specified.";
237
		}
238
	}
239
	if (!is_specialnet($_POST['dsttype'])) {
240
		if (($_POST['dst'] && !is_ipaddroralias($_POST['dst']))) {
241
			$input_errors[] = "{$_POST['dst']} is not a valid destination IP address or alias.";
242
		}
243
		if (($_POST['dstmask'] && !is_numericint($_POST['dstmask']))) {
244
			$input_errors[] = "A valid destination bit count must be specified.";
245
		}
246
	}
247

    
248
	if ($_POST['srcbeginport'] > $_POST['srcendport']) {
249
		/* swap */
250
		$tmp = $_POST['srcendport'];
251
		$_POST['srcendport'] = $_POST['srcbeginport'];
252
		$_POST['srcbeginport'] = $tmp;
253
	}
254
	if ($_POST['dstbeginport'] > $_POST['dstendport']) {
255
		/* swap */
256
		$tmp = $_POST['dstendport'];
257
		$_POST['dstendport'] = $_POST['dstbeginport'];
258
		$_POST['dstbeginport'] = $tmp;
259
	}
260

    
261
	if (!$input_errors) {
262
		if (($_POST['dstendport'] - $_POST['dstbeginport'] + $_POST['localbeginport']) > 65535)
263
			$input_errors[] = "The target port range must be an integer between 1 and 65535.";
264
	}
265

    
266
	/* check for overlaps */
267
	foreach ($a_nat as $natent) {
268
		if (isset($id) && ($a_nat[$id]) && ($a_nat[$id] === $natent))
269
			continue;
270
		if ($natent['interface'] != $_POST['interface'])
271
			continue;
272
		if ($natent['destination']['address'] != $_POST['dst'])
273
			continue;
274
		if (($natent['proto'] != $_POST['proto']) && ($natent['proto'] != "tcp/udp") && ($_POST['proto'] != "tcp/udp"))
275
			continue;
276

    
277
		list($begp,$endp) = explode("-", $natent['destination']['port']);
278
		if (!$endp)
279
			$endp = $begp;
280

    
281
		if (!(   (($_POST['beginport'] < $begp) && ($_POST['endport'] < $begp))
282
		      || (($_POST['beginport'] > $endp) && ($_POST['endport'] > $endp)))) {
283

    
284
			$input_errors[] = "The destination port range overlaps with an existing entry.";
285
			break;
286
		}
287
	}
288

    
289
	if (!$input_errors) {
290
		$natent = array();
291

    
292
		$natent['disabled'] = isset($_POST['disabled']) ? true:false;
293
		$natent['nordr'] = isset($_POST['nordr']) ? true:false;
294

    
295
		pconfig_to_address($natent['source'], $_POST['src'],
296
			$_POST['srcmask'], $_POST['srcnot'],
297
			$_POST['srcbeginport'], $_POST['srcendport']);
298

    
299
		pconfig_to_address($natent['destination'], $_POST['dst'],
300
			$_POST['dstmask'], $_POST['dstnot'],
301
			$_POST['dstbeginport'], $_POST['dstendport']);
302

    
303
		$natent['protocol'] = $_POST['proto'];
304

    
305
		$natent['target'] = $_POST['localip'];
306
		$natent['local-port'] = $_POST['localbeginport'];
307
		$natent['interface'] = $_POST['interface'];
308
		$natent['descr'] = $_POST['descr'];
309
		$natent['associated-rule-id'] = $_POST['associated-rule-id'];
310

    
311
		if($_POST['filter-rule-association'] == "pass")
312
			$natent['associated-rule-id'] = "pass";
313

    
314
		if($_POST['nosync'] == "yes")
315
			$natent['nosync'] = true;
316
		else
317
			unset($natent['nosync']);
318

    
319
		if ($_POST['natreflection'] == "enable" || $_POST['natreflection'] == "disable")
320
			$natent['natreflection'] = $_POST['natreflection'];
321
		else
322
			unset($natent['natreflection']);
323

    
324
		// If we used to have an associated filter rule, but no-longer should have one
325
		if (!empty($a_nat[$id]) && ( empty($natent['associated-rule-id']) || $natent['associated-rule-id'] != $a_nat[$id]['associated-rule-id'] ) ) {
326
			// Delete the previous rule
327
			delete_id($a_nat[$id]['associated-rule-id'], $config['filter']['rule']);
328
			mark_subsystem_dirty('filter');
329
		}
330

    
331
		$need_filter_rule = false;
332
		// Updating a rule with a filter rule associated
333
		if (!empty($natent['associated-rule-id']))
334
			$need_filter_rule = true;
335
		// Create a rule or if we want to create a new one
336
		if( $natent['associated-rule-id']=='new' ) {
337
			$need_filter_rule = true;
338
			unset( $natent['associated-rule-id'] );
339
			$_POST['filter-rule-association']='add-associated';
340
		}
341
		// If creating a new rule, where we want to add the filter rule, associated or not
342
		else if( isset($_POST['filter-rule-association']) &&
343
			($_POST['filter-rule-association']=='add-associated' ||
344
			$_POST['filter-rule-association']=='add-unassociated') )
345
			$need_filter_rule = true;
346

    
347
		// Determine NAT entry ID now, we need it for the firewall rule
348
		if (isset($id) && $a_nat[$id])
349
			$a_nat[$id] = $natent;
350
		else {
351
			if (is_numeric($after))
352
				$id = $after + 1;
353
			else
354
				$id = count($a_nat);
355
		}
356

    
357
		if ($need_filter_rule == true) {
358

    
359
			/* auto-generate a matching firewall rule */
360
			$filterent = array();
361
			unset($filterentid);
362
			// If a rule already exists, load it
363
			if (!empty($natent['associated-rule-id'])) {
364
				$filterentid = get_id($natent['associated-rule-id'], $config['filter']['rule']);
365
				if ($filterentid == false) {
366
					pconfig_to_address($filterent['source'], $_POST['src'],
367
						$_POST['srcmask'], $_POST['srcnot'],
368
						$_POST['srcbeginport'], $_POST['srcendport']);
369
					$filterent['associated-rule-id'] = $natent['associated-rule-id'];
370
				} else
371
					$filterent =& $config['filter']['rule'][$filterentid];
372
			} else
373
				pconfig_to_address($filterent['source'], $_POST['src'],
374
					$_POST['srcmask'], $_POST['srcnot'],
375
					$_POST['srcbeginport'], $_POST['srcendport']);
376

    
377
			// Update interface, protocol and destination
378
			$filterent['interface'] = $_POST['interface'];
379
			$filterent['protocol'] = $_POST['proto'];
380
			$filterent['destination']['address'] = $_POST['localip'];
381

    
382
			$dstpfrom = $_POST['localbeginport'];
383
			$dstpto = $dstpfrom + $_POST['dstendport'] - $_POST['dstbeginport'];
384

    
385
			if ($dstpfrom == $dstpto)
386
				$filterent['destination']['port'] = $dstpfrom;
387
			else
388
				$filterent['destination']['port'] = $dstpfrom . "-" . $dstpto;
389

    
390
			/*
391
			 * Our firewall filter description may be no longer than
392
			 * 63 characters, so don't let it be.
393
			 */
394
			$filterent['descr'] = substr("NAT " . $_POST['descr'], 0, 62);
395

    
396
			// If this is a new rule, create an ID and add the rule
397
			if( $_POST['filter-rule-association']=='add-associated' ) {
398
				$filterent['associated-rule-id'] = $natent['associated-rule-id'] = get_unique_id();
399
				$config['filter']['rule'][] = $filterent;
400
			}
401

    
402
			mark_subsystem_dirty('filter');
403
		}
404

    
405
		// Update the NAT entry now
406
		if (isset($id) && $a_nat[$id])
407
			$a_nat[$id] = $natent;
408
		else {
409
			if (is_numeric($after))
410
				array_splice($a_nat, $after+1, 0, array($natent));
411
			else
412
				$a_nat[] = $natent;
413
		}
414

    
415
		mark_subsystem_dirty('natconf');
416

    
417
		write_config();
418

    
419
		header("Location: firewall_nat.php");
420
		exit;
421
	}
422
}
423

    
424
$pgtitle = array("Firewall","NAT","Port Forward: Edit");
425
include("head.inc");
426

    
427
?>
428

    
429
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
430
<?php
431
include("fbegin.inc"); ?>
432
<?php if ($input_errors) print_input_errors($input_errors); ?>
433
            <form action="firewall_nat_edit.php" method="post" name="iform" id="iform">
434
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
435
				<tr>
436
					<td colspan="2" valign="top" class="listtopic">Edit Redirect entry</td>
437
				</tr>
438
		<tr>
439
			<td width="22%" valign="top" class="vncellreq">Disabled</td>
440
			<td width="78%" class="vtable">
441
				<input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked"; ?>>
442
				<strong>Disable this rule</strong><br />
443
				<span class="vexpl">Set this option to disable this rule without removing it from the list.</span>
444
			</td>
445
		</tr>
446
                <tr>
447
                  <td width="22%" valign="top" class="vncell">No RDR (NOT)</td>
448
                  <td width="78%" class="vtable">
449
                    <input type="checkbox" name="nordr"<?php if($pconfig['nordr']) echo " CHECKED"; ?>>
450
                    <span class="vexpl">Enabling this option will disable redirection for traffic matching this rule.
451
                    <br>Hint: this option is rarely needed, don't use this unless you know what you're doing.</span>
452
                  </td>
453
                </tr>
454
		<tr>
455
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
456
                  <td width="78%" class="vtable">
457
					<select name="interface" class="formselect" onChange="dst_change(this.value,iface_old,document.iform.dsttype.value);iface_old = document.iform.interface.value;typesel_change();">
458
						<?php
459

    
460
						$iflist = get_configured_interface_with_descr(false, true);
461
						foreach ($iflist as $if => $ifdesc)
462
							if(have_ruleint_access($if))
463
								$interfaces[$if] = $ifdesc;
464

    
465
						if ($config['l2tp']['mode'] == "server")
466
							if(have_ruleint_access("l2tp"))
467
								$interfaces['l2tp'] = "L2TP VPN";
468

    
469
						if ($config['pptpd']['mode'] == "server")
470
							if(have_ruleint_access("pptp"))
471
								$interfaces['pptp'] = "PPTP VPN";
472

    
473
						if ($config['pppoe']['mode'] == "server")
474
							if(have_ruleint_access("pppoe"))
475
								$interfaces['pppoe'] = "PPPoE VPN";
476

    
477
						/* add ipsec interfaces */
478
						if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
479
							if(have_ruleint_access("enc0"))
480
								$interfaces["enc0"] = "IPsec";
481

    
482
						/* add openvpn/tun interfaces */
483
						if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
484
							$interfaces["openvpn"] = "OpenVPN";
485

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

    
630
<?php 							foreach ($ifdisp as $if => $ifdesc): ?>
631
								<?php if(have_ruleint_access($if)): ?>
632
									<option value="<?=$if;?>" <?php if ($pconfig['dst'] == $if) { echo "selected"; } ?>><?=htmlspecialchars($ifdesc);?> subnet</option>
633
									<option value="<?=$if;?>ip"<?php if ($pconfig['dst'] == $if . "ip") { echo "selected"; } ?>>
634
										<?=$ifdesc;?> address
635
									</option>
636
								<?php endif; ?>
637
<?php 							endforeach; ?>
638

    
639
<?php							if (is_array($config['virtualip']['vip'])):
640
									foreach ($config['virtualip']['vip'] as $sn):
641
										if ($sn['mode'] == "proxyarp" && $sn['type'] == "network"):
642
											$start = ip2long32(gen_subnet($sn['subnet'], $sn['subnet_bits']));
643
											$end = ip2long32(gen_subnet_max($sn['subnet'], $sn['subnet_bits']));
644
											$len = $end - $start;
645
											for ($i = 0; $i <= $len; $i++):
646
												$snip = long2ip32($start+$i);
647
?>
648
												<option value="<?=$snip;?>" <?php if ($snip == $pconfig['dst']) echo "selected"; ?>><?=htmlspecialchars("{$snip} ({$sn['descr']})");?></option>
649
<?php										endfor;
650
										else:
651
?>
652
											<option value="<?=$sn['subnet'];?>" <?php if ($sn['subnet'] == $pconfig['dst']) echo "selected"; ?>><?=htmlspecialchars("{$sn['subnet']} ({$sn['descr']})");?></option>
653
<?php									endif;
654
									endforeach;
655
								endif;
656
?>
657
							</select>
658
						</td>
659
					</tr>
660
					<tr>
661
						<td>Address:&nbsp;&nbsp;</td>
662
						<td>
663
							<input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>">
664
							/
665
							<select name="dstmask" class="formselect" id="dstmask">
666
<?php
667
							for ($i = 31; $i > 0; $i--): ?>
668
								<option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected"; ?>><?=$i;?></option>
669
<?php						endfor; ?>
670
							</select>
671
						</td>
672
					</tr>
673
				</table>
674
			</td>
675
		</tr>
676
		<tr id="dprtr" name="dprtr">
677
			<td width="22%" valign="top" class="vncellreq">Destination port range </td>
678
			<td width="78%" class="vtable">
679
				<table border="0" cellspacing="0" cellpadding="0">
680
					<tr>
681
						<td>from:&nbsp;&nbsp;</td>
682
						<td>
683
							<select name="dstbeginport" class="formselect" onchange="dst_rep_change();ext_change()">
684
								<option value="">(other)</option>
685
<?php 							$bfound = 0;
686
								foreach ($wkports as $wkport => $wkportdesc): ?>
687
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstbeginport']) { echo "selected"; $bfound = 1; }?>><?=htmlspecialchars($wkportdesc);?></option>
688
<?php 							endforeach; ?>
689
							</select>
690
							<input autocomplete='off' class="formfldalias" name="dstbeginport_cust" id="dstbeginport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstbeginport']) echo $pconfig['dstbeginport']; ?>">
691
						</td>
692
					</tr>
693
					<tr>
694
						<td>to:</td>
695
						<td>
696
							<select name="dstendport" class="formselect" onchange="ext_change()">
697
								<option value="">(other)</option>
698
<?php							$bfound = 0;
699
								foreach ($wkports as $wkport => $wkportdesc): ?>
700
									<option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['dstendport']) { echo "selected"; $bfound = 1; } ?>><?=htmlspecialchars($wkportdesc);?></option>
701
<?php 							endforeach; ?>
702
							</select>
703
							<input autocomplete='off' class="formfldalias" name="dstendport_cust" id="dstendport_cust" type="text" size="5" value="<?php if (!$bfound && $pconfig['dstendport']) echo $pconfig['dstendport']; ?>">
704
						</td>
705
					</tr>
706
				</table>
707
				<br />
708
				<span class="vexpl">
709
					Specify the port or port range for the destination of the packet for this mapping.
710
					<br />
711
					Hint: you can leave the <em>'to'</em> field empty if you only want to map a single port
712
				</span>
713
			</td>
714
		</tr>
715
                <tr>
716
                  <td width="22%" valign="top" class="vncellreq">Redirect target IP</td>
717
                  <td width="78%" class="vtable">
718
                    <input autocomplete='off' name="localip" type="text" class="formfldalias" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>">
719
                    <br> <span class="vexpl">Enter the internal IP address of
720
                    the server on which you want to map the ports.<br>
721
                    e.g. <em>192.168.1.12</em></span></td>
722
                </tr>
723
                <tr name="lprtr" id="lprtr">
724
                  <td width="22%" valign="top" class="vncellreq">Redirect target port</td>
725
                  <td width="78%" class="vtable">
726
                    <select name="localbeginport" class="formselect" onChange="ext_change();check_for_aliases();">
727
                      <option value="">(other)</option>
728
                      <?php $bfound = 0; foreach ($wkports as $wkport => $wkportdesc): ?>
729
                      <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['localbeginport']) {
730
							echo "selected";
731
							$bfound = 1;
732
						}?>>
733
					  <?=htmlspecialchars($wkportdesc);?>
734
					  </option>
735
                      <?php endforeach; ?>
736
                    </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']; ?>">
737
                    <br>
738
                    <span class="vexpl">Specify the port on the machine with the
739
                    IP address entered above. In case of a port range, specify
740
                    the beginning port of the range (the end port will be calculated
741
                    automatically).<br>
742
                    Hint: this is usually identical to the 'from' port above</span></td>
743
                </tr>
744
                <tr>
745
                  <td width="22%" valign="top" class="vncell">Description</td>
746
                  <td width="78%" class="vtable">
747
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
748
                    <br> <span class="vexpl">You may enter a description here
749
                    for your reference (not parsed).</span></td>
750
                </tr>
751
				<tr>
752
					<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
753
					<td width="78%" class="vtable">
754
						<input type="checkbox" value="yes" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
755
						HINT: This prevents the rule from automatically syncing to other CARP members.
756
					</td>
757
				</tr>
758
				<tr>
759
					<td width="22%" valign="top" class="vncell">NAT reflection</td>
760
					<td width="78%" class="vtable">
761
						<select name="natreflection" class="formselect">
762
						<option value="default" <?php if ($pconfig['natreflection'] != "enable" && $pconfig['natreflection'] != "disable") echo "selected"; ?>>use system default</option>
763
						<option value="enable" <?php if ($pconfig['natreflection'] == "enable") echo "selected"; ?>>enable</option>
764
						<option value="disable" <?php if ($pconfig['natreflection'] == "disable") echo "selected"; ?>>disable</option>
765
						</select>
766
					</td>
767
				</tr>
768
				<?php if (isset($id) && $a_nat[$id] && !isset($_GET['dup'])): ?>
769
				<tr>
770
					<td width="22%" valign="top" class="vncell">Filter rule association</td>
771
					<td width="78%" class="vtable">
772
						<select name="associated-rule-id">
773
							<option value="">None</option>
774
							<option value="pass" <?php if($pconfig['associated-rule-id'] == "pass") echo " SELECTED"; ?>>Pass</option>
775
							<?php
776
							$linkedrule = "";
777
							if (is_array($config['filter']['rule'])) {
778
								$filter_id = 0;
779
							      foreach ($config['filter']['rule'] as $filter_rule) {
780
								if (isset($filter_rule['associated-rule-id'])) {
781
									echo "<option value=\"{$filter_rule['associated-rule-id']}\"";
782
									if ($filter_rule['associated-rule-id']==$pconfig['associated-rule-id']) {
783
										echo " SELECTED";
784
										$linkedrule = "<br /><a href=\"firewall_rules_edit.php?id={$filter_id}\">View the filter rule</a><br/>";
785
									}
786
									echo ">". htmlspecialchars('Rule ' . $filter_rule['descr']) . "</option>\n";
787

    
788
								}
789
								if ($filter_rule['interface'] == $pconfig['interface'])
790
									$filter_id++;
791
							      }
792
							}
793
							if (isset($pconfig['associated-rule-id']))
794
								echo "<option value=\"new\">Create new associated filter rule</option>\n";
795
						echo "</select>\n";
796
						echo $linkedrule;
797
						?>
798
					</td>
799
				</tr>
800
				<?php endif; ?>
801
                <?php if ((!(isset($id) && $a_nat[$id])) || (isset($_GET['dup']))): ?>
802
                <tr>
803
                  <td width="22%" valign="top" class="vncell">Filter rule association</td>
804
                  <td width="78%" class="vtable">
805
                    <select name="filter-rule-association" id="filter-rule-association">
806
						<option value="">None</option>
807
						<option value="add-associated" selected="selected">Add associated filter rule</option>
808
						<option value="add-unassociated">Add unassociated filter rule</option>
809
						<option value="pass">Pass</option>
810
					</select>
811
				  </td>
812
                </tr><?php endif; ?>
813
				<tr>
814
                  <td width="22%" valign="top">&nbsp;</td>
815
                  <td width="78%">&nbsp;</td>
816
				</tr>
817
                <tr>
818
                  <td width="22%" valign="top">&nbsp;</td>
819
                  <td width="78%">
820
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
821
                    <?php if (isset($id) && $a_nat[$id]): ?>
822
                    <input name="id" type="hidden" value="<?=$id;?>">
823
                    <?php endif; ?>
824
                  </td>
825
                </tr>
826
              </table>
827
</form>
828
<script language="JavaScript">
829
<!--
830
	ext_change();
831
	dst_change(document.iform.interface.value,'<?=$pconfig['interface']?>','<?=$pconfig['dst']?>');
832
	var iface_old = document.iform.interface.value;
833
	typesel_change();
834
	proto_change();
835
	<?php if ($pconfig['srcnot'] || $pconfig['src'] != "any" || $pconfig['srcbeginport'] != "any" || $pconfig['srcendport'] != "any"): ?>
836
	show_source();
837
	<?php endif; ?>
838
//-->
839
</script>
840
<?php
841
$isfirst = 0;
842
$aliases = "";
843
$addrisfirst = 0;
844
$aliasesaddr = "";
845
if($config['aliases']['alias'] <> "")
846
	foreach($config['aliases']['alias'] as $alias_name) {
847
		switch ($alias_name['type']) {
848
                        case "port":
849
                                if($isfirst == 1) $portaliases .= ",";
850
                                $portaliases .= "'" . $alias_name['name'] . "'";
851
                                $isfirst = 1;
852
                                break;
853
                        case "host":
854
                        case "network":
855
                        case "openvpn":
856
			case "urltable":
857
                                if($addrisfirst == 1) $aliasesaddr .= ",";
858
                                $aliasesaddr .= "'" . $alias_name['name'] . "'";
859
                                $addrisfirst = 1;
860
                                break;
861
                        default:
862
                                break;
863
		}
864
	}
865
?>
866
<script language="JavaScript">
867
<!--
868
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
869
	var customarray=new Array(<?php echo $portaliases; ?>);
870

    
871
	var oTextbox1 = new AutoSuggestControl(document.getElementById("localip"), new StateSuggestions(addressarray));
872
	var oTextbox2 = new AutoSuggestControl(document.getElementById("src"), new StateSuggestions(addressarray));
873
	var oTextbox3 = new AutoSuggestControl(document.getElementById("dst"), new StateSuggestions(addressarray));
874
	var oTextbox4 = new AutoSuggestControl(document.getElementById("dstbeginport_cust"), new StateSuggestions(customarray));
875
	var oTextbox5 = new AutoSuggestControl(document.getElementById("dstendport_cust"), new StateSuggestions(customarray));
876
	var oTextbox6 = new AutoSuggestControl(document.getElementById("srcbeginport_cust"), new StateSuggestions(customarray));
877
	var oTextbox7 = new AutoSuggestControl(document.getElementById("srcendport_cust"), new StateSuggestions(customarray));
878
	var oTextbox8 = new AutoSuggestControl(document.getElementById("localbeginport_cust"), new StateSuggestions(customarray));
879
//-->
880
</script>
881
<?php include("fend.inc"); ?>
882
</body>
883
</html>
(54-54/222)