Project

General

Profile

Download (13.8 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
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
require("guiconfig.inc");
35

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

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

    
42
if ($_POST) {
43

    
44
    $pconfig = $_POST;
45

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

    
48
        write_config();
49

    
50
        $retval = 0;
51

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

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

    
71

    
72

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

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

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

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

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

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

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

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

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

    
151

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

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