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) }(username, password, validator, validator_err)
if connection(stdscr, in, validator, validator_err) { if connection(stdscr, in, validator, validator_err) {
e := <- validator_err e := <-validator_err
return username, e.Error(), true return username, e.Error(), true
} else { } else {
return goLogin(stdscr, in) return goLogin(stdscr, in)

View File

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

View File

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

View File

@ -27,7 +27,6 @@ type loginUpload struct {
Password string Password string
} }
func (l loginChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (l loginChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if addr := r.Header.Get("X-Forwarded-For"); addr != "" { if addr := r.Header.Get("X-Forwarded-For"); addr != "" {
r.RemoteAddr = addr r.RemoteAddr = addr
@ -86,7 +85,7 @@ func (l loginChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var ip net.IP var ip net.IP
spl := strings.SplitN(r.RemoteAddr, ":", 2) spl := strings.SplitN(r.RemoteAddr, ":", 2)
if ip = net.ParseIP(spl[0]); ip == nil { 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 return
} }
var mac *ARPEntry var mac *ARPEntry

View File

@ -105,7 +105,8 @@ func main() {
log.Println(fmt.Sprintf("Ready, listening on %s", *bind)) log.Println(fmt.Sprintf("Ready, listening on %s", *bind))
// Wait shutdown signal // Wait shutdown signal
mloop: for { mloop:
for {
switch <-interrupt { switch <-interrupt {
case syscall.SIGHUP: case syscall.SIGHUP:
log.Println("Reloading students files...") log.Println("Reloading students files...")
@ -113,7 +114,7 @@ func main() {
log.Println("Error during students.csv reload:", err) log.Println("Error during students.csv reload:", err)
} }
case syscall.SIGTERM, syscall.SIGINT: case syscall.SIGTERM, syscall.SIGINT:
break mloop; break mloop
} }
} }

View File

@ -5,7 +5,7 @@ import (
"fmt" "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 := sha512.New()
h.Write([]byte(fmt.Sprintf("%x", pkey))) h.Write([]byte(fmt.Sprintf("%x", pkey)))