mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 17:44:41 +00:00
Merge branch 'trunet-add-dhcpv6-ddns'
This commit is contained in:
commit
18f3c65fd8
@ -1129,14 +1129,12 @@ EOD;
|
||||
}
|
||||
|
||||
$dhcpdifs[] = get_real_interface($dhcpif);
|
||||
if (!empty($newzone['domain-name'])) {
|
||||
if (isset($dhcpifconf['ddnsupdate'])) {
|
||||
$newzone['dns-servers'] = array($dhcpifconf['ddnsdomainprimary']);
|
||||
$newzone['ddnsdomainkeyname'] = $dhcpifconf['ddnsdomainkeyname'];
|
||||
$newzone['ddnsdomainkey'] = $dhcpifconf['ddnsdomainkey'];
|
||||
$newzone['ddnsdomainalgorithm'] = !empty($dhcpifconf['ddnsdomainalgorithm']) ? $dhcpifconf['ddnsdomainalgorithm'] : "hmac-md5";
|
||||
$ddns_zones[] = $newzone;
|
||||
}
|
||||
if (!empty($newzone['domain-name']) && isset($dhcpifconf['ddnsupdate']) && is_ipaddrv4($dhcpifconf['ddnsdomainprimary'])) {
|
||||
$newzone['dns-servers'] = array($dhcpifconf['ddnsdomainprimary']);
|
||||
$newzone['ddnsdomainkeyname'] = $dhcpifconf['ddnsdomainkeyname'];
|
||||
$newzone['ddnsdomainkey'] = $dhcpifconf['ddnsdomainkey'];
|
||||
$newzone['ddnsdomainalgorithm'] = !empty($dhcpifconf['ddnsdomainalgorithm']) ? $dhcpifconf['ddnsdomainalgorithm'] : "hmac-md5";
|
||||
$ddns_zones[] = $newzone;
|
||||
}
|
||||
|
||||
if ($dhcpifconf['omapi'] && !$omapi_added) {
|
||||
@ -1173,40 +1171,21 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
function dhcpd_zones($ddns_zones)
|
||||
function dhcpd_zones($ddns_zones, $ipproto = 'inet')
|
||||
{
|
||||
$dhcpdconf = '';
|
||||
|
||||
if (is_array($ddns_zones)) {
|
||||
$added_zones = array();
|
||||
$added_keys = array();
|
||||
foreach ($ddns_zones as $zone) {
|
||||
if (!is_array($zone) || empty($zone) || !is_array($zone['dns-servers'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$primary = $zone['dns-servers'][0];
|
||||
$secondary = empty($zone['dns-servers'][1]) ? "" : $zone['dns-servers'][1];
|
||||
|
||||
// Make sure we aren't using any invalid or IPv6 DNS servers.
|
||||
if (!is_ipaddrv4($primary)) {
|
||||
if (is_ipaddrv4($secondary)) {
|
||||
$primary = $secondary;
|
||||
$secondary = "";
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$versionsuffix = $ipproto == "inet6" ? "6" : "";
|
||||
// We don't need to add zones multiple times.
|
||||
foreach (array($zone['domain-name'], $zone['ptr-domain']) as $domain) {
|
||||
if (!empty($domain) && !in_array($domain, $added_zones)) {
|
||||
/* dhcpdconf2 is injected *after* the key */
|
||||
$dhcpdconf2 = "zone {$domain}. {\n";
|
||||
$dhcpdconf2 .= " primary {$primary};\n";
|
||||
if (is_ipaddrv4($secondary)) {
|
||||
$dhcpdconf2 .= " secondary {$secondary};\n";
|
||||
}
|
||||
// XXX: $zone['dns-servers'] only contains one item, ref $newzone['dns-servers']
|
||||
$dhcpdconf2 .= " primary{$versionsuffix} {$zone['dns-servers'][0]};\n";
|
||||
if (!empty($zone['ddnsdomainkeyname']) && !empty($zone['ddnsdomainkey'])) {
|
||||
if (!in_array($zone['ddnsdomainkeyname'], $added_keys)) {
|
||||
$dhcpdconf .= "key {$zone['ddnsdomainkeyname']} {\n";
|
||||
@ -1406,7 +1385,7 @@ EOD;
|
||||
|
||||
$dhcpdv6ifs = array();
|
||||
$ddns_zones = array();
|
||||
$nsupdate = false;
|
||||
$need_ddns_updates = false;
|
||||
|
||||
foreach ($dhcpdv6cfg as $dhcpv6if => $dhcpv6ifconf) {
|
||||
if (!isset($dhcpv6ifconf['enable']) || !isset($iflist[$dhcpv6if])) {
|
||||
@ -1434,6 +1413,7 @@ EOD;
|
||||
$newzone = array();
|
||||
|
||||
if (isset($dhcpv6ifconf['ddnsupdate'])) {
|
||||
$need_ddns_updates = true;
|
||||
if (!empty($dhcpv6ifconf['ddnsdomain'])) {
|
||||
$dnscfgv6 .= " ddns-domainname \"{$dhcpv6ifconf['ddnsdomain']}\";\n";
|
||||
$newzone['domain-name'] = $dhcpv6ifconf['ddnsdomain'];
|
||||
@ -1441,7 +1421,20 @@ EOD;
|
||||
$newzone['domain-name'] = $config['system']['domain'];
|
||||
}
|
||||
|
||||
$nsupdate = true;
|
||||
$subnetv6 = explode("/", $networkv6)[0];
|
||||
$addr = inet_pton($subnetv6);
|
||||
$addr_unpack = unpack('H*hex', $addr);
|
||||
$addr_hex = $addr_unpack['hex'];
|
||||
$revsubnet = array_reverse(str_split($addr_hex));
|
||||
foreach ($revsubnet as $octet) {
|
||||
if ($octet == "0") {
|
||||
array_shift($revsubnet);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$newzone['ptr-domain'] = implode(".", $revsubnet) . ".ip6.arpa";
|
||||
}
|
||||
|
||||
if (isset($dhcpv6ifconf['dnsserver'][0])) {
|
||||
@ -1544,15 +1537,12 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($newzone['domain-name'])) {
|
||||
if (isset($dhcpv6ifconf['ddnsupdate'])) {
|
||||
$newzone['dns-servers'] = array($dhcpv6ifconf['ddnsdomainprimary']);
|
||||
$newzone['ddnsdomainkeyname'] = $dhcpv6ifconf['ddnsdomainkeyname'];
|
||||
$newzone['ddnsdomainkey'] = $dhcpv6ifconf['ddnsdomainkey'];
|
||||
/* XXX not implemented for IPv6 */
|
||||
$newzone['ddnsdomainalgorithm'] = 'hmac-md5';
|
||||
$ddns_zones[] = $newzone;
|
||||
}
|
||||
if (!empty($newzone['domain-name']) && isset($dhcpv6ifconf['ddnsupdate']) && is_ipaddrv6($dhcpv6ifconf['ddnsdomainprimary'])) {
|
||||
$newzone['dns-servers'] = array($dhcpv6ifconf['ddnsdomainprimary']);
|
||||
$newzone['ddnsdomainkeyname'] = $dhcpv6ifconf['ddnsdomainkeyname'];
|
||||
$newzone['ddnsdomainkey'] = $dhcpv6ifconf['ddnsdomainkey'];
|
||||
$newzone['ddnsdomainalgorithm'] = !empty($dhcpv6ifconf['ddnsdomainalgorithm']) ? $dhcpv6ifconf['ddnsdomainalgorithm'] : "hmac-md5";
|
||||
$ddns_zones[] = $newzone;
|
||||
}
|
||||
|
||||
if (preg_match("/poes/si", $dhcpv6if)) {
|
||||
@ -1571,9 +1561,10 @@ EOD;
|
||||
}
|
||||
}
|
||||
|
||||
if ($nsupdate) {
|
||||
if ($need_ddns_updates) {
|
||||
$dhcpdv6conf .= "\nddns-update-style interim;\n";
|
||||
$dhcpdv6conf .= dhcpd_zones($ddns_zones);
|
||||
$dhcpdv6conf .= "update-static-leases on;\n";
|
||||
$dhcpdv6conf .= dhcpd_zones($ddns_zones, "inet6");
|
||||
} else {
|
||||
$dhcpdv6conf .= "\nddns-update-style none;\n";
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$pconfig['prefixrange_length'] = $config['dhcpdv6'][$if]['prefixrange']['prefixlength'];
|
||||
}
|
||||
$config_copy_fieldsnames = array('defaultleasetime', 'maxleasetime', 'domainsearchlist', 'ddnsdomain',
|
||||
'ddnsdomainprimary', 'ddnsdomainkeyname', 'ddnsdomainkey', 'bootfile_url', 'netmask',
|
||||
'ddnsdomainprimary', 'ddnsdomainkeyname', 'ddnsdomainkey', 'ddnsdomainalgorithm', 'bootfile_url', 'netmask',
|
||||
'numberoptions', 'dhcpv6leaseinlocaltime', 'staticmap');
|
||||
foreach ($config_copy_fieldsnames as $fieldname) {
|
||||
if (isset($config['dhcpdv6'][$if][$fieldname])) {
|
||||
@ -235,7 +235,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
|
||||
// simple 1-on-1 copy
|
||||
$config_copy_fieldsnames = array('defaultleasetime', 'maxleasetime', 'netmask', 'domainsearchlist',
|
||||
'ddnsdomain', 'ddnsdomainprimary', 'ddnsdomainkeyname', 'ddnsdomainkey', 'bootfile_url',
|
||||
'ddnsdomain', 'ddnsdomainprimary', 'ddnsdomainkeyname', 'ddnsdomainkey', 'ddnsdomainalgorithm', 'bootfile_url',
|
||||
'dhcpv6leaseinlocaltime');
|
||||
foreach ($config_copy_fieldsnames as $fieldname) {
|
||||
if (!empty($pconfig[$fieldname])) {
|
||||
@ -612,6 +612,16 @@ if (isset($config['interfaces'][$if]['dhcpd6track6allowoverride'])) {
|
||||
<input name="ddnsdomainkeyname" type="text" id="ddnsdomainkeyname" size="20" value="<?=$pconfig['ddnsdomainkeyname'];?>" />
|
||||
<?=gettext("Enter the dynamic DNS domain key secret which will be used to register client names in the DNS server.");?>
|
||||
<input name="ddnsdomainkey" type="text" id="ddnsdomainkey" size="20" value="<?=$pconfig['ddnsdomainkey'];?>" />
|
||||
<?=gettext("Choose the dynamic DNS domain key algorithm.");?><br />
|
||||
<select name='ddnsdomainalgorithm' id="ddnsdomainalgorithm" class="selectpicker">
|
||||
<?php
|
||||
foreach (array("hmac-md5", "hmac-sha512") as $algorithm) :?>
|
||||
<option value="<?=$algorithm;?>" <?=$pconfig['ddnsdomainalgorithm'] == $algorithm ? "selected=\"selected\"" :"";?>>
|
||||
<?=$algorithm;?>
|
||||
</option>
|
||||
<?php
|
||||
endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user