Project

General

Profile

Download (16.9 KB) Statistics
| Branch: | Tag: | Revision:
1 19ae0929 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
    firewall_nat_out.php
5 c55b323d Scott Ullrich
    Copyright (C) 2004 Scott Ullrich
6
    All rights reserved.
7 19ae0929 Scott Ullrich
8 c55b323d Scott Ullrich
    originally part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
    All rights reserved.
11 19ae0929 Scott Ullrich
12 5b237745 Scott Ullrich
    Redistribution and use in source and binary forms, with or without
13
    modification, are permitted provided that the following conditions are met:
14 19ae0929 Scott Ullrich
15 5b237745 Scott Ullrich
    1. Redistributions of source code must retain the above copyright notice,
16
       this list of conditions and the following disclaimer.
17 19ae0929 Scott Ullrich
18 5b237745 Scott Ullrich
    2. Redistributions in binary form must reproduce the above copyright
19
       notice, this list of conditions and the following disclaimer in the
20
       documentation and/or other materials provided with the distribution.
21 19ae0929 Scott Ullrich
22 5b237745 Scott Ullrich
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
    POSSIBILITY OF SUCH DAMAGE.
32
*/
33 7ac5a4cb Scott Ullrich
/*
34
	pfSense_MODULE:	nat
35
*/
36 5b237745 Scott Ullrich
37 6b07c15a Matthew Grooms
##|+PRIV
38
##|*IDENT=page-firewall-nat-outbound
39
##|*NAME=Firewall: NAT: Outbound page
40
##|*DESCR=Allow access to the 'Firewall: NAT: Outbound' page.
41
##|*MATCH=firewall_nat_out.php*
42
##|-PRIV
43
44 5b237745 Scott Ullrich
require("guiconfig.inc");
45
46
if (!is_array($config['nat']['advancedoutbound']['rule']))
47 82d0dfc4 Scott Ullrich
	$config['nat']['advancedoutbound']['rule'] = array();
48 19ae0929 Scott Ullrich
49 5b237745 Scott Ullrich
$a_out = &$config['nat']['advancedoutbound']['rule'];
50
51 82d0dfc4 Scott Ullrich
if ($_POST['apply']) {
52
	write_config();
53 5b237745 Scott Ullrich
54 82d0dfc4 Scott Ullrich
	$retval = 0;
55 920b3bb0 Scott Ullrich
	$retval |= filter_configure();
56
57 e8c2c890 Bill Marquette
	if(stristr($retval, "error") <> true)
58
	        $savemsg = get_std_save_message($retval);
59
	else
60
		$savemsg = $retval;
61 19ae0929 Scott Ullrich
62 82d0dfc4 Scott Ullrich
	if ($retval == 0) {
63 a368a026 Ermal Lu?i
		clear_subsystem_dirty('natconf');
64
		clear_subsystem_dirty('filter');
65 9c96aff5 Bill Marquette
        }
66 5b237745 Scott Ullrich
}
67
68 fe693b89 Bill Marquette
69
70 82d0dfc4 Scott Ullrich
if (isset($_POST['save']) && $_POST['save'] == "Save") {
71 53bf5f1d Seth Mos
	/* mutually exclusive settings - if user wants advanced NAT, we don't generate automatic rules */
72 82d0dfc4 Scott Ullrich
	switch ($_POST['advancedoripsec']) {
73
	case "ipsecpassthru":
74
               	$config['nat']['ipsecpassthru']['enable'] = true;
75
               	unset($config['nat']['advancedoutbound']['enable']);
76
               	if(count($config['nat']['advancedoutbound']['rule']) == 0)
77
			unset($config['nat']['advancedoutbound']['rule']);
78
		break;
79
	case "advancedoutboundnat":
80
        	$was_enabled = isset($config['nat']['advancedoutbound']['enable']);
81
		$config['nat']['advancedoutbound']['enable'] = true;
82 f1f60c92 Ermal Luçi
		if (isset($config['nat']['ipsecpassthru']['enable']))
83
			unset($config['nat']['ipsecpassthru']['enable']);
84 82d0dfc4 Scott Ullrich
		if($was_enabled == false) {
85
			/*
86
			 *    user has enabled advanced outbound nat -- lets automatically create entries
87
			 *    for all of the interfaces to make life easier on the pip-o-chap
88
			 */
89 cbe3ea96 Ermal Luçi
			$ifdescrs = get_configured_interface_with_descr();
90
				
91
			foreach($ifdescrs as $if => $ifdesc) {
92 a55e9c70 Ermal Lu?i
				if (interface_has_gateway($if))
93 e1f675e4 Ermal Luçi
					continue;
94 a55e9c70 Ermal Lu?i
				if($ifdesc == "wan")
95 533e6800 Scott Ullrich
					continue;
96 82d0dfc4 Scott Ullrich
				$natent = array();
97 a55e9c70 Ermal Lu?i
				$osipaddr = get_interface_ip($if);
98
				$ossubnet = get_interface_subnet($if);
99
				if (!is_ipaddr($osipaddr) || empty($ossubnet))
100
					continue;
101
				$osn = gen_subnet($osipaddr, $ossubnet);
102
				$natent['source']['network'] = "{$osn}/{$ossubnet}";
103 82d0dfc4 Scott Ullrich
				$natent['sourceport'] = "";
104 cbe3ea96 Ermal Luçi
				$natent['descr'] = "Auto created rule for {$ifdesc}";
105 82d0dfc4 Scott Ullrich
				$natent['target'] = "";
106
				$natent['interface'] = "wan";
107
				$natent['destination']['any'] = true;
108
				$natent['natport'] = "";
109
				$a_out[] = $natent;
110 fa56ab75 Scott Ullrich
			}
111 82d0dfc4 Scott Ullrich
			$savemsg = "Default rules for each interface have been created.";
112
		}
113
		break;
114
	}
115 63868cb8 Scott Ullrich
        write_config();
116 a368a026 Ermal Lu?i
	mark_subsystem_dirty('natconf');
117 63868cb8 Scott Ullrich
        header("Location: firewall_nat_out.php");
118
        exit;
119 fe693b89 Bill Marquette
}
120
121 9c96aff5 Bill Marquette
if (isset($_POST['del_x'])) {
122
        /* delete selected rules */
123
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
124
                foreach ($_POST['rule'] as $rulei) {
125
                        unset($a_out[$rulei]);
126
                }
127
                write_config();
128 a368a026 Ermal Lu?i
		mark_subsystem_dirty('natconf');
129 9c96aff5 Bill Marquette
                header("Location: firewall_nat_out.php");
130
                exit;
131
        }
132
133
} else {
134 87b10bed Bill Marquette
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
135 9c96aff5 Bill Marquette
        unset($movebtn);
136
        foreach ($_POST as $pn => $pd) {
137
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
138
                        $movebtn = $matches[1];
139
                        break;
140
                }
141
        }
142
        /* move selected rules before this rule */
143
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
144
                $a_out_new = array();
145
146
                /* copy all rules < $movebtn and not selected */
147
                for ($i = 0; $i < $movebtn; $i++) {
148
                        if (!in_array($i, $_POST['rule']))
149
                                $a_out_new[] = $a_out[$i];
150
                }
151
152
                /* copy all selected rules */
153
                for ($i = 0; $i < count($a_out); $i++) {
154
                        if ($i == $movebtn)
155
                                continue;
156
                        if (in_array($i, $_POST['rule']))
157
                                $a_out_new[] = $a_out[$i];
158
                }
159
160
                /* copy $movebtn rule */
161
                if ($movebtn < count($a_out))
162
                        $a_out_new[] = $a_out[$movebtn];
163
164
                /* copy all rules > $movebtn and not selected */
165
                for ($i = $movebtn+1; $i < count($a_out); $i++) {
166
                        if (!in_array($i, $_POST['rule']))
167
                                $a_out_new[] = $a_out[$i];
168
                }
169 82d0dfc4 Scott Ullrich
                if (count($a_out_new) > 0)
170
			$a_out = $a_out_new;
171
		else
172
			unset($config['nat']['advancedoutbound']);
173
174 9c96aff5 Bill Marquette
                write_config();
175 a368a026 Ermal Lu?i
		mark_subsystem_dirty('natconf');
176 9c96aff5 Bill Marquette
                header("Location: firewall_nat_out.php");
177
                exit;
178
        }
179 5b237745 Scott Ullrich
}
180 9c96aff5 Bill Marquette
181
182 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","NAT","Outbound");
183 6eb17647 Scott Ullrich
include("head.inc");
184
185 24f600b0 Scott Ullrich
?>
186 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
187
<?php include("fbegin.inc"); ?>
188 fe693b89 Bill Marquette
<form action="firewall_nat_out.php" method="post" name="iform">
189 625dcc40 Bill Marquette
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js">
190 3f57ceee Bill Marquette
</script>
191 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
192 a368a026 Ermal Lu?i
<?php if (is_subsystem_dirty('natconf')): ?><p>
193 5b237745 Scott Ullrich
<?php print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
194
<?php endif; ?>
195
<table width="100%" border="0" cellpadding="0" cellspacing="0">  <tr><td>
196 a8726a3d Scott Ullrich
<?php
197
	$tab_array = array();
198 1425e067 Bill Marquette
	$tab_array[] = array("Port Forward", false, "firewall_nat.php");
199
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
200
	$tab_array[] = array("Outbound", true, "firewall_nat_out.php");
201 a8726a3d Scott Ullrich
	display_top_tabs($tab_array);
202
?>
203 5b237745 Scott Ullrich
  </td></tr>
204 19ae0929 Scott Ullrich
  <tr>
205 d732f186 Bill Marquette
    <td>
206
	<div id="mainarea">
207
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
208 fe693b89 Bill Marquette
              <tr>
209 5b237745 Scott Ullrich
                  <td class="vtable"><p>
210 82d0dfc4 Scott Ullrich
                      <input name="advancedoripsec" type="radio" id="ipsecpassthru" value="ipsecpassthru" <?php if (isset($config['nat']['ipsecpassthru']['enable'])) echo "checked";?>>
211 69e108df Chris Buechler
                      <strong><?=gettext("Automatic outbound NAT rule generation (IPsec passthrough)");?></strong></p>
212 6b3a7398 Scott Ullrich
                  </td>
213 5b237745 Scott Ullrich
                </tr>
214 19ae0929 Scott Ullrich
                <tr>
215 fe693b89 Bill Marquette
                  <td class="vtable"><p>
216 82d0dfc4 Scott Ullrich
                      <input name="advancedoripsec" type="radio" id="advancedoutbound" value="advancedoutboundnat" <?php if (isset($config['nat']['advancedoutbound']['enable'])) echo "checked";?>>
217 53bf5f1d Seth Mos
                      <strong><?=gettext("Manual Outbound NAT rule generation (Advanced Outbound NAT (AON))");?></strong></p></td>
218 fe693b89 Bill Marquette
                </tr>
219
                <tr>
220
                  <td> <input name="save" type="submit" class="formbtn" value="Save">
221 5b237745 Scott Ullrich
                  </td>
222
                </tr>
223
                <tr>
224 6b3a7398 Scott Ullrich
                  <td colspan="2"><p><span class="vexpl"><span class="red"><strong>Note:<br>
225 5b237745 Scott Ullrich
                      </strong></span>If advanced outbound NAT is enabled, no outbound NAT
226 af35a7e8 Scott Ullrich
                      rules will be automatically generated any longer. Instead, only the mappings
227 5b237745 Scott Ullrich
                      you specify below will be used. With advanced outbound NAT disabled,
228
                      a mapping is automatically created for each interface's subnet
229 0a82ada4 Bill Marquette
                      (except WAN).  If you use target addresses other than the WAN interface's
230
		      IP address, then depending on the way your WAN connection is setup, you
231
	              may also need a <a href="firewall_virtual_ip.php">Virtual IP</a>.</span><br>
232 5b237745 Scott Ullrich
                      <br>
233
                      You may enter your own mappings below.</p>
234
                    </td>
235
                </tr>
236
              </table>
237 d732f186 Bill Marquette
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
238 3f57ceee Bill Marquette
                <tr id="frheader">
239
                  <td width="3%" class="list">&nbsp;</td>
240
                  <td width="3%" class="list">&nbsp;</td>
241 5b237745 Scott Ullrich
                  <td width="10%" class="listhdrr">Interface</td>
242 3af33993 Scott Ullrich
                  <td width="15%" class="listhdrr">Source</td>
243
                  <td width="10%" class="listhdrr">Source Port</td>
244
                  <td width="15%" class="listhdrr">Destination</td>
245
                  <td width="10%" class="listhdrr">Destination Port</td>
246
                  <td width="15%" class="listhdrr">NAT Address</td>
247 5d8b0205 Scott Ullrich
                  <td width="10%" class="listhdrr">NAT Port</td>
248
		  <td width="10%" class="listhdrr">Static Port</td>
249 5b237745 Scott Ullrich
                  <td width="25%" class="listhdr">Description</td>
250 d415d821 Seth Mos
                  <td width="5%" class="list">
251
                    <table border="0" cellspacing="0" cellpadding="1">
252
                      <tr>
253
			<td width="17"></td>
254
                        <td><a href="firewall_nat_out_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add new mapping"></a></td>
255
                      </tr>
256
                    </table>
257
		  </td>
258 5b237745 Scott Ullrich
                </tr>
259 9c96aff5 Bill Marquette
              <?php $nnats = $i = 0; foreach ($a_out as $natent): ?>
260 3f57ceee Bill Marquette
                <tr valign="top" id="fr<?=$nnats;?>">
261
                  <td class="listt"><input type="checkbox" id="frc<?=$nnats;?>" name="rule[]" value="<?=$i;?>" onClick="fr_bgcolor('<?=$nnats;?>')" style="margin: 0; padding: 0; width: 15px; height: 15px;"></td>
262 3364bed4 Bill Marquette
                  <td class="listt" align="center"></td>
263 f8b8c2fd Bill Marquette
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
264 5b237745 Scott Ullrich
                    <?php
265
					if (!$natent['interface'] || ($natent['interface'] == "wan"))
266
					  	echo "WAN";
267 c7f97efa Scott Ullrich
                                        else if (!$natent['interface'] || ($natent['interface'] == "lan"))
268
                                                 echo "LAN";                                                
269 f1f60c92 Ermal Luçi
					else if ($natent['interface'] == "openvpn")
270
						echo "OpenVPN";
271 5b237745 Scott Ullrich
					else
272 bb43786e Scott Ullrich
						echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
273 5b237745 Scott Ullrich
					?>
274 19f09ae1 Scott Ullrich
                                        &nbsp;
275 5b237745 Scott Ullrich
                  </td>
276 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
277 5b237745 Scott Ullrich
                    <?=$natent['source']['network'];?>
278
                  </td>
279 a88aca62 Scott Ullrich
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
280
                    <?php
281
                      if (!$natent['sourceport'])
282
                          echo "*";
283
                      else
284
                          echo $natent['sourceport'];
285
                    ?>
286
                  </td>
287 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
288 5b237745 Scott Ullrich
                    <?php
289
                      if (isset($natent['destination']['any']))
290
                          echo "*";
291
                      else {
292
                          if (isset($natent['destination']['not']))
293
                              echo "!&nbsp;";
294 2e56710c Scott Ullrich
                          echo $natent['destination']['address'];
295 5b237745 Scott Ullrich
                      }
296
                    ?>
297
                  </td>
298 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
299 a539f08b Bill Marquette
                    <?php
300 a88aca62 Scott Ullrich
                      if (!$natent['dstport'])
301 a539f08b Bill Marquette
                          echo "*";
302
                      else
303 a88aca62 Scott Ullrich
                          echo $natent['dstport'];
304 a539f08b Bill Marquette
                    ?>
305
                  </td>
306 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
307 5b237745 Scott Ullrich
                    <?php
308
                      if (!$natent['target'])
309
                          echo "*";
310
                      else
311
                          echo $natent['target'];
312
                    ?>
313
                  </td>
314 4d38bfc3 Scott Ullrich
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
315
                    <?php
316 3af33993 Scott Ullrich
                      if (!$natent['natport'])
317 4d38bfc3 Scott Ullrich
                          echo "*";
318
                      else
319 3af33993 Scott Ullrich
                          echo $natent['natport'];
320
                    ?>
321 5d8b0205 Scott Ullrich
                  </td>
322
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
323
                    <?php
324 b6905de8 Scott Ullrich
			if(isset($natent['staticnatport']))
325 3ea05ff4 Scott Ullrich
			    echo "<CENTER>YES</CENTER>";
326 b6905de8 Scott Ullrich
			else
327 3ea05ff4 Scott Ullrich
			    echo "<CENTER>NO</CENTER>";
328 5d8b0205 Scott Ullrich
                    ?>		    
329 4d38bfc3 Scott Ullrich
                  </td>
330 f8b8c2fd Bill Marquette
                  <td class="listbg"  onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
331 64286300 Scott Ullrich
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
332 5b237745 Scott Ullrich
                  </td>
333 9c96aff5 Bill Marquette
                  <td class="list" valign="middle" nowrap>
334
                    <table border="0" cellspacing="0" cellpadding="1">
335
                      <tr>
336 90e4939a Bill Marquette
                        <td><a href="firewall_nat_out_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="edit mapping"></a></td>
337 9c96aff5 Bill Marquette
                      </tr>
338
                      <tr>
339 677c0869 Erik Kristensen
                        <td><input onmouseover="fr_insline(<?=$nnats;?>, true)" onmouseout="fr_insline(<?=$nnats;?>, false)" name="move_<?=$i;?>" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" title="move selected rules before this rule" height="17" type="image" width="17" border="0"></td>
340
                        <td><a href="firewall_nat_out_edit.php?dup=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new nat based on this one" width="17" height="17" border="0"></a></td>
341 9c96aff5 Bill Marquette
                      </tr>
342
                    </table>
343
              <?php $i++; $nnats++; endforeach; ?>
344 19ae0929 Scott Ullrich
                <tr>
345 3af33993 Scott Ullrich
                  <td class="list" colspan="11"></td>
346 9c96aff5 Bill Marquette
                  <td class="list" valign="middle" nowrap>
347
                    <table border="0" cellspacing="0" cellpadding="1">
348
                      <tr>
349 677c0869 Erik Kristensen
                        <td><?php if ($nnats == 0): ?><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php endif; ?></td>
350 90e4939a Bill Marquette
                        <td><a href="firewall_nat_out_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="add new mapping"></a></td>
351 9c96aff5 Bill Marquette
                      </tr>
352
                      <tr>
353 677c0869 Erik Kristensen
                        <td><?php if ($nnats == 0): ?><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" title="delete selected mappings" onclick="return confirm('Do you really want to delete the selected mappings?')"><?php endif; ?></td>
354 9c96aff5 Bill Marquette
                      </tr>
355
                    </table></td>
356 5b237745 Scott Ullrich
                </tr>
357
              </table>
358 d732f186 Bill Marquette
	    </div>
359 5b237745 Scott Ullrich
</td>
360
  </tr>
361
</table>
362
            </form>
363
<?php include("fend.inc"); ?>
364
</body>
365
</html>