コード例 #1
0
ファイル: namedmanager.php プロジェクト: claybbs/namedmanager
 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");
     }
 }
コード例 #2
0
ファイル: inc_domain.php プロジェクト: claybbs/namedmanager
 function action_autofill_forward()
 {
     log_write("debug", "domains", "Executing action_autofill_forward()");
     // create
     $obj_record = new domain_records();
     $obj_record->id = $this->data["ipv4_autofill_domain_id"];
     $obj_record->load_data();
     $tmp_network = explode(".", $this->data["ipv4_network"]);
     // assuming /24 only
     for ($i = 0; $i < 255; $i++) {
         // check if there is an existing record.
         $obj_record->id_record = $obj_record->find_forward_record($tmp_network[0] . "-" . $tmp_network[1] . "-" . $tmp_network[2] . "-{$i}");
         $obj_record->data_record["type"] = "A";
         $obj_record->data_record["name"] = $tmp_network[0] . "-" . $tmp_network[1] . "-" . $tmp_network[2] . "-{$i}";
         // name
         $obj_record->data_record["content"] = $tmp_network[0] . "." . $tmp_network[1] . "." . $tmp_network[2] . ".{$i}";
         // ipv4
         $obj_record->data_record["ttl"] = $this->data["soa_default_ttl"];
         $obj_record->action_update_record();
     }
     // update serial to regenerate domain files
     $obj_record->action_update_serial();
     unset($obj_record);
     return 1;
 }
コード例 #3
0
 $obj_record->load_data_record();
 // load record data
 if ($record["mode"] == "update") {
     // data sent through, we should update an existing record. But first, let's check if we actually need to
     // make a change or not.
     if ($obj_record->data_record["name"] != $record["name"] || $obj_record->data_record["type"] != $record["type"] || $obj_record->data_record["content"] != $record["content"] || $obj_record->data_record["ttl"] != (int) $record["ttl"] || $obj_record->data_record["prio"] != (int) $record["prio"] || $record["reverse_ptr"] != $record["reverse_ptr_orig"]) {
         /*
         	Update record
         */
         log_write("debug", "process", "Updating record " . $record["id"] . " due to changed details");
         $obj_record->data_record["name"] = $record["name"];
         $obj_record->data_record["type"] = $record["type"];
         $obj_record->data_record["content"] = $record["content"];
         $obj_record->data_record["ttl"] = $record["ttl"];
         $obj_record->data_record["prio"] = $record["prio"];
         $obj_record->action_update_record();
         /*
         	Update reverse PTR (if required)
         
         	At this stage we have already validated the reverse IP domains and we know
         	that the reverse request is valid and what the id of the domain is. Really
         	all that we need to do is set the details for the record create/update
         */
         if ($record["reverse_ptr"]) {
             log_write("debug", "process", "Updating reverse PTR record for " . $record["name"] . "--&gt; " . $record["content"] . "");
             $obj_ptr = new domain_records();
             $obj_ptr->id = $record["reverse_ptr_id_domain"];
             // will always be set
             $obj_ptr->id_record = $record["reverse_ptr_id_record"];
             // might be set, if not, a new record will be added
             $obj_ptr->load_data();