Projet

Général

Profil

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

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

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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_nat_npt.php');
62

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

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

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

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

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

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

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

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

    
99

    
100
if ($_POST) {
101
	
102
	unset($input_errors);
103
	$pconfig = $_POST;
104

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

    
115
	if (!$input_errors) {
116
		$natent = array();
117

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

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

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

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

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

    
139
		if (write_config())
140
			mark_subsystem_dirty('natconf');
141

    
142
		header("Location: firewall_nat_npt.php");
143
		exit;
144
	}
145
}
146

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

    
150
?>
151

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

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

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

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

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

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

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

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