more validation for NS and SRV records; fix display of long records

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2016-05-10 10:54:59 +02:00
parent e33d7b756f
commit 64d068659f
3 changed files with 35 additions and 7 deletions

View File

@@ -18,7 +18,7 @@ if (! defined('AREA'))
*/
// This file is being included in admin_domains and customer_domains
// and therefore does not need to require lib/init.php
// and therefore does not need to require lib/init.php
$domain_id = isset($_GET['domain_id']) ? (int) $_GET['domain_id'] : null;
@@ -34,7 +34,7 @@ $domain = Database::pexecute_first($dom_stmt, array(
'did' => $domain_id
));
if ($domain['isbinddomain'] != '0') {
if ($domain['isbinddomain'] != '1') {
standard_error('dns_domain_nodns');
}
$domain = $idna_convert->decode($domain['domain']);
@@ -114,6 +114,17 @@ if ($action == 'add_record' && ! empty($_POST)) {
}
// append trailing dot (again)
$content .= '.';
} elseif ($type == 'NS') {
// check for trailing dot
if (substr($content, - 1) == '.') {
// remove it for checks
$content = substr($content, 0, - 1);
}
if (! validateDomain($content)) {
$errors[] = $lng['error']['dns_ns_invaliddom'];
}
// append trailing dot (again)
$content .= '.';
} elseif ($type == 'TXT' && ! empty($content)) {
// check that TXT content is enclosed in " "
if (substr($content, 0, 1) != '"') {
@@ -123,6 +134,9 @@ if ($action == 'add_record' && ! empty($_POST)) {
$content .= '"';
}
} elseif ($type == 'SRV') {
if ($prio === null || $prio < 0) {
$errors[] = $lng['error']['dns_srv_prioempty'];
}
// check for trailing dot
if (substr($content, - 1) == '.') {
// remove it for checks
@@ -131,7 +145,11 @@ if ($action == 'add_record' && ! empty($_POST)) {
// check only last part of content, as it can look like:
// _service._proto.name. TTL class SRV priority weight port target.
$_split_content = explode(" ", $content);
$target = trim($_split_content[count($_split_content)-1]);
// SRV content must be [weight] [port] [target]
if (count($_split_content) != 3) {
$errors[] = $lng['error']['dns_srv_invalidcontent'];
}
$target = trim($_split_content[count($_split_content) - 1]);
if (! validateDomain($target)) {
$errors[] = $lng['error']['dns_srv_needdom'];
} else {
@@ -167,9 +185,9 @@ if ($action == 'add_record' && ! empty($_POST)) {
// sort by key
ksort($check_entry);
// format integer fields to real integer (as they are read as string from the DB)
$check_entry['prio'] = (int)$check_entry['prio'];
$check_entry['ttl'] = (int)$check_entry['ttl'];
$check_entry['domain_id'] = (int)$check_entry['domain_id'];
$check_entry['prio'] = (int) $check_entry['prio'];
$check_entry['ttl'] = (int) $check_entry['ttl'];
$check_entry['domain_id'] = (int) $check_entry['domain_id'];
// serialize both
$check_entry = serialize($check_entry);
$new = serialize($new_entry);
@@ -202,6 +220,12 @@ if ($action == 'add_record' && ! empty($_POST)) {
// success message (inline)
$success_message = $lng['success']['dns_record_added'];
unset($record);
unset($type);
unset($prio);
unset($content);
unset($ttl);
} else {
// show $errors
$errors = implode("<br>", $errors);
@@ -238,6 +262,7 @@ $entriescount = 0;
if (! empty($dom_entries)) {
$entriescount = count($dom_entries);
foreach ($dom_entries as $entry) {
$entry['content'] = wordwrap($entry['content'], 100, '<br>', true);
eval("\$existing_entries.=\"" . getTemplate("dns_editor/entry_bit", true) . "\";");
}
}

View File

@@ -1999,6 +1999,9 @@ $lng['error']['dns_mx_needdom'] = 'The MX content value must be a valid domain-n
$lng['error']['dns_mx_noalias'] = 'The MX-content value cannot be an CNAME entry.';
$lng['error']['dns_cname_invaliddom'] = 'Invalid domain-name for CNAME record';
$lng['error']['dns_cname_nomorerr'] = 'There already exists a resource-record with the same record-name. It cannot be used as CNAME.';
$lng['error']['dns_ns_invaliddom'] = 'Invalid domain-name for NS record';
$lng['error']['dns_srv_prioempty'] = 'Invalid SRV priority given';
$lng['error']['dns_srv_invalidcontent'] = 'Invalid SRV content, must contain of fields weight, port and target, e.g.: 5 5060 sipserver.example.com.';
$lng['error']['dns_srv_needdom'] = 'The SRV target value must be a valid domain-name';
$lng['error']['dns_srv_noalias'] = 'The SRV-target value cannot be an CNAME entry.';
$lng['error']['dns_duplicate_entry'] = 'Record already exists';

View File

@@ -1,7 +1,7 @@
<tr>
<td>{$entry['record']}</td>
<td>{$entry['type']}</td>
<td><if $entry['prio'] <= 0>&nbsp;<else>{$entry['prio']}</if></td>
<td><if ($entry['prio'] <= 0 && $entry['type'] != 'MX' && $entry['type'] != 'SRV')>&nbsp;<else>{$entry['prio']}</if></td>
<td>{$entry['content']}</td>
<td>{$entry['ttl']}</td>
<td>