Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
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
		config_lock();
53
		$retval |= filter_configure();
54
		config_unlock();
55

    
56
		if(stristr($retval, "error") <> true)
57
		    $savemsg = get_std_save_message($retval);
58
		else
59
		    $savemsg = $retval;
60

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

    
70
if (isset($_POST['del_x'])) {
71
        /* delete selected rules */
72
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
73
                foreach ($_POST['rule'] as $rulei) {
74
                        unset($a_nat[$rulei]);
75
                }
76
                write_config();
77
                touch($d_natconfdirty_path);
78
                header("Location: firewall_nat.php");
79
                exit;
80
        }
81

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

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

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

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

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

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

    
129
?>
130
<body link="#000000" vlink="#000000" alink="#000000">
131
<?php include("fbegin.inc"); ?>
132
<p class="pgtitle"><?=$pgtitle?></font></p>
133
<form action="firewall_nat.php" method="post" name="iform">
134
<script type="text/javascript" language="javascript" src="row_toggle.js">
135
</script>
136
<?php if ($savemsg) print_info_box($savemsg); ?>
137
<?php if (file_exists($d_natconfdirty_path)): ?><p>
138
<?php print_info_box_np("The NAT configuration has been changed.<br>You must apply the changes in order for them to take effect.");?>
139
<?php endif; ?>
140
<table width="100%" border="0" cellpadding="0" cellspacing="0">
141
  <tr><td>
142
<?php
143
	$tab_array = array();
144
	$tab_array[] = array("Port Forward", true, "firewall_nat.php");
145
	$tab_array[] = array("1:1", false, "firewall_nat_1to1.php");
146
	$tab_array[] = array("Outbound", false, "firewall_nat_out.php");
147
	display_top_tabs($tab_array);
148
?>
149
 </td></tr>
150
  <tr>
151
    <td>
152
	<div id="mainarea">
153
              <table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
154
                <tr id="frheader">
155
		  <td width="3%" class="list">&nbsp;</td>
156
                  <td width="3%" class="list">&nbsp;</td>
157
                  <td width="5%" class="listhdrr">If</td>
158
                  <td width="5%" class="listhdrr">Proto</td>
159
                  <td width="20%" class="listhdrr">Ext. port range</td>
160
                  <td width="20%" class="listhdrr">NAT IP</td>
161
                  <td width="20%" class="listhdrr">Int. port range</td>
162
                  <td width="20%" class="listhdr">Description</td>
163
                  <td width="5%" class="list"></td>
164
		</tr>
165
	<?php $nnats = $i = 0; foreach ($a_nat as $natent): ?>
166
                <tr valign="top" id="fr<?=$nnats;?>">
167
                  <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>
168
                  <td class="listt" align="center"></td>
169
                  <td class="listlr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
170
		    <?php
171
			if (!$natent['interface'] || ($natent['interface'] == "wan"))
172
				echo "WAN";
173
			else
174
				echo strtoupper($natent['interface']);
175
		    ?>
176
                  </td>
177
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
178
                    <?=strtoupper($natent['protocol']);?>
179
                  </td>
180
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
181
                    <?php
182
						list($beginport, $endport) = split("-", $natent['external-port']);
183
						if ((!$endport) || ($beginport == $endport)) {
184
				  			echo $beginport;
185
							if ($wkports[$beginport])
186
								echo " (" . $wkports[$beginport] . ")";
187
						} else
188
							echo $beginport . " - " . $endport;
189
				  ?>
190
                  </td>
191
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
192
                    <?=$natent['target'];?>
193
					<?php if ($natent['external-address'])
194
						echo "<br>(ext.: " . $natent['external-address'] . ")";
195
					?>
196
                  </td>
197
                  <td class="listr" onClick="fr_toggle(<?=$nnats;?>)" id="frd<?=$nnats;?>" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
198
                    <?php if ((!$endport) || ($beginport == $endport)) {
199
				  			echo $natent['local-port'];
200
							if ($wkports[$natent['local-port']])
201
								echo " (" . $wkports[$natent['local-port']] . ")";
202
						} else
203
							echo $natent['local-port'] . " - " .
204
								($natent['local-port']+$endport-$beginport);
205
				  ?>
206
                  </td>
207
                  <td class="listbg" onClick="fr_toggle(<?=$nnats;?>)" ondblclick="document.location='firewall_nat_edit.php?id=<?=$nnats;?>';">
208
		  <font color="#ffffff">
209
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
210
                  </td>
211
                  <td valign="middle" class="list" nowrap>
212
                    <table border="0" cellspacing="0" cellpadding="1">
213
                      <tr>
214
                        <td><a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="edit rule"></a></td>
215
                      </tr>
216
                      <tr>
217
                        <td><input onmouseover="fr_insline(<?=$nnats;?>, true)" onmouseout="fr_insline(<?=$nnats;?>, false)" name="move_<?=$i;?>" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" title="move selected rules before this rule" height="17" type="image" width="17" border="0"></td>
218
                        <td><a href="firewall_nat_edit.php?dup=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add a new nat based on this one" width="17" height="17" border="0"></a></td>
219
                      </tr>
220
                    </table>
221
		</tr>
222
  	     <?php $i++; $nnats++; endforeach; ?>
223
                <tr>
224
                  <td class="list" colspan="8"></td>
225
                  <td class="list" valign="middle" nowrap>
226
                    <table border="0" cellspacing="0" cellpadding="1">
227
                      <tr>
228
                        <td><?php if ($nnats == 0): ?><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_left_d.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php else: ?><input name="move_<?=$i;?>" type="image" src="/themes/<?= $g['theme']; ?>/images/icons/icon_left.gif" width="17" height="17" title="move selected mappings to end" border="0"><?php endif; ?></td>
229
                        <td><a href="firewall_nat_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
230
                      </tr>
231
                      <tr>
232
                        <td><?php if ($nnats == 0): ?><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x_d.gif" width="17" height="17" title="delete selected rules" border="0"><?php else: ?><input name="del" type="image" src="./themes/<?= $g['theme']; ?>/images/icons/icon_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>
233
                      </tr>
234
                    </table></td>
235
                </tr>
236
	</table>
237
	</div>
238
	</td>
239
  </tr>
240
</table>
241

    
242
<?php
243
if ($pkg['tabs'] <> "") {
244
    echo "</td></tr></table>";
245
}
246
?>
247

    
248
</form>
249
<?php include("fend.inc"); ?>
250
</body>
251
</html>
(35-35/155)