Skip to content

Commit

Permalink
v1.4.4 i: fixed bug and add new feature(server support TLS)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzy613 committed Apr 21, 2022
1 parent 03034e8 commit 1dc7259
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 55 deletions.
46 changes: 0 additions & 46 deletions .travis.yml

This file was deleted.

19 changes: 13 additions & 6 deletions cmd/ddns-watchdog-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 13 additions & 3 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 1dc7259

Please sign in to comment.