1
|
<?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
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
10
|
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
|
usort($config['dhcpdv6'][$ifgui]['staticmap'], "staticmapcmp");
|
53
|
}
|
54
|
|
55
|
require_once('globals.inc');
|
56
|
|
57
|
if(!$g['services_dhcp_server_enable']) {
|
58
|
header("Location: /");
|
59
|
exit;
|
60
|
}
|
61
|
|
62
|
require("guiconfig.inc");
|
63
|
|
64
|
$if = $_GET['if'];
|
65
|
|
66
|
if ($_POST['if'])
|
67
|
$if = $_POST['if'];
|
68
|
|
69
|
if (!$if) {
|
70
|
header("Location: services_dhcpv6.php");
|
71
|
exit;
|
72
|
}
|
73
|
|
74
|
if (!is_array($config['dhcpdv6']))
|
75
|
$config['dhcpdv6'] = array();
|
76
|
|
77
|
if (!is_array($config['dhcpdv6'][$if]))
|
78
|
$config['dhcpdv6'][$if] = array();
|
79
|
|
80
|
if (!is_array($config['dhcpdv6'][$if]['staticmap']))
|
81
|
$config['dhcpdv6'][$if]['staticmap'] = array();
|
82
|
|
83
|
$netboot_enabled=isset($config['dhcpdv6'][$if]['netboot']);
|
84
|
$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
|
85
|
$ifcfgipv6 = get_interface_ipv6($if);
|
86
|
$ifcfgsnv6 = get_interface_subnetv6($if);
|
87
|
$ifcfgdescr = convert_friendly_interface_to_friendly_descr($if);
|
88
|
|
89
|
if (is_numericint($_GET['id']))
|
90
|
$id = $_GET['id'];
|
91
|
|
92
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
93
|
$id = $_POST['id'];
|
94
|
|
95
|
if (isset($id) && $a_maps[$id]) {
|
96
|
$pconfig['duid'] = $a_maps[$id]['duid'];
|
97
|
$pconfig['hostname'] = $a_maps[$id]['hostname'];
|
98
|
$pconfig['ipaddrv6'] = $a_maps[$id]['ipaddrv6'];
|
99
|
$pconfig['filename'] = $a_maps[$id]['filename'];
|
100
|
$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
|
101
|
$pconfig['descr'] = $a_maps[$id]['descr'];
|
102
|
} else {
|
103
|
$pconfig['duid'] = $_GET['duid'];
|
104
|
$pconfig['hostname'] = $_GET['hostname'];
|
105
|
$pconfig['filename'] = $_GET['filename'];
|
106
|
$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
|
107
|
$pconfig['descr'] = $_GET['descr'];
|
108
|
}
|
109
|
|
110
|
if ($_POST) {
|
111
|
|
112
|
unset($input_errors);
|
113
|
$pconfig = $_POST;
|
114
|
|
115
|
/* input validation */
|
116
|
$reqdfields = explode(" ", "duid");
|
117
|
$reqdfieldsn = array(gettext("DUID"));
|
118
|
|
119
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
120
|
|
121
|
if ($_POST['hostname']) {
|
122
|
preg_match("/\-\$/", $_POST['hostname'], $matches);
|
123
|
if($matches)
|
124
|
$input_errors[] = gettext("The hostname cannot end with a hyphen according to RFC952");
|
125
|
if (!is_hostname($_POST['hostname'])) {
|
126
|
$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
|
127
|
} else {
|
128
|
if (!is_unqualified_hostname($_POST['hostname'])) {
|
129
|
$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
|
130
|
}
|
131
|
}
|
132
|
}
|
133
|
if (($_POST['ipaddrv6'] && !is_ipaddrv6($_POST['ipaddrv6']))) {
|
134
|
$input_errors[] = gettext("A valid IPv6 address must be specified.");
|
135
|
}
|
136
|
|
137
|
if (empty($_POST['duid'])) {
|
138
|
$input_errors[] = gettext("A valid DUID must be specified.");
|
139
|
}
|
140
|
|
141
|
/* check for overlaps */
|
142
|
foreach ($a_maps as $mapent) {
|
143
|
if (isset($id) && ($a_maps[$id]) && ($a_maps[$id] === $mapent))
|
144
|
continue;
|
145
|
|
146
|
if ((($mapent['hostname'] == $_POST['hostname']) && $mapent['hostname']) || ($mapent['duid'] == $_POST['duid'])) {
|
147
|
$input_errors[] = gettext("This Hostname, IP or DUID already exists.");
|
148
|
break;
|
149
|
}
|
150
|
}
|
151
|
|
152
|
/* make sure it's not within the dynamic subnet */
|
153
|
if ($_POST['ipaddrv6']) {
|
154
|
/* oh boy, we need to be able to somehow do this at some point. skip */
|
155
|
}
|
156
|
|
157
|
if (!$input_errors) {
|
158
|
$mapent = array();
|
159
|
$mapent['duid'] = $_POST['duid'];
|
160
|
$mapent['ipaddrv6'] = $_POST['ipaddrv6'];
|
161
|
$mapent['hostname'] = $_POST['hostname'];
|
162
|
$mapent['descr'] = $_POST['descr'];
|
163
|
$mapent['filename'] = $_POST['filename'];
|
164
|
$mapent['rootpath'] = $_POST['rootpath'];
|
165
|
|
166
|
if (isset($id) && $a_maps[$id])
|
167
|
$a_maps[$id] = $mapent;
|
168
|
else
|
169
|
$a_maps[] = $mapent;
|
170
|
|
171
|
staticmaps_sort($if);
|
172
|
|
173
|
write_config();
|
174
|
|
175
|
if(isset($config['dhcpdv6'][$if]['enable'])) {
|
176
|
mark_subsystem_dirty('staticmaps');
|
177
|
if (isset($config['dnsmasq']['enable']) && isset($config['dnsmasq']['regdhcpstatic']))
|
178
|
mark_subsystem_dirty('hosts');
|
179
|
if (isset($config['unbound']['enable']) && isset($config['unbound']['regdhcpstatic']))
|
180
|
mark_subsystem_dirty('unbound');
|
181
|
}
|
182
|
|
183
|
header("Location: services_dhcpv6.php?if={$if}");
|
184
|
exit;
|
185
|
}
|
186
|
}
|
187
|
|
188
|
$pgtitle = array(gettext("Services"),gettext("DHCPv6"),gettext("Edit static mapping"));
|
189
|
$shortcut_section = "dhcp6";
|
190
|
|
191
|
include("head.inc");
|
192
|
|
193
|
if ($input_errors)
|
194
|
print_input_errors($input_errors);
|
195
|
|
196
|
require('classes/Form.class.php');
|
197
|
|
198
|
$form = new Form();
|
199
|
|
200
|
$section = new Form_Section('Static DHCPv6 Mapping');
|
201
|
|
202
|
$section->addInput(new Form_Input(
|
203
|
'duid',
|
204
|
'DUID',
|
205
|
'text',
|
206
|
$pconfig['duid'],
|
207
|
['placeholder' => 'DUID-LLT - ETH -- TIME --- ---- address ---- xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx']
|
208
|
))->setHelp(gettext('Enter a DUID in the following format: ') . '<br />' .
|
209
|
'DUID-LLT - ETH -- TIME --- ---- address ---- ' .
|
210
|
'xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx');
|
211
|
|
212
|
$section->addInput(new Form_Input(
|
213
|
'ipaddrv6',
|
214
|
'Server 3',
|
215
|
'text',
|
216
|
$pconfig['ipaddrv6']
|
217
|
))->setHelp('If an IPv6 address is entered, the address must be outside of the pool.' . '<br />' .
|
218
|
'If no IPv6 address is given, one will be dynamically allocated from the pool.');
|
219
|
|
220
|
$section->addInput(new Form_Input(
|
221
|
'hostname',
|
222
|
'Hostname',
|
223
|
'text',
|
224
|
$pconfig['hostname']
|
225
|
))->setHelp('Name of the host, without domain part.');
|
226
|
|
227
|
$section->addInput(new Form_Input(
|
228
|
'descr',
|
229
|
'Description',
|
230
|
'text',
|
231
|
$pconfig['descr']
|
232
|
))->setHelp('You may enter a description here for your reference (not parsed).');
|
233
|
|
234
|
if($netboot_enabled) {
|
235
|
$section->addInput(new Form_Input(
|
236
|
'filename',
|
237
|
'Netboot filename',
|
238
|
'text',
|
239
|
$pconfig['remoteserver3']
|
240
|
))->setHelp('Name of the file that should be loaded when this host boots off of the network, overrides setting on main page.');
|
241
|
|
242
|
$section->addInput(new Form_Input(
|
243
|
'rootpath',
|
244
|
'Root path',
|
245
|
'text',
|
246
|
$pconfig['remoteserver3']
|
247
|
))->setHelp('Enter the root-path string. This overrides setting on main page.');
|
248
|
}
|
249
|
|
250
|
if (isset($id) && $a_maps[$id]) {
|
251
|
$section->addInput(new Form_Input(
|
252
|
'id',
|
253
|
null,
|
254
|
'hidden',
|
255
|
$id
|
256
|
));
|
257
|
}
|
258
|
|
259
|
$section->addInput(new Form_Input(
|
260
|
'if',
|
261
|
null,
|
262
|
'hidden',
|
263
|
$if
|
264
|
));
|
265
|
|
266
|
$form->add($section);
|
267
|
print($form);
|
268
|
|
269
|
include("foot.inc");
|