Introduce overrideID option to allow multiple tunnels in parellel

This commit is contained in:
nemunaire 2022-04-30 02:41:12 +02:00
commit 7187a7d187
6 changed files with 32 additions and 30 deletions

View file

@ -28,7 +28,7 @@ func init() {
}))
}
func check_GLUE_respond(student *adlin.Student, domain string, ip string) (err error) {
if !strings.HasPrefix(ip, adlin.StudentIP(student.Id).String()) {
if !strings.HasPrefix(ip, adlin.StudentIP(student.Id, 0).String()) {
return fmt.Errorf("%q is not your IP range", ip)
}

View file

@ -312,8 +312,8 @@ func AddAssociatedDomains(student *adlin.Student, aaaa net.IP) (err error) {
}
if aaaa == nil {
aaaa = net.ParseIP(adlin.StudentIP(student.Id).String() + "1")
} else if !adlin.StudentNet(student.Id).Contains(aaaa) {
aaaa = net.ParseIP(adlin.StudentIP(student.Id, 0).String() + "1")
} else if !adlin.StudentNet(student.Id, 0).Contains(aaaa) {
return errors.New("The associated IP has to be in your IP range.")
}

View file

@ -57,7 +57,7 @@ func showIPs(_ httprouter.Params, body []byte) (interface{}, error) {
func GetStudentTunnelIPs(student *adlin.Student) (ips []string) {
if ts, err := student.GetActivesTunnels(); err != nil || len(ts) == 0 || ts[0].SuffixIP == 0 {
ips = append(ips, adlin.StudentIP(student.Id).String()+"1")
ips = append(ips, adlin.StudentIP(student.Id, 0).String()+"1")
} else {
for _, t := range ts {
ips = append(ips, t.GetStudentIP())

View file

@ -31,7 +31,7 @@ func init() {
})
router.GET("/api/wg/", apiAuthHandler(showWgTunnel))
router.GET("/api/wginfo", apiAuthHandler(func(student *adlin.Student, ps httprouter.Params, body []byte) (interface{}, error) {
return getTunnelInfo(student.Id), nil
return getTunnelInfo(student.Id, 0), nil
}))
router.POST("/api/wg/", apiAuthHandler(genWgToken))
router.GET("/api/wg/:token", getWgTunnelInfo)
@ -59,13 +59,13 @@ type TunnelInfo struct {
SrvGW6 string `json:"srv_gw6"`
}
func getTunnelInfo(student int64) TunnelInfo {
func getTunnelInfo(student int64, idoverride int) TunnelInfo {
srv_pubkey, _ := base64.StdEncoding.DecodeString("uSpqyYovvP4OG6wDxZ0Qkq45MfyK58PMUuPaLesY8FI=")
return TunnelInfo{
Status: "OK",
SrvPubKey: srv_pubkey,
SrvPort: 42912,
CltIPv6: adlin.StudentIP(student),
CltIPv6: adlin.StudentIP(student, idoverride),
CltRange: adlin.StdNetmask,
SrvGW6: "2a01:e0a:2b:2252::1",
}
@ -133,7 +133,7 @@ func getWgTunnelInfo(w http.ResponseWriter, r *http.Request, ps httprouter.Param
syncWgConf()
tinfo := getTunnelInfo(token.IdStudent)
tinfo := getTunnelInfo(token.IdStudent, token.OverrideID)
var student *adlin.Student
student, err = adlin.GetStudent(int(token.IdStudent))
@ -218,7 +218,7 @@ func GenWGConfig(w io.Writer) error {
#IdStudent = %d
PublicKey = %s
AllowedIPs = %s/%d
`, t.IdStudent, base64.StdEncoding.EncodeToString(t.PubKey), adlin.StudentIP(t.IdStudent), 80)))
`, t.IdStudent, base64.StdEncoding.EncodeToString(t.PubKey), adlin.StudentIP(t.IdStudent, t.OverrideID), 80)))
}
return nil