2018-02-10 12:54:18 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
gc "github.com/rthornton128/goncurses"
|
|
|
|
)
|
|
|
|
|
2018-02-21 21:59:12 +00:00
|
|
|
const URLLogin = "https://auth.adlin.nemunai.re/login"
|
2018-02-10 12:54:18 +00:00
|
|
|
|
2019-02-26 22:48:01 +00:00
|
|
|
func goLogin(stdscr *gc.Window, in chan gc.Key) (string, string, bool) {
|
2018-02-10 12:54:18 +00:00
|
|
|
username, password := login(stdscr, in)
|
|
|
|
|
2019-02-26 22:48:01 +00:00
|
|
|
validator := make(chan bool)
|
|
|
|
validator_err := make(chan error)
|
|
|
|
go func(username, password string, progress chan bool, err chan error) {
|
|
|
|
st, errm := checkLogin(username, password)
|
|
|
|
progress <- st
|
|
|
|
err <- errm
|
|
|
|
}(username, password, validator, validator_err)
|
|
|
|
|
|
|
|
if connection(stdscr, in, validator, validator_err) {
|
|
|
|
e := <- validator_err
|
|
|
|
return username, e.Error(), true
|
2018-02-10 12:54:18 +00:00
|
|
|
} else {
|
|
|
|
return goLogin(stdscr, in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
stdscr, _ := gc.Init()
|
|
|
|
defer gc.End()
|
|
|
|
|
|
|
|
// Set main properties
|
|
|
|
gc.Cursor(0)
|
|
|
|
gc.StartColor()
|
|
|
|
gc.Raw(true)
|
|
|
|
gc.Echo(false)
|
|
|
|
stdscr.Keypad(true)
|
|
|
|
|
|
|
|
// Define colors
|
|
|
|
gc.InitPair(1, gc.C_WHITE, gc.C_BLUE)
|
|
|
|
gc.InitPair(2, gc.C_GREEN, gc.C_BLACK)
|
|
|
|
gc.InitPair(3, gc.C_CYAN, gc.C_BLACK)
|
|
|
|
gc.InitPair(4, gc.C_RED, gc.C_BLACK)
|
2018-02-10 13:37:23 +00:00
|
|
|
gc.InitPair(5, gc.C_BLACK, gc.C_WHITE)
|
2018-02-10 12:54:18 +00:00
|
|
|
|
|
|
|
// Register pressed key through channel
|
|
|
|
in := make(chan gc.Key)
|
|
|
|
go func(w *gc.Window, ch chan<- gc.Key) {
|
|
|
|
for {
|
|
|
|
ch <- w.GetChar()
|
|
|
|
}
|
|
|
|
}(stdscr, in)
|
|
|
|
|
|
|
|
// Run!
|
2019-02-26 22:48:01 +00:00
|
|
|
if username, ip, ok := goLogin(stdscr, in); ok {
|
|
|
|
okreboot(stdscr, username, ip)
|
2018-02-10 12:54:18 +00:00
|
|
|
}
|
|
|
|
}
|