token-validator: display custom IP

This commit is contained in:
nemunaire 2021-03-04 01:05:24 +01:00
parent 8427a0adb8
commit b6eb652929
3 changed files with 26 additions and 2 deletions

View File

@ -103,6 +103,10 @@ type TunnelToken struct {
Dump *WGDump
}
func (tt *TunnelToken) GetStudentIP() string {
return fmt.Sprintf("%s%x", StudentIP(tt.IdStudent).String(), tt.SuffixIP)
}
func TokenFromText(token string) []byte {
sha := sha512.Sum512([]byte(token))
return sha[:]

View File

@ -72,7 +72,7 @@
<ul ng-if="ips" style="padding-left:0">
<li><strong>Domaine&nbsp;:</strong> <a href="http://{{ips.adn}}/">{{ips.adn}}</a></li>
<li><strong>Délégation&nbsp;:</strong> <a href="http://{{ips.ddn}}/">{{ips.ddn}}</a></li>
<li><strong>IPv6&nbsp;:</strong> {{ips.wg}}1/96</li>
<li><strong>IPv6&nbsp;:</strong> {{ips.wg}}/80</li>
</ul>
<div ng-repeat="(tutoid,tuto) in tuto_progress">
<hr>

View File

@ -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()