Project

General

Profile

Download (6.37 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php 
3
/*
4
	firewall_nat.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9
	
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
	
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
	
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
	
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31

    
32
require("guiconfig.inc");
33

    
34
if (!is_array($config['nat']['rule'])) {
35
	$config['nat']['rule'] = array();
36
}
37
nat_rules_sort();
38
$a_nat = &$config['nat']['rule'];
39

    
40
if ($_POST) {
41

    
42
	$pconfig = $_POST;
43

    
44
	if ($_POST['apply']) {
45
		$retval = 0;
46
		if (!file_exists($d_sysrebootreqd_path)) {
47
			config_lock();
48
			$retval |= filter_configure();
49
			config_unlock();
50
		}
51
		$savemsg = get_std_save_message($retval);
52
		
53
		if ($retval == 0) {
54
			if (file_exists($d_natconfdirty_path))
55
				unlink($d_natconfdirty_path);
56
			if (file_exists($d_filterconfdirty_path))
57
				unlink($d_filterconfdirty_path);
58
		}
59
	}
60
}
61

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

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