chore: update code
This commit is contained in:
5
go.mod
5
go.mod
@@ -2,7 +2,10 @@ module rpi-charon
|
||||
|
||||
go 1.25.5
|
||||
|
||||
require fyne.io/fyne/v2 v2.7.2
|
||||
require (
|
||||
fyne.io/fyne/v2 v2.7.2
|
||||
golang.org/x/crypto v0.46.0
|
||||
)
|
||||
|
||||
require (
|
||||
fyne.io/systray v1.12.0 // indirect
|
||||
|
||||
4
go.sum
4
go.sum
@@ -67,12 +67,16 @@ github.com/yuin/goldmark v1.7.16 h1:n+CJdUxaFMiDUNnWC3dMWCIQJSkxH4uz3ZwQBkAlVNE=
|
||||
github.com/yuin/goldmark v1.7.16/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
|
||||
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
|
||||
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
||||
golang.org/x/image v0.34.0 h1:33gCkyw9hmwbZJeZkct8XyR11yH889EQt/QH4VmXMn8=
|
||||
golang.org/x/image v0.34.0/go.mod h1:2RNFBZRB+vnwwFil8GkMdRvrJOFd1AzdZI6vOY+eJVU=
|
||||
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/term v0.38.0 h1:PQ5pkm/rLO6HnxFR7N2lJHOZX6Kez5Y1gDSJla6jo7Q=
|
||||
golang.org/x/term v0.38.0/go.mod h1:bSEAKrOT1W+VSu9TSCMtoGEOUcKxOKgl3LE5QEF/xVg=
|
||||
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -1,5 +1,45 @@
|
||||
package main
|
||||
|
||||
func connect() {
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
func translateRaspiName(targetName string) (string, string) {
|
||||
for _, raspiObj := range raspiList {
|
||||
if raspiObj[0] == targetName {
|
||||
// Found!
|
||||
return raspiObj[1], raspiObj[2]
|
||||
}
|
||||
}
|
||||
|
||||
return "", ""
|
||||
}
|
||||
|
||||
func verifyCred(username, password, targetName string) bool {
|
||||
hostname, port := translateRaspiName(targetName)
|
||||
log.Println("Connecting to:", hostname, port)
|
||||
|
||||
config := &ssh.ClientConfig{
|
||||
User: username,
|
||||
Auth: []ssh.AuthMethod{
|
||||
ssh.Password(password),
|
||||
},
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), // OK for internal tools (and me in production)
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
connAddr := net.JoinHostPort(hostname, port)
|
||||
client, err := ssh.Dial("tcp", connAddr, config)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Err occurred %v", err)
|
||||
return false
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
34
src/draw.go
34
src/draw.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"image/color"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
@@ -12,6 +13,23 @@ import (
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
func flashRed(btnPtr *widget.Button) {
|
||||
// Set red on UI thread
|
||||
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
||||
btnPtr.Importance = widget.DangerImportance
|
||||
refreshButtons(btnPtr)
|
||||
}, false)
|
||||
|
||||
log.Println("Waiting")
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Reset on UI thread
|
||||
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
||||
btnPtr.Importance = widget.LowImportance
|
||||
refreshButtons(btnPtr)
|
||||
}, false)
|
||||
}
|
||||
|
||||
func drawSeparator(trailNewLine bool) *fyne.Container {
|
||||
emptyLabel := widget.NewLabel("") // Give it some space at the bottom with an empty line
|
||||
separatorLine := canvas.NewLine(color.Gray{Y: 128})
|
||||
@@ -126,10 +144,24 @@ func drawTargetSection(raspiNames []string, raspiTarget *string) *fyne.Container
|
||||
)
|
||||
|
||||
var verifyBtn *widget.Button
|
||||
var credOK bool
|
||||
verifyBtn = widget.NewButton("Verify Credentials", func() {
|
||||
verifyBtn.Importance = widget.HighImportance
|
||||
|
||||
log.Println("Verifying credentials...")
|
||||
refreshButtons(verifyBtn)
|
||||
go func() {
|
||||
credOK = verifyCred(userEntry.Text, passEntry.Text, *raspiTarget)
|
||||
|
||||
if credOK {
|
||||
// Must update UI on main thread
|
||||
fyne.CurrentApp().Driver().DoFromGoroutine(func() {
|
||||
verifyBtn.Importance = widget.SuccessImportance
|
||||
refreshButtons(verifyBtn)
|
||||
}, true)
|
||||
} else {
|
||||
flashRed(verifyBtn) // flashRed should handle RunOnMain internally
|
||||
}
|
||||
}()
|
||||
})
|
||||
verifyWide := container.NewGridWrap(
|
||||
buttonSize,
|
||||
|
||||
@@ -10,6 +10,13 @@ import (
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type ActionConfig struct {
|
||||
username string
|
||||
password string
|
||||
hostname string
|
||||
port int
|
||||
}
|
||||
|
||||
const (
|
||||
appName string = "RPi Charon Configuration Tool"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user