From 919b34aac838895bf8309a5f33eae308a6f8b950 Mon Sep 17 00:00:00 2001
From: Thom Pol <thom@thompol.nl>
Date: Thu, 10 Dec 2020 14:29:20 +0100
Subject: [PATCH] Move @ replacement function to idnividual records that need
 it. Fix typo in comment

---
 interface/web/dns/dns_alias_edit.php | 11 +++++++++++
 interface/web/dns/dns_cname_edit.php | 10 ++++++++++
 interface/web/dns/dns_dname_edit.php | 11 +++++++++++
 interface/web/dns/dns_edit_base.php  |  5 +----
 4 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/interface/web/dns/dns_alias_edit.php b/interface/web/dns/dns_alias_edit.php
index 20bbc38d86..3dfb59dead 100644
--- a/interface/web/dns/dns_alias_edit.php
+++ b/interface/web/dns/dns_alias_edit.php
@@ -51,6 +51,17 @@ class page_action extends dns_page_action {
 		if($tmp['number'] > 0) return true;
 		return false;
 	}
+
+  function onSubmit() {
+		global $app, $conf;
+		// Get the parent soa record of the domain
+		$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $_POST["zone"]);
+		// Replace @ to example.com. in data field
+		if($this->dataRecord["data"] === '@') {
+			$this->dataRecord["data"] = $soa['origin'];
+		}
+		parent::onSubmit();
+	}
 }
 
 $page = new page_action;
diff --git a/interface/web/dns/dns_cname_edit.php b/interface/web/dns/dns_cname_edit.php
index 38bb8140c4..e2fde267d2 100644
--- a/interface/web/dns/dns_cname_edit.php
+++ b/interface/web/dns/dns_cname_edit.php
@@ -53,6 +53,16 @@ class page_action extends dns_page_action {
 		return false;
 	}
 
+	function onSubmit() {
+		global $app, $conf;
+		// Get the parent soa record of the domain
+		$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $_POST["zone"]);
+		// Replace @ to example.com. in data field
+		if($this->dataRecord["data"] === '@') {
+			$this->dataRecord["data"] = $soa['origin'];
+		}
+		parent::onSubmit();
+	}
 }
 
 $page = new page_action;
diff --git a/interface/web/dns/dns_dname_edit.php b/interface/web/dns/dns_dname_edit.php
index a1e1cb6c07..4e97a8632c 100644
--- a/interface/web/dns/dns_dname_edit.php
+++ b/interface/web/dns/dns_dname_edit.php
@@ -52,6 +52,17 @@ class page_action extends dns_page_action {
 		if($tmp['number'] > 0) return true;
 		return false;
 	}
+
+	function onSubmit() {
+		global $app, $conf;
+		// Get the parent soa record of the domain
+		$soa = $app->db->queryOneRecord("SELECT * FROM dns_soa WHERE id = ? AND " . $app->tform->getAuthSQL('r'), $_POST["zone"]);
+		// Replace @ to example.com. in data field
+		if($this->dataRecord["data"] === '@') {
+			$this->dataRecord["data"] = $soa['origin'];
+		}
+		parent::onSubmit();
+	}
 }
 
 $page = new page_action;
diff --git a/interface/web/dns/dns_edit_base.php b/interface/web/dns/dns_edit_base.php
index 843f377db5..61c08f6576 100644
--- a/interface/web/dns/dns_edit_base.php
+++ b/interface/web/dns/dns_edit_base.php
@@ -104,7 +104,7 @@ class dns_page_action extends tform_actions {
 			$client_group_id = intval($_SESSION["s"]["user"]["default_group"]);
 			$client = $app->db->queryOneRecord("SELECT limit_dns_record FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = ?", $client_group_id);
 
-			// Check if the user may add another mailbox.
+			// Check if the user may add another record.
 			if($this->id == 0 && $client["limit_dns_record"] >= 0) {
 				$tmp = $app->db->queryOneRecord("SELECT count(id) as number FROM dns_rr WHERE sys_groupid = ?", $client_group_id);
 				if($tmp["number"] >= $client["limit_dns_record"]) {
@@ -117,9 +117,6 @@ class dns_page_action extends tform_actions {
 		if($this->dataRecord["name"] === '@') {
 			$this->dataRecord["name"] = $soa['origin'];
 		}
-		if($this->dataRecord["data"] === '@') {
-			$this->dataRecord["data"] = $soa['origin'];
-		}
 
 		// Replace * to *.example.com.
 		if($this->dataRecord["name"] === '*') {
-- 
GitLab