Project

General

Profile

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

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

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

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

    
19
    2. Redistributions in binary form must reproduce the above copyright
20
       notice, this list of conditions and the following disclaimer in the
21
       documentation and/or other materials provided with the distribution.
22

    
23
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
    POSSIBILITY OF SUCH DAMAGE.
33
*/
34

    
35
require("guiconfig.inc");
36

    
37
if (!is_array($config['nat']['advancedoutbound']['rule']))
38
    $config['nat']['advancedoutbound']['rule'] = array();
39

    
40
$a_out = &$config['nat']['advancedoutbound']['rule'];
41
//nat_out_rules_sort();
42

    
43
if ($_POST) {
44

    
45
    $pconfig = $_POST;
46

    
47
    if ($_POST['apply']) {
48

    
49
        write_config();
50

    
51
        $retval = 0;
52

    
53
        if (!file_exists($d_sysrebootreqd_path)) {
54
		config_lock();
55
		$retval |= filter_configure();
56
		config_unlock();
57
        }
58
	if(stristr($retval, "error") <> true)
59
	        $savemsg = get_std_save_message($retval);
60
	else
61
		$savemsg = $retval;
62

    
63
        if ($retval == 0) {
64
            if (file_exists($d_natconfdirty_path))
65
                unlink($d_natconfdirty_path);
66
            if (file_exists($d_filterconfdirty_path))
67
                unlink($d_filterconfdirty_path);
68
        }
69
    }
70
}
71

    
72

    
73

    
74
if (isset($_POST['save'])) {
75

    
76
    /* mutually exclusive settings - if user wants advanced NAT, we don't help with IPSec */
77
    if ($_POST['ipsecpassthru'] == true) {
78
            $config['nat']['ipsecpassthru']['enable'] = true;
79
            $config['nat']['advancedoutbound']['enable'] = false;
80
    }
81
    if ($_POST['advancedoutbound'] == true) {
82
            $config['nat']['advancedoutbound']['enable'] = true;
83
            $config['nat']['ipsecpassthru']['enable'] = false;
84
    }
85
    if ($_POST['ipsecpassthru'] == false)
86
            $config['nat']['ipsecpassthru']['enable'] = false;
87
    if ($_POST['advancedoutbound'] == false)
88
            $config['nat']['advancedoutbound']['enable'] = false;
89

    
90
    write_config();
91
    touch($d_natconfdirty_path);
92
    header("Location: firewall_nat_out.php");
93
    exit;
94
}
95

    
96
if (isset($_POST['del_x'])) {
97
        /* delete selected rules */
98
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
99
                foreach ($_POST['rule'] as $rulei) {
100
                        unset($a_out[$rulei]);
101
                }
102
                write_config();
103
                touch($d_natconfdirty_path);
104
                header("Location: firewall_nat_out.php");
105
                exit;
106
        }
107

    
108
} else {
109
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
110
        unset($movebtn);
111
        foreach ($_POST as $pn => $pd) {
112
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
113
                        $movebtn = $matches[1];
114
                        break;
115
                }
116
        }
117
        /* move selected rules before this rule */
118
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
119
                $a_out_new = array();
120

    
121
                /* copy all rules < $movebtn and not selected */
122
                for ($i = 0; $i < $movebtn; $i++) {
123
                        if (!in_array($i, $_POST['rule']))
124
                                $a_out_new[] = $a_out[$i];
125
                }
126

    
127
                /* copy all selected rules */
128
                for ($i = 0; $i < count($a_out); $i++) {
129
                        if ($i == $movebtn)
130
                                continue;
131
                        if (in_array($i, $_POST['rule']))
132
                                $a_out_new[] = $a_out[$i];
133
                }
134

    
135
                /* copy $movebtn rule */
136
                if ($movebtn < count($a_out))
137
                        $a_out_new[] = $a_out[$movebtn];
138

    
139
                /* copy all rules > $movebtn and not selected */
140
                for ($i = $movebtn+1; $i < count($a_out); $i++) {
141
                        if (!in_array($i, $_POST['rule']))
142
                                $a_out_new[] = $a_out[$i];
143
                }
144
                $a_out = $a_out_new;
145
                write_config();
146
                touch($d_natconfdirty_path);
147
                header("Location: firewall_nat_out.php");
148
                exit;
149
        }
150
}
151

    
152

    
153
?>
154
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
155
<html>
156
<head>
157
<title><?=gentitle("Firewall: NAT: Outbound");?></title>
158
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
159
<link href="gui.css" rel="stylesheet" type="text/css">
160
</head>
161

    
162
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
163
<?php include("fbegin.inc"); ?>
164
<p class="pgtitle">Firewall: NAT: Outbound</p>
165
<form action="firewall_nat_out.php" method="post" name="iform">
166
<script type="text/javascript" language="javascript" src="row_toggle.js">
167
</script>
168
<?php if ($savemsg) print_info_box($savemsg); ?>
169
<?php if (file_exists($d_natconfdirty_path)): ?><p>
170
<?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>
171
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
172
<?php endif; ?>
173
<table width="100%" border="0" cellpadding="0" cellspacing="0">  <tr><td>
174
  <ul id="tabnav">
175
    <li class="tabinact"><a href="firewall_nat.php">Inbound</a></li>
176
    <li class="tabinact"><a href="firewall_nat_server.php">Server NAT</a></li>
177
    <li class="tabinact"><a href="firewall_nat_1to1.php">1:1</a></li>
178
    <li class="tabact">Outbound</li>
179
    <li class="tabinact"><a href="firewall_nat_out_load_balancing.php">Outbound Load Balancing</a></li>
180
  </ul>
181
  </td></tr>
182
  <tr>
183
    <td class="tabcont">
184
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
185
              <tr>
186
                  <td class="vtable"><p>
187
                      <input name="ipsecpassthru" type="checkbox" id="ipsecpassthru" value="yes" onClick="document.iform.advancedoutbound.checked=false" <?php if (isset($config['nat']['ipsecpassthru']['enable'])) echo "checked";?>>
188
                      <strong>Enable IPSec passthru</strong></p>
189
                  </td>
190
                </tr>
191
                <tr>
192
                  <td class="vtable"><p>
193
                      <input name="advancedoutbound" type="checkbox" id="advancedoutbound" value="yes" onClick="document.iform.ipsecpassthru.checked=false" <?php if (isset($config['nat']['advancedoutbound']['enable'])) echo "checked";?>>
194
                      <strong>Enable advanced outbound NAT</strong></p></td>
195
                </tr>
196
                <tr>
197
                  <td> <input name="save" type="submit" class="formbtn" value="Save">
198
                  </td>
199
                </tr>
200
                <tr>
201
                  <td colspan="2"><p><span class="vexpl"><span class="red"><strong>Note:<br>
202
                      </strong></span>If advanced outbound NAT is enabled, no outbound NAT
203
                      rules will be automatically generated anymore. Instead, only the mappings
204
                      you specify below will be used. With advanced outbound NAT disabled,
205
                      a mapping is automatically created for each interface's subnet
206
                      (except WAN).</span> If you use target addresses other than the WAN interface's IP address, then depending on<span class="vexpl"> the way your WAN connection is setup, you may also need <a href="services_proxyarp.php">proxy ARP</a>.</span><br>
207
                      <br>
208
                      You may enter your own mappings below.</p>
209
                    </td>
210
                </tr>
211
              </table>
212
              &nbsp;<br>
213
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
214
                <tr id="frheader">
215
                  <td width="3%" class="list">&nbsp;</td>
216
                  <td width="3%" class="list">&nbsp;</td>
217
                  <td width="10%" class="listhdrr">Interface</td>
218
                  <td width="20%" class="listhdrr">Source</td>
219
                  <td width="20%" class="listhdrr">Source Port</td>
220
                  <td width="20%" class="listhdrr">Destination</td>
221
                  <td width="20%" class="listhdrr">NAT Port</td>
222
                  <td width="20%" class="listhdrr">Target</td>
223
                  <td width="25%" class="listhdr">Description</td>
224
                  <td width="5%" class="list"></td>
225
                </tr>
226
              <?php $nnats = $i = 0; foreach ($a_out as $natent): ?>
227
                <tr valign="top" id="fr<?=$nnats;?>">
228
                  <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>
229
                  <td class="listt" align="center"></td>
230
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
231
                    <?php
232
					if (!$natent['interface'] || ($natent['interface'] == "wan"))
233
					  	echo "WAN";
234
					else
235
						echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
236
					?>
237
                                        &nbsp;
238
                  </td>
239
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
240
                    <?=$natent['source']['network'];?>
241
                  </td>
242
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
243
                    <?php
244
                      if (!$natent['sourceport'])
245
                          echo "*";
246
                      else
247
                          echo $natent['sourceport'];
248
                    ?>
249
                  </td>
250
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
251
                    <?php
252
                      if (isset($natent['destination']['any']))
253
                          echo "*";
254
                      else {
255
                          if (isset($natent['destination']['not']))
256
                              echo "!&nbsp;";
257
                          echo $natent['destination']['network'];
258
                      }
259
                    ?>
260
                  </td>
261
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
262
                    <?php
263
                      if (!$natent['natport'])
264
                          echo "*";
265
                      else
266
                          echo $natent['natport'];
267
                    ?>
268
                  </td>
269
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
270
                    <?php
271
                      if (!$natent['target'])
272
                          echo "*";
273
                      else
274
                          echo $natent['target'];
275
                    ?>
276
                  </td>
277
                  <td class="listbg"  onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_out_edit.php?id=<?=$nnats;?>';">
278
                    <font color="#FFFFFF"><?=htmlspecialchars($natent['descr']);?>&nbsp;
279
                  </td>
280
                  <td class="list" valign="middle" nowrap>
281
                    <table border="0" cellspacing="0" cellpadding="1">
282
                      <tr>
283
                        <td><a href="firewall_nat_out_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
284
                      </tr>
285
                      <tr>
286
                        <td><input onmouseover="fr_insline(<?=$nnats;?>, true)" onmouseout="fr_insline(<?=$nnats;?>, false)" name="move_<?=$i;?>" src="left.gif" title="move selected rules before this rule" height="17" type="image" width="17" border="0"></td>
287
                        <!-- <billm><td><a href="firewall_nat_out_edit.php?dup=<?=$i;?>"><img src="plus.gif" title="add a new nat based on this one" width="17" height="17" border="0"></a></td><billm> -->
288
                      </tr>
289
                    </table>
290
              <?php $i++; $nnats++; endforeach; ?>
291
                <tr>
292
                  <td class="list" colspan="9"></td>
293
                  <td class="list" valign="middle" nowrap>
294
                    <table border="0" cellspacing="0" cellpadding="1">
295
                      <tr>
296
                        <td><?php if ($nnats == 0): ?><img src="left_d.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="left.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php endif; ?></td>
297
                        <td><a href="firewall_nat_out_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
298
                      </tr>
299
                      <tr>
300
                        <td><?php if ($nnats == 0): ?><img src="x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="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>
301
                      </tr>
302
                    </table></td>
303
                </tr>
304
              </table>
305
</td>
306
  </tr>
307
</table>
308
            </form>
309
<?php include("fend.inc"); ?>
310
</body>
311
</html>
(29-29/112)