Project

General

Profile

Download (22.8 KB) Statistics
| Branch: | Tag: | Revision:
1 9ae40f2b Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_nat_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 9ae40f2b Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 9ae40f2b Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 9ae40f2b Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 9ae40f2b Scott Ullrich
16 5b237745 Scott Ullrich
	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 9ae40f2b Scott Ullrich
20 5b237745 Scott Ullrich
	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 7ac5a4cb Scott Ullrich
/*
32
	pfSense_MODULE:	nat
33
*/
34 5b237745 Scott Ullrich
35 6b07c15a Matthew Grooms
##|+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 5b237745 Scott Ullrich
require("guiconfig.inc");
43 483e6de8 Scott Ullrich
require_once("itemid.inc");
44 1a03cf69 Scott Ullrich
require("filter.inc");
45
require("shaper.inc");
46 5b237745 Scott Ullrich
47
if (!is_array($config['nat']['rule'])) {
48
	$config['nat']['rule'] = array();
49
}
50
$a_nat = &$config['nat']['rule'];
51
52
$id = $_GET['id'];
53
if (isset($_POST['id']))
54
	$id = $_POST['id'];
55
56 4a991889 Bill Marquette
if (isset($_GET['dup'])) {
57
        $id = $_GET['dup'];
58
        $after = $_GET['dup'];
59
}
60
61 5b237745 Scott Ullrich
if (isset($id) && $a_nat[$id]) {
62
	$pconfig['extaddr'] = $a_nat[$id]['external-address'];
63
	$pconfig['proto'] = $a_nat[$id]['protocol'];
64
	list($pconfig['beginport'],$pconfig['endport']) = explode("-", $a_nat[$id]['external-port']);
65 21f88b49 sullrich
	if(!$pconfig['endport'])
66
		$pconfig['endport'] = $pconfig['beginport'];
67 5b237745 Scott Ullrich
	$pconfig['localip'] = $a_nat[$id]['target'];
68
	$pconfig['localbeginport'] = $a_nat[$id]['local-port'];
69
	$pconfig['descr'] = $a_nat[$id]['descr'];
70
	$pconfig['interface'] = $a_nat[$id]['interface'];
71 9b16b834 Ermal Lu?i
	$pconfig['associated-rule-id'] = $a_nat[$id]['associated-rule-id'];
72 ea0805c1 Scott Ullrich
	$pconfig['nosync'] = isset($a_nat[$id]['nosync']);
73 5b237745 Scott Ullrich
	if (!$pconfig['interface'])
74
		$pconfig['interface'] = "wan";
75
} else {
76
	$pconfig['interface'] = "wan";
77
}
78
79 a6713b32 Bill Marquette
if (isset($_GET['dup']))
80
	unset($id);
81
82 ef2a753c Scott Ullrich
/*  run through $_POST items encoding HTML entties so that the user
83
 *  cannot think he is slick and perform a XSS attack on the unwilling 
84
 */
85 21eff66f Scott Ullrich
foreach ($_POST as $key => $value) {
86
	$temp = $value;
87
	$newpost = htmlentities($temp);
88
	if($newpost <> $temp) 
89 f320386c Scott Ullrich
		$input_errors[] = "Invalid characters detected ($temp).  Please remove invalid characters and save again.";		
90 ef2a753c Scott Ullrich
}
91
92 5b237745 Scott Ullrich
if ($_POST) {
93
94
	if ($_POST['beginport_cust'] && !$_POST['beginport'])
95
		$_POST['beginport'] = $_POST['beginport_cust'];
96
	if ($_POST['endport_cust'] && !$_POST['endport'])
97
		$_POST['endport'] = $_POST['endport_cust'];
98
	if ($_POST['localbeginport_cust'] && !$_POST['localbeginport'])
99
		$_POST['localbeginport'] = $_POST['localbeginport_cust'];
100 9ae40f2b Scott Ullrich
101 5b237745 Scott Ullrich
	if (!$_POST['endport'])
102
		$_POST['endport'] = $_POST['beginport'];
103 aa3400b8 Scott Ullrich
        /* Make beginning port end port if not defined and endport is */
104
        if (!$_POST['beginport'] && $_POST['endport'])
105
                $_POST['beginport'] = $_POST['endport'];
106 9ae40f2b Scott Ullrich
107 5b237745 Scott Ullrich
	unset($input_errors);
108
	$pconfig = $_POST;
109
110
	/* input validation */
111 aa3400b8 Scott Ullrich
	if(strtoupper($_POST['proto']) == "TCP" or strtoupper($_POST['proto']) == "UDP" or strtoupper($_POST['proto']) == "TCP/UDP") {
112 92442757 Scott Ullrich
		$reqdfields = explode(" ", "interface proto beginport endport localip localbeginport");
113 221c77a6 Scott Ullrich
		$reqdfieldsn = explode(",", "Interface,Protocol,External port from,External port to,NAT IP,Local port");
114 b66f7667 Scott Ullrich
	} else {
115
		$reqdfields = explode(" ", "interface proto localip");
116 ea0805c1 Scott Ullrich
		$reqdfieldsn = explode(",", "Interface,Protocol,NAT IP");
117 b66f7667 Scott Ullrich
	}
118 9ae40f2b Scott Ullrich
119 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
120 9ae40f2b Scott Ullrich
121 5b237745 Scott Ullrich
	if (($_POST['localip'] && !is_ipaddroralias($_POST['localip']))) {
122 5eb817bc Bill Marquette
		$input_errors[] = "\"{$_POST['localip']}\" is not valid NAT IP address or host alias.";
123 5b237745 Scott Ullrich
	}
124 9ae40f2b Scott Ullrich
125 b66f7667 Scott Ullrich
	/* only validate the ports if the protocol is TCP, UDP or TCP/UDP */
126 aa3400b8 Scott Ullrich
	if(strtoupper($_POST['proto']) == "TCP" or strtoupper($_POST['proto']) == "UDP" or strtoupper($_POST['proto']) == "TCP/UDP") {
127 9ae40f2b Scott Ullrich
128 1e578a7f Ermal Lu?i
		if ($_POST['beginport'] && !is_portoralias($_POST['beginport'])) {
129 b66f7667 Scott Ullrich
			$input_errors[] = "The start port must be an integer between 1 and 65535.";
130
		}
131
132 1e578a7f Ermal Lu?i
		if ($_POST['endport'] && !is_portoralias($_POST['endport'])) {
133 b66f7667 Scott Ullrich
			$input_errors[] = "The end port must be an integer between 1 and 65535.";
134
		}
135
136 1e578a7f Ermal Lu?i
		if ($_POST['localbeginport'] && !is_portoralias($_POST['localbeginport'])) {
137 b66f7667 Scott Ullrich
			$input_errors[] = "The local port must be an integer between 1 and 65535.";
138
		}
139
140
		if ($_POST['beginport'] > $_POST['endport']) {
141
			/* swap */
142
			$tmp = $_POST['endport'];
143
			$_POST['endport'] = $_POST['beginport'];
144
			$_POST['beginport'] = $tmp;
145
		}
146
147
		if (!$input_errors) {
148
			if (($_POST['endport'] - $_POST['beginport'] + $_POST['localbeginport']) > 65535)
149
				$input_errors[] = "The target port range must be an integer between 1 and 65535.";
150
		}
151 ea0805c1 Scott Ullrich
152 5b237745 Scott Ullrich
	}
153 9ae40f2b Scott Ullrich
154 5b237745 Scott Ullrich
	/* check for overlaps */
155
	foreach ($a_nat as $natent) {
156
		if (isset($id) && ($a_nat[$id]) && ($a_nat[$id] === $natent))
157
			continue;
158
		if ($natent['interface'] != $_POST['interface'])
159
			continue;
160
		if ($natent['external-address'] != $_POST['extaddr'])
161
			continue;
162 0cea6311 Scott Ullrich
		if (($natent['proto'] != $_POST['proto']) && ($natent['proto'] != "tcp/udp") && ($_POST['proto'] != "tcp/udp"))
163
			continue;
164 ea0805c1 Scott Ullrich
165 5b237745 Scott Ullrich
		list($begp,$endp) = explode("-", $natent['external-port']);
166
		if (!$endp)
167
			$endp = $begp;
168 ea0805c1 Scott Ullrich
169 5b237745 Scott Ullrich
		if (!(   (($_POST['beginport'] < $begp) && ($_POST['endport'] < $begp))
170
		      || (($_POST['beginport'] > $endp) && ($_POST['endport'] > $endp)))) {
171 ea0805c1 Scott Ullrich
172 5b237745 Scott Ullrich
			$input_errors[] = "The external port range overlaps with an existing entry.";
173
			break;
174
		}
175
	}
176
177
	if (!$input_errors) {
178
		$natent = array();
179
		if ($_POST['extaddr'])
180
			$natent['external-address'] = $_POST['extaddr'];
181
		$natent['protocol'] = $_POST['proto'];
182 9ae40f2b Scott Ullrich
183 5b237745 Scott Ullrich
		if ($_POST['beginport'] == $_POST['endport'])
184
			$natent['external-port'] = $_POST['beginport'];
185
		else
186
			$natent['external-port'] = $_POST['beginport'] . "-" . $_POST['endport'];
187 9ae40f2b Scott Ullrich
188 5b237745 Scott Ullrich
		$natent['target'] = $_POST['localip'];
189
		$natent['local-port'] = $_POST['localbeginport'];
190
		$natent['interface'] = $_POST['interface'];
191
		$natent['descr'] = $_POST['descr'];
192 9b16b834 Ermal Lu?i
		$natent['associated-rule-id'] = $_POST['associated-rule-id'];
193 297ed624 unknown
		
194 f891bf66 Chris Buechler
		if($_POST['filter-rule-association'] == "pass")
195 9b16b834 Ermal Lu?i
			$natent['associated-rule-id'] = "pass";
196 9ae40f2b Scott Ullrich
197 d00055f8 Scott Ullrich
		if($_POST['nosync'] == "yes")
198
			$natent['nosync'] = true;
199
		else
200
			unset($natent['nosync']);
201
202 473d0ff0 pierrepomes
		// If we used to have an associated filter rule, but no-longer should have one
203 9b16b834 Ermal Lu?i
		if ($a_nat[$id]>0 && empty($natent['associated-rule-id'])) {
204 473d0ff0 pierrepomes
			// Delete the previous rule
205 9b16b834 Ermal Lu?i
			delete_id($a_nat[$id]['associated-rule-id'], $config['filter']['rule']);
206 473d0ff0 pierrepomes
			mark_subsystem_dirty('filter');
207
		}
208
209 5335abae unknown
		$need_filter_rule = false;
210
		// Updating a rule with a filter rule associated
211 9b16b834 Ermal Lu?i
		if (!empty($natent['associated-rule-id']))
212 5335abae unknown
			$need_filter_rule = true;
213 473d0ff0 pierrepomes
		// Create a rule or if we want to create a new one
214 9b16b834 Ermal Lu?i
		if( $natent['associated-rule-id']=='new' ) {
215 473d0ff0 pierrepomes
			$need_filter_rule = true;
216 9b16b834 Ermal Lu?i
			unset( $natent['associated-rule-id'] );
217 473d0ff0 pierrepomes
			$_POST['filter-rule-association']='add-associated';
218
		}
219 5335abae unknown
		// If creating a new rule, where we want to add the filter rule, associated or not
220 473d0ff0 pierrepomes
		else if( isset($_POST['filter-rule-association']) &&
221
			($_POST['filter-rule-association']=='add-associated' ||
222 5335abae unknown
			$_POST['filter-rule-association']=='add-unassociated') )
223
			$need_filter_rule = true;
224
225 473d0ff0 pierrepomes
		// Determine NAT entry ID now, we need it for the firewall rule
226
		if (isset($id) && $a_nat[$id])
227
			$a_nat[$id] = $natent;
228
		else {
229
			if (is_numeric($after))
230
				$id = $after + 1;
231
			else
232
				$id = count($a_nat);
233
		}
234 5335abae unknown
235 9b16b834 Ermal Lu?i
		if ($need_filter_rule == true) {
236 9ae40f2b Scott Ullrich
237 5b237745 Scott Ullrich
			/* auto-generate a matching firewall rule */
238 9ae40f2b Scott Ullrich
			$filterent = array();
239 9b16b834 Ermal Lu?i
			unset($filterentid);
240 473d0ff0 pierrepomes
			// If a rule already exists, load it
241 9b16b834 Ermal Lu?i
			if (!empty($natent['associated-rule-id'])) {
242
				$filterentid = get_id($natent['associated-rule-id'], $config['filter']['rule']);
243
				if ($filterentid == false) {
244
					$filterent['source']['any'] = "";
245
					$filterent['associated-rule-id'] = $natent['associated-rule-id'];
246
				} else
247
					$filterent =& $config['filter']['rule'][$filterentid];
248
			} else
249 473d0ff0 pierrepomes
				// Create the default source entry for new filter entries
250
				$filterent['source']['any'] = "";
251
252
			// Update interface, protocol and destination
253 5b237745 Scott Ullrich
			$filterent['interface'] = $_POST['interface'];
254
			$filterent['protocol'] = $_POST['proto'];
255
			$filterent['destination']['address'] = $_POST['localip'];
256 9ae40f2b Scott Ullrich
257 5b237745 Scott Ullrich
			$dstpfrom = $_POST['localbeginport'];
258
			$dstpto = $dstpfrom + $_POST['endport'] - $_POST['beginport'];
259 9ae40f2b Scott Ullrich
260 5b237745 Scott Ullrich
			if ($dstpfrom == $dstpto)
261
				$filterent['destination']['port'] = $dstpfrom;
262
			else
263
				$filterent['destination']['port'] = $dstpfrom . "-" . $dstpto;
264 9ae40f2b Scott Ullrich
265 06246e5b Seth Mos
			/*
266
			 * Our firewall filter description may be no longer than
267
			 * 63 characters, so don't let it be.
268
			 */
269 9b16b834 Ermal Lu?i
			$filterent['descr'] = substr("NAT " . $_POST['descr'], 0, 62);
270 9ae40f2b Scott Ullrich
271 473d0ff0 pierrepomes
			// If this is a new rule, create an ID and add the rule
272
			if( $_POST['filter-rule-association']=='add-associated' ) {
273 9b16b834 Ermal Lu?i
				$filterent['associated-rule-id'] = $natent['associated-rule-id'] = get_unique_id();
274 473d0ff0 pierrepomes
				$config['filter']['rule'][] = $filterent;
275
			}
276 9ae40f2b Scott Ullrich
277 a368a026 Ermal Lu?i
			mark_subsystem_dirty('filter');
278 5b237745 Scott Ullrich
		}
279 9ae40f2b Scott Ullrich
280 473d0ff0 pierrepomes
		// Update the NAT entry now
281 b9e28d57 unknown
		if (isset($id) && $a_nat[$id])
282
			$a_nat[$id] = $natent;
283
		else {
284
			if (is_numeric($after))
285
				array_splice($a_nat, $after+1, 0, array($natent));
286
			else
287
				$a_nat[] = $natent;
288
		}
289
290
		mark_subsystem_dirty('natconf');
291
292 5b237745 Scott Ullrich
		write_config();
293 9ae40f2b Scott Ullrich
294 5b237745 Scott Ullrich
		header("Location: firewall_nat.php");
295
		exit;
296
	}
297
}
298 da7ae7ef Bill Marquette
299 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","NAT","Port Forward: Edit");
300 da7ae7ef Bill Marquette
include("head.inc");
301
302 5b237745 Scott Ullrich
?>
303 da7ae7ef Bill Marquette
304 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
305 4ce8ac00 Erik Kristensen
<?php
306
include("fbegin.inc"); ?>
307 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
308
            <form action="firewall_nat_edit.php" method="post" name="iform" id="iform">
309
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
310 2a6cb2d6 Scott Ullrich
				<tr>
311
					<td colspan="2" valign="top" class="listtopic">Edit NAT entry</td>
312
				</tr>	
313
				<tr>
314 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Interface</td>
315
                  <td width="78%" class="vtable">
316 b5c78501 Seth Mos
					<select name="interface" class="formselect">
317 5b237745 Scott Ullrich
						<?php
318 40b56dc1 Scott Ullrich
						
319 cbe3ea96 Ermal Luçi
						$iflist = get_configured_interface_with_descr(false, true);
320
						foreach ($iflist as $if => $ifdesc) 
321
							if(have_ruleint_access($if)) 
322
								$interfaces[$if] = $ifdesc;
323 40b56dc1 Scott Ullrich
						
324
						if ($config['pptpd']['mode'] == "server")
325
							if(have_ruleint_access("pptp")) 
326
								$interfaces['pptp'] = "PPTP VPN";
327
						
328
						if ($config['pppoe']['mode'] == "server")
329
							if(have_ruleint_access("pppoe")) 
330
								$interfaces['pppoe'] = "PPPoE VPN";
331
						
332
						/* add ipsec interfaces */
333
						if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
334
							if(have_ruleint_access("enc0")) 
335 0f266b2e Chris Buechler
								$interfaces["enc0"] = "IPsec";						
336 40b56dc1 Scott Ullrich
337 5b237745 Scott Ullrich
						foreach ($interfaces as $iface => $ifacename): ?>
338
						<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected"; ?>>
339
						<?=htmlspecialchars($ifacename);?>
340
						</option>
341
						<?php endforeach; ?>
342
					</select><br>
343
                     <span class="vexpl">Choose which interface this rule applies to.<br>
344
                     Hint: in most cases, you'll want to use WAN here.</span></td>
345
                </tr>
346 9ae40f2b Scott Ullrich
			    <tr>
347 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">External address</td>
348 9ae40f2b Scott Ullrich
                  <td width="78%" class="vtable">
349 b5c78501 Seth Mos
					<select name="extaddr" class="formselect">
350 4ce8ac00 Erik Kristensen
						<option value="" <?php if (!$pconfig['extaddr']) echo "selected"; ?>>Interface address</option>
351
<?php					if (is_array($config['virtualip']['vip'])):
352
						foreach ($config['virtualip']['vip'] as $sn): ?>
353
						<option value="<?=$sn['subnet'];?>" <?php if ($sn['subnet'] == $pconfig['extaddr']) echo "selected"; ?>><?=htmlspecialchars("{$sn['subnet']} ({$sn['descr']})");?></option>
354
<?php					endforeach;
355
						endif; ?>
356
						<option value="any" <?php if($pconfig['extaddr'] == "any") echo "selected"; ?>>any</option>
357
					</select>
358
					<br />
359 5b237745 Scott Ullrich
                    <span class="vexpl">
360
					If you want this rule to apply to another IP address than the IP address of the interface chosen above,
361 1425e067 Bill Marquette
					select it here (you need to define <a href="firewall_virtual_ip.php">Virtual IP</a> addresses on the first).  Also note that if you are trying to redirect connections on the LAN select the "any" option.</span></td>
362 5b237745 Scott Ullrich
                </tr>
363 9ae40f2b Scott Ullrich
                <tr>
364 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Protocol</td>
365 9ae40f2b Scott Ullrich
                  <td width="78%" class="vtable">
366 b5c78501 Seth Mos
                    <select name="proto" class="formselect" onChange="proto_change(); check_for_aliases();">
367 e598eab5 Scott Ullrich
                      <?php $protocols = explode(" ", "TCP UDP TCP/UDP GRE ESP"); foreach ($protocols as $proto): ?>
368 5b237745 Scott Ullrich
                      <option value="<?=strtolower($proto);?>" <?php if (strtolower($proto) == $pconfig['proto']) echo "selected"; ?>><?=htmlspecialchars($proto);?></option>
369
                      <?php endforeach; ?>
370 9ae40f2b Scott Ullrich
                    </select> <br> <span class="vexpl">Choose which IP protocol
371 5b237745 Scott Ullrich
                    this rule should match.<br>
372
                    Hint: in most cases, you should specify <em>TCP</em> &nbsp;here.</span></td>
373
                </tr>
374 9ae40f2b Scott Ullrich
                <tr>
375
                  <td width="22%" valign="top" class="vncellreq">External port
376 5b237745 Scott Ullrich
                    range </td>
377 9ae40f2b Scott Ullrich
                  <td width="78%" class="vtable">
378 5b237745 Scott Ullrich
                    <table border="0" cellspacing="0" cellpadding="0">
379 9ae40f2b Scott Ullrich
                      <tr>
380 5b237745 Scott Ullrich
                        <td>from:&nbsp;&nbsp;</td>
381 b5c78501 Seth Mos
                        <td><select name="beginport" class="formselect" onChange="ext_rep_change(); ext_change(); check_for_aliases();">
382 5b237745 Scott Ullrich
                            <option value="">(other)</option>
383
                            <?php $bfound = 0; foreach ($wkports as $wkport => $wkportdesc): ?>
384
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['beginport']) {
385 0e6998d1 Scott Ullrich
								echo "selected";
386
								$bfound = 1;
387
							}?>>
388 5b237745 Scott Ullrich
							<?=htmlspecialchars($wkportdesc);?>
389
							</option>
390
                            <?php endforeach; ?>
391 e2705d67 Scott Ullrich
                          </select> <input onChange="check_for_aliases();" autocomplete='off' class="formfldalias" name="beginport_cust" id="beginport_cust" type="text" size="5" value="<?php if (!$bfound) echo $pconfig['beginport']; ?>"></td>
392 5b237745 Scott Ullrich
                      </tr>
393 9ae40f2b Scott Ullrich
                      <tr>
394 5b237745 Scott Ullrich
                        <td>to:</td>
395 b5c78501 Seth Mos
                        <td><select name="endport" class="formselect" onChange="ext_change(); check_for_aliases();">
396 5b237745 Scott Ullrich
                            <option value="">(other)</option>
397
                            <?php $bfound = 0; foreach ($wkports as $wkport => $wkportdesc): ?>
398
                            <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['endport']) {
399 0e6998d1 Scott Ullrich
								echo "selected";
400
								$bfound = 1;
401
							}?>>
402 5b237745 Scott Ullrich
							<?=htmlspecialchars($wkportdesc);?>
403
							</option>
404
							<?php endforeach; ?>
405 e2705d67 Scott Ullrich
                          </select> <input onChange="check_for_aliases();" class="formfldalias" autocomplete='off' name="endport_cust" id="endport_cust" type="text" size="5" value="<?php if (!$bfound) echo $pconfig['endport']; ?>"></td>
406 5b237745 Scott Ullrich
                      </tr>
407
                    </table>
408 9ae40f2b Scott Ullrich
                    <br> <span class="vexpl">Specify the port or port range on
409 5b237745 Scott Ullrich
                    the firewall's external address for this mapping.<br>
410 9ae40f2b Scott Ullrich
                    Hint: you can leave the <em>'to'</em> field empty if you only
411 5b237745 Scott Ullrich
                    want to map a single port</span></td>
412
                </tr>
413 9ae40f2b Scott Ullrich
                <tr>
414 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">NAT IP</td>
415 9ae40f2b Scott Ullrich
                  <td width="78%" class="vtable">
416 4ce8ac00 Erik Kristensen
                    <input autocomplete='off' name="localip" type="text" class="formfldalias" id="localip" size="20" value="<?=htmlspecialchars($pconfig['localip']);?>">
417 9ae40f2b Scott Ullrich
                    <br> <span class="vexpl">Enter the internal IP address of
418 5b237745 Scott Ullrich
                    the server on which you want to map the ports.<br>
419
                    e.g. <em>192.168.1.12</em></span></td>
420
                </tr>
421 9ae40f2b Scott Ullrich
                <tr>
422 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncellreq">Local port</td>
423 9ae40f2b Scott Ullrich
                  <td width="78%" class="vtable">
424 b5c78501 Seth Mos
                    <select name="localbeginport" class="formselect" onChange="ext_change();check_for_aliases();">
425 5b237745 Scott Ullrich
                      <option value="">(other)</option>
426
                      <?php $bfound = 0; foreach ($wkports as $wkport => $wkportdesc): ?>
427
                      <option value="<?=$wkport;?>" <?php if ($wkport == $pconfig['localbeginport']) {
428 0e6998d1 Scott Ullrich
							echo "selected";
429
							$bfound = 1;
430
						}?>>
431 5b237745 Scott Ullrich
					  <?=htmlspecialchars($wkportdesc);?>
432
					  </option>
433
                      <?php endforeach; ?>
434 e2705d67 Scott Ullrich
                    </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']; ?>">
435 5b237745 Scott Ullrich
                    <br>
436 9ae40f2b Scott Ullrich
                    <span class="vexpl">Specify the port on the machine with the
437
                    IP address entered above. In case of a port range, specify
438
                    the beginning port of the range (the end port will be calculated
439 5b237745 Scott Ullrich
                    automatically).<br>
440
                    Hint: this is usually identical to the 'from' port above</span></td>
441
                </tr>
442 9ae40f2b Scott Ullrich
                <tr>
443 5b237745 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Description</td>
444 9ae40f2b Scott Ullrich
                  <td width="78%" class="vtable">
445 b5c78501 Seth Mos
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
446 9ae40f2b Scott Ullrich
                    <br> <span class="vexpl">You may enter a description here
447 5b237745 Scott Ullrich
                    for your reference (not parsed).</span></td>
448 53ea15e0 Scott Ullrich
                </tr>
449 d00055f8 Scott Ullrich
				<tr>
450
					<td width="22%" valign="top" class="vncell">No XMLRPC Sync</td>
451
					<td width="78%" class="vtable">
452 3fafce5a Scott Ullrich
						<input type="checkbox" value="yes" name="nosync"<?php if($pconfig['nosync']) echo " CHECKED"; ?>><br>
453 df593437 Scott Ullrich
						HINT: This prevents the rule from automatically syncing to other CARP members.
454 d00055f8 Scott Ullrich
					</td>
455 ea0805c1 Scott Ullrich
				</tr>
456 b9e28d57 unknown
				<?php if (isset($id) && $a_nat[$id] && !isset($_GET['dup'])): ?>
457
				<tr>
458 5335abae unknown
					<td width="22%" valign="top" class="vncell">Filter rule association</td>
459 b9e28d57 unknown
					<td width="78%" class="vtable">
460 9b16b834 Ermal Lu?i
						<select name="associated-rule-id">
461 5335abae unknown
							<option value="">None</option>
462 9b16b834 Ermal Lu?i
							<option value="pass" <?php if($pconfig['associated-rule-id'] == "pass") echo " SELECTED"; ?>>Pass</option>
463
							<?php 
464 cdf9847b Ermal Lu?i
							$linkedrule = "";
465 9b16b834 Ermal Lu?i
							if (is_array($config['filter']['rule'])) {
466 cdf9847b Ermal Lu?i
								$filter_id = 0;
467 9b16b834 Ermal Lu?i
							      foreach ($config['filter']['rule'] as $filter_rule) {
468
								if (isset($filter_rule['associated-rule-id'])) {
469
									echo "<option value=\"{$filter_rule['associated-rule-id']}\"";
470 cdf9847b Ermal Lu?i
									if ($filter_rule['associated-rule-id']==$pconfig['associated-rule-id']) {
471 9b16b834 Ermal Lu?i
										echo " SELECTED";
472 cdf9847b Ermal Lu?i
										$linkedrule = "<br /><a href=\"firewall_rules_edit.php?id={$filter_id}\">View the filter rule</a><br/>";
473
									}
474 9b16b834 Ermal Lu?i
									echo ">". htmlspecialchars('Rule ' . $filter_rule['descr']) . "</option>\n";
475
									
476
								}
477 cdf9847b Ermal Lu?i
								if ($filter_rule['interface'] == $pconfig['interface'])
478
									$filter_id++;
479 9b16b834 Ermal Lu?i
							      }
480
							}
481
							if (isset($pconfig['associated-rule-id']))
482
								echo "<option value=\"new\">Create new associated filter rule</option>\n";
483
						echo "</select>\n";
484 cdf9847b Ermal Lu?i
						echo $linkedrule;
485 9b16b834 Ermal Lu?i
						?>
486 b9e28d57 unknown
					</td>
487
				</tr>
488
				<?php endif; ?>
489 53ea15e0 Scott Ullrich
                <?php if ((!(isset($id) && $a_nat[$id])) || (isset($_GET['dup']))): ?>
490 9ae40f2b Scott Ullrich
                <tr>
491 64716c95 Scott Ullrich
                  <td width="22%" valign="top" class="vncell">Filter rule association</td>
492 5d2742d5 sullrich
                  <td width="78%" class="vtable">
493 5335abae unknown
                    <select name="filter-rule-association" id="filter-rule-association">
494
						<option value="">None</option>
495 8b1f77be Scott Ullrich
						<option value="add-associated" selected="selected">Add associated filter rule</option>
496
						<option value="add-unassociated">Add unassociated filter rule</option>
497 5335abae unknown
						<option value="pass">Pass</option>
498
					</select>
499
				  </td>
500 5b237745 Scott Ullrich
                </tr><?php endif; ?>
501 147b90b8 Scott Ullrich
				<tr>
502
                  <td width="22%" valign="top">&nbsp;</td>
503
                  <td width="78%">&nbsp;</td>
504
				</tr>
505 9ae40f2b Scott Ullrich
                <tr>
506 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
507 9ae40f2b Scott Ullrich
                  <td width="78%">
508 fc01e414 Scott Ullrich
                    <input name="Submit" type="submit" class="formbtn" value="Save"> <input type="button" class="formbtn" value="Cancel" onclick="history.back()">
509 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_nat[$id]): ?>
510 9ae40f2b Scott Ullrich
                    <input name="id" type="hidden" value="<?=$id;?>">
511 5b237745 Scott Ullrich
                    <?php endif; ?>
512
                  </td>
513
                </tr>
514
              </table>
515
</form>
516
<script language="JavaScript">
517
<!--
518 4ce8ac00 Erik Kristensen
	ext_change();
519 5b237745 Scott Ullrich
//-->
520
</script>
521 9ae40f2b Scott Ullrich
<?php
522
$isfirst = 0;
523
$aliases = "";
524
$addrisfirst = 0;
525
$aliasesaddr = "";
526 b964717d Scott Ullrich
if($config['aliases']['alias'] <> "")
527
	foreach($config['aliases']['alias'] as $alias_name) {
528 b6867d81 Ermal Lu?i
		switch ($alias_name['type']) {
529
                        case "port":
530
                                if($isfirst == 1) $portaliases .= ",";
531
                                $portaliases .= "'" . $alias_name['name'] . "'";
532
                                $isfirst = 1;
533
                                break;
534
                        case "host":
535
                        case "network":
536
                        case "openvpn":
537
                                if($addrisfirst == 1) $aliasesaddr .= ",";
538
                                $aliasesaddr .= "'" . $alias_name['name'] . "'";
539
                                $addrisfirst = 1;
540
                                break;
541
                        default:
542
                                break;
543 b964717d Scott Ullrich
		}
544 9ae40f2b Scott Ullrich
	}
545
?>
546
<script language="JavaScript">
547
<!--
548 4ce8ac00 Erik Kristensen
	var addressarray=new Array(<?php echo $aliasesaddr; ?>);
549 b6867d81 Ermal Lu?i
	var customarray=new Array(<?php echo $portaliases; ?>);
550 9eb60dcc Ermal Lu?i
551
	var oTextbox1 = new AutoSuggestControl(document.getElementById("localip"), new StateSuggestions(addressarray));
552
        var oTextbox2 = new AutoSuggestControl(document.getElementById("beginport_cust"), new StateSuggestions(customarray));
553
        var oTextbox3 = new AutoSuggestControl(document.getElementById("endport_cust"), new StateSuggestions(customarray));
554
        var oTextbox4 = new AutoSuggestControl(document.getElementById("localbeginport_cust"), new StateSuggestions(customarray));
555 9ae40f2b Scott Ullrich
//-->
556
</script>
557 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
558
</body>
559
</html>