checker: for each tun IP
This commit is contained in:
parent
0af7437693
commit
9cd237daff
@ -129,7 +129,7 @@ func check_https(domain, ip string) (err error) {
|
||||
|
||||
// Main
|
||||
|
||||
func minTunnelVersion(std adlin.Student) (int, error) {
|
||||
func minTunnelVersion(std adlin.Student, suffixip int) (int, error) {
|
||||
tunnels, err := std.GetTunnelTokens()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -141,7 +141,7 @@ func minTunnelVersion(std adlin.Student) (int, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
if tunnel.Dump != nil && tunnel.Version < minversion {
|
||||
if tunnel.Dump != nil && tunnel.Version < minversion && suffixip == tunnel.SuffixIP {
|
||||
minversion = tunnel.Version
|
||||
}
|
||||
}
|
||||
@ -161,104 +161,111 @@ func studentsChecker() {
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
// Check ping
|
||||
std := s
|
||||
stdIP := adlin.StudentIP(std.Id).String() + "1"
|
||||
go check_ping(stdIP, func(pkt *ping.Packet) {
|
||||
tunnel_version, err := minTunnelVersion(std)
|
||||
if verbose {
|
||||
log.Printf("%s PONG; version=%d (%v)\n", std.Login, tunnel_version, err)
|
||||
}
|
||||
std.OnPong(true)
|
||||
tuns, err := std.GetActivesTunnels()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, tun := range tuns {
|
||||
stdIP := tun.GetStudentIP()
|
||||
go check_ping(stdIP, func(pkt *ping.Packet) {
|
||||
tunnel_version, err := minTunnelVersion(std, tun.SuffixIP)
|
||||
if verbose {
|
||||
log.Printf("%s PONG (on %x); version=%d (%v)\n", std.Login, tun.SuffixIP, tunnel_version, err)
|
||||
}
|
||||
std.OnPong(true)
|
||||
|
||||
if tunnel_version == 2147483647 || tunnel_version == 0 {
|
||||
log.Printf("%s unknown tunnel version: %d skipping tests (%v)", std.Login, tunnel_version, err)
|
||||
return
|
||||
}
|
||||
|
||||
dnsIP := stdIP
|
||||
// Is GLUE defined?
|
||||
if glueIP, err := get_GLUE(std.MyDelegatedDomain()); glueIP != nil {
|
||||
dnsIP = glueIP.String()
|
||||
|
||||
if verbose {
|
||||
log.Printf("%s has defined GLUE: %s\n", std.Login, dnsIP)
|
||||
}
|
||||
} else if err != nil {
|
||||
log.Printf("%s and GLUE: %s\n", std.Login, err)
|
||||
}
|
||||
|
||||
// Check DNS
|
||||
if addr, err := check_dns(std.MyDelegatedDomain(), dnsIP); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked DNS challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+2, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+2, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Check HTTP with DNS
|
||||
if addr == nil {
|
||||
log.Printf("%s and HTTP (with DNS ip=%s): skipped due to empty response\n", std.Login, addr.String())
|
||||
} else if err := check_http(addr.String()); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTP challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTP (with DNS ip=%s): %s\n", std.Login, addr.String(), err)
|
||||
}
|
||||
|
||||
// Check HTTPs with DNS
|
||||
if addr == nil {
|
||||
log.Printf("%s and HTTPS (with DNS ip=%s): skipped due to empty response\n", std.Login, addr.String())
|
||||
} else if err := check_https(std.MyDelegatedDomain(), addr.String()); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTPS challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTPS (with DNS ip=%s): %s\n", std.Login, addr.String(), err)
|
||||
}
|
||||
} else {
|
||||
// Check HTTP without DNS
|
||||
if err := check_http(stdIP); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTP challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTP (without DNS): %s\n", std.Login, err)
|
||||
}
|
||||
|
||||
// Check HTTPs without DNS
|
||||
if err := check_https(std.MyAssociatedDomain(), stdIP); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTPS challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTPS (without DNS): %s\n", std.Login, err)
|
||||
}
|
||||
}
|
||||
|
||||
if tunnel_version == 2147483647 || tunnel_version == 0 {
|
||||
log.Printf("%s unknown tunnel version: %d skipping tests (%v)", std.Login, tunnel_version, err)
|
||||
return
|
||||
}
|
||||
|
||||
dnsIP := stdIP
|
||||
// Is GLUE defined?
|
||||
if glueIP, err := get_GLUE(std.MyDelegatedDomain()); glueIP != nil {
|
||||
dnsIP = glueIP.String()
|
||||
|
||||
if verbose {
|
||||
log.Printf("%s has defined GLUE: %s\n", std.Login, dnsIP)
|
||||
}
|
||||
} else if err != nil {
|
||||
log.Printf("%s and GLUE: %s\n", std.Login, err)
|
||||
}
|
||||
|
||||
// Check DNS
|
||||
if addr, err := check_dns(std.MyDelegatedDomain(), dnsIP); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked DNS challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+2, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+2, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Check HTTP with DNS
|
||||
if addr == nil {
|
||||
log.Printf("%s and HTTP (with DNS ip=%s): skipped due to empty response\n", std.Login, addr.String())
|
||||
} else if err := check_http(addr.String()); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTP challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTP (with DNS ip=%s): %s\n", std.Login, addr.String(), err)
|
||||
}
|
||||
|
||||
// Check HTTPs with DNS
|
||||
if addr == nil {
|
||||
log.Printf("%s and HTTPS (with DNS ip=%s): skipped due to empty response\n", std.Login, addr.String())
|
||||
} else if err := check_https(std.MyDelegatedDomain(), addr.String()); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTPS challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTPS (with DNS ip=%s): %s\n", std.Login, addr.String(), err)
|
||||
}
|
||||
} else {
|
||||
// Check HTTP without DNS
|
||||
if err := check_http(stdIP); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTP challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+0, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTP (without DNS): %s\n", std.Login, err)
|
||||
}
|
||||
|
||||
// Check HTTPs without DNS
|
||||
if err := check_https(std.MyAssociatedDomain(), stdIP); err == nil {
|
||||
if verbose {
|
||||
log.Printf("%s just unlocked HTTPS challenge\n", std.Login)
|
||||
}
|
||||
if _, err := std.UnlockNewChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
if _, err := std.UpdateUnlockedChallenge(100*(tunnel_version-1)+1, ""); err != nil {
|
||||
log.Printf("Unable to register challenge for %s: %s\n", std.Login, err.Error())
|
||||
}
|
||||
}
|
||||
} else if verbose {
|
||||
log.Printf("%s and HTTPS (without DNS): %s\n", std.Login, err)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,11 @@ type TunnelToken struct {
|
||||
}
|
||||
|
||||
func (tt *TunnelToken) GetStudentIP() string {
|
||||
return fmt.Sprintf("%s%x", StudentIP(tt.IdStudent).String(), tt.SuffixIP)
|
||||
if tt.SuffixIP == 0 {
|
||||
return fmt.Sprintf("%s%x", StudentIP(tt.IdStudent).String(), 1)
|
||||
} else {
|
||||
return fmt.Sprintf("%s%x", StudentIP(tt.IdStudent).String(), tt.SuffixIP)
|
||||
}
|
||||
}
|
||||
|
||||
func TokenFromText(token string) []byte {
|
||||
|
@ -60,7 +60,7 @@ func GetStudentTunnelIPs(student adlin.Student) (ips []string) {
|
||||
ips = append(ips, adlin.StudentIP(student.Id).String()+"1")
|
||||
} else {
|
||||
for _, t := range ts {
|
||||
ips = append(ips, t.GetTunnelIP())
|
||||
ips = append(ips, t.GetStudentIP())
|
||||
}
|
||||
}
|
||||
return
|
||||
|
Reference in New Issue
Block a user