mirror of
https://github.com/webmin/webmin.git
synced 2026-04-14 13:10:25 +01:00
Factor out DNS zone finding code, and deal with multiple levels of subdomains https://www.virtualmin.com/node/53438
This commit is contained in:
@@ -15,13 +15,8 @@ my $dname = $ENV{'CERTBOT_DOMAIN'};
|
||||
$dname || die "Missing CERTBOT_DOMAIN environment variable";
|
||||
|
||||
# Find the DNS domain and records
|
||||
my $zname = $dname;
|
||||
my $zone = &bind8::get_zone_name($zname, "any");
|
||||
if (!$zone) {
|
||||
# Maybe in the parent?
|
||||
$zname =~ s/^[^\.]+\.//;
|
||||
$zone = &bind8::get_zone_name($zname, "any");
|
||||
}
|
||||
my $zone;
|
||||
($zone, $zname) = &get_bind_zone_for_domain($zname);
|
||||
$zone || die "No zone named $dname found";
|
||||
&lock_file(&bind8::make_chroot(&bind8::absolute_path($zone->{'file'})));
|
||||
my @recs = &bind8::read_zone_file($zone->{'file'}, $zname);
|
||||
|
||||
@@ -17,13 +17,8 @@ $dname || die "Missing CERTBOT_DOMAIN environment variable";
|
||||
$val || die "Missing CERTBOT_VALIDATION environment variable";
|
||||
|
||||
# Find the DNS domain and records
|
||||
my $zname = $dname;
|
||||
my $zone = &bind8::get_zone_name($zname, "any");
|
||||
if (!$zone) {
|
||||
# Maybe in the parent?
|
||||
$zname =~ s/^[^\.]+\.//;
|
||||
$zone = &bind8::get_zone_name($zname, "any");
|
||||
}
|
||||
my $zone;
|
||||
($zone, $zname) = &get_bind_zone_for_domain($zname);
|
||||
$zone || die "No zone named $dname found";
|
||||
&lock_file(&bind8::make_chroot(&bind8::absolute_path($zone->{'file'})));
|
||||
my @recs = &bind8::read_zone_file($zone->{'file'}, $zname);
|
||||
|
||||
@@ -90,11 +90,9 @@ elsif ($mode eq "dns") {
|
||||
# Make sure all the DNS zones exist
|
||||
&foreign_require("bind8");
|
||||
foreach my $d (@doms) {
|
||||
my $bd = $d;
|
||||
$bd =~ s/^[^\.]+\.//;
|
||||
my $z = &bind8::get_zone_name($bd, "any") ||
|
||||
&bind8::get_zone_name($d, "any");
|
||||
$z || return (0, "DNS zone $d or $bd do not exist on this system");
|
||||
my $z = &get_bind_zone_for_domain($d);
|
||||
$z || return (0, "Neither DNS zone $d or any of its ".
|
||||
"sub-domains exist on this system");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,4 +277,22 @@ else {
|
||||
}
|
||||
}
|
||||
|
||||
# get_bind_zone_for_domain(domain)
|
||||
# Given a hostname like www.foo.com, return the local BIND zone that contains
|
||||
# it like foo.com
|
||||
sub get_bind_zone_for_domain
|
||||
{
|
||||
my ($d) = @_;
|
||||
&foreign_require("bind8");
|
||||
my $bd = $d;
|
||||
while ($bd) {
|
||||
my $z = &bind8::get_zone_name($bd, "any");
|
||||
if ($z) {
|
||||
return ($z, $bd);
|
||||
}
|
||||
$bd =~ s/^[^\.]+\.//;
|
||||
}
|
||||
return ( );
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user