This commit is contained in:
nemunaire 2021-02-13 18:34:44 +01:00
commit 2f4cc04db2
7 changed files with 30 additions and 29 deletions

View file

@ -4,7 +4,7 @@ type AuthMethod interface {
checkAuth(username, password string) (bool, error)
}
type NoAuth struct {}
type NoAuth struct{}
func (NoAuth) checkAuth(username, password string) (res bool, err error) {
return true, nil

View file

@ -27,7 +27,6 @@ type loginUpload struct {
Password string
}
func (l loginChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if addr := r.Header.Get("X-Forwarded-For"); addr != "" {
r.RemoteAddr = addr
@ -86,7 +85,7 @@ func (l loginChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var ip net.IP
spl := strings.SplitN(r.RemoteAddr, ":", 2)
if ip = net.ParseIP(spl[0]); ip == nil {
http.Error(w, "Unable to parse given IPv4: " + spl[0], http.StatusInternalServerError)
http.Error(w, "Unable to parse given IPv4: "+spl[0], http.StatusInternalServerError)
return
}
var mac *ARPEntry
@ -120,9 +119,9 @@ func (l loginChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
type myIP struct {
Id int64 `json:"id"`
Login string `json:"login"`
IP string `json:"ip"`
Id int64 `json:"id"`
Login string `json:"login"`
IP string `json:"ip"`
}
func (l loginChecker) registerUser(username, remoteAddr string, ent ARPEntry) (net.IP, error) {

View file

@ -51,10 +51,10 @@ func main() {
if auth != nil && *auth == "ldap" {
log.Printf("Auth method: LDAP(%s@%s:%d?%s)", *ldapbindusername, *ldapAddr, *ldapPort, *ldapbase)
lc.authMethod = LDAPAuth{
Addr: *ldapAddr,
Port: *ldapPort,
IsTLS: *ldaptls,
Base: *ldapbase,
Addr: *ldapAddr,
Port: *ldapPort,
IsTLS: *ldaptls,
Base: *ldapbase,
BindUsername: *ldapbindusername,
BindPassword: *ldapbindpassword,
}
@ -105,7 +105,8 @@ func main() {
log.Println(fmt.Sprintf("Ready, listening on %s", *bind))
// Wait shutdown signal
mloop: for {
mloop:
for {
switch <-interrupt {
case syscall.SIGHUP:
log.Println("Reloading students files...")
@ -113,7 +114,7 @@ func main() {
log.Println("Error during students.csv reload:", err)
}
case syscall.SIGTERM, syscall.SIGINT:
break mloop;
break mloop
}
}

View file

@ -41,8 +41,8 @@ func registerUser(tplPath string, filename string, username string, ip net.IP) e
return err
} else if err := pxeTmpl.Execute(userfd, map[string]string{
"username": username,
"pkey": fmt.Sprintf("%x", pkey.Sum([]byte(username))),
"ip": fmt.Sprintf("%d.%d.%d.%d", ip.To4()[0], ip.To4()[1], ip.To4()[2], ip.To4()[3]),
"pkey": fmt.Sprintf("%x", pkey.Sum([]byte(username))),
"ip": fmt.Sprintf("%d.%d.%d.%d", ip.To4()[0], ip.To4()[1], ip.To4()[2], ip.To4()[3]),
}); err != nil {
return err
}