Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
1 ae091de3 Seth Mos
<?php 
2
/* $Id$ */
3
/*
4
	services_dhcpv6_edit.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	Copyright (C) 2011 Seth Mos <seth.mos@dds.nl>.
9 29aef6c4 Jim Thompson
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
10 ae091de3 Seth Mos
	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
	pfSense_BUILDER_BINARIES:	/usr/sbin/arp
35
	pfSense_MODULE:	dhcpserver
36
*/
37
38
##|+PRIV
39
##|*IDENT=page-services-dhcpserverv6-editstaticmapping
40
##|*NAME=Services: DHCPv6 Server : Edit static mapping page
41
##|*DESCR=Allow access to the 'Services: DHCPv6 Server : Edit static mapping' page.
42
##|*MATCH=services_dhcpv6_edit.php*
43
##|-PRIV
44
45
function staticmapcmp($a, $b) {
46
        return ipcmp($a['ipaddrv6'], $b['ipaddrv6']);
47
}
48
49
function staticmaps_sort($ifgui) {
50
        global $g, $config;
51
52 656f1763 Seth Mos
        usort($config['dhcpdv6'][$ifgui]['staticmap'], "staticmapcmp");
53 ae091de3 Seth Mos
}
54
55
require_once('globals.inc');
56
57 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_dhcpv6.php');
58
59 ae091de3 Seth Mos
if(!$g['services_dhcp_server_enable']) {
60 6f3d2063 Renato Botelho
	header("Location: /");
61 ae091de3 Seth Mos
	exit;
62
}
63
64
require("guiconfig.inc");
65
66
$if = $_GET['if'];
67
if ($_POST['if'])
68
	$if = $_POST['if'];
69
	
70
if (!$if) {
71
	header("Location: services_dhcpv6.php");
72
	exit;
73
}
74
75 5b668994 Erik Fonnesbeck
if (!is_array($config['dhcpdv6']))
76
	$config['dhcpdv6'] = array();
77
if (!is_array($config['dhcpdv6'][$if]))
78
	$config['dhcpdv6'][$if] = array();
79
if (!is_array($config['dhcpdv6'][$if]['staticmap']))
80 ae091de3 Seth Mos
	$config['dhcpdv6'][$if]['staticmap'] = array();
81
82
$netboot_enabled=isset($config['dhcpdv6'][$if]['netboot']);
83
$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
84
$ifcfgipv6 = get_interface_ipv6($if);
85
$ifcfgsnv6 = get_interface_subnetv6($if);
86
$ifcfgdescr = convert_friendly_interface_to_friendly_descr($if);
87
88 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
89
	$id = $_GET['id'];
90
if (isset($_POST['id']) && is_numericint($_POST['id']))
91 ae091de3 Seth Mos
	$id = $_POST['id'];
92
93
if (isset($id) && $a_maps[$id]) {
94 2fb056d8 Seth Mos
        $pconfig['duid'] = $a_maps[$id]['duid'];
95 93a138ab Seth Mos
	$pconfig['hostname'] = $a_maps[$id]['hostname'];
96 ae091de3 Seth Mos
        $pconfig['ipaddrv6'] = $a_maps[$id]['ipaddrv6'];
97 a2578c27 Anthony Wrather
	$pconfig['filename'] = $a_maps[$id]['filename'];
98
		$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
99 ae091de3 Seth Mos
        $pconfig['descr'] = $a_maps[$id]['descr'];
100
} else {
101 2fb056d8 Seth Mos
        $pconfig['duid'] = $_GET['duid'];
102 93a138ab Seth Mos
	$pconfig['hostname'] = $_GET['hostname'];
103 a2578c27 Anthony Wrather
	$pconfig['filename'] = $_GET['filename'];
104
		$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
105 ae091de3 Seth Mos
        $pconfig['descr'] = $_GET['descr'];
106
}
107
108
if ($_POST) {
109
110
	unset($input_errors);
111
	$pconfig = $_POST;
112
113
	/* input validation */
114 2fb056d8 Seth Mos
	$reqdfields = explode(" ", "duid");
115
	$reqdfieldsn = array(gettext("DUID Identifier"));
116 ae091de3 Seth Mos
	
117 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
118 ae091de3 Seth Mos
119
	if ($_POST['hostname']) {
120
		preg_match("/\-\$/", $_POST['hostname'], $matches);
121
		if($matches)
122
			$input_errors[] = gettext("The hostname cannot end with a hyphen according to RFC952");		
123
		if (!is_hostname($_POST['hostname'])) {
124
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
125
		} else {
126 762fc5c0 Phil Davis
			if (!is_unqualified_hostname($_POST['hostname'])) {
127 ae091de3 Seth Mos
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
128
			}
129
		}
130
	}
131
	if (($_POST['ipaddrv6'] && !is_ipaddrv6($_POST['ipaddrv6']))) {
132
		$input_errors[] = gettext("A valid IPv6 address must be specified.");
133
	}
134 93a138ab Seth Mos
	if (empty($_POST['duid'])) {
135 2fb056d8 Seth Mos
		$input_errors[] = gettext("A valid DUID Identifier must be specified.");
136 ae091de3 Seth Mos
	}
137
	
138
	/* check for overlaps */
139
	foreach ($a_maps as $mapent) {
140
		if (isset($id) && ($a_maps[$id]) && ($a_maps[$id] === $mapent))
141
			continue;
142
143 2fb056d8 Seth Mos
		if ((($mapent['hostname'] == $_POST['hostname']) && $mapent['hostname'])  || ($mapent['duid'] == $_POST['duid'])) {
144
			$input_errors[] = gettext("This Hostname, IP or DUID Identifier already exists.");
145 ae091de3 Seth Mos
			break;
146
		}
147
	}
148
		
149
	/* make sure it's not within the dynamic subnet */
150
	if ($_POST['ipaddrv6']) {
151
		/* oh boy, we need to be able to somehow do this at some point. skip */
152
	}
153
154
	if (!$input_errors) {
155
		$mapent = array();
156 2fb056d8 Seth Mos
		$mapent['duid'] = $_POST['duid'];
157 ae091de3 Seth Mos
		$mapent['ipaddrv6'] = $_POST['ipaddrv6'];
158
		$mapent['hostname'] = $_POST['hostname'];
159
		$mapent['descr'] = $_POST['descr'];
160 a2578c27 Anthony Wrather
		$mapent['filename'] = $_POST['filename'];
161
		$mapent['rootpath'] = $_POST['rootpath'];
162 ae091de3 Seth Mos
163
		if (isset($id) && $a_maps[$id])
164
			$a_maps[$id] = $mapent;
165
		else
166
			$a_maps[] = $mapent;
167
		staticmaps_sort($if);
168
		
169
		write_config();
170
171
		if(isset($config['dhcpdv6'][$if]['enable'])) {
172
			mark_subsystem_dirty('staticmaps');
173 ea1aca13 Renato Botelho
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))
174 ae091de3 Seth Mos
				mark_subsystem_dirty('hosts');
175 ed225b4c Warren Baker
			if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic']))
176
				mark_subsystem_dirty('unbound');
177
178 ae091de3 Seth Mos
		}
179
180
		header("Location: services_dhcpv6.php?if={$if}");
181
		exit;
182
	}
183
}
184
185
$pgtitle = array(gettext("Services"),gettext("DHCPv6"),gettext("Edit static mapping"));
186 b32dd0a6 jim-p
$shortcut_section = "dhcp6";
187 ae091de3 Seth Mos
188
include("head.inc");
189
190
?>
191
192
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
193
<?php include("fbegin.inc"); ?>
194
<?php if ($input_errors) print_input_errors($input_errors); ?>
195
            <form action="services_dhcpv6_edit.php" method="post" name="iform" id="iform">
196 ee9530e1 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="static mapping">
197 ae091de3 Seth Mos
				<tr>
198
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Static DHCPv6 Mapping");?></td>
199
				</tr>	
200
                <tr> 
201 2fb056d8 Seth Mos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("DUID Identifier");?></td>
202 ae091de3 Seth Mos
                  <td width="78%" class="vtable"> 
203 ee9530e1 Colin Fleming
                    <input name="duid" type="text" class="formfld unknown" id="duid" size="40" value="<?=htmlspecialchars($pconfig['duid']);?>" />
204 8cd558b6 ayvis
                    <br />
205 2fb056d8 Seth Mos
                    <span class="vexpl"><?=gettext("Enter a DUID Identifier in the following format: ");?><br />
206
"DUID-LLT - ETH -- TIME --- ---- address ----" <br />
207
"xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"</span></td>
208 ae091de3 Seth Mos
                </tr>
209 93a138ab Seth Mos
                <tr>
210 ae091de3 Seth Mos
                  <td width="22%" valign="top" class="vncell"><?=gettext("IPv6 address");?></td>
211
                  <td width="78%" class="vtable"> 
212 ee9530e1 Colin Fleming
                    <input name="ipaddrv6" type="text" class="formfld unknown" id="ipaddrv6" size="28" value="<?=htmlspecialchars($pconfig['ipaddrv6']);?>" />
213 8cd558b6 ayvis
                    <br />
214 dbb1cdb5 jim-p
			<?=gettext("If an IPv6 address is entered, the address must be outside of the pool.");?>
215 8cd558b6 ayvis
			<br />
216 dbb1cdb5 jim-p
			<?=gettext("If no IPv6 address is given, one will be dynamically allocated from the pool.");?>
217
			</td>
218 ae091de3 Seth Mos
                </tr>
219
                <tr> 
220
                  <td width="22%" valign="top" class="vncell"><?=gettext("Hostname");?></td>
221
                  <td width="78%" class="vtable"> 
222 ee9530e1 Colin Fleming
                    <input name="hostname" type="text" class="formfld unknown" id="hostname" size="28" value="<?=htmlspecialchars($pconfig['hostname']);?>" />
223 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("Name of the host, without domain part.");?></span></td>
224 ae091de3 Seth Mos
                </tr>				
225
                <?php if($netboot_enabled) { ?>
226
		<tr>
227
		  <td width="22%" valign="top" class="vncell">Netboot filename</td>
228
		  <td width="78%" class="vtable">
229 ee9530e1 Colin Fleming
		    <input name="filename" type="text" class="formfld unknown" id="filename" size="28" value="<?=htmlspecialchars($pconfig['filename']);?>" />
230 8cd558b6 ayvis
		    <br /> <span class="vexpl">Name of the file that should be loaded when this host boots off of the network, overrides setting on main page.</span></td>
231 ae091de3 Seth Mos
		</tr>
232 a2578c27 Anthony Wrather
		<tr>
233
		  <td width="22%" valign="top" class="vncell">Root Path</td>
234
		  <td width="78%" class="vtable">
235 ee9530e1 Colin Fleming
			<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>" />
236 8cd558b6 ayvis
		    <br /> <span class="vexpl"><?=gettext("Enter the"); ?> <b><?=gettext("root-path"); ?></b>-<?=gettext("string");?>, overrides setting on main page.</span></td>
237 a2578c27 Anthony Wrather
		</tr>
238 ae091de3 Seth Mos
		<?php } ?>
239
                <tr> 
240
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
241
                  <td width="78%" class="vtable"> 
242 ee9530e1 Colin Fleming
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
243 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
244 ae091de3 Seth Mos
                    "for your reference (not parsed).");?></span></td>
245
                </tr>
246
                <tr> 
247
                  <td width="22%" valign="top">&nbsp;</td>
248
                  <td width="78%"> 
249 62424bdb Renato Botelho
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
250
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
251 ae091de3 Seth Mos
                    <?php if (isset($id) && $a_maps[$id]): ?>
252 ee9530e1 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
253 ae091de3 Seth Mos
                    <?php endif; ?>
254 ee9530e1 Colin Fleming
                    <input name="if" type="hidden" value="<?=htmlspecialchars($if);?>" />
255 ae091de3 Seth Mos
                  </td>
256
                </tr>
257
              </table>
258
</form>
259
<?php include("fend.inc"); ?>
260
</body>
261
</html>