add gitignore, add first pass at info screen handler
This commit is contained in:
parent
fb4aa62f16
commit
5342c7933c
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
go-bbs
|
||||
getTubesPeers.bash
|
||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
||||
module versestudios.com/go-telnet-asyncio-test
|
||||
module versestudios.com/go-bbs
|
||||
|
||||
go 1.16
|
||||
|
||||
|
51
main.go
51
main.go
@ -19,7 +19,7 @@ import (
|
||||
"github.com/creack/pty"
|
||||
"github.com/xtaci/gaio"
|
||||
"golang.org/x/term"
|
||||
"versestudios.com/go-telnet-asyncio-test/openconn"
|
||||
"versestudios.com/go-bbs/openconn"
|
||||
)
|
||||
|
||||
type InChanKey string
|
||||
@ -104,7 +104,7 @@ func main() {
|
||||
log.Printf("new context for client %v: %v\n", conn.RemoteAddr(), ctx)
|
||||
|
||||
// submit the first async write IO request
|
||||
welcomeScreen, err := screenHandler("welcome")
|
||||
welcomeScreen, err := screenHandler("welcome", nil)
|
||||
if err != nil {
|
||||
log.Printf("err loading initial welcome screen: %v\n", err)
|
||||
}
|
||||
@ -185,7 +185,7 @@ func menuHandler(ctx context.Context, conn net.Conn, w *gaio.Watcher) {
|
||||
switch string(strings.TrimSpace(string(res.Buffer[:res.Size-2]))) {
|
||||
|
||||
case "welcome":
|
||||
welcomeStr, err := screenHandler("welcome")
|
||||
welcomeStr, err := screenHandler("welcome", nil)
|
||||
if err != nil {
|
||||
log.Printf("err loading welcome screen: %v\n", err)
|
||||
}
|
||||
@ -194,7 +194,7 @@ func menuHandler(ctx context.Context, conn net.Conn, w *gaio.Watcher) {
|
||||
}
|
||||
|
||||
case "help":
|
||||
helpStr, err := screenHandler("help")
|
||||
helpStr, err := screenHandler("help", nil)
|
||||
if err != nil {
|
||||
log.Printf("err loading help screen: %v\n", err)
|
||||
}
|
||||
@ -203,7 +203,7 @@ func menuHandler(ctx context.Context, conn net.Conn, w *gaio.Watcher) {
|
||||
}
|
||||
|
||||
case "operator":
|
||||
opStr, err := screenHandler("operator")
|
||||
opStr, err := screenHandler("operator", nil)
|
||||
if err != nil {
|
||||
log.Printf("err loading operator screen: %v\n", err)
|
||||
}
|
||||
@ -253,8 +253,23 @@ func menuHandler(ctx context.Context, conn net.Conn, w *gaio.Watcher) {
|
||||
log.Printf("error writing to connection: %v", err)
|
||||
}
|
||||
|
||||
case "info":
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(2)
|
||||
uptime := getUptime(wg)
|
||||
tubes := getTubePeers(wg)
|
||||
wg.Wait()
|
||||
data := struct{ Uptime, TubesInfo string }{uptime, tubes}
|
||||
infoStr, err := screenHandler("info", data)
|
||||
if err != nil {
|
||||
log.Printf("err loading info screen: %v\n", err)
|
||||
}
|
||||
if err := w.Write(ctx, conn, infoStr); err != nil {
|
||||
log.Printf("error sending screenHandler from cmd `info`: %v", err)
|
||||
}
|
||||
|
||||
case "exit":
|
||||
exitStr, err := screenHandler("exit")
|
||||
exitStr, err := screenHandler("exit", nil)
|
||||
if err != nil {
|
||||
log.Printf("err loading exit screen: %v\n", err)
|
||||
}
|
||||
@ -295,13 +310,13 @@ func menuHandler(ctx context.Context, conn net.Conn, w *gaio.Watcher) {
|
||||
log.Println("terminating menucontrol for client")
|
||||
}
|
||||
|
||||
func screenHandler(screenName string) (screen []byte, err error) {
|
||||
func screenHandler(screenName string, tplData interface{}) (screen []byte, err error) {
|
||||
var screenBuf *bytes.Buffer
|
||||
if tmpl, err := template.ParseFiles("screens/" + screenName + ".ans"); err != nil {
|
||||
log.Printf("err loading welcome template: %v\n", err)
|
||||
} else {
|
||||
screenBuf = new(bytes.Buffer)
|
||||
tmpl.Execute(screenBuf, nil)
|
||||
tmpl.Execute(screenBuf, tplData)
|
||||
}
|
||||
|
||||
return screenBuf.Bytes(), err
|
||||
@ -416,3 +431,23 @@ func doorHandler(ctx context.Context, c net.Conn, w *gaio.Watcher, menuwg *sync.
|
||||
log.Println("leaving door handler")
|
||||
return nil
|
||||
}
|
||||
|
||||
// returns output of `uptime` as a string
|
||||
func getUptime(wg *sync.WaitGroup) string {
|
||||
defer wg.Done()
|
||||
out, err := exec.Command("uptime").Output()
|
||||
if err != nil {
|
||||
return string(err.Error()) // might as well pass on the love to my future co-workers for debugging assistance
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func getTubePeers(wg *sync.WaitGroup) string {
|
||||
defer wg.Done()
|
||||
out, err := exec.Command("/usr/local/bin/getTubesPeers.bash").Output()
|
||||
if err != nil {
|
||||
log.Printf("err loading getTubePeers: %v\n", err)
|
||||
return string(err.Error()) // again, might as well pass on the love to my future co-workers for debugging assistance
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
[2J[H
|
||||
[38;2;0;0;255m
|
||||
_____ __ ____ ____ [38;2;0;0;224m
|
||||
/ ___/__ _______/ /____ ____ ___ / _/___ / __/___ [38;2;0;0;196m
|
||||
\__ \/ / / / ___/ __/ _ \/ __ '__ \ / // __ \/ /_/ __ \ [38;2;0;0;160m
|
||||
___/ / /_/ (__ ) /_/ __/ / / / / / _/ // / / / __/ /_/ / [38;2;0;0;128m
|
||||
/____/\__, /____/\__/\___/_/ /_/ /_/ /___/_/ /_/_/ \____/ [38;2;0;0;96m
|
||||
/____/ `[38;2;0;0;72m
|
||||
|
||||
`
|
||||
[32m
|
||||
Version: Saturday morning
|
||||
|
||||
This bulletin board system is written in [38;2;90;255;0mGo[32m leveraging the [38;2;90;255;0mgaio[32m async i/o library.
|
||||
It is hosted on a [38;2;90;255;0m Raspberry Pi 4[32m running [38;2;90;255;0mUbuntu 20.04[32m
|
||||
The web-based ANSI terminal is provided by [38;2;90;255;0m rtty[32m and [38;2;90;255;0m rttys[32m
|
||||
ASCII art banners generated at [38;2;90;255;0m https://www.ascii-art-generator.org/[32m
|
||||
ANSI escape codes from [38;2;90;255;0m https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797[32m
|
||||
|
||||
Current system uptime is [38;2;90;255;0m {{ .Uptime }}[32m
|
||||
|
||||
This system is also hosting multiple Wireguard peer connections with other operators in
|
||||
an experimental distributed mesh overlay network we call [38;2;90;255;0m the Tubes[32m
|
||||
|
||||
Current peer tunnels
|
||||
|
||||
iface peer public key bytes sent bytes rec'd
|
||||
[38;2;90;255;0m
|
||||
{{ .TubesInfo }}
|
||||
[32m
|
||||
|
||||
>
|
Loading…
Reference in New Issue
Block a user