Skip to content

Commit ebdc1c7

Browse files
WebsliceMarius Burkard
authored andcommitted
Fix SPF multiple records validation
1 parent 0589b0b commit ebdc1c7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

interface/web/dns/dns_spf_edit.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function onSubmit() {
157157
} // end if user is not admin
158158

159159
// Check that the record does not yet exist
160-
$existing_records = $app->db->queryAllRecords("SELECT id FROM dns_rr WHERE id != ? AND zone = ? AND name = ? AND type = 'TXT'", $this->dataRecord['id'], $_POST['zone'], $_POST['name']);
160+
$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']);
161161
if (!empty($existing_records)) {
162162
if (count($existing_records) > 1) {
163163
$multiple_existing_records_error_txt = $app->tform->wordbook['spf_record_exists_multiple_txt'];
@@ -166,13 +166,18 @@ function onSubmit() {
166166
$app->error($multiple_existing_records_error_txt);
167167
}
168168

169+
// If there is just one existing record, three things can be going on:
170+
// - if we are adding a new record, show a warning that it already exists and offer to edit it
171+
// - if we are editing an existing record and changing its 'name' field to one that is already existing, also show the warning
172+
// - otherwise we are just editing the existing the record, so there is no need for a warning
169173
$existing_record = array_pop($existing_records);
170-
171-
$existing_record_error_txt = $app->tform->wordbook['spf_record_exists_txt'];
172-
$existing_record_error_txt = str_replace('{hostname}', $_POST['name'], $existing_record_error_txt);
173-
$existing_record_error_txt = str_replace('{existing_record_id}', $existing_record['id'], $existing_record_error_txt);
174+
if (empty($this->dataRecord['id']) || ($this->dataRecord['id'] !== $existing_record['id'])) {
175+
$existing_record_error_txt = $app->tform->wordbook['spf_record_exists_txt'];
176+
$existing_record_error_txt = str_replace('{hostname}', $_POST['name'], $existing_record_error_txt);
177+
$existing_record_error_txt = str_replace('{existing_record_id}', $existing_record['id'], $existing_record_error_txt);
174178

175-
$app->error($existing_record_error_txt);
179+
$app->error($existing_record_error_txt);
180+
}
176181
}
177182

178183
// Create spf-record

interface/web/dns/dns_txt_edit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function onLoad() {
5353
}
5454

5555
// Redirect to SPF wizard if we detect a SPF record
56-
if (!empty($this->dataRecord['data'])) {
56+
if ('GET' === $_SERVER['REQUEST_METHOD'] && !empty($this->dataRecord['data'])) {
5757
if ('v=spf1' === mb_substr($this->dataRecord['data'], 0, 6)) {
5858
header(sprintf('Location: dns_spf_edit.php?id=%d', $this->dataRecord['id']));
5959
exit;

0 commit comments

Comments
 (0)