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

View File

@ -18,7 +18,7 @@ func goLogin(stdscr *gc.Window, in chan gc.Key) (string, string, bool) {
}(username, password, validator, validator_err)
if connection(stdscr, in, validator, validator_err) {
e := <- validator_err
e := <-validator_err
return username, e.Error(), true
} else {
return goLogin(stdscr, in)

View File

@ -3,10 +3,11 @@ package main
import (
"strings"
"time"
gc "github.com/rthornton128/goncurses"
)
func login(stdscr *gc.Window, in chan gc.Key) (username , password string) {
func login(stdscr *gc.Window, in chan gc.Key) (username, password string) {
gc.Cursor(1)
stdscr.Clear()
@ -75,7 +76,7 @@ func login(stdscr *gc.Window, in chan gc.Key) (username , password string) {
login:
for {
select {
case ch := <- in:
case ch := <-in:
switch ch {
case gc.KEY_DOWN, gc.KEY_TAB:
form.Driver(gc.REQ_NEXT_FIELD)
@ -144,16 +145,16 @@ func connection(stdscr *gc.Window, in chan gc.Key, validator chan bool, validato
loginloop:
for {
select {
case ch := <- in:
case ch := <-in:
if gc.Char(ch) == gc.Char('r') {
break loginloop
}
case st := <- validator:
case st := <-validator:
if st {
canContinue = true
break loginloop
} else {
e := <- validator_err
e := <-validator_err
mainwin.ColorOn(4)
mainwin.MovePrint(4, 2, e.Error())
@ -162,19 +163,19 @@ loginloop:
mainwin.MovePrint(6, 2, " Press any key to retry ")
mainwin.Refresh()
<- in
<-in
break loginloop
}
case <- ticker.C:
case <-ticker.C:
switch rotPos += 1; rotPos {
case 0,4:
case 0, 4:
mainwin.MovePrint(4, 4, "|")
case 1,5:
case 1, 5:
mainwin.MovePrint(4, 4, "/")
case 2,6:
case 2, 6:
mainwin.MovePrint(4, 4, "-")
case 3,7:
case 3, 7:
mainwin.MovePrint(4, 4, "\\")
default:
mainwin.MovePrint(4, 4, "|")
@ -235,8 +236,8 @@ func okreboot(stdscr *gc.Window, login string, ip string) {
rebootloop:
for {
select {
case <- ticker.C:
mainwin.MovePrint(11, 3 + pos, "*")
case <-ticker.C:
mainwin.MovePrint(11, 3+pos, "*")
pos += 1
if pos > 36 {
break rebootloop

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
}

View File

@ -5,7 +5,7 @@ import (
"fmt"
)
func GenerateToken(pkey []byte, id int, a... []byte) ([]byte, error) {
func GenerateToken(pkey []byte, id int, a ...[]byte) ([]byte, error) {
h := sha512.New()
h.Write([]byte(fmt.Sprintf("%x", pkey)))