token-validator: better calculate IP contained
This commit is contained in:
parent
6fcdc44952
commit
d28b14fa50
@ -12,10 +12,19 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const StdNetmask = 80
|
||||||
|
|
||||||
func StudentIP(idstd int64) net.IP {
|
func StudentIP(idstd int64) net.IP {
|
||||||
return net.ParseIP(fmt.Sprintf("2a01:e0a:2b:2252:%x::", idstd))
|
return net.ParseIP(fmt.Sprintf("2a01:e0a:2b:2252:%x::", idstd))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StudentNet(idstd int64) *net.IPNet {
|
||||||
|
return &net.IPNet{
|
||||||
|
IP: StudentIP(idstd),
|
||||||
|
Mask: net.CIDRMask(StdNetmask, 128),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type WGDump struct {
|
type WGDump struct {
|
||||||
PubKey string
|
PubKey string
|
||||||
PSK string
|
PSK string
|
||||||
|
@ -246,7 +246,7 @@ func AddAssociatedDomains(student adlin.Student, aaaa net.IP) (err error) {
|
|||||||
|
|
||||||
if aaaa == nil {
|
if aaaa == nil {
|
||||||
aaaa = net.ParseIP(adlin.StudentIP(student.Id).String() + "1")
|
aaaa = net.ParseIP(adlin.StudentIP(student.Id).String() + "1")
|
||||||
} else if !strings.HasPrefix(aaaa.String(), adlin.StudentIP(student.Id).String()) {
|
} else if !adlin.StudentNet(student.Id).Contains(aaaa) {
|
||||||
return errors.New("The associated IP has to be in your IP range.")
|
return errors.New("The associated IP has to be in your IP range.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func getTunnelInfo(student int64) TunnelInfo {
|
|||||||
SrvPubKey: srv_pubkey,
|
SrvPubKey: srv_pubkey,
|
||||||
SrvPort: 42912,
|
SrvPort: 42912,
|
||||||
CltIPv6: adlin.StudentIP(student),
|
CltIPv6: adlin.StudentIP(student),
|
||||||
CltRange: 80,
|
CltRange: adlin.StdNetmask,
|
||||||
SrvGW6: "2a01:e0a:2b:2252::1",
|
SrvGW6: "2a01:e0a:2b:2252::1",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user