コード例 #1
0
 public function ip_to_arpa($ip)
 {
     if (strpos($ip, ":") !== false) {
         return HelperFunctions::ipv6_to_arpa($ip);
     } else {
         return HelperFunctions::ipv4_to_arpa($ip);
     }
 }
コード例 #2
0
 public function get_zone($response, $identifier, &$out = null, $details = true, $arpa_expand = true, $include_zone_id = false)
 {
     $arpa = null;
     if (preg_match(VALID_IPV4, $identifier) === 1) {
         $arpa = HelperFunctions::ipv4_to_arpa($identifier);
     } else {
         if (preg_match(VALID_IPV6, $identifier) === 1) {
             $arpa = HelperFunctions::ipv6_to_arpa($identifier);
         }
     }
     if ($arpa !== null && $arpa_expand === true) {
         for ($i = 0; ($ret = HelperFunctions::truncate_arpa($arpa, $i)) !== false; $i++) {
             $response = ZoneFunctions::get_zone($response, $ret, $out, $details, false);
             if ($response->code !== Response::NOTFOUND) {
                 return $response;
             }
         }
         $response->code = Response::NOTFOUND;
         $response->error = sprintf("Could not find a reverse DNS zone for %s", $identifier);
         $response->error_detail = "ARPA_ZONE_NOT_FOUND";
         return $response;
     }
     try {
         $connection = Database::getConnection();
     } catch (PDOException $e) {
         $response->code = Response::INTERNALSERVERERROR;
         $response->error = "Could not connect to PowerDNS server.";
         $response->error_detail = "INTERNAL_SERVER_ERROR";
         return $response;
     }
     $statement = $connection->prepare(sprintf("SELECT z.id as z_id, z.name as z_name, z.master as z_master, z.last_check as z_last_check, z.type as z_type, z.notified_serial as z_notified_serial,\n\t\t\t        r.id as r_id, r.name as r_name, r.type as r_type, r.content as r_content, r.ttl as r_ttl, r.prio as r_prio, r.change_date as r_change_date\n\t\t\t FROM `%s` z\n\t\t\t LEFT JOIN `%s` r ON (z.id = r.domain_id)\n\t\t\t WHERE z.name = :name\n\t\t\t ORDER BY CAST(r_name AS UNSIGNED) ASC,\n\t\t\t r_name ASC,\n\t\t\t r_type DESC,\n\t\t\t r_prio ASC,\n\t\t\t r_content ASC;", PowerDNSConfig::DB_ZONE_TABLE, PowerDNSConfig::DB_RECORD_TABLE));
     if ($statement === false || $statement->execute(array(":name" => $identifier)) === false) {
         $response->code = Response::INTERNALSERVERERROR;
         $response->error = "Could not query PowerDNS server.";
         $response->error_detail = "INTERNAL_SERVER_ERROR";
         return $response;
     }
     $output = array();
     $first = true;
     while (($row = $statement->fetch(PDO::FETCH_ASSOC)) !== false) {
         if ($first) {
             if ($include_zone_id) {
                 $output['z_id'] = $row['z_id'];
             }
             $output['name'] = $row['z_name'];
             $output['type'] = $row['z_type'];
             if (!empty($row['z_master'])) {
                 $output['master'] = $row['z_master'];
             }
             if (!empty($row['z_last_check'])) {
                 $output['last_check'] = $row['z_last_check'];
             }
             if (!empty($row['z_notified_serial'])) {
                 $output['notified_serial'] = $row['z_notified_serial'];
             }
             $first = false;
             if ($details === false) {
                 break;
             }
         }
         if (empty($row['r_name']) && empty($row['r_content'])) {
             break;
         }
         $record = array();
         $record['name'] = $row['r_name'];
         $record['type'] = $row['r_type'];
         $record['content'] = $row['r_content'];
         $record['ttl'] = $row['r_ttl'];
         $record['priority'] = $row['r_prio'];
         if (!empty($row['r_change_date'])) {
             $record['change_date'] = $row['r_change_date'];
         }
         $output['records'][] = $record;
     }
     if (empty($output)) {
         $response->code = Response::NOTFOUND;
         $response->body = array();
         $response->log_message = sprintf("Zone %s was not found.", $identifier);
         $out = array();
     } else {
         if (!isset($output['records'])) {
             $output['records'] = array();
         }
         $response->code = Response::OK;
         $response->body = $output;
         $response->log_message = sprintf("Zone %s with %d records was retrieved.", $identifier, count($output['records']));
         $out = $output;
     }
     return $response;
 }