Skip to content

Commit 7ed7ca9

Browse files
committed
Added CNAME data not validated phpipam#515
1 parent c5a6f3e commit 7ed7ca9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

functions/classes/class.PowerDNS.php

+31
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,9 @@ public function add_domain_record ($record, $print_success = true) {
831831
# null empty values
832832
$record = $this->reformat_empty_array_fields ($record, null);
833833

834+
# checks
835+
$this->validate_record_content ($record);
836+
834837
# execute
835838
try { $this->Database_pdns->insertObject("records", $record); }
836839
catch (Exception $e) {
@@ -866,6 +869,9 @@ public function update_domain_record ($domain_id, $content, $print_success=true)
866869
// validate domain
867870
if ($this->fetch_domain ($domain_id)===false) { $this->Result->show("danger", "Invalid domain id", true); }
868871

872+
# checks
873+
$this->validate_record_content ($record);
874+
869875
// remove domain_id if set !
870876
unset($content->domain_id);
871877

@@ -1136,6 +1142,31 @@ public function formulate_update_record ($name=null, $type=null, $content=null,
11361142
return (array) $record;
11371143
}
11381144

1145+
/**
1146+
* Validates record content.
1147+
*
1148+
* @access private
1149+
* @param mixed $record
1150+
* @return void
1151+
*/
1152+
private function validate_record_content ($record) {
1153+
// to object
1154+
$record = (object) $record;
1155+
1156+
// a record check
1157+
if($record->type=="A") {
1158+
if (filter_var($record->content, FILTER_VALIDATE_IP) === false) {
1159+
$this->Result->show("danger", _("A record must be an IP address"), true);
1160+
}
1161+
}
1162+
// AAA records check
1163+
elseif($record->type=="AAAA") {
1164+
if (filter_var($record->content, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
1165+
$this->Result->show("danger", _("AAAA record must be an IP address"), true);
1166+
}
1167+
}
1168+
}
1169+
11391170
/**
11401171
* Validate domain id
11411172
*

0 commit comments

Comments
 (0)