token-validator: display custom IP
This commit is contained in:
parent
8427a0adb8
commit
b6eb652929
|
@ -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[:]
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
<ul ng-if="ips" style="padding-left:0">
|
||||
<li><strong>Domaine :</strong> <a href="http://{{ips.adn}}/">{{ips.adn}}</a></li>
|
||||
<li><strong>Délégation :</strong> <a href="http://{{ips.ddn}}/">{{ips.ddn}}</a></li>
|
||||
<li><strong>IPv6 :</strong> {{ips.wg}}1/96</li>
|
||||
<li><strong>IPv6 :</strong> {{ips.wg}}/80</li>
|
||||
</ul>
|
||||
<div ng-repeat="(tutoid,tuto) in tuto_progress">
|
||||
<hr>
|
||||
|
|
|
@ -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 New Issue