mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-20 11:26:13 +00:00
unbound: Added different DNS RRs to be overwritten
Added the possibility to overwrite MX records by unbound DNS resolver.
This commit is contained in:
parent
75ce22549f
commit
c632424ec7
@ -518,13 +518,25 @@ function unbound_add_host_entries() {
|
||||
if ($host['host'] != "")
|
||||
$host['host'] = $host['host'].".";
|
||||
if (!$added_item[$current_host]) {
|
||||
$host_entries .= "local-data-ptr: \"{$host['ip']} {$host['host']}{$host['domain']}\"\n";
|
||||
if (is_ipaddrv6($host['ip']))
|
||||
$host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN AAAA {$host['ip']}\"\n";
|
||||
else
|
||||
$host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN A {$host['ip']}\"\n";
|
||||
if (!empty($host['descr']) && isset($config['unbound']['txtsupport']))
|
||||
/* Backwards compatibility for records created before introducing RR types. */
|
||||
if (!isset($host['rr'])) {
|
||||
$host['rr'] = (is_ipaddrv6($host['ip'])) ? 'AAAA' : 'A';
|
||||
}
|
||||
|
||||
switch ($host['rr']) {
|
||||
case 'A':
|
||||
case 'AAAA':
|
||||
$host_entries .= "local-data-ptr: \"{$host['ip']} {$host['host']}{$host['domain']}\"\n";
|
||||
$host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN {$host['rr']} {$host['ip']}\"\n";
|
||||
break;
|
||||
case 'MX':
|
||||
$host_entries .= "local-data: \"{$host['host']}{$host['domain']} IN MX {$host['mxprio']} {$host['mx']}\"\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($host['descr']) && isset($config['unbound']['txtsupport'])) {
|
||||
$host_entries .= "local-data: '{$host['host']}{$host['domain']} TXT \"".addslashes($host['descr'])."\"'\n";
|
||||
}
|
||||
|
||||
// Do not add duplicate entries
|
||||
$added_item[$current_host] = true;
|
||||
|
||||
@ -58,9 +58,17 @@ if (isset($_POST['id']) && is_numericint($_POST['id']))
|
||||
$id = $_POST['id'];
|
||||
|
||||
if (isset($id) && $a_hosts[$id]) {
|
||||
/* Backwards compatibility for records created before introducing different RR types. */
|
||||
if (!isset($a_hosts[$id]['rr'])) {
|
||||
$a_hosts[$id]['rr'] = 'A';
|
||||
}
|
||||
|
||||
$pconfig['host'] = $a_hosts[$id]['host'];
|
||||
$pconfig['domain'] = $a_hosts[$id]['domain'];
|
||||
$pconfig['rr'] = $a_hosts[$id]['rr'];
|
||||
$pconfig['ip'] = $a_hosts[$id]['ip'];
|
||||
$pconfig['mxprio'] = $a_hosts[$id]['mxprio'];
|
||||
$pconfig['mx'] = $a_hosts[$id]['mx'];
|
||||
$pconfig['descr'] = $a_hosts[$id]['descr'];
|
||||
$pconfig['aliases'] = $a_hosts[$id]['aliases'];
|
||||
}
|
||||
@ -71,19 +79,48 @@ if ($_POST) {
|
||||
$pconfig = $_POST;
|
||||
|
||||
/* input validation */
|
||||
$reqdfields = explode(" ", "domain ip");
|
||||
$reqdfieldsn = array(gettext("Domain"),gettext("IP address"));
|
||||
$reqdfields = explode(" ", "domain rr");
|
||||
$reqdfieldsn = array(gettext("Domain"),gettext("Type"));
|
||||
|
||||
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
||||
|
||||
if (($_POST['host'] && !is_hostname($_POST['host'])))
|
||||
if (($_POST['host'] && !is_hostname($_POST['host']))) {
|
||||
$input_errors[] = gettext("The hostname can only contain the characters A-Z, 0-9 and '-'.");
|
||||
}
|
||||
|
||||
if (($_POST['domain'] && !is_domain($_POST['domain'])))
|
||||
if (($_POST['domain'] && !is_domain($_POST['domain']))) {
|
||||
$input_errors[] = gettext("A valid domain must be specified.");
|
||||
}
|
||||
|
||||
if (($_POST['ip'] && !is_ipaddr($_POST['ip'])))
|
||||
$input_errors[] = gettext("A valid IP address must be specified.");
|
||||
switch ($_POST['rr']) {
|
||||
case 'A': /* also: AAAA */
|
||||
$reqdfields = explode(" ", "ip");
|
||||
$reqdfieldsn = array(gettext("IP address"));
|
||||
|
||||
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
||||
|
||||
if (($_POST['ip'] && !is_ipaddr($_POST['ip']))) {
|
||||
$input_errors[] = gettext("A valid IP address must be specified.");
|
||||
}
|
||||
break;
|
||||
case 'MX':
|
||||
$reqdfields = explode(" ", "mxprio mx");
|
||||
$reqdfieldsn = array(gettext("MX Priority"), gettext("MX Host"));
|
||||
|
||||
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
||||
|
||||
if (($_POST['mxprio'] && !is_numericint($_POST['mxprio']))) {
|
||||
$input_errors[] = gettext("A valid MX priority must be specified.");
|
||||
}
|
||||
|
||||
if (($_POST['mx'] && !is_domain($_POST['mx']))) {
|
||||
$input_errors[] = gettext("A valid MX host must be specified.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$input_errors[] = gettext("A valid resource record type must be specified.");
|
||||
break;
|
||||
}
|
||||
|
||||
/* collect aliases */
|
||||
$aliases = array();
|
||||
@ -136,10 +173,20 @@ if ($_POST) {
|
||||
$hostent = array();
|
||||
$hostent['host'] = $_POST['host'];
|
||||
$hostent['domain'] = $_POST['domain'];
|
||||
$hostent['rr'] = $_POST['rr'];
|
||||
$hostent['ip'] = $_POST['ip'];
|
||||
$hostent['mxprio'] = $_POST['mxprio'];
|
||||
$hostent['mx'] = $_POST['mx'];
|
||||
$hostent['descr'] = $_POST['descr'];
|
||||
$hostent['aliases']['item'] = $aliases;
|
||||
|
||||
/* Destinguish between A and AAAA by parsing the passed IP address */
|
||||
if ($_POST['rr'] == 'A') {
|
||||
if (is_ipaddrv6($_POST['ip'])) {
|
||||
$hostent['rr'] = 'AAAA';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($id) && $a_hosts[$id])
|
||||
$a_hosts[$id] = $hostent;
|
||||
else
|
||||
@ -175,6 +222,25 @@ include("head.inc");
|
||||
rowname[2] = "aliasdescription";
|
||||
rowtype[2] = "textbox";
|
||||
rowsize[2] = "20";
|
||||
|
||||
function type_change() {
|
||||
switch (jQuery('#rr').val()) {
|
||||
case 'A':
|
||||
jQuery('#ip').prop('disabled', false);
|
||||
jQuery('#mxprio').prop('disabled', true);
|
||||
jQuery('#mx').prop('disabled', true);
|
||||
break;
|
||||
case 'MX':
|
||||
jQuery('#ip').prop('disabled', true);
|
||||
jQuery('#mxprio').prop('disabled', false);
|
||||
jQuery('#mx').prop('disabled', false);
|
||||
break;
|
||||
default:
|
||||
jQuery('#ip').prop('disabled', false);
|
||||
jQuery('#mxprio').prop('disabled', false);
|
||||
jQuery('#mx').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
|
||||
@ -216,13 +282,46 @@ include("head.inc");
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%" valign="top" class="vncellreq"><?=gettext("IP address");?></td>
|
||||
<td width="22%" valign="top" class="vncellreq"><?=gettext("Type");?></td>
|
||||
<td width="78%" class="vtable">
|
||||
<select name="rr" id="rr" class="formselect" onchange="type_change()">
|
||||
<?php
|
||||
$rrs = array("A" => gettext("A or AAAA (IPv4 or IPv6 address)"), "MX" => gettext("MX (Mail server)"));
|
||||
foreach ($rrs as $rr => $name) :
|
||||
?>
|
||||
<option value="<?=$rr;?>" <?=($rr == $pconfig['rr'] || ($rr == 'A' && $pconfig['rr'] == 'AAAA')) ? "selected=\"selected\"" : "";?> >
|
||||
<?=$name;?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<span class="vexpl"><?=gettext("Type of resource record"); ?><br />
|
||||
<?=gettext("e.g."); ?> <em>A</em> <?=gettext("or"); ?> <em>AAAA</em> <?=gettext("for IPv4 or IPv6 addresses"); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%" valign="top" class="vncellreq"><?=gettext("IP");?></td>
|
||||
<td width="78%" class="vtable">
|
||||
<input name="ip" type="text" class="formfld" id="ip" size="40" value="<?=htmlspecialchars($pconfig['ip']);?>" /><br />
|
||||
<span class="vexpl"><?=gettext("IP address of the host"); ?><br />
|
||||
<?=gettext("e.g."); ?> <em>192.168.100.100</em> <?=gettext("or"); ?> <em>fd00:abcd::1</em></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%" valign="top" class="vncellreq"><?=gettext("MX Priority");?></td>
|
||||
<td width="78%" class="vtable">
|
||||
<input name="mxprio" type="text" class="formfld" id="mxprio" size="6" value="<?=htmlspecialchars($pconfig['mxprio']);?>" /><br />
|
||||
<span class="vexpl"><?=gettext("Priority of MX record"); ?><br />
|
||||
<?=gettext("e.g."); ?> <em>10</em></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%" valign="top" class="vncellreq"><?=gettext("MX Host");?></td>
|
||||
<td width="78%" class="vtable">
|
||||
<input name="mx" type="text" class="formfld" id="mx" size="6" value="<?=htmlspecialchars($pconfig['mx']);?>" /><br />
|
||||
<span class="vexpl"><?=gettext("Host name of MX host"); ?><br />
|
||||
<?=gettext("e.g."); ?> <em>mail.example.com</em></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
|
||||
<td width="78%" class="vtable">
|
||||
@ -306,4 +405,9 @@ include("head.inc");
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
type_change();
|
||||
//]]>
|
||||
</script>
|
||||
<?php include("foot.inc"); ?>
|
||||
|
||||
@ -41,6 +41,13 @@ if (!is_array($config['unbound']['hosts']))
|
||||
$config['unbound']['hosts'] = array();
|
||||
$a_hosts =& $config['unbound']['hosts'];
|
||||
|
||||
/* Backwards compatibility for records created before introducing RR types. */
|
||||
foreach ($a_hosts as $i => $hostent) {
|
||||
if (!isset($hostent['rr'])) {
|
||||
$a_hosts[$i]['rr'] = (is_ipaddrv6($hostent['ip'])) ? 'AAAA' : 'A';
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_array($config['unbound']['domainoverrides']))
|
||||
$config['unbound']['domainoverrides'] = array();
|
||||
$a_domainOverrides = &$config['unbound']['domainoverrides'];
|
||||
@ -112,6 +119,7 @@ include_once("head.inc");
|
||||
<div class="content-box-main col-xs-12">
|
||||
<?=gettext("Entries in this section override individual results from the forwarders.");?>
|
||||
<?=gettext("Use these for changing DNS results or for adding custom DNS records.");?>
|
||||
<?=gettext("Keep in mind that all resource record types (i.e. A, AAAA, MX, etc. records) of a specified host below are being overwritten.");?>
|
||||
</div>
|
||||
<div class="content-box-main col-xs-12">
|
||||
<div class="table-responsive">
|
||||
@ -119,8 +127,9 @@ include_once("head.inc");
|
||||
<thead>
|
||||
<tr>
|
||||
<td width="20%" class="listhdrr"><?=gettext("Host");?></td>
|
||||
<td width="25%" class="listhdrr"><?=gettext("Domain");?></td>
|
||||
<td width="20%" class="listhdrr"><?=gettext("IP");?></td>
|
||||
<td width="20%" class="listhdrr"><?=gettext("Domain");?></td>
|
||||
<td width="5%" class="listhdrr"><?=gettext("Type");?></td>
|
||||
<td width="20%" class="listhdrr"><?=gettext("Value");?></td>
|
||||
<td width="30%" class="listhdr"><?=gettext("Description");?></td>
|
||||
<td width="5%" class="list">
|
||||
<table border="0" cellspacing="0" cellpadding="1" summary="add">
|
||||
@ -142,7 +151,24 @@ include_once("head.inc");
|
||||
<?=strtolower($hostent['domain']);?>
|
||||
</td>
|
||||
<td class="listr" ondblclick="document.location='services_unbound_host_edit.php?id=<?=$i;?>';">
|
||||
<?=$hostent['ip'];?>
|
||||
<?=strtoupper($hostent['rr']);?>
|
||||
</td>
|
||||
<td class="listr" ondblclick="document.location='services_unbound_host_edit.php?id=<?=$i;?>';">
|
||||
<?php
|
||||
/* Presentation of DNS value differs between chosen RR type. */
|
||||
switch ($hostent['rr']) {
|
||||
case 'A':
|
||||
case 'AAAA':
|
||||
print $hostent['ip'];
|
||||
break;
|
||||
case 'MX':
|
||||
print $hostent['mxprio'] . " " . $hostent['mx'];
|
||||
break;
|
||||
default:
|
||||
print ' ';
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<td class="listbg" ondblclick="document.location='services_unbound_host_edit.php?id=<?=$i;?>';">
|
||||
<?=htmlspecialchars($hostent['descr']);?>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user