split checker from token-validator
This commit is contained in:
parent
685dc0b0ea
commit
0c661f36f6
20 changed files with 634 additions and 748 deletions
|
@ -4,23 +4,25 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
|
||||
"git.nemunai.re/lectures/adlin/libadlin"
|
||||
)
|
||||
|
||||
func init() {
|
||||
router.GET("/api/ips", apiHandler(showIPs))
|
||||
router.GET("/api/students/:sid/ips", apiHandler(studentHandler(func(student Student, body []byte) (interface{}, error) {
|
||||
router.GET("/api/students/:sid/ips", apiHandler(studentHandler(func(student adlin.Student, body []byte) (interface{}, error) {
|
||||
return getStudentIPs(student), nil
|
||||
})))
|
||||
}
|
||||
|
||||
func (s Student) IPSuffix() int64 {
|
||||
return s.Id * 5 + 10
|
||||
func IPSuffix(s adlin.Student) int64 {
|
||||
return s.Id*4 + 10
|
||||
}
|
||||
|
||||
func showIPs(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
r := make(map[string]map[string]string)
|
||||
|
||||
students, err := getStudents()
|
||||
students, err := adlin.GetStudents()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -40,13 +42,14 @@ func showIPs(_ httprouter.Params, body []byte) (interface{}, error) {
|
|||
return r, nil
|
||||
}
|
||||
|
||||
func getStudentIPs(student Student) (r map[string]string) {
|
||||
func getStudentIPs(student adlin.Student) (r map[string]string) {
|
||||
r = make(map[string]string)
|
||||
|
||||
r["vlan0"] = fmt.Sprintf("172.23.0.%d", student.IPSuffix())
|
||||
r["vlan7"] = fmt.Sprintf("172.23.142.%d", student.IPSuffix())
|
||||
r["wg"] = studentIP(student.Id).String()
|
||||
r["adn"] = student.myAssociatedDomain()
|
||||
r["vlan0"] = fmt.Sprintf("172.23.0.%d", IPSuffix(student))
|
||||
r["wg0"] = fmt.Sprintf("172.17.0.%d", IPSuffix(student))
|
||||
r["vlan7"] = fmt.Sprintf("172.23.142.%d", IPSuffix(student))
|
||||
r["wg"] = adlin.StudentIP(student.Id).String()
|
||||
r["adn"] = student.MyAssociatedDomain()
|
||||
r["ddn"] = student.MyDelegatedDomain()
|
||||
|
||||
return
|
||||
|
|
Reference in a new issue