Project

General

Profile

Download (9.94 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
	All rights reserved.
10
	
11
	Redistribution and use in source and binary forms, with or without
12
	modification, are permitted provided that the following conditions are met:
13
	
14
	1. Redistributions of source code must retain the above copyright notice,
15
	   this list of conditions and the following disclaimer.
16
	
17
	2. Redistributions in binary form must reproduce the above copyright
18
	   notice, this list of conditions and the following disclaimer in the
19
	   documentation and/or other materials provided with the distribution.
20
	
21
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
	POSSIBILITY OF SUCH DAMAGE.
31
*/
32
/*
33
	pfSense_BUILDER_BINARIES:	/usr/sbin/arp
34
	pfSense_MODULE:	dhcpserver
35
*/
36
37
##|+PRIV
38
##|*IDENT=page-services-dhcpserverv6-editstaticmapping
39
##|*NAME=Services: DHCPv6 Server : Edit static mapping page
40
##|*DESCR=Allow access to the 'Services: DHCPv6 Server : Edit static mapping' page.
41
##|*MATCH=services_dhcpv6_edit.php*
42
##|-PRIV
43
44
function staticmapcmp($a, $b) {
45
        return ipcmp($a['ipaddrv6'], $b['ipaddrv6']);
46
}
47
48
function staticmaps_sort($ifgui) {
49
        global $g, $config;
50
51 656f1763 Seth Mos
        usort($config['dhcpdv6'][$ifgui]['staticmap'], "staticmapcmp");
52 ae091de3 Seth Mos
}
53
54
require_once('globals.inc');
55
56
if(!$g['services_dhcp_server_enable']) {
57
	Header("Location: /");
58
	exit;
59
}
60
61
require("guiconfig.inc");
62
63
$if = $_GET['if'];
64
if ($_POST['if'])
65
	$if = $_POST['if'];
66
	
67
if (!$if) {
68
	header("Location: services_dhcpv6.php");
69
	exit;
70
}
71
72 5b668994 Erik Fonnesbeck
if (!is_array($config['dhcpdv6']))
73
	$config['dhcpdv6'] = array();
74
if (!is_array($config['dhcpdv6'][$if]))
75
	$config['dhcpdv6'][$if] = array();
76
if (!is_array($config['dhcpdv6'][$if]['staticmap']))
77 ae091de3 Seth Mos
	$config['dhcpdv6'][$if]['staticmap'] = array();
78
79
$netboot_enabled=isset($config['dhcpdv6'][$if]['netboot']);
80
$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
81
$ifcfgipv6 = get_interface_ipv6($if);
82
$ifcfgsnv6 = get_interface_subnetv6($if);
83
$ifcfgdescr = convert_friendly_interface_to_friendly_descr($if);
84
85 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
86
	$id = $_GET['id'];
87
if (isset($_POST['id']) && is_numericint($_POST['id']))
88 ae091de3 Seth Mos
	$id = $_POST['id'];
89
90
if (isset($id) && $a_maps[$id]) {
91 2fb056d8 Seth Mos
        $pconfig['duid'] = $a_maps[$id]['duid'];
92 93a138ab Seth Mos
	$pconfig['hostname'] = $a_maps[$id]['hostname'];
93 ae091de3 Seth Mos
        $pconfig['ipaddrv6'] = $a_maps[$id]['ipaddrv6'];
94 a2578c27 Anthony Wrather
	$pconfig['filename'] = $a_maps[$id]['filename'];
95
		$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
96 ae091de3 Seth Mos
        $pconfig['descr'] = $a_maps[$id]['descr'];
97
} else {
98 2fb056d8 Seth Mos
        $pconfig['duid'] = $_GET['duid'];
99 93a138ab Seth Mos
	$pconfig['hostname'] = $_GET['hostname'];
100 a2578c27 Anthony Wrather
	$pconfig['filename'] = $_GET['filename'];
101
		$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
102 ae091de3 Seth Mos
        $pconfig['descr'] = $_GET['descr'];
103
}
104
105
if ($_POST) {
106
107
	unset($input_errors);
108
	$pconfig = $_POST;
109
110
	/* input validation */
111 2fb056d8 Seth Mos
	$reqdfields = explode(" ", "duid");
112
	$reqdfieldsn = array(gettext("DUID Identifier"));
113 ae091de3 Seth Mos
	
114 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
115 ae091de3 Seth Mos
116
	if ($_POST['hostname']) {
117
		preg_match("/\-\$/", $_POST['hostname'], $matches);
118
		if($matches)
119
			$input_errors[] = gettext("The hostname cannot end with a hyphen according to RFC952");		
120
		if (!is_hostname($_POST['hostname'])) {
121
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
122
		} else {
123
			if (strpos($_POST['hostname'],'.')) {
124
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
125
			}
126
		}
127
	}
128
	if (($_POST['ipaddrv6'] && !is_ipaddrv6($_POST['ipaddrv6']))) {
129
		$input_errors[] = gettext("A valid IPv6 address must be specified.");
130
	}
131 93a138ab Seth Mos
	if (empty($_POST['duid'])) {
132 2fb056d8 Seth Mos
		$input_errors[] = gettext("A valid DUID Identifier must be specified.");
133 ae091de3 Seth Mos
	}
134
	
135
	/* check for overlaps */
136
	foreach ($a_maps as $mapent) {
137
		if (isset($id) && ($a_maps[$id]) && ($a_maps[$id] === $mapent))
138
			continue;
139
140 2fb056d8 Seth Mos
		if ((($mapent['hostname'] == $_POST['hostname']) && $mapent['hostname'])  || ($mapent['duid'] == $_POST['duid'])) {
141
			$input_errors[] = gettext("This Hostname, IP or DUID Identifier already exists.");
142 ae091de3 Seth Mos
			break;
143
		}
144
	}
145
		
146
	/* make sure it's not within the dynamic subnet */
147
	if ($_POST['ipaddrv6']) {
148
		/* oh boy, we need to be able to somehow do this at some point. skip */
149
	}
150
151
	if (!$input_errors) {
152
		$mapent = array();
153 2fb056d8 Seth Mos
		$mapent['duid'] = $_POST['duid'];
154 ae091de3 Seth Mos
		$mapent['ipaddrv6'] = $_POST['ipaddrv6'];
155
		$mapent['hostname'] = $_POST['hostname'];
156
		$mapent['descr'] = $_POST['descr'];
157 a2578c27 Anthony Wrather
		$mapent['filename'] = $_POST['filename'];
158
		$mapent['rootpath'] = $_POST['rootpath'];
159 ae091de3 Seth Mos
160
		if (isset($id) && $a_maps[$id])
161
			$a_maps[$id] = $mapent;
162
		else
163
			$a_maps[] = $mapent;
164
		staticmaps_sort($if);
165
		
166
		write_config();
167
168
		if(isset($config['dhcpdv6'][$if]['enable'])) {
169
			mark_subsystem_dirty('staticmaps');
170 ea1aca13 Renato Botelho
			if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))
171 ae091de3 Seth Mos
				mark_subsystem_dirty('hosts');
172 ed225b4c Warren Baker
			if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic']))
173
				mark_subsystem_dirty('unbound');
174
175 ae091de3 Seth Mos
		}
176
177
		header("Location: services_dhcpv6.php?if={$if}");
178
		exit;
179
	}
180
}
181
182
$pgtitle = array(gettext("Services"),gettext("DHCPv6"),gettext("Edit static mapping"));
183 b32dd0a6 jim-p
$shortcut_section = "dhcp6";
184 ae091de3 Seth Mos
185
include("head.inc");
186
187
?>
188
189
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
190
<?php include("fbegin.inc"); ?>
191
<?php if ($input_errors) print_input_errors($input_errors); ?>
192
            <form action="services_dhcpv6_edit.php" method="post" name="iform" id="iform">
193 ee9530e1 Colin Fleming
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="static mapping">
194 ae091de3 Seth Mos
				<tr>
195
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Static DHCPv6 Mapping");?></td>
196
				</tr>	
197
                <tr> 
198 2fb056d8 Seth Mos
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("DUID Identifier");?></td>
199 ae091de3 Seth Mos
                  <td width="78%" class="vtable"> 
200 ee9530e1 Colin Fleming
                    <input name="duid" type="text" class="formfld unknown" id="duid" size="40" value="<?=htmlspecialchars($pconfig['duid']);?>" />
201 8cd558b6 ayvis
                    <br />
202 2fb056d8 Seth Mos
                    <span class="vexpl"><?=gettext("Enter a DUID Identifier in the following format: ");?><br />
203
"DUID-LLT - ETH -- TIME --- ---- address ----" <br />
204
"xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"</span></td>
205 ae091de3 Seth Mos
                </tr>
206 93a138ab Seth Mos
                <tr>
207 ae091de3 Seth Mos
                  <td width="22%" valign="top" class="vncell"><?=gettext("IPv6 address");?></td>
208
                  <td width="78%" class="vtable"> 
209 ee9530e1 Colin Fleming
                    <input name="ipaddrv6" type="text" class="formfld unknown" id="ipaddrv6" size="28" value="<?=htmlspecialchars($pconfig['ipaddrv6']);?>" />
210 8cd558b6 ayvis
                    <br />
211 dbb1cdb5 jim-p
			<?=gettext("If an IPv6 address is entered, the address must be outside of the pool.");?>
212 8cd558b6 ayvis
			<br />
213 dbb1cdb5 jim-p
			<?=gettext("If no IPv6 address is given, one will be dynamically allocated from the pool.");?>
214
			</td>
215 ae091de3 Seth Mos
                </tr>
216
                <tr> 
217
                  <td width="22%" valign="top" class="vncell"><?=gettext("Hostname");?></td>
218
                  <td width="78%" class="vtable"> 
219 ee9530e1 Colin Fleming
                    <input name="hostname" type="text" class="formfld unknown" id="hostname" size="28" value="<?=htmlspecialchars($pconfig['hostname']);?>" />
220 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("Name of the host, without domain part.");?></span></td>
221 ae091de3 Seth Mos
                </tr>				
222
                <?php if($netboot_enabled) { ?>
223
		<tr>
224
		  <td width="22%" valign="top" class="vncell">Netboot filename</td>
225
		  <td width="78%" class="vtable">
226 ee9530e1 Colin Fleming
		    <input name="filename" type="text" class="formfld unknown" id="filename" size="28" value="<?=htmlspecialchars($pconfig['filename']);?>" />
227 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>
228 ae091de3 Seth Mos
		</tr>
229 a2578c27 Anthony Wrather
		<tr>
230
		  <td width="22%" valign="top" class="vncell">Root Path</td>
231
		  <td width="78%" class="vtable">
232 ee9530e1 Colin Fleming
			<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>" />
233 8cd558b6 ayvis
		    <br /> <span class="vexpl"><?=gettext("Enter the"); ?> <b><?=gettext("root-path"); ?></b>-<?=gettext("string");?>, overrides setting on main page.</span></td>
234 a2578c27 Anthony Wrather
		</tr>
235 ae091de3 Seth Mos
		<?php } ?>
236
                <tr> 
237
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
238
                  <td width="78%" class="vtable"> 
239 ee9530e1 Colin Fleming
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
240 8cd558b6 ayvis
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
241 ae091de3 Seth Mos
                    "for your reference (not parsed).");?></span></td>
242
                </tr>
243
                <tr> 
244
                  <td width="22%" valign="top">&nbsp;</td>
245
                  <td width="78%"> 
246 ee9530e1 Colin Fleming
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" /> <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()" />
247 ae091de3 Seth Mos
                    <?php if (isset($id) && $a_maps[$id]): ?>
248 ee9530e1 Colin Fleming
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
249 ae091de3 Seth Mos
                    <?php endif; ?>
250 ee9530e1 Colin Fleming
                    <input name="if" type="hidden" value="<?=htmlspecialchars($if);?>" />
251 ae091de3 Seth Mos
                  </td>
252
                </tr>
253
              </table>
254
</form>
255
<?php include("fend.inc"); ?>
256
</body>
257
</html>