token-validator: display custom IP
This commit is contained in:
parent
8427a0adb8
commit
b6eb652929
3 changed files with 26 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
|
|
@ -54,13 +55,32 @@ func showIPs(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return r, nil
|
||||
}
|
||||
|
||||
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")
|
||||
} else {
|
||||
for _, t := range ts {
|
||||
ips = append(ips, t.GetTunnelIP())
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getStudentIPs(student adlin.Student) (r map[string]string) {
|
||||
r = make(map[string]string)
|
||||
|
||||
r["vlan0"] = IPSuffix(student, net.IPNet{net.ParseIP("172.23.0.0"), net.CIDRMask(17, 32)}).String()
|
||||
r["wg0"] = IPSuffix(student, net.IPNet{net.ParseIP("172.17.0.0"), net.CIDRMask(16, 32)}).String()
|
||||
r["vlan7"] = IPSuffix(student, net.IPNet{net.ParseIP("172.23.142.0"), net.CIDRMask(23, 32)}).String()
|
||||
r["wg"] = adlin.StudentIP(student.Id).String()
|
||||
|
||||
for d, ip := range GetStudentTunnelIPs(student) {
|
||||
key := "wg"
|
||||
if d > 0 {
|
||||
key += strconv.Itoa(d)
|
||||
}
|
||||
r[key] = ip
|
||||
}
|
||||
|
||||
r["adn"] = student.MyAssociatedDomain()
|
||||
r["ddn"] = student.MyDelegatedDomain()
|
||||
|
||||
|
|
|
|||
Reference in a new issue