From fa2279d473d61c0bfee892e9ef6841b1188ecf15 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 31 Dec 2020 10:36:27 +0100 Subject: [PATCH] Add SVCB and HTTPS types and reduce code duplication Signed-off-by: DL6ER --- api_db.php | 36 +++++-------------------------- queries.php | 7 +----- scripts/pi-hole/php/func.php | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/api_db.php b/api_db.php index 76b0ca5f8..51d59ba41 100644 --- a/api_db.php +++ b/api_db.php @@ -120,40 +120,14 @@ function resolveHostname($clientip, $printIP) if(!is_bool($results)) while ($row = $results->fetchArray()) { + // Try to resolve host name of this client $c = resolveHostname($row[3],false); // Convert query type ID to name - // Names taken from FTL's query type names - switch($row[1]) { - case 1: - $query_type = "A"; - break; - case 2: - $query_type = "AAAA"; - break; - case 3: - $query_type = "ANY"; - break; - case 4: - $query_type = "SRV"; - break; - case 5: - $query_type = "SOA"; - break; - case 6: - $query_type = "PTR"; - break; - case 7: - $query_type = "TXT"; - break; - case 8: - $query_type = "NAPTR"; - break; - default: - $query_type = "UNKN"; - break; - } - // array: time type domain client status upstream destination + $query_type = getQueryTypeStr($row[1]); + + // Insert into array + // array: time type domain client status upstream destination $allQueries[] = [$row[0], $query_type, utf8_encode(str_replace("~"," ",$row[2])), utf8_encode($c), $row[4], utf8_encode($row[5])]; } } diff --git a/queries.php b/queries.php index 6044a2441..b22c19543 100644 --- a/queries.php +++ b/queries.php @@ -59,12 +59,7 @@ } else if(isset($_GET["querytype"])) { - $qtypes = ["A (IPv4)", "AAAA (IPv6)", "ANY", "SRV", "SOA", "PTR", "TXT", "NAPTR", "MX", "DS", "RRSIG", "DNSKEY", "NS", "OTHER"]; - $qtype = intval($_GET["querytype"]); - if($qtype > 0 && $qtype <= count($qtypes)) - $showing .= " ".$qtypes[$qtype-1]." queries"; - else - $showing .= " type ".$qtype." queries"; + $showing .= " type ".getQueryTypeStr($_GET["querytype"])." queries"; } else if(isset($_GET["domain"])) { diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index 0db73b180..1960760d5 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -405,4 +405,45 @@ function returnError($message = "", $json = true) } } +function getQueryTypeStr($querytype) +{ + $qtype = intval($querytype); + switch ($qtype) { + case 1: + return "A (IPv4)"; + case 2: + return "AAAA (IPv6)"; + case 3: + return "ANY"; + case 4: + return "SRV"; + case 5: + return "SOA"; + case 6: + return "PTR"; + case 7: + return "TXT"; + case 8: + return "NAPTR"; + case 9: + return "MX"; + case 10: + return "DS"; + case 11: + return "RRSIG"; + case 12: + return "DNSKEY"; + case 13: + return "NS"; + case 14: + return "OTHER"; + case 15: + return "SVCB"; + case 16: + return "HTTPS"; + default: + return "UNKN (".$qtype.")"; + } +} + ?>