diff --git a/interface/web/dns/dns_spf_edit.php b/interface/web/dns/dns_spf_edit.php index 20626ba159add3f79aeda33fc70502642b2c614f..ecfa6c3212a624c59abd95876d626dbfae1af1bc 100644 --- a/interface/web/dns/dns_spf_edit.php +++ b/interface/web/dns/dns_spf_edit.php @@ -109,6 +109,12 @@ class page_action extends tform_actions { $spf_domain = rtrim($spf_domain); $spf_mechanism = substr($rec['data'], -4, 1); } + else { + // Set the domainname itself as default name, to indicatie it's not for a subdomain. + $sql = "SELECT origin FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'); + $rec = $app->db->queryOneRecord($sql, $app->functions->intval($_REQUEST["zone"])); + $app->tpl->setVar("name", $rec['origin'], true); + } //set html-values $app->tpl->setVar("spf_ip", $spf_ip, true); @@ -156,8 +162,17 @@ class page_action extends tform_actions { } } // end if user is not admin - // Check that the record does not yet exist - $existing_records = $app->db->queryAllRecords("SELECT id FROM dns_rr WHERE zone = ? AND name = ? AND type = 'TXT' AND data LIKE 'v=spf1%'", $_POST['zone'], $_POST['name']); + // Check that the record does not yet exist. + // '' and 'example.com.' are effectively the same name so we also look for those variants. + $existing_records = $app->db->queryAllRecords("SELECT r.*, s.origin FROM dns_rr r + LEFT JOIN dns_soa s ON (r.zone=s.id) + WHERE zone = ? AND (name = ? /* an exact match */ + OR (name = s.origin AND ? = '') /* e.g. name = 'example.com.' and we're posting an empty value */ + OR (name = '' AND s.origin = ?) /* e.g. name is empty and we're posting e.g. 'example.com' */ ) + AND type = 'TXT' AND data LIKE 'v=spf1%' + AND " . $app->tform->getAuthSQL('r', 'r'), + $_POST['zone'], $_POST['name'], $_POST['name'], $_POST['name']); + if (!empty($existing_records)) { if (count($existing_records) > 1) { $multiple_existing_records_error_txt = $app->tform->wordbook['spf_record_exists_multiple_txt'];