@@ -831,6 +831,9 @@ public function add_domain_record ($record, $print_success = true) {
831
831
# null empty values
832
832
$ record = $ this ->reformat_empty_array_fields ($ record , null );
833
833
834
+ # checks
835
+ $ this ->validate_record_content ($ record );
836
+
834
837
# execute
835
838
try { $ this ->Database_pdns ->insertObject ("records " , $ record ); }
836
839
catch (Exception $ e ) {
@@ -866,6 +869,9 @@ public function update_domain_record ($domain_id, $content, $print_success=true)
866
869
// validate domain
867
870
if ($ this ->fetch_domain ($ domain_id )===false ) { $ this ->Result ->show ("danger " , "Invalid domain id " , true ); }
868
871
872
+ # checks
873
+ $ this ->validate_record_content ($ record );
874
+
869
875
// remove domain_id if set !
870
876
unset($ content ->domain_id );
871
877
@@ -1136,6 +1142,31 @@ public function formulate_update_record ($name=null, $type=null, $content=null,
1136
1142
return (array ) $ record ;
1137
1143
}
1138
1144
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
+
1139
1170
/**
1140
1171
* Validate domain id
1141
1172
*
0 commit comments