function update_record($id_domain, $id_record, $record_name, $record_type, $record_content, $record_ttl, $record_prio) { log_write("debug", "api_namedmanager", "Executing update_record( {$id_domain}, {$id_record}, {$record_name}, {$record_type}, {$record_content}, {$record_ttl}, {$record_prio} )"); if ($this->auth_admin) { $obj_record = new domain_records(); // validate record inpit $data = array(); $data["id_domain"] = @security_script_input_predefined("int", $id_domain); $data["id_record"] = @security_script_input_predefined("int", $id_record); $data["record_name"] = @security_script_input_predefined("any", $record_name); $data["record_type"] = @security_script_input_predefined("any", $record_type); $data["record_content"] = @security_script_input_predefined("any", $record_content); $data["record_ttl"] = @security_script_input_predefined("int", $record_ttl); $data["record_prio"] = @security_script_input_predefined("int", $record_prio); foreach ($data as $value) { if ($value == "error" && $value != 0) { throw new SoapFault("Sender", "INVALID_INPUT"); } } if (!$data["id_domain"] || !$data["record_name"] || !$data["record_type"] || !$data["record_content"]) { throw new SoapFault("Sender", "INVALID_INPUT"); } // verify domain ID $obj_record->id = $data["id_domain"]; if (!$obj_record->verify_id()) { throw new SoapFault("Sender", "INVALID_ID"); } // load domain and record data $obj_record->load_data(); if ($data["id_record"]) { $obj_record->id_record = $data["id_record"]; if (!$obj_record->verify_id_record()) { // ID is invalid // // blank the ID and create a new record - we do this for apps like // phpfreeradius, but it might not be the best approach long-term $data["id_record"] = 0; } else { $obj_record->load_data_record(); } } else { // check if there is a record with the same values already - if so, we should // take it's ID. // // TODO: turn this into a proper function // $sql_obj = new sql_query(); $sql_obj->string = "SELECT id FROM `dns_records` WHERE id_domain='" . $data["id_domain"] . "' AND name='" . $data["record_name"] . "' LIMIT 1"; $sql_obj->execute(); if ($sql_obj->num_rows()) { $sql_obj->fetch_array(); $obj_record->id_record = $sql_obj->data[0]["id"]; $obj_record->load_data_record(); } } // apply changes $obj_record->data_record["name"] = $data["record_name"]; $obj_record->data_record["type"] = $data["record_type"]; $obj_record->data_record["content"] = $data["record_content"]; $obj_record->data_record["ttl"] = $data["record_ttl"]; $obj_record->data_record["prio"] = $data["record_prio"]; if (!$data["record_ttl"]) { $obj_record->data_record["ttl"] = $obj_record->data["soa_default_ttl"]; } if ($obj_record->action_update_record()) { return $obj_record->id_record; } else { throw new SoapFault("Sender", "UNKNOWN_ERROR"); } } else { throw new SoapFault("Sender", "ACCESS_DENIED"); } }