Project

General

Profile

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