Skip to content

Commit

Permalink
Allow DNS proxy option to control if some or all records are proxied
Browse files Browse the repository at this point in the history
  • Loading branch information
jcameron committed Mar 29, 2023
1 parent 727440b commit dec3ef8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
38 changes: 23 additions & 15 deletions feature-dns.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1160,16 +1160,20 @@ sub split_long_txt_record
# Adds MX and mail.domain records to a DNS domain
sub create_mail_records
{
local ($recs, $file, $d, $ip, $ip6) = @_;
my ($recs, $file, $d, $ip, $ip6) = @_;
my $tmpl = &get_template($d->{'template'});
my $proxied = $tmpl->{'dns_cloud_proxy'};
local $withdot = $d->{'dom'}.".";
my $r = { 'name' => "mail.$withdot",
'type' => "A",
'proxied' => $proxied == 1 ? 1 : 0,
'values' => [ $ip ] };
my ($already) = grep { $_->{'name'} eq $r->{'name'} } @$recs;
&create_dns_record($recs, $file, $r) if (!$already);
if ($d->{'ip6'} && $ip6) {
my $r = { 'name' => "mail.$withdot",
'type' => "AAAA",
'proxied' => $proxied == 1 ? 1 : 0,
'values' => [ $ip6 ] };
my ($already) = grep { $_->{'name'} eq $r->{'name'} } @$recs;
&create_dns_record($recs, $file, $r) if (!$already);
Expand Down Expand Up @@ -1318,7 +1322,7 @@ sub create_standard_records
&create_dns_record($recs, $file,
{ 'name' => $r,
'type' => 'A',
'proxied' => $proxied,
'proxied' => $proxied == 1 ? 1 : 0,
'values' => [ $a ] });
$i++;
}
Expand Down Expand Up @@ -1359,7 +1363,7 @@ sub create_standard_records
&create_dns_record($recs, $file,
{ 'name' => $n,
'type' => 'A',
'proxied' => $proxied,
'proxied' => $proxied ? 1 : 0,
'values' => [ $ip ] });
}
}
Expand All @@ -1374,7 +1378,7 @@ sub create_standard_records
&create_dns_record($recs, $file,
{ 'name' => $ns,
'type' => 'A',
'proxied' => $proxied,
'proxied' => $proxied == 1 ? 1 : 0,
'values' => [ $ip ] });
}
}
Expand All @@ -1386,7 +1390,6 @@ sub create_standard_records
&create_dns_record($recs, $file,
{ 'name' => $n,
'type' => 'A',
'proxied' => $proxied,
'values' => [ "127.0.0.1" ] });
}

Expand All @@ -1397,7 +1400,7 @@ sub create_standard_records
&create_dns_record($recs, $file,
{ 'name' => $hn.".",
'type' => 'A',
'proxied' => $proxied,
'proxied' => $proxied == 1 ? 1 : 0,
'values' => [ &get_default_ip() ] });
}

Expand Down Expand Up @@ -1455,7 +1458,7 @@ sub create_standard_records
join("\n", split(/\t+/, $tmpl->{'dns'}))."\n", \%subs);
local @tmplrecs = &text_to_dns_records($recstxt, $d->{'dom'});
foreach my $r (@tmplrecs) {
$r->{'proxied'} = $proxied;
$r->{'proxied'} = $proxied == 1 ? 1 : 0;
&create_dns_record($recs, $file, $r);
}
}
Expand Down Expand Up @@ -1773,7 +1776,7 @@ sub save_domain_matchall_record
my $ip = $d->{'dns_ip'} || $d->{'ip'};
$r = { 'name' => $withstar,
'type' => 'A',
'proxied' => $tmpl->{'dns_cloud_proxy'},
'proxied' => $tmpl->{'dns_cloud_proxy'} == 1 ? 1 : 0,
'values' => [ $ip ] };
&create_dns_record($recs, $file, $r);
$any++;
Expand Down Expand Up @@ -2890,13 +2893,18 @@ sub show_template_dns
}
print &ui_table_row(&hlink($text{'tmpl_dns_cloud'},
"template_dns_cloud"),
&ui_select("dns_cloud", $tmpl->{'dns_cloud'}, \@clouds).
"<br>\n".
&ui_checkbox("dns_cloud_import", 1, $text{'tmpl_dns_cloud_import'},
$tmpl->{'dns_cloud_import'}).
"<br>\n".
&ui_checkbox("dns_cloud_proxy", 1, $text{'tmpl_dns_cloud_proxy'},
$tmpl->{'dns_cloud_proxy'}));
&ui_select("dns_cloud", $tmpl->{'dns_cloud'}, \@clouds));

print &ui_table_row(&hlink($text{'tmpl_dns_cloud_import'},
"template_dns_cloud_import"),
&ui_yesno_radio("dns_cloud_import", $tmpl->{'dns_cloud_import'}));

print &ui_table_row(&hlink($text{'tmpl_dns_cloud_proxy'},
"template_dns_cloud_proxy"),
&ui_radio("dns_cloud_proxy", $tmpl->{'dns_cloud_proxy'} || 0,
[ [ 0, $text{'no'} ],
[ 1, $text{'tmpl_dns_cloud_proxy1'} ],
[ 2, $text{'tmpl_dns_cloud_proxy2'} ] ]));

# Create on slave DNS servers
local @slaves = &bind8::list_slave_servers();
Expand Down
4 changes: 2 additions & 2 deletions help/template_dns_cloud.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<header>Create new DNS zones on</header>

This field controls whether DNS domains for virtual servers created using this
template are setup locally, or on one of the configured Cloud DNS providers.
<p>
template are setup locally, or on one of the configured Cloud DNS providers or
remote DNS servers.<p>

<footer>
8 changes: 8 additions & 0 deletions help/template_dns_cloud_import.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<header>Take over existing zone when creating?</header>

If a Cloud DNS provider is selected, this option determines what happens
if a new domain already exists at the provider. If <b>No</b> is selected,
domain creation will fail. But if <b>Yes</b> is chosen, the existing domain
will be used and managed by Virtualmin. <p>

<footer>
8 changes: 8 additions & 0 deletions help/template_dns_cloud_proxy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<header>Enable proxing on new records?</header>

For Cloud DNS providers that support proxying, this option determines if
records in new domains are created with proxing enabled or not. You can
choose to either proxy all records, or just the ones used for website
hosting (domain.com and www.domain.com). <p>

<footer>
6 changes: 4 additions & 2 deletions lang/en
Original file line number Diff line number Diff line change
Expand Up @@ -3543,8 +3543,10 @@ tmpl_edns=No DNS records entered
tmpl_dns_sub=Add sub-domain DNS records to parent domain?
tmpl_dns_cloud=Create new DNS zones on
tmpl_dns_remote=Remote DNS $1
tmpl_dns_cloud_import=Take over existing zone when creating
tmpl_dns_cloud_proxy=Enable proxing on new records
tmpl_dns_cloud_import=Take over existing zone when creating?
tmpl_dns_cloud_proxy=Enable proxing on new records?
tmpl_dns_cloud_proxy1=For all records
tmpl_dns_cloud_proxy2=Only for website records
tmpl_dns_slaves=DNS slaves to create zones on
tmpl_dns_slaves_all=All configured
tmpl_dns_slaves_none=No slaves
Expand Down

0 comments on commit dec3ef8

Please sign in to comment.