diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b089552..0000000 --- a/.travis.yml +++ /dev/null @@ -1,46 +0,0 @@ -language: go - -os: - - linux - -dist: "focal" - -go: - - 1.18.x - # 使用最新 Go 源码运行,但是测试时间会大大延长 - #- master - -# 每次 Git 提交后触发 -script: - #- chmod +x ./build.sh && ./build.sh - - make -f Makefile.client - - make -f Makefile.server - -# 发布前触发 (Travis-CI 现按运行时间计算使用,注释以缩短运行时间) -#before_deploy: -# - chmod +x ./build.sh && ./build.sh - -# 发布触发 -deploy: - provider: releases - edge: true - token: ${TOKEN} - cleanup: false - file: - - ddns-watchdog-client.darwin-amd64.tar.gz - - ddns-watchdog-client.darwin-arm64.tar.gz - - ddns-watchdog-client.linux-amd64.tar.gz - - ddns-watchdog-client.linux-arm64.tar.gz - - ddns-watchdog-client.linux-armv7.tar.gz - - ddns-watchdog-client.windows-amd64.tar.gz - - ddns-watchdog-client.windows-arm64.tar.gz - - ddns-watchdog-server.darwin-amd64.tar.gz - - ddns-watchdog-server.darwin-arm64.tar.gz - - ddns-watchdog-server.linux-amd64.tar.gz - - ddns-watchdog-server.linux-arm64.tar.gz - - ddns-watchdog-server.linux-armv7.tar.gz - - ddns-watchdog-server.windows-amd64.tar.gz - - ddns-watchdog-server.windows-arm64.tar.gz - on: - tags: true - all_branches: true \ No newline at end of file diff --git a/cmd/ddns-watchdog-server/main.go b/cmd/ddns-watchdog-server/main.go index 947f25d..183c384 100644 --- a/cmd/ddns-watchdog-server/main.go +++ b/cmd/ddns-watchdog-server/main.go @@ -86,21 +86,28 @@ func main() { http.HandleFunc("/", ddnsServerHandler) // 启动监听 - log.Println("Work on", conf.Port) - err = http.ListenAndServe(conf.Port, nil) + if conf.TLS.Enable { + log.Println("Work on", conf.Port, "with TLS") + err = http.ListenAndServeTLS(conf.Port, server.ConfDirectoryName+"/"+conf.TLS.CertFile, server.ConfDirectoryName+"/"+conf.TLS.KeyFile, nil) + } else { + log.Println("Work on", conf.Port) + err = http.ListenAndServe(conf.Port, nil) + } if err != nil { log.Fatal(err) } } func RunInit() (err error) { - conf := server.ServerConf{} - conf.Port = ":10032" - conf.IsRoot = false - conf.RootServerAddr = "https://yzyweb.cn/ddns-watchdog" + conf := server.ServerConf{ + Port: ":10032", + IsRoot: false, + RootServerAddr: "https://yzyweb.cn/ddns-watchdog", + } err = common.MarshalAndSave(conf, server.ConfDirectoryName+"/"+server.ConfFileName) if err != nil { return } + log.Println("初始化 " + server.ConfDirectoryName + "/" + server.ConfFileName) return } diff --git a/internal/server/server.go b/internal/server/server.go index ce9eca4..13595de 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -21,10 +21,17 @@ var ( ConfDirectoryName = "conf" ) +type TLSConf struct { + Enable bool `json:"enable"` + CertFile string `json:"cert_file"` + KeyFile string `json:"key_file"` +} + type ServerConf struct { - Port string `json:"port"` - IsRoot bool `json:"is_root"` - RootServerAddr string `json:"root_server_addr"` + Port string `json:"port"` + IsRoot bool `json:"is_root"` + RootServerAddr string `json:"root_server_addr"` + TLS TLSConf `json:"tls"` } func (conf ServerConf) GetLatestVersion() (str string) { @@ -68,6 +75,9 @@ func (conf ServerConf) CheckLatestVersion() { func GetClientIP(req *http.Request) (ipAddr string) { ipAddr = req.Header.Get("X-Forwarded-For") + if ipAddr != "" && strings.Contains(ipAddr, ", ") { + ipAddr = strings.Split(ipAddr, ", ")[0] + } if ipAddr == "" { ipAddr = req.Header.Get("X-Real-IP") }