Can use the busybox wget by passing special header to GET, instead of requiring curl
This commit is contained in:
parent
68065f4e89
commit
af88c485b6
@ -18,7 +18,7 @@ cmdline() {
|
|||||||
[ -f "/etc/wireguard/adlin.conf" ] && WGPRVKEY=$(sed 's/^.*PrivateKey *= *//p;d' /etc/wireguard/adlin.conf)
|
[ -f "/etc/wireguard/adlin.conf" ] && WGPRVKEY=$(sed 's/^.*PrivateKey *= *//p;d' /etc/wireguard/adlin.conf)
|
||||||
[ -z "${WGPRVKEY}" ] && WGPRVKEY=$(/usr/bin/wg genkey)
|
[ -z "${WGPRVKEY}" ] && WGPRVKEY=$(/usr/bin/wg genkey)
|
||||||
WGPUBKEY=$(echo $WGPRVKEY | /usr/bin/wg pubkey)
|
WGPUBKEY=$(echo $WGPRVKEY | /usr/bin/wg pubkey)
|
||||||
while ! { echo -e "[Interface]\nPrivateKey = ${WGPRVKEY}"; /usr/bin/curl -f -d '{"pubkey": "'$WGPUBKEY'"}' https://adlin.nemunai.re/api/wg/$(echo -n "$WGTOKEN" | /usr/bin/sha512sum | /usr/bin/cut -d ' ' -f 1); } > /etc/wireguard/adlin.conf
|
while ! { echo -e "[Interface]\nPrivateKey = ${WGPRVKEY}"; /usr/bin/wget -O - --header "X-WG-pubkey: $WGPUBKEY" https://adlin.nemunai.re/api/wg/$(echo -n "$WGTOKEN" | /usr/bin/sha512sum | /usr/bin/cut -d ' ' -f 1); } > /etc/wireguard/adlin.conf
|
||||||
do
|
do
|
||||||
exit 1
|
exit 1
|
||||||
done
|
done
|
||||||
|
@ -31,6 +31,7 @@ func init() {
|
|||||||
return getTunnelInfo(student.Id), nil
|
return getTunnelInfo(student.Id), nil
|
||||||
}))
|
}))
|
||||||
router.POST("/api/wg/", apiAuthHandler(genWgToken))
|
router.POST("/api/wg/", apiAuthHandler(genWgToken))
|
||||||
|
router.GET("/api/wg/:token", getWgTunnelInfo)
|
||||||
router.POST("/api/wg/:token", getWgTunnelInfo)
|
router.POST("/api/wg/:token", getWgTunnelInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +98,17 @@ func getWgTunnelInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Param
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pt PubTunnel
|
var pt PubTunnel
|
||||||
|
if r.Method == "POST" {
|
||||||
if err := json.NewDecoder(r.Body).Decode(&pt); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&pt); err != nil {
|
||||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest)
|
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest)
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|
||||||
token.PubKey = pt.PubKey
|
token.PubKey = pt.PubKey
|
||||||
_, err = token.Update()
|
_, err = token.Update()
|
||||||
@ -113,6 +121,13 @@ func getWgTunnelInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Param
|
|||||||
|
|
||||||
tinfo := getTunnelInfo(token.IdStudent)
|
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.Header().Set("Content-Type", "text/plain")
|
||||||
w.Write([]byte(fmt.Sprintf(`[Peer]
|
w.Write([]byte(fmt.Sprintf(`[Peer]
|
||||||
PublicKey = %s
|
PublicKey = %s
|
||||||
@ -122,7 +137,8 @@ PersistentKeepalive = 5
|
|||||||
# MyIPv6=%s1/%d
|
# MyIPv6=%s1/%d
|
||||||
# MyNetwork=%s/%d
|
# MyNetwork=%s/%d
|
||||||
# GWIPv6=%s
|
# 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 {
|
func GenWGConfig(w io.Writer) error {
|
||||||
|
Reference in New Issue
Block a user