Skip to content

Commit

Permalink
修复若干小问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lanyi1998 committed Sep 8, 2020
1 parent f3c534d commit ec4862c
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 22 deletions.
8 changes: 6 additions & 2 deletions Core/Core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package Core

var Config = struct {
HTTP struct {
Port string
Token string
Port string
Token string
ConsoleDisable bool
}
Dns struct{
Domain string
}
}{}
18 changes: 12 additions & 6 deletions Dns/Core.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package Dns

import (
"../Core"
"encoding/json"
"fmt"
"golang.org/x/net/dns/dnsmessage"
"net"
"os"
"strings"
"sync"
"time"
)
Expand All @@ -26,7 +28,7 @@ var D DnsInfo
func ListingDnsServer() {
conn, err := net.ListenUDP("udp", &net.UDPAddr{Port: 53})
if err != nil {
println("DNS port listing error")
println("DNS port listing error,Please run as root")
os.Exit(0)
}
defer conn.Close()
Expand Down Expand Up @@ -54,11 +56,15 @@ func serverDNS(addr *net.UDPAddr, conn *net.UDPConn, msg dnsmessage.Message) {
queryType = question.Type
queryName, _ = dnsmessage.NewName(queryNameStr)
)
D.Set(DnsInfo{
Subdomain: queryNameStr,
Ipaddress: addr.IP.String(),
Time: time.Now().Unix() ,
})
if strings.Contains(queryNameStr, Core.Config.Dns.Domain) {
D.Set(DnsInfo{
Subdomain: queryNameStr[:len(queryNameStr)-1],
Ipaddress: addr.IP.String(),
Time: time.Now().Unix(),
})
}else{
return
}
var resource dnsmessage.Resource
switch queryType {
case dnsmessage.TypeA:
Expand Down
9 changes: 5 additions & 4 deletions Http/Core.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ var DnsData = make(map[string]string)

func ListingHttpManagementServer() {
mux := http.NewServeMux()
mux.Handle("/template/", http.FileServer(http.Dir("")))
if !Core.Config.HTTP.ConsoleDisable {
mux.Handle("/template/", http.FileServer(http.Dir("")))
mux.HandleFunc("/", index)
}
mux.HandleFunc("/api/verifyToken", verifyToken)
mux.HandleFunc("/api/getDnsData", GetDnsData)
mux.HandleFunc("/api/Clean", Clean)
mux.HandleFunc("/", index)
mux.HandleFunc("/api/verifyDns", verifyDns)
println("Http Listing Start...")
server := &http.Server{
Addr: ":" + Core.Config.HTTP.Port,
Expand All @@ -24,5 +27,3 @@ func ListingHttpManagementServer() {
log.Fatal(err)
}
}


37 changes: 29 additions & 8 deletions Http/Route.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ func verifyToken(w http.ResponseWriter, r *http.Request) {
}
}

func verifyHeadToken(token string) bool {
if token == Core.Config.HTTP.Token {
return true
} else {
return false
}
}

func JsonRespData(resp RespData) string {
rs, err := json.Marshal(resp)
if err != nil {
Expand All @@ -84,3 +76,32 @@ func Clean(w http.ResponseWriter, r *http.Request) {
}))
}
}

func verifyDns(w http.ResponseWriter, r *http.Request) {
type queryInfo struct {
Query string // 首字母大写
}
var Q queryInfo
key := r.Header.Get("token")
if key == Core.Config.HTTP.Token {
body, _ := ioutil.ReadAll(r.Body)
json.Unmarshal(body, &Q)
resp := RespData{
HTTPStatusCode: "200",
Msg: "false",
}
for _, v := range Dns.DnsData {
if v.Subdomain == Q.Query {
resp.Msg = "true"
break
}

}
fmt.Fprintf(w, JsonRespData(resp))
} else {
fmt.Fprintf(w, JsonRespData(RespData{
HTTPStatusCode: "403",
Msg: "false",
}))
}
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ DNSLog-GO 是一款golang编写的监控 DNS 解析记录的工具,自带WEB

安装
---

详细图文教程:https://mp.weixin.qq.com/s/m_UXJa0imfOi721bkBpwFg

1.获取发行版
这里 https://github.com/lanyi1998/DNSlog-GO/releases 下载最新发行版,并解压

Expand All @@ -26,8 +29,10 @@ DNSLog-GO 是一款golang编写的监控 DNS 解析记录的工具,自带WEB
3.修改配置文件 config.ini

Port = 8080 //HTTP监听端口

Token = admin //API token
ConsoleDisable = false //禁用web控制台,设置为true以后无法访问web页面,只能通过API获取数据
Domain = a.com //绑定自己的域名,避免无效域名和其他网络扫描


4.启动服务
VPS上,root运行 ./main,即可启动DNS和HTTP监听
Expand Down
6 changes: 5 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[HTTP]
Port = 8080
Token = admin
Token = admin
ConsoleDisable = false

[DNS]
Domain = demo.com

0 comments on commit ec4862c

Please sign in to comment.