initial commit
This commit is contained in:
commit
44d4a91bfa
3 changed files with 43 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
ddns
|
||||
KEY
|
||||
39
ddns.go
Normal file
39
ddns.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"net/http"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
mu sync.RWMutex
|
||||
ip string
|
||||
key string
|
||||
)
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/get", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
w.Write([]byte(ip))
|
||||
return
|
||||
}
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
})
|
||||
http.HandleFunc("/set", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
r.ParseForm()
|
||||
if subtle.ConstantTimeCompare([]byte(key), []byte(r.FormValue("token"))) == 1 {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
ip = r.FormValue("ip")
|
||||
w.Write([]byte("ok"))
|
||||
return
|
||||
}
|
||||
}
|
||||
http.Error(w, "bad request", http.StatusBadRequest)
|
||||
})
|
||||
panic(http.ListenAndServe("127.0.0.1:9090", nil))
|
||||
}
|
||||
2
make.sh
Executable file
2
make.sh
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
go build -ldflags="-X main.key=$(cat KEY) -s -w"
|
||||
Loading…
Add table
Add a link
Reference in a new issue