Can use the busybox wget by passing special header to GET, instead of requiring curl
This commit is contained in:
parent
68065f4e89
commit
af88c485b6
2 changed files with 20 additions and 4 deletions
|
|
@ -31,6 +31,7 @@ func init() {
|
|||
return getTunnelInfo(student.Id), nil
|
||||
}))
|
||||
router.POST("/api/wg/", apiAuthHandler(genWgToken))
|
||||
router.GET("/api/wg/:token", getWgTunnelInfo)
|
||||
router.POST("/api/wg/:token", getWgTunnelInfo)
|
||||
}
|
||||
|
||||
|
|
@ -97,8 +98,15 @@ func getWgTunnelInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Param
|
|||
}
|
||||
|
||||
var pt PubTunnel
|
||||
if err := json.NewDecoder(r.Body).Decode(&pt); err != nil {
|
||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest)
|
||||
if r.Method == "POST" {
|
||||
if err := json.NewDecoder(r.Body).Decode(&pt); err != nil {
|
||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
} else if pubkey := r.Header.Get("X-WG-PubKey"); pubkey != "" {
|
||||
pt.PubKey, _ = base64.StdEncoding.DecodeString(pubkey)
|
||||
} else {
|
||||
http.Error(w, fmt.Sprintf("{errmsg:\"No public key given\"}", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +121,13 @@ func getWgTunnelInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Param
|
|||
|
||||
tinfo := getTunnelInfo(token.IdStudent)
|
||||
|
||||
var student adlin.Student
|
||||
student, err = adlin.GetStudent(int(token.IdStudent))
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte(fmt.Sprintf(`[Peer]
|
||||
PublicKey = %s
|
||||
|
|
@ -122,7 +137,8 @@ PersistentKeepalive = 5
|
|||
# MyIPv6=%s1/%d
|
||||
# MyNetwork=%s/%d
|
||||
# GWIPv6=%s
|
||||
`, base64.StdEncoding.EncodeToString(tinfo.SrvPubKey), "82.64.31.248", tinfo.SrvPort, tinfo.CltIPv6, 64, tinfo.CltIPv6, tinfo.CltRange, tinfo.SrvGW6)))
|
||||
# MyLogin=%s
|
||||
`, base64.StdEncoding.EncodeToString(tinfo.SrvPubKey), "82.64.31.248", tinfo.SrvPort, tinfo.CltIPv6, 64, tinfo.CltIPv6, tinfo.CltRange, tinfo.SrvGW6, student.Login)))
|
||||
}
|
||||
|
||||
func GenWGConfig(w io.Writer) error {
|
||||
|
|
|
|||
Reference in a new issue