initial commit of file from CVS for e-smith-tinydns on Wed 12 Jul 09:11:00 BST 2023
This commit is contained in:
@@ -0,0 +1 @@
|
||||
53
|
@@ -0,0 +1 @@
|
||||
localhost
|
@@ -0,0 +1 @@
|
||||
enabled
|
1
root/etc/e-smith/db/configuration/defaults/tinydns/type
Normal file
1
root/etc/e-smith/db/configuration/defaults/tinydns/type
Normal file
@@ -0,0 +1 @@
|
||||
service
|
11
root/etc/e-smith/db/configuration/migrate/tinydns_ListenIP
Normal file
11
root/etc/e-smith/db/configuration/migrate/tinydns_ListenIP
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
# $tinydns{ListenIP} must not be set in serveronly mode
|
||||
my $tinydns = $DB->get('tinydns');
|
||||
return unless $tinydns;
|
||||
my $mode = $DB->get_value('SystemMode');
|
||||
return unless $mode;
|
||||
if ($mode eq 'serveronly')
|
||||
{
|
||||
$tinydns->delete_prop("ListenIP");
|
||||
}
|
||||
}
|
30
root/etc/e-smith/db/hosts/migrate/20tinydns
Normal file
30
root/etc/e-smith/db/hosts/migrate/20tinydns
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
use esmith::ConfigDB;
|
||||
my $confdb = esmith::ConfigDB->open_ro;
|
||||
return unless $confdb;
|
||||
|
||||
my $systemname = $confdb->get_value('SystemName');
|
||||
my $domainname = $confdb->get_value('DomainName');
|
||||
return unless $systemname && $domainname; # nothing to do
|
||||
|
||||
my $fqdn = "$systemname.$domainname";
|
||||
|
||||
# Make sure that the ReverseDNS property of the proper name of the server
|
||||
# is set to "yes", unless the $LocalIP has a configured PTR record already.
|
||||
my $self_host = undef;
|
||||
foreach my $host ( $DB->get_all() )
|
||||
{
|
||||
next unless $host->prop('HostType') eq 'Self';
|
||||
if ( $host->{key} eq $fqdn )
|
||||
{
|
||||
$self_host = $host;
|
||||
}
|
||||
if ( $host->prop('ReverseDNS')
|
||||
&& ( $host->prop('ReverseDNS') eq 'yes' ) )
|
||||
{
|
||||
# It already has one configured. Nothing to do.
|
||||
return;
|
||||
}
|
||||
}
|
||||
$self_host->set_prop( 'ReverseDNS', 'yes' ) if $self_host;
|
||||
}
|
0
root/etc/e-smith/events/bootstrap-console-save/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/bootstrap-console-save/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/post-install/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/post-install/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/post-upgrade/.gitignore
vendored
Normal file
0
root/etc/e-smith/events/post-upgrade/.gitignore
vendored
Normal file
4
root/etc/e-smith/templates/var/service/tinydns/env/DATALIMIT
vendored
Normal file
4
root/etc/e-smith/templates/var/service/tinydns/env/DATALIMIT
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
my $datalimit = $tinydns{'DataLimit'} || "300000";
|
||||
"$datalimit";
|
||||
}
|
3
root/etc/e-smith/templates/var/service/tinydns/env/IP
vendored
Normal file
3
root/etc/e-smith/templates/var/service/tinydns/env/IP
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
$OUT = $tinydns{'ListenIP'} || "127.0.0.1";
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
{
|
||||
|
||||
use esmith::HostsDB;
|
||||
$hosts = esmith::HostsDB->open_ro;
|
||||
|
||||
use esmith::DomainsDB;
|
||||
my $ddb = esmith::DomainsDB->open_ro;
|
||||
|
||||
use esmith::util;
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Returns a hash of hostnames with IP addresses as values
|
||||
#--------------------------------------------------------
|
||||
|
||||
sub get_generic_hostentries
|
||||
{
|
||||
#--------------------------------------------------
|
||||
# Compute local IP address, netmask and network values.
|
||||
#--------------------------------------------------
|
||||
|
||||
my $ipaddrBits = esmith::util::IPquadToAddr ($LocalIP);
|
||||
my $netmaskBits = esmith::util::IPquadToAddr ($LocalNetmask);
|
||||
my $networkBits = $ipaddrBits & $netmaskBits;
|
||||
|
||||
#--------------------------------------------------
|
||||
# Compute our hostid, and the highest hostid, limiting range
|
||||
# to a class B at most (so we don't get a huge output file).
|
||||
#--------------------------------------------------
|
||||
|
||||
my $myHostid = (~ $netmaskBits) & $ipaddrBits;
|
||||
|
||||
my $maxHostid = ((~ $netmaskBits) & 0xffffff) - 1;
|
||||
$maxHostid = ($maxHostid <= 65534) ? $maxHostid : 65534;
|
||||
|
||||
my %name2ip;
|
||||
#--------------------------------------------------
|
||||
# Generate A records for the entire local network
|
||||
# We can then override particular entries if we need to
|
||||
# However, multiple A records are not an issue
|
||||
# as long as there is a PTR record pointing to the correct
|
||||
# hostname
|
||||
#--------------------------------------------------
|
||||
|
||||
for ($i = 1; $i <= $maxHostid; $i++)
|
||||
{
|
||||
my $ip = esmith::util::IPaddrToQuad ($networkBits | $i);
|
||||
my $hostname = sprintf ("pc-%.5d", $i);
|
||||
|
||||
$name2ip{$hostname} = $ip;
|
||||
}
|
||||
|
||||
return %name2ip;
|
||||
}
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Calculates an array of domains that require DNS
|
||||
#--------------------------------------------------------
|
||||
@domains = map { $_->key } $ddb->get_all_by_prop('type' => 'domain');
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Returns an array of domains that require DNS
|
||||
#--------------------------------------------------------
|
||||
sub get_domains { return @domains; }
|
||||
|
||||
sub get_local_domainname { return $DomainName; }
|
||||
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Returns the IP Address of the host in question.
|
||||
#--------------------------------------------------------
|
||||
sub host2ip
|
||||
{
|
||||
my $host = shift;
|
||||
my $ip = undef;
|
||||
die "Host record must have HostType prop!"
|
||||
unless my $hosttype = $host->prop('HostType');
|
||||
|
||||
if ($hosttype eq 'Self')
|
||||
{
|
||||
$ip = $LocalIP;
|
||||
}
|
||||
$ip ||= $host->prop('ExternalIP') || $host->prop('InternalIP');
|
||||
return $ip;
|
||||
}
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Returns a hash of IPs to hostnames, representing the
|
||||
# chosen hostnames for reverse dns lookups for each IP.
|
||||
#--------------------------------------------------------
|
||||
sub get_reverse_lookup_choices
|
||||
{
|
||||
my %reverse_lookups = ();
|
||||
foreach my $host ($hosts->hosts())
|
||||
{
|
||||
# A remote host must be a DNS alias.
|
||||
next if $host->prop('HostType') eq 'Remote';
|
||||
|
||||
my $alias = $host->prop('ReverseDNS') || "no";
|
||||
if ($alias eq "yes")
|
||||
{
|
||||
# This host is not a DNS alias, so we should make note of it
|
||||
# for reverse DNS lookup purposes.
|
||||
my $ip = host2ip($host);
|
||||
$reverse_lookups{$ip} = $host->{key};
|
||||
# Note: Here we clobber any existing key/value pair, so if
|
||||
# there is more than one host with the same ip flagged as
|
||||
# being the reversedns host, the last one entered in this hash
|
||||
# will win. Don't do that. ;-)
|
||||
}
|
||||
}
|
||||
return %reverse_lookups;
|
||||
}
|
||||
|
||||
$OUT = '';
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
{
|
||||
$OUT .= "# NS Records\n";
|
||||
foreach my $domain (get_domains())
|
||||
{
|
||||
$OUT .= ".$domain:\:$SystemName." . get_local_domainname(). "\n";
|
||||
}
|
||||
|
||||
use esmith::util;
|
||||
# Add name server record for local reverse zone
|
||||
my $reverse =
|
||||
esmith::util::computeLocalNetworkReversed ($LocalIP, $LocalNetmask);
|
||||
$reverse =~ s/\.$//;
|
||||
$OUT .= ".$reverse\:\:127.0.0.1\n";
|
||||
$reverse =
|
||||
esmith::util::computeLocalNetworkReversed ('127.0.0.1', '255.255.255.0');
|
||||
$reverse =~ s/\.$//;
|
||||
$OUT .= ".$reverse\:\:127.0.0.1\n";
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
$OUT .= "# MX Records\n";
|
||||
foreach my $domain (get_domains())
|
||||
{
|
||||
$OUT .= "\@$domain:\:$SystemName." . get_local_domainname(). "\n";
|
||||
}
|
||||
$OUT .= "\n";
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
$OUT .= "# A Records for domains\n";
|
||||
foreach my $domain (get_domains())
|
||||
{
|
||||
$OUT .= "+$domain:$LocalIP\n";
|
||||
}
|
||||
$OUT .= "\n";
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
{
|
||||
%allocated_ips = ();
|
||||
foreach my $domain (get_domains())
|
||||
{
|
||||
|
||||
$OUT .= "# A Records for Hosts in $domain\n";
|
||||
foreach my $h ($hosts->get_hosts_by_domain($domain))
|
||||
{
|
||||
my $anIP = host2ip($h);
|
||||
|
||||
my $prefixchar = '+';
|
||||
if ($anIP !~ /^\d+\.\d+\.\d+\.\d+$/)
|
||||
{
|
||||
$prefixchar = 'C';
|
||||
}
|
||||
else
|
||||
{
|
||||
my %reverse_lookups = get_reverse_lookup_choices();
|
||||
# If this IP is spoken for, then we know which host to use for the
|
||||
# reverse DNS lookup PTR.
|
||||
if (exists $reverse_lookups{$anIP})
|
||||
{
|
||||
my $reverse_host = $reverse_lookups{$anIP};
|
||||
if ($reverse_host eq $h->key)
|
||||
{
|
||||
$prefixchar = '=';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# Otherwise, we'll just use the first host that comes along.
|
||||
# Have we picked one already?
|
||||
unless (exists $allocated_ips{$anIP})
|
||||
{
|
||||
$prefixchar = '=';
|
||||
}
|
||||
}
|
||||
# Note that this ip is taken.
|
||||
$allocated_ips{$anIP} = 1;
|
||||
|
||||
}
|
||||
$OUT .= $prefixchar . $h->key . ":$anIP\n";
|
||||
}
|
||||
$OUT .= "\n";
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
{
|
||||
my %name2ip = get_generic_hostentries();
|
||||
|
||||
my $domain = $DomainName;
|
||||
|
||||
$OUT .= "# Generic A Records for $domain\n";
|
||||
foreach (sort keys %name2ip)
|
||||
{
|
||||
$prefixchar = '=';
|
||||
$prefixchar = '+' if exists $allocated_ips{$name2ip{$_}};
|
||||
$OUT .= $prefixchar . "$_.$domain" . ":" . $name2ip{$_} . "\n";
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user