Project

General

Profile

Download (17 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
34 6b07c15a Matthew Grooms
##|+PRIV
35
##|*IDENT=page-firewall-nat-outbound
36
##|*NAME=Firewall: NAT: Outbound page
37
##|*DESCR=Allow access to the 'Firewall: NAT: Outbound' page.
38
##|*MATCH=firewall_nat_out.php*
39
##|-PRIV
40
41
42 5b237745 Scott Ullrich
require("guiconfig.inc");
43
44
if (!is_array($config['nat']['advancedoutbound']['rule']))
45 82d0dfc4 Scott Ullrich
	$config['nat']['advancedoutbound']['rule'] = array();
46 19ae0929 Scott Ullrich
47 5b237745 Scott Ullrich
$a_out = &$config['nat']['advancedoutbound']['rule'];
48
49
50 82d0dfc4 Scott Ullrich
if ($_POST['apply']) {
51
	write_config();
52 5b237745 Scott Ullrich
53 82d0dfc4 Scott Ullrich
	$retval = 0;
54 920b3bb0 Scott Ullrich
	$retval |= filter_configure();
55
56 e8c2c890 Bill Marquette
	if(stristr($retval, "error") <> true)
57
	        $savemsg = get_std_save_message($retval);
58
	else
59
		$savemsg = $retval;
60 19ae0929 Scott Ullrich
61 82d0dfc4 Scott Ullrich
	if ($retval == 0) {
62
		unlink_if_exists($d_natconfdirty_path);
63
		unlink_if_exists($d_filterconfdirty_path);
64 9c96aff5 Bill Marquette
        }
65 5b237745 Scott Ullrich
}
66
67 fe693b89 Bill Marquette
68
69 82d0dfc4 Scott Ullrich
if (isset($_POST['save']) && $_POST['save'] == "Save") {
70 53bf5f1d Seth Mos
	/* mutually exclusive settings - if user wants advanced NAT, we don't generate automatic rules */
71 82d0dfc4 Scott Ullrich
	switch ($_POST['advancedoripsec']) {
72
	case "ipsecpassthru":
73
               	$config['nat']['ipsecpassthru']['enable'] = true;
74
               	unset($config['nat']['advancedoutbound']['enable']);
75
               	if(count($config['nat']['advancedoutbound']['rule']) == 0)
76
			unset($config['nat']['advancedoutbound']['rule']);
77
		break;
78
	case "advancedoutboundnat":
79
        	$was_enabled = isset($config['nat']['advancedoutbound']['enable']);
80
		$config['nat']['advancedoutbound']['enable'] = true;
81 f1f60c92 Ermal Luçi
		if (isset($config['nat']['ipsecpassthru']['enable']))
82
			unset($config['nat']['ipsecpassthru']['enable']);
83 82d0dfc4 Scott Ullrich
		if($was_enabled == false) {
84
			/*
85
			 *    user has enabled advanced outbound nat -- lets automatically create entries
86
			 *    for all of the interfaces to make life easier on the pip-o-chap
87
			 */
88 cbe3ea96 Ermal Luçi
			$ifdescrs = get_configured_interface_with_descr();
89
				
90
			foreach($ifdescrs as $if => $ifdesc) {
91 a55e9c70 Ermal Lu?i
				if (interface_has_gateway($if))
92 e1f675e4 Ermal Luçi
					continue;
93 a55e9c70 Ermal Lu?i
				if($ifdesc == "wan")
94 533e6800 Scott Ullrich
					continue;
95 82d0dfc4 Scott Ullrich
				$natent = array();
96 a55e9c70 Ermal Lu?i
				$osipaddr = get_interface_ip($if);
97
				$ossubnet = get_interface_subnet($if);
98
				if (!is_ipaddr($osipaddr) || empty($ossubnet))
99
					continue;
100
				$osn = gen_subnet($osipaddr, $ossubnet);
101
				$natent['source']['network'] = "{$osn}/{$ossubnet}";
102 82d0dfc4 Scott Ullrich
				$natent['sourceport'] = "";
103 cbe3ea96 Ermal Luçi
				$natent['descr'] = "Auto created rule for {$ifdesc}";
104 82d0dfc4 Scott Ullrich
				$natent['target'] = "";
105
				$natent['interface'] = "wan";
106
				$natent['destination']['any'] = true;
107
				$natent['natport'] = "";
108
				$a_out[] = $natent;
109 fa56ab75 Scott Ullrich
			}
110 82d0dfc4 Scott Ullrich
			$savemsg = "Default rules for each interface have been created.";
111
		}
112
		break;
113
	}
114 63868cb8 Scott Ullrich
        write_config();
115
        touch($d_natconfdirty_path);
116
        header("Location: firewall_nat_out.php");
117
        exit;
118 fe693b89 Bill Marquette
}
119
120 9c96aff5 Bill Marquette
if (isset($_POST['del_x'])) {
121
        /* delete selected rules */
122
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
123
                foreach ($_POST['rule'] as $rulei) {
124
                        unset($a_out[$rulei]);
125
                }
126
                write_config();
127
                touch($d_natconfdirty_path);
128
                header("Location: firewall_nat_out.php");
129
                exit;
130
        }
131
132
} else {
133 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... */
134 9c96aff5 Bill Marquette
        unset($movebtn);
135
        foreach ($_POST as $pn => $pd) {
136
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
137
                        $movebtn = $matches[1];
138
                        break;
139
                }
140
        }
141
        /* move selected rules before this rule */
142
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
143
                $a_out_new = array();
144
145
                /* copy all rules < $movebtn and not selected */
146
                for ($i = 0; $i < $movebtn; $i++) {
147
                        if (!in_array($i, $_POST['rule']))
148
                                $a_out_new[] = $a_out[$i];
149
                }
150
151
                /* copy all selected rules */
152
                for ($i = 0; $i < count($a_out); $i++) {
153
                        if ($i == $movebtn)
154
                                continue;
155
                        if (in_array($i, $_POST['rule']))
156
                                $a_out_new[] = $a_out[$i];
157
                }
158
159
                /* copy $movebtn rule */
160
                if ($movebtn < count($a_out))
161
                        $a_out_new[] = $a_out[$movebtn];
162
163
                /* copy all rules > $movebtn and not selected */
164
                for ($i = $movebtn+1; $i < count($a_out); $i++) {
165
                        if (!in_array($i, $_POST['rule']))
166
                                $a_out_new[] = $a_out[$i];
167
                }
168 82d0dfc4 Scott Ullrich
                if (count($a_out_new) > 0)
169
			$a_out = $a_out_new;
170
		else
171
			unset($config['nat']['advancedoutbound']);
172
173 9c96aff5 Bill Marquette
                write_config();
174
                touch($d_natconfdirty_path);
175
                header("Location: firewall_nat_out.php");
176
                exit;
177
        }
178 5b237745 Scott Ullrich
}
179 9c96aff5 Bill Marquette
180
181 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","NAT","Outbound");
182 6eb17647 Scott Ullrich
include("head.inc");
183
184 24f600b0 Scott Ullrich
?>
185 5b237745 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
186
<?php include("fbegin.inc"); ?>
187 fe693b89 Bill Marquette
<form action="firewall_nat_out.php" method="post" name="iform">
188 625dcc40 Bill Marquette
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js">
189 3f57ceee Bill Marquette
</script>
190 5b237745 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
191
<?php if (file_exists($d_natconfdirty_path)): ?><p>
192
<?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>
193
<?php endif; ?>
194
<table width="100%" border="0" cellpadding="0" cellspacing="0">  <tr><td>
195 a8726a3d Scott Ullrich
<?php
196
	$tab_array = array();
197 1425e067 Bill Marquette
	$tab_array[] = array("Port Forward", false, "firewall_nat.php");
198
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
199
	$tab_array[] = array("Outbound", true, "firewall_nat_out.php");
200 a8726a3d Scott Ullrich
	display_top_tabs($tab_array);
201
?>
202 5b237745 Scott Ullrich
  </td></tr>
203 19ae0929 Scott Ullrich
  <tr>
204 d732f186 Bill Marquette
    <td>
205
	<div id="mainarea">
206
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
207 fe693b89 Bill Marquette
              <tr>
208 5b237745 Scott Ullrich
                  <td class="vtable"><p>
209 82d0dfc4 Scott Ullrich
                      <input name="advancedoripsec" type="radio" id="ipsecpassthru" value="ipsecpassthru" <?php if (isset($config['nat']['ipsecpassthru']['enable'])) echo "checked";?>>
210 69e108df Chris Buechler
                      <strong><?=gettext("Automatic outbound NAT rule generation (IPsec passthrough)");?></strong></p>
211 6b3a7398 Scott Ullrich
                  </td>
212 5b237745 Scott Ullrich
                </tr>
213 19ae0929 Scott Ullrich
                <tr>
214 fe693b89 Bill Marquette
                  <td class="vtable"><p>
215 82d0dfc4 Scott Ullrich
                      <input name="advancedoripsec" type="radio" id="advancedoutbound" value="advancedoutboundnat" <?php if (isset($config['nat']['advancedoutbound']['enable'])) echo "checked";?>>
216 53bf5f1d Seth Mos
                      <strong><?=gettext("Manual Outbound NAT rule generation (Advanced Outbound NAT (AON))");?></strong></p></td>
217 fe693b89 Bill Marquette
                </tr>
218
                <tr>
219
                  <td> <input name="save" type="submit" class="formbtn" value="Save">
220 5b237745 Scott Ullrich
                  </td>
221
                </tr>
222
                <tr>
223 6b3a7398 Scott Ullrich
                  <td colspan="2"><p><span class="vexpl"><span class="red"><strong>Note:<br>
224 5b237745 Scott Ullrich
                      </strong></span>If advanced outbound NAT is enabled, no outbound NAT
225 af35a7e8 Scott Ullrich
                      rules will be automatically generated any longer. Instead, only the mappings
226 5b237745 Scott Ullrich
                      you specify below will be used. With advanced outbound NAT disabled,
227
                      a mapping is automatically created for each interface's subnet
228 0a82ada4 Bill Marquette
                      (except WAN).  If you use target addresses other than the WAN interface's
229
		      IP address, then depending on the way your WAN connection is setup, you
230
	              may also need a <a href="firewall_virtual_ip.php">Virtual IP</a>.</span><br>
231 5b237745 Scott Ullrich
                      <br>
232
                      You may enter your own mappings below.</p>
233
                    </td>
234
                </tr>
235
              </table>
236 d732f186 Bill Marquette
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
237 3f57ceee Bill Marquette
                <tr id="frheader">
238
                  <td width="3%" class="list">&nbsp;</td>
239
                  <td width="3%" class="list">&nbsp;</td>
240 5b237745 Scott Ullrich
                  <td width="10%" class="listhdrr">Interface</td>
241 3af33993 Scott Ullrich
                  <td width="15%" class="listhdrr">Source</td>
242
                  <td width="10%" class="listhdrr">Source Port</td>
243
                  <td width="15%" class="listhdrr">Destination</td>
244
                  <td width="10%" class="listhdrr">Destination Port</td>
245
                  <td width="15%" class="listhdrr">NAT Address</td>
246 5d8b0205 Scott Ullrich
                  <td width="10%" class="listhdrr">NAT Port</td>
247
		  <td width="10%" class="listhdrr">Static Port</td>
248 5b237745 Scott Ullrich
                  <td width="25%" class="listhdr">Description</td>
249 d415d821 Seth Mos
                  <td width="5%" class="list">
250
                    <table border="0" cellspacing="0" cellpadding="1">
251
                      <tr>
252
			<td width="17"></td>
253
                        <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>
254
                      </tr>
255
                    </table>
256
		  </td>
257 5b237745 Scott Ullrich
                </tr>
258 9c96aff5 Bill Marquette
              <?php $nnats = $i = 0; foreach ($a_out as $natent): ?>
259 3f57ceee Bill Marquette
                <tr valign="top" id="fr<?=$nnats;?>">
260
                  <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>
261 3364bed4 Bill Marquette
                  <td class="listt" align="center"></td>
262 f8b8c2fd Bill Marquette
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
263 5b237745 Scott Ullrich
                    <?php
264
					if (!$natent['interface'] || ($natent['interface'] == "wan"))
265
					  	echo "WAN";
266 c7f97efa Scott Ullrich
                                        else if (!$natent['interface'] || ($natent['interface'] == "lan"))
267
                                                 echo "LAN";                                                
268 f1f60c92 Ermal Luçi
					else if ($natent['interface'] == "openvpn")
269
						echo "OpenVPN";
270 5b237745 Scott Ullrich
					else
271 bb43786e Scott Ullrich
						echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
272 5b237745 Scott Ullrich
					?>
273 19f09ae1 Scott Ullrich
                                        &nbsp;
274 5b237745 Scott Ullrich
                  </td>
275 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
276 5b237745 Scott Ullrich
                    <?=$natent['source']['network'];?>
277
                  </td>
278 a88aca62 Scott Ullrich
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
279
                    <?php
280
                      if (!$natent['sourceport'])
281
                          echo "*";
282
                      else
283
                          echo $natent['sourceport'];
284
                    ?>
285
                  </td>
286 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
287 5b237745 Scott Ullrich
                    <?php
288
                      if (isset($natent['destination']['any']))
289
                          echo "*";
290
                      else {
291
                          if (isset($natent['destination']['not']))
292
                              echo "!&nbsp;";
293 2e56710c Scott Ullrich
                          echo $natent['destination']['address'];
294 5b237745 Scott Ullrich
                      }
295
                    ?>
296
                  </td>
297 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
298 a539f08b Bill Marquette
                    <?php
299 a88aca62 Scott Ullrich
                      if (!$natent['dstport'])
300 a539f08b Bill Marquette
                          echo "*";
301
                      else
302 a88aca62 Scott Ullrich
                          echo $natent['dstport'];
303 a539f08b Bill Marquette
                    ?>
304
                  </td>
305 f8b8c2fd Bill Marquette
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
306 5b237745 Scott Ullrich
                    <?php
307
                      if (!$natent['target'])
308
                          echo "*";
309
                      else
310
                          echo $natent['target'];
311
                    ?>
312
                  </td>
313 4d38bfc3 Scott Ullrich
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
314
                    <?php
315 3af33993 Scott Ullrich
                      if (!$natent['natport'])
316 4d38bfc3 Scott Ullrich
                          echo "*";
317
                      else
318 3af33993 Scott Ullrich
                          echo $natent['natport'];
319
                    ?>
320 5d8b0205 Scott Ullrich
                  </td>
321
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
322
                    <?php
323 b6905de8 Scott Ullrich
			if(isset($natent['staticnatport']))
324 3ea05ff4 Scott Ullrich
			    echo "<CENTER>YES</CENTER>";
325 b6905de8 Scott Ullrich
			else
326 3ea05ff4 Scott Ullrich
			    echo "<CENTER>NO</CENTER>";
327 5d8b0205 Scott Ullrich
                    ?>		    
328 4d38bfc3 Scott Ullrich
                  </td>
329 f8b8c2fd Bill Marquette
                  <td class="listbg"  onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
330 64286300 Scott Ullrich
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
331 5b237745 Scott Ullrich
                  </td>
332 9c96aff5 Bill Marquette
                  <td class="list" valign="middle" nowrap>
333
                    <table border="0" cellspacing="0" cellpadding="1">
334
                      <tr>
335 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>
336 9c96aff5 Bill Marquette
                      </tr>
337
                      <tr>
338 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>
339
                        <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>
340 9c96aff5 Bill Marquette
                      </tr>
341
                    </table>
342
              <?php $i++; $nnats++; endforeach; ?>
343 19ae0929 Scott Ullrich
                <tr>
344 3af33993 Scott Ullrich
                  <td class="list" colspan="11"></td>
345 9c96aff5 Bill Marquette
                  <td class="list" valign="middle" nowrap>
346
                    <table border="0" cellspacing="0" cellpadding="1">
347
                      <tr>
348 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>
349 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>
350 9c96aff5 Bill Marquette
                      </tr>
351
                      <tr>
352 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>
353 9c96aff5 Bill Marquette
                      </tr>
354
                    </table></td>
355 5b237745 Scott Ullrich
                </tr>
356
              </table>
357 d732f186 Bill Marquette
	    </div>
358 5b237745 Scott Ullrich
</td>
359
  </tr>
360
</table>
361
            </form>
362
<?php include("fend.inc"); ?>
363
</body>
364
</html>