1
|
<?php
|
2
|
/*
|
3
|
services_dhcpv6_relay.php
|
4
|
|
5
|
Copyright (C) 2003-2004 Justin Ellison <justin@techadvise.com>.
|
6
|
Copyright (C) 2010 Ermal Luçi
|
7
|
Copyright (C) 2010 Seth Mos
|
8
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
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_MODULE: dhcpv6relay
|
34
|
*/
|
35
|
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-services-dhcpv6relay
|
38
|
##|*NAME=Services: DHCPv6 Relay page
|
39
|
##|*DESCR=Allow access to the 'Services: DHCPv6 Relay' page.
|
40
|
##|*MATCH=services_dhcpv6_relay.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
require("guiconfig.inc");
|
44
|
require('classes/Form.class.php');
|
45
|
|
46
|
function filterDestinationServers(array $destinationServers)
|
47
|
{
|
48
|
return array_unique(
|
49
|
array_filter($destinationServers)
|
50
|
);
|
51
|
}
|
52
|
|
53
|
$pconfig['enable'] = isset($config['dhcrelay6']['enable']);
|
54
|
if (empty($config['dhcrelay6']['interface']))
|
55
|
$pconfig['interface'] = array();
|
56
|
else
|
57
|
$pconfig['interface'] = explode(",", $config['dhcrelay6']['interface']);
|
58
|
|
59
|
$pconfig['server'] = filterDestinationServers(
|
60
|
explode(',', $config['dhcrelay6']['server'])
|
61
|
);
|
62
|
$pconfig['agentoption'] = isset($config['dhcrelay6']['agentoption']);
|
63
|
|
64
|
$iflist = array_intersect_key(
|
65
|
get_configured_interface_with_descr(),
|
66
|
array_flip(
|
67
|
array_filter(
|
68
|
array_keys(get_configured_interface_with_descr()),
|
69
|
function($if) {
|
70
|
return is_ipaddrv6(get_interface_ipv6($if));
|
71
|
}
|
72
|
)
|
73
|
)
|
74
|
);
|
75
|
|
76
|
/* set the enabled flag which will tell us if DHCP server is enabled
|
77
|
* on any interface. We will use this to disable dhcp-relay since
|
78
|
* the two are not compatible with each other.
|
79
|
*/
|
80
|
$dhcpd_enabled = false;
|
81
|
if (is_array($config['dhcpdv6'])) {
|
82
|
foreach($config['dhcpdv6'] as $dhcp) {
|
83
|
if (isset($dhcp['enable']) && isset($config['interfaces'][$dhcpif]['enable'])) {
|
84
|
$dhcpd_enabled = true;
|
85
|
break;
|
86
|
}
|
87
|
}
|
88
|
}
|
89
|
|
90
|
if ($_POST) {
|
91
|
|
92
|
unset($input_errors);
|
93
|
|
94
|
if ($_POST['server'])
|
95
|
$_POST['server'] = filterDestinationServers($_POST['server']);
|
96
|
|
97
|
$pconfig = $_POST;
|
98
|
|
99
|
/* input validation */
|
100
|
if ($_POST['enable']) {
|
101
|
$reqdfields = explode(" ", "server interface");
|
102
|
$reqdfieldsn = array(gettext("Destination Server"), gettext("Interface"));
|
103
|
|
104
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
105
|
|
106
|
if ($_POST['server']) {
|
107
|
foreach ($_POST['server'] as $srv) {
|
108
|
if (!is_ipaddrv6($srv))
|
109
|
$input_errors[] = gettext("A valid Destination Server IPv6 address must be specified.");
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
|
114
|
if (!$input_errors) {
|
115
|
$config['dhcrelay6']['enable'] = $_POST['enable'] ? true : false;
|
116
|
$config['dhcrelay6']['interface'] = implode(",", $_POST['interface']);
|
117
|
$config['dhcrelay6']['agentoption'] = $_POST['agentoption'] ? true : false;
|
118
|
$config['dhcrelay6']['server'] = $_POST['server'];
|
119
|
|
120
|
write_config();
|
121
|
|
122
|
$retval = 0;
|
123
|
$retval = services_dhcrelay6_configure();
|
124
|
$savemsg = get_std_save_message($retval);
|
125
|
|
126
|
}
|
127
|
}
|
128
|
|
129
|
$closehead = false;
|
130
|
$pgtitle = array(gettext("Services"),gettext("DHCPv6 Relay"));
|
131
|
$shortcut_section = "dhcp6";
|
132
|
include("head.inc");
|
133
|
|
134
|
if ($dhcpd_enabled)
|
135
|
{
|
136
|
echo '<div class="alert alert-danger">DHCPv6 Server is currently enabled. Cannot enable the DHCPv6 Relay service while the DHCPv6 Server is enabled on any interface.</div>';
|
137
|
include("foot.inc");
|
138
|
exit;
|
139
|
}
|
140
|
|
141
|
if ($input_errors)
|
142
|
print_input_errors($input_errors);
|
143
|
|
144
|
if ($savemsg)
|
145
|
print_info_box($savemsg);
|
146
|
|
147
|
$form = new Form;
|
148
|
|
149
|
$section = new Form_Section('DHCPv6 Relay configuration');
|
150
|
|
151
|
$section->addInput(new Form_Checkbox(
|
152
|
'enable',
|
153
|
'Enable',
|
154
|
'Enable DHCPv6 relay on interface',
|
155
|
$pconfig['enable']
|
156
|
))->toggles('.form-group:not(:first-child)');
|
157
|
|
158
|
$section->addInput(new Form_Select(
|
159
|
'interface',
|
160
|
'Interface(s)',
|
161
|
$pconfig['interface'],
|
162
|
$iflist,
|
163
|
true
|
164
|
))->setHelp('Interfaces without an IPv6 address will not be shown.');
|
165
|
|
166
|
|
167
|
$section->addInput(new Form_Checkbox(
|
168
|
'agentoption',
|
169
|
'',
|
170
|
'Append circuit ID and agent ID to requests',
|
171
|
'yes',
|
172
|
$pconfig['agentoption']
|
173
|
))->setHelp(
|
174
|
'If this is checked, the DHCPv6 relay will append the circuit ID (%s interface number) and the agent ID to the DHCPv6 request.',
|
175
|
[$g['product_name']]
|
176
|
);
|
177
|
|
178
|
function createDestinationServerInputGroup($value = null)
|
179
|
{
|
180
|
$group = new Form_Group('Destination server');
|
181
|
$group->enableDuplication();
|
182
|
|
183
|
$group->add(new Form_IpAddress(
|
184
|
'server',
|
185
|
'Destination server',
|
186
|
$value
|
187
|
))->setHelp(
|
188
|
'This is the IPv6 address of the server to which DHCPv6 requests are relayed.'
|
189
|
)->setIsRepeated();
|
190
|
|
191
|
return $group;
|
192
|
}
|
193
|
|
194
|
if (!isset($pconfig['server']) || count($pconfig['server']) < 1)
|
195
|
$section->add(createDestinationServerInputGroup());
|
196
|
else
|
197
|
foreach ($pconfig['server'] as $idx => $server)
|
198
|
$section->add(createDestinationServerInputGroup($server));
|
199
|
|
200
|
$form->add($section);
|
201
|
print $form;
|
202
|
|
203
|
include("foot.inc");
|