Project

General

Profile

Download (6.57 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
nat_rules_sort();
40
$a_nat = &$config['nat']['rule'];
41

    
42
if ($_POST) {
43

    
44
	$pconfig = $_POST;
45

    
46
	if ($_POST['apply']) {
47
		$retval = 0;
48
		if (!file_exists($d_sysrebootreqd_path)) {
49
			config_lock();
50
			$retval |= filter_configure();
51
			config_unlock();
52
		}
53
		$savemsg = get_std_save_message($retval);
54

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

    
63

    
64

    
65
}
66

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

    
85
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
86
<?php include("fbegin.inc"); ?>
87
<p class="pgtitle">Firewall: NAT</font></p>
88
<form action="firewall_nat.php" method="post">
89
<?php if ($savemsg) print_info_box($savemsg); ?>
90
<?php if (file_exists($d_natconfdirty_path)): ?><p>
91
<?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>
92
<input name="apply" type="submit" class="formbtn" id="apply" value="Apply changes"></p>
93
<?php endif; ?>
94
<table width="100%" border="0" cellpadding="0" cellspacing="0">
95
  <tr><td>
96
  <ul id="tabnav">
97
    <li class="tabact">Inbound</li>
98
    <li class="tabinact"><a href="firewall_nat_server.php">Server NAT</a></li>
99
    <li class="tabinact"><a href="firewall_nat_1to1.php">1:1</a></li>
100
    <li class="tabinact"><a href="firewall_nat_out.php">Outbound</a></li>
101
    <li class="tabinact"><a href="firewall_nat_out_load_balancing.php">Outbound Load Balancing</a></li>
102
  </ul>
103
  </td></tr>
104
  <tr>
105
    <td class="tabcont">
106
              <table width="100%" border="0" cellpadding="0" cellspacing="0">
107
                <tr>
108
                  <td width="5%" class="listhdrr">If</td>
109
                  <td width="5%" class="listhdrr">Proto</td>
110
                  <td width="20%" class="listhdrr">Ext. port range</td>
111
                  <td width="20%" class="listhdrr">NAT IP</td>
112
                  <td width="20%" class="listhdrr">Int. port range</td>
113
                  <td width="20%" class="listhdr">Description</td>
114
                  <td width="5%" class="list"></td>
115
				</tr>
116
			  <?php $i = 0; foreach ($a_nat as $natent): ?>
117
                <tr valign="top">
118
				  <td class="listlr">
119
                  <?php
120
						if (!$natent['interface'] || ($natent['interface'] == "wan"))
121
							echo "WAN";
122
						else
123
							echo "<font color=\"#FFFFFF\">" . htmlspecialchars($config['interfaces'][$natent['interface']]['descr']);
124
				  ?>
125
                  </td>
126
                  <td class="listr">
127
                    <?=strtoupper($natent['protocol']);?>
128
                  </td>
129
                  <td class="listr">
130
                    <?php
131
						list($beginport, $endport) = split("-", $natent['external-port']);
132
						if ((!$endport) || ($beginport == $endport)) {
133
				  			echo $beginport;
134
							if ($wkports[$beginport])
135
								echo " (" . $wkports[$beginport] . ")";
136
						} else
137
							echo $beginport . " - " . $endport;
138
				  ?>
139
                  </td>
140
                  <td class="listr">
141
                    <?=$natent['target'];?>
142
					<?php if ($natent['external-address'])
143
						echo "<br>(ext.: " . $natent['external-address'] . ")";
144
					?>
145
                  </td>
146
                  <td class="listr">
147
                    <?php if ((!$endport) || ($beginport == $endport)) {
148
				  			echo $natent['local-port'];
149
							if ($wkports[$natent['local-port']])
150
								echo " (" . $wkports[$natent['local-port']] . ")";
151
						} else
152
							echo $natent['local-port'] . " - " .
153
								($natent['local-port']+$endport-$beginport);
154
				  ?>
155
                  </td>
156
                  <td class="listbg"><font color="#FFFFFFF">
157
                    <?=htmlspecialchars($natent['descr']);?>&nbsp;
158
                  </td>
159
                  <td valign="middle" class="list" nowrap> <a href="firewall_nat_edit.php?id=<?=$i;?>"><img src="e.gif" width="17" height="17" border="0"></a>
160
                     &nbsp;<a href="firewall_nat.php?act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this rule?')"><img src="x.gif" width="17" height="17" border="0"></a></td>
161
				</tr>
162
			  <?php $i++; endforeach; ?>
163
                <tr>
164
                  <td class="list" colspan="6"></td>
165
                  <td class="list"> <a href="firewall_nat_edit.php"><img src="plus.gif" width="17" height="17" border="0"></a></td>
166
				</tr>
167
              </table>
168
                    <p><span class="vexpl"><span class="red"><strong>Note:<br>
169
                      </strong></span>It is not possible to access NATed services
170
                      using the WAN IP address from within LAN (or an optional
171
                      network).</span></p></td>
172
  </tr>
173
</table>
174
            </form>
175
<?php include("fend.inc"); ?>
176
</body>
177
</html>
(21-21/98)