Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:
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 (isset($_POST['referer'])) {
58
	$referer = $_POST['referer'];
59
} else {
60
	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/services_dhcpv6.php');
61
}
62

    
63
if(!$g['services_dhcp_server_enable']) {
64
	header("Location: /");
65
	exit;
66
}
67

    
68
require("guiconfig.inc");
69

    
70
$if = $_GET['if'];
71
if ($_POST['if'])
72
	$if = $_POST['if'];
73
	
74
if (!$if) {
75
	header("Location: services_dhcpv6.php");
76
	exit;
77
}
78

    
79
if (!is_array($config['dhcpdv6']))
80
	$config['dhcpdv6'] = array();
81
if (!is_array($config['dhcpdv6'][$if]))
82
	$config['dhcpdv6'][$if] = array();
83
if (!is_array($config['dhcpdv6'][$if]['staticmap']))
84
	$config['dhcpdv6'][$if]['staticmap'] = array();
85

    
86
$netboot_enabled=isset($config['dhcpdv6'][$if]['netboot']);
87
$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
88
$ifcfgipv6 = get_interface_ipv6($if);
89
$ifcfgsnv6 = get_interface_subnetv6($if);
90
$ifcfgdescr = convert_friendly_interface_to_friendly_descr($if);
91

    
92
if (is_numericint($_GET['id']))
93
	$id = $_GET['id'];
94
if (isset($_POST['id']) && is_numericint($_POST['id']))
95
	$id = $_POST['id'];
96

    
97
if (isset($id) && $a_maps[$id]) {
98
        $pconfig['duid'] = $a_maps[$id]['duid'];
99
	$pconfig['hostname'] = $a_maps[$id]['hostname'];
100
        $pconfig['ipaddrv6'] = $a_maps[$id]['ipaddrv6'];
101
	$pconfig['filename'] = $a_maps[$id]['filename'];
102
		$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
103
        $pconfig['descr'] = $a_maps[$id]['descr'];
104
} else {
105
        $pconfig['duid'] = $_GET['duid'];
106
	$pconfig['hostname'] = $_GET['hostname'];
107
	$pconfig['filename'] = $_GET['filename'];
108
		$pconfig['rootpath'] = $a_maps[$id]['rootpath'];
109
        $pconfig['descr'] = $_GET['descr'];
110
}
111

    
112
if ($_POST) {
113

    
114
	unset($input_errors);
115
	$pconfig = $_POST;
116

    
117
	/* input validation */
118
	$reqdfields = explode(" ", "duid");
119
	$reqdfieldsn = array(gettext("DUID"));
120
	
121
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
122

    
123
	if ($_POST['hostname']) {
124
		preg_match("/\-\$/", $_POST['hostname'], $matches);
125
		if($matches)
126
			$input_errors[] = gettext("The hostname cannot end with a hyphen according to RFC952");		
127
		if (!is_hostname($_POST['hostname'])) {
128
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
129
		} else {
130
			if (!is_unqualified_hostname($_POST['hostname'])) {
131
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
132
			}
133
		}
134
	}
135
	if (($_POST['ipaddrv6'] && !is_ipaddrv6($_POST['ipaddrv6']))) {
136
		$input_errors[] = gettext("A valid IPv6 address must be specified.");
137
	}
138
	if (empty($_POST['duid'])) {
139
		$input_errors[] = gettext("A valid DUID must be specified.");
140
	}
141
	
142
	/* check for overlaps */
143
	foreach ($a_maps as $mapent) {
144
		if (isset($id) && ($a_maps[$id]) && ($a_maps[$id] === $mapent))
145
			continue;
146

    
147
		if ((($mapent['hostname'] == $_POST['hostname']) && $mapent['hostname'])  || ($mapent['duid'] == $_POST['duid'])) {
148
			$input_errors[] = gettext("This Hostname, IP or DUID already exists.");
149
			break;
150
		}
151
	}
152
		
153
	/* make sure it's not within the dynamic subnet */
154
	if ($_POST['ipaddrv6']) {
155
		/* oh boy, we need to be able to somehow do this at some point. skip */
156
	}
157

    
158
	if (!$input_errors) {
159
		$mapent = array();
160
		$mapent['duid'] = $_POST['duid'];
161
		$mapent['ipaddrv6'] = $_POST['ipaddrv6'];
162
		$mapent['hostname'] = $_POST['hostname'];
163
		$mapent['descr'] = $_POST['descr'];
164
		$mapent['filename'] = $_POST['filename'];
165
		$mapent['rootpath'] = $_POST['rootpath'];
166

    
167
		if (isset($id) && $a_maps[$id])
168
			$a_maps[$id] = $mapent;
169
		else
170
			$a_maps[] = $mapent;
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

    
184
		header("Location: services_dhcpv6.php?if={$if}");
185
		exit;
186
	}
187
}
188

    
189
$pgtitle = array(gettext("Services"),gettext("DHCPv6"),gettext("Edit static mapping"));
190
$shortcut_section = "dhcp6";
191

    
192
include("head.inc");
193

    
194
?>
195

    
196
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
197
<?php include("fbegin.inc"); ?>
198
<?php if ($input_errors) print_input_errors($input_errors); ?>
199
            <form action="services_dhcpv6_edit.php" method="post" name="iform" id="iform">
200
              <table width="100%" border="0" cellpadding="6" cellspacing="0" summary="static mapping">
201
				<tr>
202
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Static DHCPv6 Mapping");?></td>
203
				</tr>	
204
                <tr> 
205
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("DUID");?></td>
206
                  <td width="78%" class="vtable"> 
207
                    <input name="duid" type="text" class="formfld unknown" id="duid" size="40" value="<?=htmlspecialchars($pconfig['duid']);?>" />
208
                    <br />
209
                    <span class="vexpl"><?=gettext("Enter a DUID in the following format: ");?><br />
210
"DUID-LLT - ETH -- TIME --- ---- address ----" <br />
211
"xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"</span></td>
212
                </tr>
213
                <tr>
214
                  <td width="22%" valign="top" class="vncell"><?=gettext("IPv6 address");?></td>
215
                  <td width="78%" class="vtable"> 
216
                    <input name="ipaddrv6" type="text" class="formfld unknown" id="ipaddrv6" size="28" value="<?=htmlspecialchars($pconfig['ipaddrv6']);?>" />
217
                    <br />
218
			<?=gettext("If an IPv6 address is entered, the address must be outside of the pool.");?>
219
			<br />
220
			<?=gettext("If no IPv6 address is given, one will be dynamically allocated from the pool.");?>
221
			</td>
222
                </tr>
223
                <tr> 
224
                  <td width="22%" valign="top" class="vncell"><?=gettext("Hostname");?></td>
225
                  <td width="78%" class="vtable"> 
226
                    <input name="hostname" type="text" class="formfld unknown" id="hostname" size="28" value="<?=htmlspecialchars($pconfig['hostname']);?>" />
227
                    <br /> <span class="vexpl"><?=gettext("Name of the host, without domain part.");?></span></td>
228
                </tr>				
229
                <?php if($netboot_enabled) { ?>
230
		<tr>
231
		  <td width="22%" valign="top" class="vncell">Netboot filename</td>
232
		  <td width="78%" class="vtable">
233
		    <input name="filename" type="text" class="formfld unknown" id="filename" size="28" value="<?=htmlspecialchars($pconfig['filename']);?>" />
234
		    <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>
235
		</tr>
236
		<tr>
237
		  <td width="22%" valign="top" class="vncell">Root Path</td>
238
		  <td width="78%" class="vtable">
239
			<input name="rootpath" type="text" class="formfld unknown" id="rootpath" size="90" value="<?=htmlspecialchars($pconfig['rootpath']);?>" />
240
		    <br /> <span class="vexpl"><?=gettext("Enter the"); ?> <b><?=gettext("root-path"); ?></b>-<?=gettext("string");?>, overrides setting on main page.</span></td>
241
		</tr>
242
		<?php } ?>
243
                <tr> 
244
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
245
                  <td width="78%" class="vtable"> 
246
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
247
                    <br /> <span class="vexpl"><?=gettext("You may enter a description here ".
248
                    "for your reference (not parsed).");?></span></td>
249
                </tr>
250
                <tr> 
251
                  <td width="22%" valign="top">&nbsp;</td>
252
                  <td width="78%"> 
253
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" />
254
                    <input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
255
                    <input name="referer" type="hidden" value="<?=$referer;?>" />
256
                    <?php if (isset($id) && $a_maps[$id]): ?>
257
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
258
                    <?php endif; ?>
259
                    <input name="if" type="hidden" value="<?=htmlspecialchars($if);?>" />
260
                  </td>
261
                </tr>
262
              </table>
263
</form>
264
<?php include("fend.inc"); ?>
265
</body>
266
</html>
(149-149/251)