tokens: use adlin to transmit wg-adlin
This commit is contained in:
parent
a4d84a241d
commit
833d3198f2
3 changed files with 38 additions and 8 deletions
|
|
@ -17,7 +17,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
IFaceName = "wg0"
|
||||
IFaceName = "wg0"
|
||||
TunnelPort = 12912
|
||||
)
|
||||
|
||||
|
|
@ -48,7 +48,6 @@ func init() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
// Calculate public key
|
||||
cmdPubK := exec.Command("wg", "pubkey")
|
||||
cmdPubK.Stdin = bytes.NewReader(outPrvK)
|
||||
|
|
@ -70,7 +69,9 @@ func init() {
|
|||
}
|
||||
|
||||
type PubTunnel struct {
|
||||
PubKey []byte
|
||||
Login string `json:"login"`
|
||||
PubKey [][]byte `json:"data"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func register(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -91,11 +92,24 @@ func register(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
// Validate wg token
|
||||
if j, err := json.Marshal(pt); err != nil {
|
||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusInternalServerError)
|
||||
return
|
||||
} else if r, err := http.NewRequest("POST", "https://adlin.nemunai.re/wg-step", bytes.NewReader(j)); err != nil {
|
||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusInternalServerError)
|
||||
return
|
||||
} else if resp, err := http.DefaultClient.Do(r); err == nil {
|
||||
resp.Body.Close()
|
||||
} else {
|
||||
log.Printf("Unable to register wg-step on token-validator:", err)
|
||||
}
|
||||
|
||||
if next_ip, err := findNextIP(); err != nil {
|
||||
http.Error(w, fmt.Sprintf("{errmsg:%q}", err), http.StatusBadRequest)
|
||||
return
|
||||
} else {
|
||||
addWgPeer(pt.PubKey, next_ip)
|
||||
addWgPeer(pt.PubKey[0], next_ip)
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write([]byte(fmt.Sprintf(`# Address=%s/18
|
||||
|
|
|
|||
Reference in a new issue