243
# returns an array with all hostname structure
246
# model to iterate over
249
# array ref with this structure data:
252
# 'ip': ip address of hostname
253
# 'aliases': an array ref returned by <EBox::DNS::aliases> method.
257
my ($self, $model) = @_;
260
foreach my $id (@{$model->ids()})
262
my $hostname = $model->row($id);
265
$hostdata->{'name'} = $hostname->valueByName('hostname');
266
$hostdata->{'ip'} = $hostname->valueByName('ipaddr');
267
$hostdata->{'aliases'} =
268
$self->aliases($hostname->subModel('alias'));
270
push(@array, $hostdata);
276
# Method: _formatMailExchangers
278
# Format the mail exchangers to write configuration settings
279
# properly. That is, custom MX records appends a full stop after
284
# mailExchangers - model to iterate over
286
# hostName - String the host's name
287
# id - String the row identifier
288
# preference - Int the preference attribute
289
# ownerDomain - if the hostname owns to the same domain.
290
# custom - if the hostname is a foreign one
294
# Array ref of hashes containing the following keys:
298
sub _formatMailExchangers
300
my ($self, $mailExchangers) = @_;
303
foreach my $id (@{$mailExchangers->ids()}) {
304
my $mx = $mailExchangers->row($id);
305
my $hostName = $mx->valueByName('hostName');
306
if ($mx->elementByName('hostName')->selectedType() eq 'custom') {
307
unless ( $hostName =~ m:\.$: ) {
311
$hostName = $mx->parentRow()
312
->subModel('hostnames')
314
->valueByName('hostname');
316
push (@mailExchangers, {
317
hostName => $hostName,
318
preference => $mx->valueByName('preference')
321
return \@mailExchangers;
324
238
# Method: getHostnames
445
359
return NAMESERVER_HOST;
448
# Method: _completeDomain
450
# Return a structure with all required data to build bind db config files
454
# domain - String the domain's name
458
# hash ref - structure data with:
460
# 'name': domain name
461
# 'ipaddr': domain ip address
462
# 'hosts': an array ref returned by <EBox::DNS::_hostnames> method.
464
sub _completeDomain # (domain)
466
my ($self, $domain) = @_;
467
my $model = $self->model('DomainTable');
470
my $row = $model->find(domain => $domain->{'name'});
471
$domdata->{'name'} = $domain->{'name'};
472
$domdata->{'ipaddr'} = $domain->{'ipaddr'};
473
$domdata->{'hosts'} = $self->_hostnames(
474
$row->subModel('hostnames'));
476
my $subModel = $row->subModel('mailExchangers');
477
$domdata->{'mailExchangers'} = $self->_formatMailExchangers($subModel);
482
363
# Method: createHostDataArray
483
364
# returns host and their alias info in a single hosts array ref.
629
510
'file' => BIND9CONFFILE,
630
511
'module' => 'dns',
631
'reason' => 'main bind9 configuration file'
512
'reason' => __('main bind9 configuration file'),
634
515
'file' => BIND9CONFOPTIONSFILE,
635
516
'module' => 'dns',
636
'reason' => 'bind9 options configuration file'
517
'reason' => __('bind9 options configuration file'),
639
520
'file' => BIND9CONFLOCALFILE ,
640
521
'module' => 'dns',
641
'reason' => 'local bind9 configuration file'
522
'reason' => __('local bind9 configuration file'),
527
'reason' => __('Keys configuration file'),
646
my @domains = @{$self->domains()};
532
my @domainIds = @{$self->_domainIds()};
649
foreach my $domain (@domains)
535
foreach my $domainId (@domainIds)
651
my $domdata = $self->_completeDomain($domain);
537
my $domdata = $self->_completeDomain($domainId);
652
538
push(@domainData, $domdata);
653
539
my $file = BIND9CONFDIR . "/db." . $domdata->{'name'};
657
543
'module' => 'dns',
658
'reason' => __x('configuration file for zone {zone}',
544
'reason' => __x('configuration file for zone {zone}',
730
$self->writeConfFile(BIND9CONFFILE,
731
"dns/named.conf.mas",
633
$self->writeConfFile(BIND9CONFFILE,
634
"dns/named.conf.mas",
733
636
$self->writeConfFile(BIND9CONFOPTIONSFILE,
734
"dns/named.conf.options.mas",
637
"dns/named.conf.options.mas",
737
my @domains = @{$self->domains()};
739
# push(@array, 'domains' => \@domains);
740
# $self->writeConfFile(BIND9CONFLOCALFILE,
741
# "dns/named.conf.local.mas",
744
# root("/bin/rm -rf " . BIND9CONFDIR . "/zones/");
745
# root("/bin/mkdir " . BIND9CONFDIR . "/zones/");
640
my @domainIds = @{$self->_domainIds()};
641
# Hash to store the keys indexed by name, storing the secret
748
foreach my $domain (@domains)
750
my $domdata = $self->_completeDomain($domain);
645
foreach my $domainId (@domainIds) {
646
my $domdata = $self->_completeDomain($domainId);
751
647
push(@domainData, $domdata);
753
649
my $file = BIND9CONFDIR . "/db." . $domdata->{'name'};
755
651
push(@array, 'domain' => $domdata);
756
652
push(@array, 'nameserverHostname' => __PACKAGE__->NameserverHost());
757
$self->writeConfFile($file,"dns/db.mas",\@array);
653
# Prevent to write the file again if this is dynamic and the
654
# journal file has been already created
655
unless ( $domdata->{'dynamic'} and -e "${file}.jnl" ) {
656
$self->writeConfFile($file,"dns/db.mas",\@array);
659
# Add the updater key if the zone is dynamic
660
if ( $domdata->{'dynamic'} ) {
661
$keys{$domdata->{'name'}} = $domdata->{'tsigKey'};
760
665
my $reversedData = $self->switchToReverseInfoData(\@domainData);
800
713
my ($self, $root) = @_;
801
$root->add(new EBox::Menu::Item('url' => 'DNS/Composite/DNSComposite',
714
$root->add(new EBox::Menu::Item('url' => 'DNS/View/DomainTable',
802
715
'text' => $self->printableName(),
803
'separator' => __('Infrastructure'),
716
'separator' => 'Infrastructure',
804
717
'order' => 420));
724
my $domains = @{$self->domains()};
727
'table' => 'dns_domains',
729
'domains' => $domains
736
sub consolidateReportInfoQueries
740
'target_table' => 'dns_domains_report',
742
'select' => 'domains',
743
'from' => 'dns_domains'
752
# <EBox::Module::Base::report>
755
my ($self, $beg, $end, $options) = @_;
759
$report->{'domains'} = $self->runMonthlyQuery($beg, $end, {
760
'select' => 'domains',
761
'from' => 'dns_domains_report',
762
}, { 'name' => 'domains' });
769
# Get the keys file path
773
# String - the keys file path
780
# Group: Private methods
783
# returns an array with all hostname structure
786
# model to iterate over
789
# array ref with this structure data:
792
# 'ip': ip address of hostname
793
# 'aliases': an array ref returned by <EBox::DNS::aliases> method.
797
my ($self, $model) = @_;
800
foreach my $id (@{$model->ids()})
802
my $hostname = $model->row($id);
805
$hostdata->{'name'} = $hostname->valueByName('hostname');
806
$hostdata->{'ip'} = $hostname->valueByName('ipaddr');
807
$hostdata->{'aliases'} =
808
$self->aliases($hostname->subModel('alias'));
810
push(@array, $hostdata);
816
# Method: _formatMailExchangers
818
# Format the mail exchangers to write configuration settings
819
# properly. That is, custom MX records appends a full stop after
824
# mailExchangers - model to iterate over
826
# hostName - String the host's name
827
# id - String the row identifier
828
# preference - Int the preference attribute
829
# ownerDomain - if the hostname owns to the same domain.
830
# custom - if the hostname is a foreign one
834
# Array ref of hashes containing the following keys:
838
sub _formatMailExchangers
840
my ($self, $mailExchangers) = @_;
843
foreach my $id (@{$mailExchangers->ids()}) {
844
my $mx = $mailExchangers->row($id);
845
my $hostName = $mx->valueByName('hostName');
846
if ($mx->elementByName('hostName')->selectedType() eq 'custom') {
847
unless ( $hostName =~ m:\.$: ) {
851
$hostName = $mx->parentRow()
852
->subModel('hostnames')
854
->valueByName('hostname');
856
push (@mailExchangers, {
857
hostName => $hostName,
858
preference => $mx->valueByName('preference')
861
return \@mailExchangers;
864
# Method: _formatNameServers
866
# Format the name servers to write configuration settings
867
# properly. That is, custom NS records appends a full stop after
870
# If it has none configured, it will configure the following:
872
# @ NS 127.0.0.1 # If there is no hostname named NS
873
# @ NS ns # If there is a hostname whose name is 'ns'
877
# nameServers - model to iterate over
879
# hostName - String the host's name
880
# id - String the row identifier
881
# ownerDomain - if the hostname owns to the same domain.
882
# custom - if the hostname is a foreign one
884
# hostnames - model with hostnames for that domain
888
# Array ref of the name servers to set on
890
sub _formatNameServers
892
my ($self, $nameServers, $hostnames) = @_;
895
foreach my $id (@{$nameServers->ids()}) {
896
my $ns = $nameServers->row($id);
897
my $hostName = $ns->valueByName('hostName');
898
if ($ns->elementByName('hostName')->selectedType() eq 'custom') {
899
unless ( $hostName =~ m:\.$: ) {
903
$hostName = $ns->parentRow()
904
->subModel('hostnames')
906
->valueByName('hostname');
908
push (@nameservers, $hostName);
910
if ( @nameservers == 0 ) {
911
# Look for any hostname whose name is 'ns'
912
my $matchedId = $hostnames->findId(hostname => __PACKAGE__->NameserverHost());
913
if ( defined($matchedId) ) {
914
push(@nameservers, __PACKAGE__->NameserverHost());
918
return \@nameservers;
921
# Method: _completeDomain
923
# Return a structure with all required data to build bind db config files
927
# domain - String the domain's identifier
931
# hash ref - structure data with:
933
# 'name': domain name
934
# 'ipaddr': domain ip address
935
# 'dynamic' : the domain is dynamically updated
936
# 'tsigKey' : the TSIG key is the domain is dynamic
937
# 'hosts': an array ref returned by <EBox::DNS::_hostnames> method.
938
# 'mailExchangers' : an array ref returned by <EBox::DNS::_formatMailExchangers>
939
# 'nameServers' : an array ref returned by <EBox::DNS::_formatNameServers>
941
sub _completeDomain # (domainId)
943
my ($self, $domainId) = @_;
945
my $model = $self->model('DomainTable');
946
my $row = $model->row($domainId);
949
$domdata->{'name'} = $row->valueByName('domain');
950
foreach my $key (qw(ipaddr dynamic tsigKey)) {
951
$domdata->{$key} = $row->valueByName($key);
953
$domdata->{'hosts'} = $self->_hostnames(
954
$row->subModel('hostnames'));
956
my $subModel = $row->subModel('mailExchangers');
957
$domdata->{'mailExchangers'} = $self->_formatMailExchangers($subModel);
958
$domdata->{'nameServers'} = $self->_formatNameServers($row->subModel('nameServers'),
959
$row->subModel('hostnames'));
964
# Return the domain row ids in an array ref
969
my $model = $self->model('DomainTable');
970
return $model->ids();