Project

General

Profile

Download (10.9 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	firewall_nat.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']['rule']))
37
	$config['nat']['rule'] = array();
38
	
39
$a_nat = &$config['nat']['rule'];
40
//nat_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
if (isset($_POST['del_x'])) {
72
        /* delete selected rules */
73
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
74
                foreach ($_POST['rule'] as $rulei) {
75
                        unset($a_nat[$rulei]);
76
                }
77
                write_config();
78
                touch($d_natconfdirty_path);
79
                header("Location: firewall_nat.php");
80
                exit;
81
        }
82

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

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

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

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

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

    
127
?>
128
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
129
<html>
130
<head>
131
<title><?=gentitle("Firewall: NAT: Inbound");?></title>
132
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
133
<link href="gui.css" rel="stylesheet" type="text/css">
134
</head>
135

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

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

    
254
</form>
255
<?php include("fend.inc"); ?>
256
</body>
257
</html>
(24-24/106)