Skip to content

Commit

Permalink
feat: 新增bulkVerifyDns数据,用于批量验证dnslog
Browse files Browse the repository at this point in the history
  • Loading branch information
lanyi1998 committed May 1, 2023
1 parent b51fd01 commit 1080df8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions Http/Core.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func ListingHttpManagementServer() {
mux.HandleFunc("/api/getDnsData", GetDnsData)
mux.HandleFunc("/api/Clean", Clean)
mux.HandleFunc("/api/verifyDns", verifyDns)
mux.HandleFunc("/api/bulkVerifyDns", BulkVerifyDns)
log.Println("Http Listing Start...")
server := &http.Server{
Addr: fmt.Sprintf(":%s", Core.Config.HTTP.Port),
Expand Down
37 changes: 35 additions & 2 deletions Http/Route.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"DnsLog/Dns"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
Expand All @@ -15,6 +16,11 @@ type RespData struct {
Msg string
}

type BulkRespData struct {
HTTPStatusCode string
Msg []string
}

type queryInfo struct {
Query string // 首字母大写
}
Expand Down Expand Up @@ -55,7 +61,7 @@ func verifyTokenApi(w http.ResponseWriter, r *http.Request) {
}
}

func JsonRespData(resp RespData) string {
func JsonRespData(resp interface{}) string {
rs, err := json.Marshal(resp)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -83,7 +89,7 @@ func verifyDns(w http.ResponseWriter, r *http.Request) {
var Q queryInfo
key := r.Header.Get("token")
if Core.VerifyToken(key) {
body, _ := ioutil.ReadAll(r.Body)
body, _ := io.ReadAll(r.Body)
json.Unmarshal(body, &Q)
resp := RespData{
HTTPStatusCode: "200",
Expand All @@ -104,3 +110,30 @@ func verifyDns(w http.ResponseWriter, r *http.Request) {
}))
}
}

func BulkVerifyDns(w http.ResponseWriter, r *http.Request) {
var Q []string
key := r.Header.Get("token")
if Core.VerifyToken(key) {
body, _ := io.ReadAll(r.Body)
json.Unmarshal(body, &Q)
var result = []string{}
for _, v := range Dns.DnsData[key] {
for _, q := range Q {
if v.Subdomain == q {
result = append(result, q)
}
}
}
resp := BulkRespData{
HTTPStatusCode: "200",
Msg: result,
}
fmt.Fprintf(w, JsonRespData(resp))
} else {
fmt.Fprintf(w, JsonRespData(RespData{
HTTPStatusCode: "403",
Msg: "false",
}))
}
}
Binary file removed main
Binary file not shown.
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ func main() {
if err != nil {
log.Fatalln(err.Error())
}
//for _, v := range strings.Split(Core.Config.HTTP.Token, ",") {
// Core.User[v] = Core.GetRandStr()
//}
go Dns.ListingDnsServer()
Http.ListingHttpManagementServer()
}

0 comments on commit 1080df8

Please sign in to comment.