Project

General

Profile

Download (8.05 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
    firewall_nat_out.php
5
    part of m0n0wall (http://m0n0.ch/wall)
6

    
7
    Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
    All rights reserved.
9

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

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

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

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

    
32
require("guiconfig.inc");
33

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

    
37
$a_out = &$config['nat']['advancedoutbound']['rule'];
38
nat_out_rules_sort();
39

    
40
if ($_POST) {
41

    
42
    $pconfig = $_POST;
43

    
44
    $config['nat']['advancedoutbound']['enable'] = ($_POST['enable']) ? true : false;
45
    $pconfig['nat']['enableoutboundloadbalancing'] = $_POST['enableoutboundloadbalancing'] ? true : false;
46
    write_config();
47

    
48
    $retval = 0;
49

    
50
    if (!file_exists($d_sysrebootreqd_path)) {
51
		config_lock();
52
        $retval |= filter_configure();
53
		config_unlock();
54
    }
55
    $savemsg = get_std_save_message($retval);
56

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

    
65
if ($_GET['act'] == "del") {
66
    if ($a_out[$_GET['id']]) {
67
        unset($a_out[$_GET['id']]);
68
        write_config();
69
        touch($d_natconfdirty_path);
70
        header("Location: firewall_nat_out.php");
71
        exit;
72
    }
73
}
74
?>
75
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
76
<html>
77
<head>
78
<title><?=gentitle("Firewall: NAT");?></title>
79
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
80
<link href="gui.css" rel="stylesheet" type="text/css">
81
</head>
82

    
83
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
84
<?php include("fbegin.inc"); ?>
85
<p class="pgtitle">Firewall: NAT</p>
86
<form action="firewall_nat_out.php" method="post">
87
<?php if ($savemsg) print_info_box($savemsg); ?>
88
<?php if (file_exists($d_natconfdirty_path)): ?><p>
89
<?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>
90
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
91
<?php endif; ?>
92
<table width="100%" border="0" cellpadding="0" cellspacing="0">  <tr><td>
93
  <ul id="tabnav">
94
    <li class="tabinact"><a href="firewall_nat.php">Inbound</a></li>
95
    <li class="tabinact"><a href="firewall_nat_server.php">Server NAT</a></li>
96
    <li class="tabinact"><a href="firewall_nat_1to1.php">1:1</a></li>
97
    <li class="tabact">Outbound</li>
98
  </ul>
99
  </td></tr>
100
  <tr>
101
    <td class="tabcont">
102
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
103
                <tr>
104
                  <td class="vtable"><p>
105
                      <input name="enable" type="checkbox" id="enable" value="yes" <?php if (isset($config['nat']['advancedoutbound']['enable'])) echo "checked";?>>
106
                      <strong>Enable advanced outbound NAT<br>
107
                      </strong></p>
108
                  </td>
109
                  <td class="vtable"><p>
110
                        <input name="enableoutboundloadbalancing" type="checkbox" id="enableoutboundloadbalancing" value="yes" <?php if ($pconfig['enableoutboundloadbalancing'] == "yes") echo "checked";?>>
111
                        <strong>Enable outbound load balancing.<br>
112
                        </strong></p>
113
                  </td>
114
                </tr>
115
                <tr>
116
                  <td> <input name="submit" type="submit" class="formbtn" value="Save">
117
                  </td>
118
                </tr>
119
                <tr>
120
                  <td colspan="2"><p><span class="vexpl"><span class="red"><strong>Note:<br>
121
                      </strong></span>If advanced outbound NAT is enabled, no outbound NAT
122
                      rules will be automatically generated anymore. Instead, only the mappings
123
                      you specify below will be used. With advanced outbound NAT disabled,
124
                      a mapping is automatically created for each interface's subnet
125
                      (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>
126
                      <br>
127
                      You may enter your own mappings below.</p>
128
                    </td>
129
                </tr>
130
              </table>
131
              &nbsp;<br>
132
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
133
                <tr>
134
                  <td width="10%" class="listhdrr">Interface</td>
135
                  <td width="20%" class="listhdrr">Source</td>
136
                  <td width="20%" class="listhdrr">Destination</td>
137
                  <td width="20%" class="listhdrr">Target</td>
138
                  <td width="25%" class="listhdr">Description</td>
139
                  <td width="5%" class="list"></td>
140
                </tr>
141
              <?php $i = 0; foreach ($a_out as $natent): ?>
142
                <tr>
143
                  <td class="listlr">
144
                    <?php
145
					if (!$natent['interface'] || ($natent['interface'] == "wan"))
146
					  	echo "WAN";
147
					else
148
						htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
149
					?>
150
                  </td>
151
                  <td class="listr">
152
                    <?=$natent['source']['network'];?>
153
                  </td>
154
                  <td class="listr">
155
                    <?php
156
                      if (isset($natent['destination']['any']))
157
                          echo "*";
158
                      else {
159
                          if (isset($natent['destination']['not']))
160
                              echo "!&nbsp;";
161
                          echo $natent['destination']['network'];
162
                      }
163
                    ?>
164
                  </td>
165
                  <td class="listr">
166
                    <?php
167
                      if (!$natent['target'])
168
                          echo "*";
169
                      else
170
                          echo $natent['target'];
171
                    ?>
172
                  </td>
173
                  <td class="listbg">
174
                    <font color="#FFFFFF"><?=htmlspecialchars($natent['descr']);?>&nbsp;
175
                  </td>
176
                  <td class="list" nowrap> <a href="firewall_nat_out_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
177
                     &nbsp;<a href="firewall_nat_out.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this mapping?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
178
                </tr>
179
              <?php $i++; endforeach; ?>
180
                <tr>
181
                  <td class="list" colspan="5"></td>
182
                  <td class="list"> <a href="firewall_nat_out_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
183
                </tr>
184
              </table>
185
</td>
186
  </tr>
187
</table>
188
            </form>
189
<?php include("fend.inc"); ?>
190
</body>
191
</html>
(24-24/88)