Projet

Général

Profil

Télécharger (12,1 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_nat_npt_edit.php @ fab1cd2f

1
<?php 
2
/* $Id$ */
3
/*
4
	firewall_nat_npt_edit.php
5
	part of pfSense (https://www.pfsense.org)
6
	
7
	Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>.
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
	pfSense_MODULE:	nat
33
*/
34

    
35
##|+PRIV
36
##|*IDENT=page-firewall-nat-npt-edit
37
##|*NAME=Firewall: NAT: NPt: Edit page
38
##|*DESCR=Allow access to the 'Firewall: NAT: NPt: Edit' page.
39
##|*MATCH=firewall_nat_npt_edit.php*
40
##|-PRIV
41

    
42
function natnptcmp($a, $b) {
43
	return ipcmp($a['external'], $b['external']);
44
}
45

    
46
function nat_npt_rules_sort() {
47
        global $g, $config;
48

    
49
        if (!is_array($config['nat']['npt']))
50
                return;
51

    
52

    
53
        usort($config['nat']['npt'], "natnptcmp");
54
}
55

    
56
require("guiconfig.inc");
57
require_once("interfaces.inc");
58
require_once("filter.inc");
59
require("shaper.inc");
60

    
61
$ifdisp = get_configured_interface_with_descr();
62
foreach ($ifdisp as $kif => $kdescr) {
63
        $specialsrcdst[] = "{$kif}";
64
        $specialsrcdst[] = "{$kif}ip";
65
}
66

    
67
if (!is_array($config['nat']['npt'])) {
68
	$config['nat']['npt'] = array();
69
}
70
$a_npt = &$config['nat']['npt'];
71

    
72
if (is_numericint($_GET['id']))
73
	$id = $_GET['id'];
74
if (isset($_POST['id']) && is_numericint($_POST['id']))
75
	$id = $_POST['id'];
76

    
77
if (isset($id) && $a_npt[$id]) {
78
	$pconfig['disabled'] = isset($a_npt[$id]['disabled']);
79

    
80
	address_to_pconfig($a_npt[$id]['source'], $pconfig['src'],
81
                $pconfig['srcmask'], $pconfig['srcnot'],
82
		$pconfig['srcbeginport'], $pconfig['srcendport']);
83

    
84
        address_to_pconfig($a_npt[$id]['destination'], $pconfig['dst'],
85
                $pconfig['dstmask'], $pconfig['dstnot'],
86
		$pconfig['dstbeginport'], $pconfig['dstendport']);
87

    
88
	$pconfig['interface'] = $a_npt[$id]['interface'];
89
	if (!$pconfig['interface'])
90
		$pconfig['interface'] = "wan";
91

    
92
	$pconfig['external'] = $a_npt[$id]['external'];
93
	$pconfig['descr'] = $a_npt[$id]['descr'];
94
} else
95
	$pconfig['interface'] = "wan";
96

    
97

    
98
if ($_POST) {
99
	
100
	unset($input_errors);
101
	$pconfig = $_POST;
102

    
103
	/* input validation */
104
	$reqdfields = explode(" ", "interface");
105
	$reqdfieldsn = array(gettext("Interface"));
106
        $reqdfields[] = "src";
107
        $reqdfieldsn[] = gettext("Source prefix");
108
        $reqdfields[] = "dst";
109
        $reqdfieldsn[] = gettext("Destination prefix");
110
	
111
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
112

    
113
	if (!$input_errors) {
114
		$natent = array();
115

    
116
		$natent['disabled'] = isset($_POST['disabled']) ? true:false;
117
		$natent['descr'] = $_POST['descr'];
118
		$natent['interface'] = $_POST['interface'];
119

    
120
	if ($_POST['src'])
121
		$_POST['src'] = trim($_POST['src']);
122
	if ($_POST['dst'])
123
		$_POST['dst'] = trim($_POST['dst']);
124

    
125
		pconfig_to_address($natent['source'], $_POST['src'],
126
                        $_POST['srcmask'], $_POST['srcnot']);
127

    
128
                pconfig_to_address($natent['destination'], $_POST['dst'],
129
                        $_POST['dstmask'], $_POST['dstnot']);
130

    
131
		if (isset($id) && $a_npt[$id])
132
			$a_npt[$id] = $natent;
133
		else
134
			$a_npt[] = $natent;
135
		nat_npt_rules_sort();
136

    
137
		if (write_config())
138
			mark_subsystem_dirty('natconf');
139

    
140
		header("Location: firewall_nat_npt.php");
141
		exit;
142
	}
143
}
144

    
145
$pgtitle = array(gettext("Firewall"),gettext("NAT"),gettext("NPt"),gettext("Edit"));
146
include("head.inc");
147

    
148
?>
149

    
150
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
151
<script type="text/javascript" src="/javascript/suggestions.js"></script>
152
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
153

    
154
<?php include("fbegin.inc"); ?>
155
<?php if ($input_errors) print_input_errors($input_errors); ?>
156
            <form action="firewall_nat_npt_edit.php" method="post" name="iform" id="iform">
157
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall nat npt edit">
158
				<tr>
159
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Edit NAT NPt entry"); ?></td>
160
				</tr>	
161
		<tr>
162
                        <td width="22%" valign="top" class="vncellreq"><?=gettext("Disabled"); ?></td>
163
                        <td width="78%" class="vtable">
164
                                <input name="disabled" type="checkbox" id="disabled" value="yes" <?php if ($pconfig['disabled']) echo "checked=\"checked\""; ?> />
165
                                <strong><?=gettext("Disable this rule"); ?></strong><br />
166
                                <span class="vexpl"><?=gettext("Set this option to disable this rule without removing it from the list."); ?></span>
167
                        </td>
168
		</tr>
169
		<tr>
170
			  <td width="22%" valign="top" class="vncellreq"><?=gettext("Interface"); ?></td>
171
			  <td width="78%" class="vtable">
172
				<select name="interface" class="formselect">
173
					<?php
174
					foreach ($ifdisp as $if => $ifdesc)
175
						if(have_ruleint_access($if))
176
							$interfaces[$if] = $ifdesc;
177

    
178
					if ($config['l2tp']['mode'] == "server")
179
						if(have_ruleint_access("l2tp"))
180
							$interfaces['l2tp'] = "L2TP VPN";
181

    
182
					if ($config['pptpd']['mode'] == "server")
183
						if(have_ruleint_access("pptp"))
184
							$interfaces['pptp'] = "PPTP VPN";
185

    
186
					if ($config['pppoe']['mode'] == "server")
187
						if(have_ruleint_access("pppoe"))
188
							$interfaces['pppoe'] = "PPPoE VPN";
189

    
190
					/* add ipsec interfaces */
191
					if (isset($config['ipsec']['enable']) || isset($config['ipsec']['mobileclients']['enable']))
192
						if(have_ruleint_access("enc0"))
193
							$interfaces["enc0"] = "IPsec";
194

    
195
					/* add openvpn/tun interfaces */
196
					if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
197
						$interfaces["openvpn"] = "OpenVPN";
198

    
199
					foreach ($interfaces as $iface => $ifacename): 
200
					?>
201
					<option value="<?=$iface;?>" <?php if ($iface == $pconfig['interface']) echo "selected=\"selected\""; ?>>
202
					<?=htmlspecialchars($ifacename);?>
203
					</option>
204
					<?php endforeach; ?>
205
				</select><br />
206
			  <span class="vexpl"><?=gettext("Choose which interface this rule applies to"); ?>.<br />
207
			  <?=gettext("Hint: in most cases, you'll want to use WAN here"); ?>.</span></td>
208
		</tr>
209
		<tr>
210
                        <td width="22%" valign="top" class="vncellreq"><?=gettext("Internal IPv6 Prefix"); ?></td>
211
                        <td width="78%" class="vtable">
212
                                <input name="srcnot" type="checkbox" id="srcnot" value="yes" <?php if ($pconfig['srcnot']) echo "checked=\"checked\""; ?> />
213
                                <strong><?=gettext("not"); ?></strong>
214
                                <br />
215
                                <?=gettext("Use this option to invert the sense of the match."); ?>
216
                                <br />
217
                                <br />
218
                                <table border="0" cellspacing="0" cellpadding="0" summary="internal">
219
                                        <tr>
220
                                                <td><?=gettext("Address:"); ?>&nbsp;&nbsp;</td>
221
                                                <td>
222
                                                        <input name="src" type="text" class="formfldalias" id="src" size="20" value="<?php if (!is_specialnet($pconfig['src'])) echo htmlspecialchars($pconfig['src']);?>" /> /
223
                                                        <select name="srcmask" class="formselect" id="srcmask">
224
<?php                                           for ($i = 128; $i > 0; $i--): ?>
225
                                                        <option value="<?=$i;?>" <?php if ($i == $pconfig['srcmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
226
<?php                                           endfor; ?>
227
                                                        </select>
228
                                                </td>
229
                                        </tr>
230
                                </table>
231
			<br />
232
                     <span class="vexpl"><?=gettext("Enter the internal (LAN) ULA IPv6 Prefix for the Network Prefix translation. The prefix size specified for the internal IPv6 prefix will be applied to the 
233
external prefix."); 
234
?></span>
235
			</td>
236
                </tr>
237
		<tr>
238
                        <td width="22%" valign="top" class="vncellreq"><?=gettext("Destination IPv6 Prefix"); ?></td>
239
                        <td width="78%" class="vtable">
240
                                <input name="dstnot" type="checkbox" id="dstnot" value="yes" <?php if ($pconfig['dstnot']) echo "checked=\"checked\""; ?> />
241
                                <strong><?=gettext("not"); ?></strong>
242
                                        <br />
243
                                <?=gettext("Use this option to invert the sense of the match."); ?>
244
                                        <br />
245
                                        <br />
246
                                <table border="0" cellspacing="0" cellpadding="0" summary="destination">
247
                                        <tr>
248
                                                <td><?=gettext("Address:"); ?>&nbsp;&nbsp;</td>
249
                                                <td>
250
                                                        <input name="dst" type="text" class="formfldalias" id="dst" size="20" value="<?php if (!is_specialnet($pconfig['dst'])) echo htmlspecialchars($pconfig['dst']);?>" />
251
                                                        /
252
                                                        <select name="dstmask" class="formselect" id="dstmask">
253
<?php
254
                                                        for ($i = 128; $i > 0; $i--): ?>
255
                                                                <option value="<?=$i;?>" <?php if ($i == $pconfig['dstmask']) echo "selected=\"selected\""; ?>><?=$i;?></option>
256
<?php                                           endfor; ?>
257
                                                        </select>
258
                                                </td>
259
                                        </tr>
260
                                </table>
261
			<br />
262
                     <span class="vexpl"><?=gettext("Enter the Global Unicast routable IPv6 prefix here"); ?><br /></span>
263
                     </td>
264
                </tr>
265
                <tr> 
266
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
267
                  <td width="78%" class="vtable"> 
268
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
269
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here " .
270
                    "for your reference (not parsed)."); ?></span></td>
271
                </tr>
272
                <tr> 
273
                  <td width="22%" valign="top">&nbsp;</td>
274
                  <td width="78%"> 
275
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" /> <input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
276
                    <?php if (isset($id) && $a_npt[$id]): ?>
277
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
278
                    <?php endif; ?>
279
                  </td>
280
                </tr>
281
              </table>
282
</form>
283
<?php include("fend.inc"); ?>
284
</body>
285
</html>
(67-67/255)