Project

General

Profile

Download (18.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
    firewall_nat_out.php
5
    Copyright (C) 2004 Scott Ullrich
6
    All rights reserved.
7

    
8
    originally part of m0n0wall (http://m0n0.ch/wall)
9
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
    All rights reserved.
11

    
12
    Redistribution and use in source and binary forms, with or without
13
    modification, are permitted provided that the following conditions are met:
14

    
15
    1. Redistributions of source code must retain the above copyright notice,
16
       this list of conditions and the following disclaimer.
17

    
18
    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

    
22
    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
	pfSense_MODULE:	nat
35
*/
36

    
37
##|+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
require("guiconfig.inc");
45
require_once("functions.inc");
46
require_once("filter.inc");
47
require_once("shaper.inc");
48

    
49
if (!is_array($config['nat']['advancedoutbound']))
50
	$config['nat']['advancedoutbound'] = array();
51

    
52
if (!is_array($config['nat']['advancedoutbound']['rule']))
53
	$config['nat']['advancedoutbound']['rule'] = array();
54

    
55
$a_out = &$config['nat']['advancedoutbound']['rule'];
56

    
57
if ($_POST['apply']) {
58
	write_config();
59

    
60
	$retval = 0;
61
	$retval |= filter_configure();
62

    
63
	if(stristr($retval, "error") <> true)
64
	        $savemsg = get_std_save_message($retval);
65
	else
66
		$savemsg = $retval;
67

    
68
	if ($retval == 0) {
69
		clear_subsystem_dirty('natconf');
70
		clear_subsystem_dirty('filter');
71
        }
72
}
73

    
74

    
75

    
76
if (isset($_POST['save']) && $_POST['save'] == "Save") {
77
	/* mutually exclusive settings - if user wants advanced NAT, we don't generate automatic rules */
78
	switch ($_POST['advancedoripsec']) {
79
	case "ipsecpassthru":
80
               	$config['nat']['ipsecpassthru']['enable'] = true;
81
               	unset($config['nat']['advancedoutbound']['enable']);
82
               	if(count($config['nat']['advancedoutbound']['rule']) > 0)
83
			unset($config['nat']['advancedoutbound']['rule']);
84
		break;
85
	case "advancedoutboundnat":
86
        	if (!isset($config['nat']['advancedoutbound']['enable'])) {
87
			$config['nat']['advancedoutbound']['enable'] = true;
88
			/*
89
			 *    user has enabled advanced outbound nat -- lets automatically create entries
90
			 *    for all of the interfaces to make life easier on the pip-o-chap
91
			 */
92
			$ifdescrs = get_configured_interface_with_descr();
93
				
94
			foreach($ifdescrs as $if => $ifdesc) {
95
				if (interface_has_gateway($if))
96
					continue;
97
				$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
				foreach ($ifdescrs as $if2 => $ifdesc2) {
103
					if (!interface_has_gateway($if2))
104
						continue;
105

    
106
					$natent = array();
107
					$natent['nonat'] = true;
108
                                        $natent['source']['network'] = "any";
109
                                        $natent['sourceport'] = "";
110
                                        $natent['descr'] = "Auto nonat TFTP proxy created rule for {$ifdesc2}";
111
                                        $natent['target'] = "tftp";
112
                                        $natent['interface'] = $if2;
113
                                        $natent['destination']['any'] = true;
114
                                        $natent['natport'] = "";
115
                                        $a_out[] = $natent;
116

    
117
					$natent = array();
118
					$natent['source']['network'] = "{$osn}/{$ossubnet}";
119
					$natent['sourceport'] = "500";
120
					$natent['descr'] = "Auto NAT-T created rule for {$ifdesc2}";
121
					$natent['target'] = "";
122
					$natent['interface'] = $if2;
123
					$natent['destination']['any'] = true;
124
					$natent['natport'] = "500";
125
					$a_out[] = $natent;
126

    
127
					$natent = array();
128
					$natent['source']['network'] = "{$osn}/{$ossubnet}";
129
                                        $natent['sourceport'] = "5060";
130
                                        $natent['descr'] = "Auto NAT-T created rule for {$ifdesc2}";
131
                                        $natent['target'] = "";
132
                                        $natent['interface'] = $if2;
133
                                        $natent['destination']['any'] = true;
134
                                        $natent['natport'] = "5060";
135
                                        $a_out[] = $natent;
136
					
137
					$natent = array();
138
                                        $natent['source']['network'] = "{$osn}/{$ossubnet}";
139
                                        $natent['sourceport'] = "";
140
                                        $natent['descr'] = "Auto created rule for {$ifdesc2}";
141
                                        $natent['target'] = "";
142
                                        $natent['interface'] = $if2;
143
                                        $natent['destination']['any'] = true;
144
                                        $natent['natport'] = "";
145
                                        $a_out[] = $natent;
146
				}	
147
			}
148
			$savemsg = "Default rules for each interface have been created.";
149
		}
150
		break;
151
	}
152
        write_config();
153
	mark_subsystem_dirty('natconf');
154
        header("Location: firewall_nat_out.php");
155
        exit;
156
}
157

    
158
if (isset($_POST['del_x'])) {
159
        /* delete selected rules */
160
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
161
                foreach ($_POST['rule'] as $rulei) {
162
                        unset($a_out[$rulei]);
163
                }
164
                write_config();
165
		mark_subsystem_dirty('natconf');
166
                header("Location: firewall_nat_out.php");
167
                exit;
168
        }
169

    
170
} else {
171
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
172
        unset($movebtn);
173
        foreach ($_POST as $pn => $pd) {
174
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
175
                        $movebtn = $matches[1];
176
                        break;
177
                }
178
        }
179
        /* move selected rules before this rule */
180
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
181
                $a_out_new = array();
182

    
183
                /* copy all rules < $movebtn and not selected */
184
                for ($i = 0; $i < $movebtn; $i++) {
185
                        if (!in_array($i, $_POST['rule']))
186
                                $a_out_new[] = $a_out[$i];
187
                }
188

    
189
                /* copy all selected rules */
190
                for ($i = 0; $i < count($a_out); $i++) {
191
                        if ($i == $movebtn)
192
                                continue;
193
                        if (in_array($i, $_POST['rule']))
194
                                $a_out_new[] = $a_out[$i];
195
                }
196

    
197
                /* copy $movebtn rule */
198
                if ($movebtn < count($a_out))
199
                        $a_out_new[] = $a_out[$movebtn];
200

    
201
                /* copy all rules > $movebtn and not selected */
202
                for ($i = $movebtn+1; $i < count($a_out); $i++) {
203
                        if (!in_array($i, $_POST['rule']))
204
                                $a_out_new[] = $a_out[$i];
205
                }
206
                if (count($a_out_new) > 0)
207
			$a_out = $a_out_new;
208
		else
209
			unset($config['nat']['advancedoutbound']);
210

    
211
                write_config();
212
		mark_subsystem_dirty('natconf');
213
                header("Location: firewall_nat_out.php");
214
                exit;
215
        }
216
}
217

    
218

    
219
$pgtitle = array("Firewall","NAT","Outbound");
220
include("head.inc");
221

    
222
?>
223
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
224
<?php include("fbegin.inc"); ?>
225
<form action="firewall_nat_out.php" method="post" name="iform">
226
<script type="text/javascript" language="javascript" src="/javascript/row_toggle.js">
227
</script>
228
<?php if ($savemsg) print_info_box($savemsg); ?>
229
<?php if (is_subsystem_dirty('natconf')): ?><p>
230
<?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>
231
<?php endif; ?>
232
<table width="100%" border="0" cellpadding="0" cellspacing="0">  <tr><td>
233
<?php
234
	$tab_array = array();
235
	$tab_array[] = array("Port Forward", false, "firewall_nat.php");
236
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
237
	$tab_array[] = array("Outbound", true, "firewall_nat_out.php");
238
	display_top_tabs($tab_array);
239
?>
240
  </td></tr>
241
  <tr>
242
    <td>
243
	<div id="mainarea">
244
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
245
              <tr>
246
                  <td class="vtable"><p>
247
                      <input name="advancedoripsec" type="radio" id="ipsecpassthru" value="ipsecpassthru" <?php if (isset($config['nat']['ipsecpassthru']['enable'])) echo "checked";?>>
248
                      <strong><?=gettext("Automatic outbound NAT rule generation (IPsec passthrough)");?></strong></p>
249
                  </td>
250
                </tr>
251
                <tr>
252
                  <td class="vtable"><p>
253
                      <input name="advancedoripsec" type="radio" id="advancedoutbound" value="advancedoutboundnat" <?php if (isset($config['nat']['advancedoutbound']['enable'])) echo "checked";?>>
254
                      <strong><?=gettext("Manual Outbound NAT rule generation (Advanced Outbound NAT (AON))");?></strong></p></td>
255
                </tr>
256
                <tr>
257
                  <td> <input name="save" type="submit" class="formbtn" value="Save">
258
                  </td>
259
                </tr>
260
                <tr>
261
                  <td colspan="2"><p><span class="vexpl"><span class="red"><strong>Note:<br>
262
                      </strong></span>If advanced outbound NAT is enabled, no outbound NAT
263
                      rules will be automatically generated any longer. Instead, only the mappings
264
                      you specify below will be used. With advanced outbound NAT disabled,
265
                      a mapping is automatically created for each interface's subnet
266
                      (except WAN).  If you use target addresses other than the WAN interface's
267
		      IP address, then depending on the way your WAN connection is setup, you
268
	              may also need a <a href="firewall_virtual_ip.php">Virtual IP</a>.</span><br>
269
                      <br>
270
                      You may enter your own mappings below.</p>
271
                    </td>
272
                </tr>
273
              </table>
274
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
275
                <tr id="frheader">
276
                  <td width="3%" class="list">&nbsp;</td>
277
                  <td width="3%" class="list">&nbsp;</td>
278
                  <td width="10%" class="listhdrr">Interface</td>
279
                  <td width="15%" class="listhdrr">Source</td>
280
                  <td width="10%" class="listhdrr">Source Port</td>
281
                  <td width="15%" class="listhdrr">Destination</td>
282
                  <td width="10%" class="listhdrr">Destination Port</td>
283
                  <td width="15%" class="listhdrr">NAT Address</td>
284
                  <td width="10%" class="listhdrr">NAT Port</td>
285
		  <td width="10%" class="listhdrr">Static Port</td>
286
                  <td width="25%" class="listhdr">Description</td>
287
                  <td width="5%" class="list">
288
                    <table border="0" cellspacing="0" cellpadding="1">
289
                      <tr>
290
			<td width="17"></td>
291
                        <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>
292
                      </tr>
293
                    </table>
294
		  </td>
295
                </tr>
296
              <?php $nnats = $i = 0; foreach ($a_out as $natent): ?>
297
                <tr valign="top" id="fr<?=$nnats;?>">
298
                  <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>
299
                  <td class="listt" align="center"></td>
300
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
301
                    <?php
302
					if (!$natent['interface'] || ($natent['interface'] == "wan"))
303
					  	echo "WAN";
304
                                        else if (!$natent['interface'] || ($natent['interface'] == "lan"))
305
                                                 echo "LAN";                                                
306
					else if ($natent['interface'] == "openvpn")
307
						echo "OpenVPN";
308
					else
309
						echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
310
					?>
311
                                        &nbsp;
312
                  </td>
313
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
314
                    <?=$natent['source']['network'];?>
315
                  </td>
316
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
317
                    <?php
318
                      if (!$natent['sourceport'])
319
                          echo "*";
320
                      else
321
                          echo $natent['sourceport'];
322
                    ?>
323
                  </td>
324
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
325
                    <?php
326
                      if (isset($natent['destination']['any']))
327
                          echo "*";
328
                      else {
329
                          if (isset($natent['destination']['not']))
330
                              echo "!&nbsp;";
331
                          echo $natent['destination']['address'];
332
                      }
333
                    ?>
334
                  </td>
335
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
336
                    <?php
337
                      if (!$natent['dstport'])
338
                          echo "*";
339
                      else
340
                          echo $natent['dstport'];
341
                    ?>
342
                  </td>
343
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
344
                    <?php
345
                      if (!$natent['target'])
346
                          echo "*";
347
                      else
348
                          echo $natent['target'];
349
                    ?>
350
                  </td>
351
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
352
                    <?php
353
                      if (!$natent['natport'])
354
                          echo "*";
355
                      else
356
                          echo $natent['natport'];
357
                    ?>
358
                  </td>
359
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
360
                    <?php
361
			if(isset($natent['staticnatport']))
362
			    echo "<CENTER>YES</CENTER>";
363
			else
364
			    echo "<CENTER>NO</CENTER>";
365
                    ?>		    
366
                  </td>
367
                  <td class="listbg"  onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
368
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
369
                  </td>
370
                  <td class="list" valign="middle" nowrap>
371
                    <table border="0" cellspacing="0" cellpadding="1">
372
                      <tr>
373
                        <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>
374
                      </tr>
375
                      <tr>
376
                        <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>
377
                        <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>
378
                      </tr>
379
                    </table>
380
              <?php $i++; $nnats++; endforeach; ?>
381
                <tr>
382
                  <td class="list" colspan="11"></td>
383
                  <td class="list" valign="middle" nowrap>
384
                    <table border="0" cellspacing="0" cellpadding="1">
385
                      <tr>
386
                        <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>
387
                        <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>
388
                      </tr>
389
                      <tr>
390
                        <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>
391
                      </tr>
392
                    </table></td>
393
                </tr>
394
              </table>
395
	    </div>
396
</td>
397
  </tr>
398
</table>
399
            </form>
400
<?php include("fend.inc"); ?>
401
</body>
402
</html>
(53-53/214)