Revision 4541f84d
Added by Jim Pingle almost 8 years ago
src/etc/inc/system.inc | ||
---|---|---|
298 | 298 |
$hosts = array(); |
299 | 299 |
$hosts[] = array( |
300 | 300 |
'ipaddr' => '127.0.0.1', |
301 |
'fqdn' => 'localhost', |
|
302 |
'name' => 'localhost.' . $syscfg['domain'] |
|
301 |
'fqdn' => 'localhost.' . $syscfg['domain'], |
|
302 |
'name' => 'localhost', |
|
303 |
'domain' => $syscfg['domain'] |
|
303 | 304 |
); |
304 | 305 |
$hosts[] = array( |
305 | 306 |
'ipaddr' => '::1', |
306 |
'fqdn' => 'localhost', |
|
307 |
'name' => 'localhost.' . $syscfg['domain'] |
|
307 |
'fqdn' => 'localhost.' . $syscfg['domain'], |
|
308 |
'name' => 'localhost', |
|
309 |
'domain' => $syscfg['domain'] |
|
308 | 310 |
); |
309 | 311 |
|
310 | 312 |
if ($config['interfaces']['lan']) { |
... | ... | |
323 | 325 |
if (is_ipaddrv4($cfgip)) { |
324 | 326 |
$hosts[] = array( |
325 | 327 |
'ipaddr' => $cfgip, |
326 |
'fqdn' => $local_fqdn |
|
328 |
'fqdn' => $local_fqdn, |
|
329 |
'name' => $syscfg['hostname'], |
|
330 |
'domain' => $syscfg['domain'] |
|
327 | 331 |
); |
328 | 332 |
$hosts_if_found = true; |
329 | 333 |
} |
... | ... | |
332 | 336 |
if (is_ipaddrv6($cfgipv6)) { |
333 | 337 |
$hosts[] = array( |
334 | 338 |
'ipaddr' => $cfgipv6, |
335 |
'fqdn' => $local_fqdn |
|
339 |
'fqdn' => $local_fqdn, |
|
340 |
'name' => $syscfg['hostname'], |
|
341 |
'domain' => $syscfg['domain'] |
|
336 | 342 |
); |
337 | 343 |
$hosts_if_found = true; |
338 | 344 |
} |
... | ... | |
364 | 370 |
|
365 | 371 |
$hosts[] = array( |
366 | 372 |
'ipaddr' => $host['ip'], |
367 |
'fqdn' => $fqdn |
|
373 |
'fqdn' => $fqdn, |
|
374 |
'name' => $host['host'], |
|
375 |
'domain' => $host['domain'] |
|
368 | 376 |
); |
369 | 377 |
|
370 | 378 |
if (!is_array($host['aliases']) || |
... | ... | |
381 | 389 |
|
382 | 390 |
$hosts[] = array( |
383 | 391 |
'ipaddr' => $host['ip'], |
384 |
'fqdn' => $fqdn |
|
392 |
'fqdn' => $fqdn, |
|
393 |
'name' => $alias['host'], |
|
394 |
'domain' => $alias['domain'] |
|
385 | 395 |
); |
386 | 396 |
} |
387 | 397 |
} |
... | ... | |
414 | 424 |
} |
415 | 425 |
|
416 | 426 |
$fqdn = $host['hostname'] . "."; |
427 |
$domain = ""; |
|
417 | 428 |
if ($host['domain']) { |
418 |
$fqdn .= $host['domain'];
|
|
429 |
$domain = $host['domain'];
|
|
419 | 430 |
} elseif ($dhcpifconf['domain']) { |
420 |
$fqdn .= $dhcpifconf['domain'];
|
|
431 |
$domain = $dhcpifconf['domain'];
|
|
421 | 432 |
} else { |
422 |
$fqdn .= $syscfg['domain'];
|
|
433 |
$domain = $syscfg['domain'];
|
|
423 | 434 |
} |
424 | 435 |
|
425 | 436 |
$hosts[] = array( |
426 | 437 |
'ipaddr' => $host['ipaddr'], |
427 |
'fqdn' => $fqdn |
|
438 |
'fqdn' => $fqdn . $domain, |
|
439 |
'name' => $host['hostname'], |
|
440 |
'domain' => $domain |
|
428 | 441 |
); |
429 | 442 |
} |
430 | 443 |
} |
... | ... | |
468 | 481 |
} |
469 | 482 |
|
470 | 483 |
$fqdn = $host['hostname'] . "."; |
484 |
$domain = ""; |
|
471 | 485 |
if ($host['domain']) { |
472 |
$fqdn .= $host['domain'];
|
|
473 |
} else if ($dhcpifconf['domain']) {
|
|
474 |
$fqdn .= $dhcpifconf['domain'];
|
|
486 |
$domain = $host['domain'];
|
|
487 |
} elseif ($dhcpifconf['domain']) { |
|
488 |
$domain = $dhcpifconf['domain'];
|
|
475 | 489 |
} else { |
476 |
$fqdn .= $syscfg['domain'];
|
|
490 |
$domain = $syscfg['domain'];
|
|
477 | 491 |
} |
478 | 492 |
|
479 | 493 |
$hosts[] = array( |
480 | 494 |
'ipaddr' => $ipaddrv6, |
481 |
'fqdn' => $fqdn |
|
495 |
'fqdn' => $fqdn . $domain, |
|
496 |
'name' => $host['hostname'], |
|
497 |
'domain' => $domain |
|
482 | 498 |
); |
483 | 499 |
} |
484 | 500 |
} |
... | ... | |
532 | 548 |
|
533 | 549 |
$hosts_array = system_hosts_entries($dnsmasqcfg); |
534 | 550 |
foreach ($hosts_array as $host) { |
535 |
$hosts .= "{$host['ipaddr']}\t{$host['fqdn']}";
|
|
551 |
$hosts .= "{$host['ipaddr']}\t"; |
|
536 | 552 |
if (!empty($host['name'])) { |
537 |
$hosts .= " {$host['name']}";
|
|
553 |
$hosts .= "{$host['name']} ";
|
|
538 | 554 |
} |
555 |
$hosts .= "{$host['fqdn']}"; |
|
539 | 556 |
$hosts .= "\n"; |
540 | 557 |
} |
541 | 558 |
unset($hosts_array); |
src/etc/inc/unbound.inc | ||
---|---|---|
536 | 536 |
} |
537 | 537 |
} |
538 | 538 |
|
539 |
function unbound_add_host_entries($cfgsubdir = "") { |
|
540 |
global $config, $g; |
|
541 |
|
|
542 |
// Check if auto add host entries is not set |
|
543 |
if (!isset($config['unbound']['disable_auto_added_host_entries'])) { |
|
544 |
// Make sure the config setting is a valid unbound local zone type. If not use "transparent". |
|
545 |
if (array_key_exists($config['unbound']['system_domain_local_zone_type'], unbound_local_zone_types())) { |
|
546 |
$system_domain_local_zone_type = $config['unbound']['system_domain_local_zone_type']; |
|
547 |
} else { |
|
548 |
$system_domain_local_zone_type = "transparent"; |
|
549 |
} |
|
550 |
|
|
551 |
$unbound_entries = "local-zone: \"{$config['system']['domain']}\" {$system_domain_local_zone_type}\n"; |
|
539 |
function unbound_generate_zone_data($domain, $hosts, &$added_ptr, $zone_type = "transparent", $write_domiain_zone_declaration = false, $always_add_short_names = false) { |
|
540 |
global $config; |
|
541 |
if ($write_domiain_zone_declaration) { |
|
542 |
$zone_data = "local-zone: \"{$domain}.\" {$zone_type}\n"; |
|
543 |
} else { |
|
544 |
$zone_data = ""; |
|
552 | 545 |
} |
553 |
|
|
554 |
$hosts = system_hosts_entries($config['unbound']); |
|
555 |
$added_ptr = array(); |
|
556 | 546 |
foreach ($hosts as $host) { |
557 | 547 |
if (is_ipaddrv4($host['ipaddr'])) { |
558 | 548 |
$type = 'A'; |
... | ... | |
561 | 551 |
} else { |
562 | 552 |
continue; |
563 | 553 |
} |
564 |
|
|
565 | 554 |
if (!$added_ptr[$host['ipaddr']]) { |
566 |
$unbound_entries .= "local-data-ptr: \"{$host['ipaddr']} {$host['fqdn']}\"\n";
|
|
555 |
$zone_data .= "local-data-ptr: \"{$host['ipaddr']} {$host['fqdn']}\"\n";
|
|
567 | 556 |
$added_ptr[$host['ipaddr']] = true; |
568 | 557 |
} |
569 |
$unbound_entries .= "local-data: \"{$host['fqdn']} {$type} {$host['ipaddr']}\"\n"; |
|
558 |
/* For the system localhost entry, write an entry for just the hostname. */ |
|
559 |
if ((($host['name'] == "localhost") && ($domain == $config['system']['domain'])) || $always_add_short_names) { |
|
560 |
$zone_data .= "local-data: \"{$host['name']}. {$type} {$host['ipaddr']}\"\n"; |
|
561 |
} |
|
562 |
/* Redirect zones must have a zone declaration that matches the |
|
563 |
* local-data record exactly, it cannot have entries "under" the |
|
564 |
* domain. |
|
565 |
*/ |
|
566 |
if ($zone_type == "redirect") { |
|
567 |
$zone_data .= "local-zone: \"{$host['fqdn']}.\" {$zone_type}\n";; |
|
568 |
} |
|
569 |
$zone_data .= "local-data: \"{$host['fqdn']}. {$type} {$host['ipaddr']}\"\n"; |
|
570 |
} |
|
571 |
return $zone_data; |
|
572 |
} |
|
573 |
|
|
574 |
function unbound_add_host_entries($cfgsubdir = "") { |
|
575 |
global $config, $g; |
|
576 |
|
|
577 |
$hosts = system_hosts_entries($config['unbound']); |
|
578 |
|
|
579 |
/* Pass 1: Build domain list and hosts inside domains */ |
|
580 |
$hosts_by_domain = array(); |
|
581 |
foreach ($hosts as $host) { |
|
582 |
if (!array_key_exists($host['domain'], $hosts_by_domain)) { |
|
583 |
$hosts_by_domain[$host['domain']] = array(); |
|
584 |
} |
|
585 |
$hosts_by_domain[$host['domain']][] = $host; |
|
586 |
} |
|
587 |
|
|
588 |
$added_ptr = array(); |
|
589 |
/* Build local zone data */ |
|
590 |
// Check if auto add host entries is not set |
|
591 |
$system_domain_local_zone_type = "transparent"; |
|
592 |
if (!isset($config['unbound']['disable_auto_added_host_entries'])) { |
|
593 |
// Make sure the config setting is a valid unbound local zone type. If not use "transparent". |
|
594 |
if (array_key_exists($config['unbound']['system_domain_local_zone_type'], unbound_local_zone_types())) { |
|
595 |
$system_domain_local_zone_type = $config['unbound']['system_domain_local_zone_type']; |
|
596 |
} |
|
597 |
} |
|
598 |
/* Add entries for the system domain before all others */ |
|
599 |
if (array_key_exists($config['system']['domain'], $hosts_by_domain)) { |
|
600 |
$unbound_entries .= unbound_generate_zone_data($config['system']['domain'], |
|
601 |
$hosts_by_domain[$config['system']['domain']], |
|
602 |
$added_ptr, |
|
603 |
$system_domain_local_zone_type, |
|
604 |
true); |
|
605 |
/* Unset this so it isn't processed again by the loop below. */ |
|
606 |
unset($hosts_by_domain[$config['system']['domain']]); |
|
607 |
} |
|
608 |
|
|
609 |
/* Build zone data for other domain */ |
|
610 |
foreach ($hosts_by_domain as $domain => $hosts) { |
|
611 |
$unbound_entries .= unbound_generate_zone_data($domain, |
|
612 |
$hosts, |
|
613 |
$added_ptr, |
|
614 |
"transparent", |
|
615 |
false, |
|
616 |
isset($config['unbound']['always_add_short_names'])); |
|
570 | 617 |
} |
571 | 618 |
|
572 | 619 |
// Write out entries |
src/usr/local/www/services_unbound.php | ||
---|---|---|
158 | 158 |
$input_errors[] = gettext("DHCP Server must be enabled for DHCP Registration to work in DNS Resolver."); |
159 | 159 |
} |
160 | 160 |
|
161 |
if (($pconfig['system_domain_local_zone_type'] == "redirect") && isset($pconfig['regdhcp'])) { |
|
162 |
$input_errors[] = gettext('A System Domain Local Zone Type of "redirect" is not compatible with dynamic DHCP Registration.'); |
|
163 |
} |
|
164 |
|
|
161 | 165 |
$display_custom_options = $pconfig['custom_options']; |
162 | 166 |
$pconfig['custom_options'] = base64_encode(str_replace("\r\n", "\n", $pconfig['custom_options'])); |
163 | 167 |
|
Also available in: Unified diff
Restructure how unbound zone data is written to fix processing of "redirect" zone entries. Fixes #7690
Also corrects some other misc issues for formatting of zone data.
While here, add an option, not exposed in the GUI, for users to get the previous behavior of defining short names for hosts.