Project

General

Profile

Download (9.7 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
	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
        usort($config['dhcpdv6'][$ifgui]['staticmap'], "staticmapcmp");
52
}
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
if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
73
	$config['dhcpdv6'][$if]['staticmap'] = array();
74
}
75

    
76
$static_arp_enabled=isset($config['dhcpdv6'][$if]['staticarp']);
77
$netboot_enabled=isset($config['dhcpdv6'][$if]['netboot']);
78
$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
79
$ifcfgipv6 = get_interface_ipv6($if);
80
$ifcfgsnv6 = get_interface_subnetv6($if);
81
$ifcfgdescr = convert_friendly_interface_to_friendly_descr($if);
82

    
83
$id = $_GET['id'];
84
if (isset($_POST['id']))
85
	$id = $_POST['id'];
86

    
87
if (isset($id) && $a_maps[$id]) {
88
        $pconfig['mac'] = $a_maps[$id]['mac'];
89
		$pconfig['hostname'] = $a_maps[$id]['hostname'];
90
        $pconfig['ipaddrv6'] = $a_maps[$id]['ipaddrv6'];
91
	$pconfig['netbootfile'] = $a_maps[$id]['netbootfile'];
92
        $pconfig['descr'] = $a_maps[$id]['descr'];
93
} else {
94
        $pconfig['mac'] = $_GET['mac'];
95
		$pconfig['hostname'] = $_GET['hostname'];
96
	$pconfig['netbootfile'] = $_GET['netbootfile'];
97
        $pconfig['descr'] = $_GET['descr'];
98
}
99

    
100
if ($_POST) {
101

    
102
	unset($input_errors);
103
	$pconfig = $_POST;
104

    
105
	/* input validation */
106
	$reqdfields = explode(" ", "mac");
107
	$reqdfieldsn = array(gettext("MAC address"));
108
	
109
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
110

    
111
	/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
112
	$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
113
	
114
	if ($_POST['hostname']) {
115
		preg_match("/^[0-9]/", $_POST['hostname'], $matches);
116
		if($matches)
117
			$input_errors[] = gettext("The hostname cannot start with a numeric character according to RFC952");
118
		preg_match("/\-\$/", $_POST['hostname'], $matches);
119
		if($matches)
120
			$input_errors[] = gettext("The hostname cannot end with a hyphen according to RFC952");		
121
		if (!is_hostname($_POST['hostname'])) {
122
			$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
123
		} else {
124
			if (strpos($_POST['hostname'],'.')) {
125
				$input_errors[] = gettext("A valid hostname is specified, but the domain name part should be omitted");
126
			}
127
		}
128
	}
129
	if (($_POST['ipaddrv6'] && !is_ipaddrv6($_POST['ipaddrv6']))) {
130
		$input_errors[] = gettext("A valid IPv6 address must be specified.");
131
	}
132
	if (($_POST['mac'] && !is_macaddr($_POST['mac']))) {
133
		$input_errors[] = gettext("A valid MAC address must be specified.");
134
	}
135
	if($static_arp_enabled && !$_POST['ipaddrv6']) {
136
		$input_errors[] = gettext("Static ARP is enabled.  You must specify an IPv6 address.");
137
	}
138
	
139
	/* check for overlaps */
140
	foreach ($a_maps as $mapent) {
141
		if (isset($id) && ($a_maps[$id]) && ($a_maps[$id] === $mapent))
142
			continue;
143

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

    
155
	if (!$input_errors) {
156
		$mapent = array();
157
		$mapent['mac'] = $_POST['mac'];
158
		$mapent['ipaddrv6'] = $_POST['ipaddrv6'];
159
		$mapent['hostname'] = $_POST['hostname'];
160
		$mapent['descr'] = $_POST['descr'];
161
		$mapent['netbootfile'] = $_POST['netbootfile'];
162

    
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
			if (isset($config['dnsmasq']['regdhcpstatic']))	
174
				mark_subsystem_dirty('hosts');
175
		}
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
$statusurl = "status_dhcpv6_leases.php";
184
$logurl = "diag_logs_dhcp.php";
185

    
186
include("head.inc");
187

    
188
?>
189

    
190
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
191
<?php include("fbegin.inc"); ?>
192
<?php if ($input_errors) print_input_errors($input_errors); ?>
193
            <form action="services_dhcpv6_edit.php" method="post" name="iform" id="iform">
194
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
195
				<tr>
196
					<td colspan="2" valign="top" class="listtopic"><?=gettext("Static DHCPv6 Mapping");?></td>
197
				</tr>	
198
                <tr> 
199
                  <td width="22%" valign="top" class="vncellreq"><?=gettext("MAC address");?></td>
200
                  <td width="78%" class="vtable"> 
201
                    <input name="mac" type="text" class="formfld unknown" id="mac" size="30" value="<?=htmlspecialchars($pconfig['mac']);?>">
202
		    <?php
203
			$ip = getenv('REMOTE_ADDR');
204
			$mac = `/usr/sbin/arp -an | grep {$ip} | cut -d" " -f4`;
205
			$mac = str_replace("\n","",$mac);
206
		    ?>
207
		    <a OnClick="document.forms[0].mac.value='<?=$mac?>';" href="#"><?=gettext("Copy my MAC address");?></a>   		    
208
                    <br>
209
                    <span class="vexpl"><?=gettext("Enter a MAC address in the following format: ".
210
                    "xx:xx:xx:xx:xx:xx");?></span></td>
211
                </tr>
212
                <tr> 
213
                  <td width="22%" valign="top" class="vncell"><?=gettext("IPv6 address");?></td>
214
                  <td width="78%" class="vtable"> 
215
                    <input name="ipaddrv6" type="text" class="formfld unknown" id="ipaddrv6" size="28" value="<?=htmlspecialchars($pconfig['ipaddrv6']);?>">
216
                    <br>
217
                    <?=gettext("If no IPv6 address is given, one will be dynamically allocated  from the pool.");?></td>
218
                </tr>
219
                <tr> 
220
                  <td width="22%" valign="top" class="vncell"><?=gettext("Hostname");?></td>
221
                  <td width="78%" class="vtable"> 
222
                    <input name="hostname" type="text" class="formfld unknown" id="hostname" size="28" value="<?=htmlspecialchars($pconfig['hostname']);?>">
223
                    <br> <span class="vexpl"><?=gettext("Name of the host, without domain part.");?></span></td>
224
                </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
		    <input name="netbootfile" type="text" class="formfld unknown" id="netbootfile" size="28" value="<?=htmlspecialchars($pconfig['netbootfile']);?>">
230
		    <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
		</tr>
232
		<?php } ?>
233
                <tr> 
234
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
235
                  <td width="78%" class="vtable"> 
236
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>"> 
237
                    <br> <span class="vexpl"><?=gettext("You may enter a description here ".
238
                    "for your reference (not parsed).");?></span></td>
239
                </tr>
240
                <tr> 
241
                  <td width="22%" valign="top">&nbsp;</td>
242
                  <td width="78%"> 
243
                    <input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>"> <input class="formbtn" type="button" value="<?=gettext("Cancel");?>" onclick="history.back()">
244
                    <?php if (isset($id) && $a_maps[$id]): ?>
245
                    <input name="id" type="hidden" value="<?=htmlspecialchars($id);?>">
246
                    <?php endif; ?>
247
                    <input name="if" type="hidden" value="<?=htmlspecialchars($if);?>"> 
248
                  </td>
249
                </tr>
250
              </table>
251
</form>
252
<?php include("fend.inc"); ?>
253
</body>
254
</html>
(145-145/231)