Project

General

Profile

Download (11 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

    
41
if ($_POST) {
42

    
43
	$pconfig = $_POST;
44

    
45
	if ($_POST['apply']) {
46

    
47
		write_config();
48

    
49
		$retval = 0;
50
		
51
		config_lock();
52
		$retval |= filter_configure();
53
		config_unlock();
54

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

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

    
69
if (isset($_POST['del_x'])) {
70
        /* delete selected rules */
71
        if (is_array($_POST['rule']) && count($_POST['rule'])) {
72
                foreach ($_POST['rule'] as $rulei) {
73
			$target = $rule['target'];
74
			$helpers = exec("/bin/ps auwx | grep pftpx | grep {$target} | grep -v grep | cut -d\" \" -f5");
75
			if($helpers) {
76
				/* kill ftp proxy helper */
77
				mwexec("/bin/kill {$helpers}");
78
			}
79
                        unset($a_nat[$rulei]);
80
                }
81
                write_config();
82
                touch($d_natconfdirty_path);
83
                header("Location: firewall_nat.php");
84
                exit;
85
        }
86

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

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

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

    
114
                /* copy $movebtn rule */
115
                if ($movebtn < count($a_nat))
116
                        $a_nat_new[] = $a_nat[$movebtn];
117

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

    
131
$pgtitle = "Firewall: NAT: Port Forward";
132
include("head.inc");
133

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

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

    
253
</form>
254
<?php include("fend.inc"); ?>
255
</body>
256
</html>
(37-37/159)