Project

General

Profile

Download (13.1 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
        $savemsg = get_std_save_message($retval);
58

    
59
        if ($retval == 0) {
60
            if (file_exists($d_natconfdirty_path))
61
                unlink($d_natconfdirty_path);
62
            if (file_exists($d_filterconfdirty_path))
63
                unlink($d_filterconfdirty_path);
64
        }
65
    }
66
}
67

    
68

    
69

    
70
if (isset($_POST['save'])) {
71

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

    
86
    write_config();
87
    touch($d_natconfdirty_path);
88
    header("Location: firewall_nat_out.php");
89
    exit;
90
}
91

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

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

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

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

    
131
                /* copy $movebtn rule */
132
                if ($movebtn < count($a_out))
133
                        $a_out_new[] = $a_out[$movebtn];
134

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

    
148

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

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