Skip to content

Add a check for A or AAAA record #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions modules/dns_manager/code/controller.ext.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,27 @@ static function CheckForErrors()
//HOSTNAME
if (isset($hostName[$NewId]) && !fs_director::CheckForEmptyValue($hostName[$NewId]) && $hostName[$NewId] != "@") {
//Check that hostname does not already exist.
$numrows = $zdbh->prepare('SELECT dn_id_pk FROM x_dns WHERE dn_host_vc=:hostName2 AND dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL');
$numrows = $zdbh->prepare('SELECT dn_id_pk, dn_type_vc FROM x_dns WHERE dn_host_vc=:hostName2 AND dn_vhost_fk=:domainID AND dn_deleted_ts IS NULL');
$hostName2 = $hostName[$NewId];
$numrows->bindParam(':hostName2', $hostName2);
$numrows->bindParam(':domainID', $domainID);
$numrows->execute();
if ($numrows->fetch()) {
self::SetError('Hostnames must be unique.');
return FALSE;
$dbresult = $numrows->fetchAll();
$exists = false;
if (count($dbresult)) {
foreach($dbresult as $row) {
if(($row['dn_type_vc'] == 'A' && $type[$NewId] == 'AAAA') OR ($row['dn_type_vc'] == 'AAAA' && $type[$NewId] == 'A')) {
$exists = ($exists ? true : false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$exists = ($exists ? true : false); does exactely ... nothing !

I'm afraid that there is something to redesign here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a loop through all records. If there is a record wich exists $exists = true, but if the next record not is the same the $exists will not be reset to false because it is already true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With $exists = ($exists ? true : false);

  • If $exists is true, it will turned to true,
  • if $exists is false, it wll be turned to false.

=> $exists will never change (by this line), so the test and the loop have no sense !

did you want to enable both A and AAAA record for the same domain ?

It would be better to change only the query, something like :

$numrows = $zdbh->prepare('SELECT dn_id_pk FROM x_dns WHERE dn_host_vc=:hostName2 AND dn_vhost_fk=:domainID AND dn_type_vc<>:excludetype AND dn_deleted_ts IS NULL');
$hostName2 = $hostName[$NewId];
$numrows->bindParam(':hostName2', $hostName2);
$numrows->bindParam(':domainID', $domainID);
$numrows->bindParam(':excludetype', ($type[$NewId] == 'A') ? 'AAAA' : 'A' );
$numrows->execute();
.....

but i have not enought ime here to check and validate. Sorry :-(

}
elseif(($row['dn_type_vc'] == 'AAAA' && $type[$NewId] == 'AAAAA') OR ( $row['dn_type_vc'] == 'A' && $type[$NewId] == 'A')) {
$exists = true;
}
}

if($exists) {
self::SetError('Hostnames must be unique.');
return FALSE;
}
}

if ($type[$NewId] != "SRV") {
Expand Down
10 changes: 9 additions & 1 deletion modules/dns_manager/hooks/OnDaemonRun.hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ function WriteDNSZoneRecordsHook()
fs_director::CreateDirectory(ctrl_options::GetSystemOption('zone_dir'));
fs_director::SetFileSystemPermissions(ctrl_options::GetSystemOption('zone_dir'));
}
//Get the first namserver
$sql = $zdbh->prepare('SELECT * FROM x_dns WHERE dn_vhost_fk=:dnsrecord AND dn_type_vc="NS" AND dn_deleted_ts IS NULL ORDER BY dn_type_vc');
$sql->bindParam(':dnsrecord', $domain_id);
$sql->execute();
$nameserver = $sql->fetch();
//Use the first nameserver if exists, else use ns1.domainname
$soa = (count($nameserver) > 0 && strlen($nameserver['dn_target_vc']) > 0 ? $nameserver['dn_target_vc'] : 'ns1.'. $DomainName);

$zone_file = (ctrl_options::GetSystemOption('zone_dir')) . $DomainName . ".txt";
$line = "$" . "TTL 10800" . fs_filehandler::NewLine();
$line .= "@ IN SOA ns1." . $DomainName . ". postmaster." . $DomainName . ". (" . fs_filehandler::NewLine();
$line .= "@ IN SOA " . $soa . ". postmaster." . $DomainName . ". (" . fs_filehandler::NewLine();
$line .= " " . $SoaSerial . " ;serial" . fs_filehandler::NewLine();
$line .= " " . ctrl_options::GetSystemOption('refresh_ttl') . " ;refresh after 6 hours" . fs_filehandler::NewLine();
$line .= " " . ctrl_options::GetSystemOption('retry_ttl') . " ;retry after 1 hour" . fs_filehandler::NewLine();
Expand Down