2018-02-10 12:54:18 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-02-17 14:03:06 +00:00
|
|
|
"math/rand"
|
2021-02-16 20:18:56 +00:00
|
|
|
"os"
|
2021-02-17 14:03:06 +00:00
|
|
|
"time"
|
2021-02-16 20:18:56 +00:00
|
|
|
|
2021-10-31 15:43:43 +00:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2021-02-17 14:03:06 +00:00
|
|
|
"github.com/rivo/tview"
|
2018-02-10 12:54:18 +00:00
|
|
|
)
|
|
|
|
|
2018-02-21 21:59:12 +00:00
|
|
|
const URLLogin = "https://auth.adlin.nemunai.re/login"
|
2018-02-10 12:54:18 +00:00
|
|
|
|
2021-02-17 14:03:06 +00:00
|
|
|
var (
|
|
|
|
loggedAs = ""
|
|
|
|
)
|
|
|
|
|
|
|
|
func modal(p tview.Primitive, width, height int) tview.Primitive {
|
|
|
|
return tview.NewFlex().
|
|
|
|
AddItem(nil, 0, 1, false).
|
|
|
|
AddItem(tview.NewFlex().SetDirection(tview.FlexRow).
|
|
|
|
AddItem(nil, 0, 1, false).
|
|
|
|
AddItem(p, height, 1, false).
|
|
|
|
AddItem(nil, 0, 1, false), width, 1, false).
|
|
|
|
AddItem(nil, 0, 1, false)
|
|
|
|
}
|
2021-02-16 20:18:56 +00:00
|
|
|
|
2021-02-17 14:03:06 +00:00
|
|
|
func askLogin(app *tview.Application) {
|
|
|
|
CreateLoginDialog(app, func(username, password string) {
|
|
|
|
// Display check dialog
|
|
|
|
CreateCheckDialog(app)
|
2021-02-16 20:18:56 +00:00
|
|
|
|
2021-02-17 14:03:06 +00:00
|
|
|
go func() {
|
|
|
|
if ok, err := checkLogin(username, password); ok {
|
|
|
|
loggedAs = username
|
|
|
|
app.Stop()
|
|
|
|
} else {
|
|
|
|
CreateErrMsgDialog(app, err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
})
|
2018-02-10 12:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2021-02-17 14:03:06 +00:00
|
|
|
// seed the rand package with time
|
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
|
|
|
|
app := tview.NewApplication()
|
|
|
|
|
|
|
|
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
|
|
|
if event.Key() == tcell.KeyCtrlQ {
|
|
|
|
app.Stop()
|
|
|
|
}
|
|
|
|
return event
|
|
|
|
})
|
2021-02-16 20:18:56 +00:00
|
|
|
|
2021-02-17 19:25:36 +00:00
|
|
|
if _, err := os.Stat("/sys/firmware/efi"); err != nil {
|
|
|
|
CreateUEFIDialog(app, func() {
|
|
|
|
askLogin(app)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
askLogin(app)
|
|
|
|
}
|
2021-02-16 20:18:56 +00:00
|
|
|
|
2021-02-17 14:03:06 +00:00
|
|
|
if err := app.Run(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-02-10 12:54:18 +00:00
|
|
|
|
2021-02-17 14:03:06 +00:00
|
|
|
if loggedAs == "" {
|
2021-02-16 20:18:56 +00:00
|
|
|
os.Exit(1)
|
2018-02-10 12:54:18 +00:00
|
|
|
}
|
2021-02-17 14:03:06 +00:00
|
|
|
|
|
|
|
runCinematic(loggedAs)
|
2018-02-10 12:54:18 +00:00
|
|
|
}
|