Project

General

Profile

Download (11.1 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	firewall_nat.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']['rule']))
38
	$config['nat']['rule'] = array();
39

    
40
$a_nat = &$config['nat']['rule'];
41
//nat_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
if (isset($_POST['del_x'])) {
73
        /* delete selected rules */
74
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
75
                foreach ($_POST['rule'] as $rulei) {
76
                        unset($a_nat[$rulei]);
77
                }
78
                write_config();
79
                touch($d_natconfdirty_path);
80
                header("Location: firewall_nat.php");
81
                exit;
82
        }
83

    
84
} else {
85
        /* yuck - IE won't send value attributes for image buttons, while Mozilla does - so we use .x/.y to find move button clicks instead... */
86
        unset($movebtn);
87
        foreach ($_POST as $pn => $pd) {
88
                if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
89
                        $movebtn = $matches[1];
90
                        break;
91
                }
92
        }
93
        /* move selected rules before this rule */
94
        if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
95
                $a_nat_new = array();
96

    
97
                /* copy all rules < $movebtn and not selected */
98
                for ($i = 0; $i < $movebtn; $i++) {
99
                        if (!in_array($i, $_POST['rule']))
100
                                $a_nat_new[] = $a_nat[$i];
101
                }
102

    
103
                /* copy all selected rules */
104
                for ($i = 0; $i < count($a_nat); $i++) {
105
                        if ($i == $movebtn)
106
                                continue;
107
                        if (in_array($i, $_POST['rule']))
108
                                $a_nat_new[] = $a_nat[$i];
109
                }
110

    
111
                /* copy $movebtn rule */
112
                if ($movebtn < count($a_nat))
113
                        $a_nat_new[] = $a_nat[$movebtn];
114

    
115
                /* copy all rules > $movebtn and not selected */
116
                for ($i = $movebtn+1; $i < count($a_nat); $i++) {
117
                        if (!in_array($i, $_POST['rule']))
118
                                $a_nat_new[] = $a_nat[$i];
119
                }
120
                $a_nat = $a_nat_new;
121
                write_config();
122
                touch($d_natconfdirty_path);
123
                header("Location: firewall_nat.php");
124
                exit;
125
        }
126
}
127

    
128
$pgtitle = "Firewall: NAT: Port Forward";
129
include("head.inc");
130

    
131
?>
132
<body link="#000000" vlink="#000000" alink="#000000">
133
<?php include("fbegin.inc"); ?>
134
<p class="pgtitle"><?=$pgtitle?></font></p>
135
<form action="firewall_nat.php" method="post" name="iform">
136
<script type="text/javascript" language="javascript" src="row_toggle.js">
137
</script>
138
<?php if ($savemsg) print_info_box($savemsg); ?>
139
<?php if (file_exists($d_natconfdirty_path)): ?><p>
140
<?php print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");?>
141
<?php endif; ?>
142
<table width="100%" border="0" cellpadding="0" cellspacing="0">
143
  <tr><td>
144
<?php
145
	$tab_array = array();
146
	$tab_array[0] = array("Port Forward", true, "firewall_nat.php");
147
	$tab_array[1] = array("NAT Addresses", false, "firewall_nat_server.php");
148
	$tab_array[2] = array("1:1", false, "firewall_nat_1to1.php");
149
	$tab_array[3] = array("Outbound", false, "firewall_nat_out.php");
150
	$tab_array[4] = array("Outbound Load Balancing", false, "firewall_nat_out_load_balancing.php");
151
	display_top_tabs($tab_array);
152
?>
153
 </td></tr>
154
  <tr>
155
    <td>
156
	<div id="mainarea">
157
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
158
                <tr id="frheader">
159
		  <td width="3%" class="list">&nbsp;</td>
160
                  <td width="3%" class="list">&nbsp;</td>
161
                  <td width="5%" class="listhdrr">If</td>
162
                  <td width="5%" class="listhdrr">Proto</td>
163
                  <td width="20%" class="listhdrr">Ext. port range</td>
164
                  <td width="20%" class="listhdrr">NAT IP</td>
165
                  <td width="20%" class="listhdrr">Int. port range</td>
166
                  <td width="20%" class="listhdr">Description</td>
167
                  <td width="5%" class="list"></td>
168
		</tr>
169
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
170
                <tr valign="top" id="fr<?=$nnats;?>">
171
                  <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>
172
                  <td class="listt" align="center"></td>
173
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
174
                    <?php
175
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
176
				echo "WAN";
177
			else
178
				echo htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
179
		    ?>
180
                  </td>
181
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
182
                    <?=strtoupper($natent['protocol']);?>
183
                  </td>
184
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
185
                    <?php
186
						list($beginport, $endport) = split("-", $natent['external-port']);
187
						if ((!$endport) || ($beginport == $endport)) {
188
				  			echo $beginport;
189
							if ($wkports[$beginport])
190
								echo " (" . $wkports[$beginport] . ")";
191
						} else
192
							echo $beginport . " - " . $endport;
193
				  ?>
194
                  </td>
195
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
196
                    <?=$natent['target'];?>
197
					<?php if ($natent['external-address'])
198
						echo "<br>(ext.: " . $natent['external-address'] . ")";
199
					?>
200
                  </td>
201
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
202
                    <?php if ((!$endport) || ($beginport == $endport)) {
203
				  			echo $natent['local-port'];
204
							if ($wkports[$natent['local-port']])
205
								echo " (" . $wkports[$natent['local-port']] . ")";
206
						} else
207
							echo $natent['local-port'] . " - " .
208
								($natent['local-port']+$endport-$beginport);
209
				  ?>
210
                  </td>
211
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';"><font color="#FFFFFFF">
212
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
213
                  </td>
214
                  <td valign="middle" class="list" nowrap>
215
                    <table border="0" cellspacing="0" cellpadding="1">
216
                      <tr>
217
                        <td><a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a></td>
218
                      </tr>
219
                      <tr>
220
                        <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>
221
                        <td><a href="firewall_nat_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>
222
                      </tr>
223
                    </table>
224
		</tr>
225
  	     <?php $i++; $nnats++; endforeach; ?>
226
                <tr>
227
                  <td class="list" colspan="8"></td>
228
                  <td class="list" valign="middle" nowrap>
229
                    <table border="0" cellspacing="0" cellpadding="1">
230
                      <tr>
231
                        <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>
232
                        <td><a href="firewall_nat_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
233
                      </tr>
234
                      <tr>
235
                        <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>
236
                      </tr>
237
                    </table></td>
238
                </tr>
239
        <tr><td colspan="8"><p><span class="vexpl"><span class="red"><strong>Note:<br>
240
                      </strong></span>It is not possible to access NATed services
241
                      using the WAN IP address from within the LAN (or an optional
242
                      network).</span></p></td>
243
		    </tr>
244
	</table>
245
	</div>
246
	</td>
247
  </tr>
248
</table>
249

    
250
<?php
251
if ($pkg['tabs'] <> "") {
252
    echo "</td></tr></table>";
253
}
254
?>
255

    
256
</form>
257
<?php include("fend.inc"); ?>
258
</body>
259
</html>
(29-29/128)