1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package main
- import (
- "io/ioutil"
- "log"
- "os"
- "os/exec"
- "os/signal"
- "path/filepath"
- "runtime"
- "strings"
- "syscall"
- "imuslab.com/WsTTY/mod/aroz"
- )
- var (
- handler *aroz.ArozHandler
- )
- func SetupCloseHandler() {
- c := make(chan os.Signal, 2)
- signal.Notify(c, os.Interrupt, syscall.SIGTERM)
- go func() {
- <-c
- log.Println("\r- Shutting down WsTTY Service.")
- os.Exit(0)
- }()
- }
- func main() {
- //Start the aoModule pipeline (which will parse the flags as well). Pass in the module launch information
- handler = aroz.HandleFlagParse(aroz.ServiceInfo{
- Name: "WsTTY",
- Desc: "arozos Websocket Terminal",
- Group: "System Tools",
- IconPath: "SystemAO/wstty/img/small_icon.png",
- Version: "1.0",
- StartDir: "wstty/",
- SupportFW: true,
- LaunchFWDir: "wstty/",
- InitFWSize: []int{740, 500},
- })
- SetupCloseHandler()
- //Start the gotty and rproxy it to the main system
- if runtime.GOOS == "windows" {
- //Not supported, and this should not be compiled to windows binary
- panic("Not supported platform")
- }
- absolutePath := ""
- if runtime.GOARCH == "amd64" {
- abs, _ := filepath.Abs("./gotty/gotty_linux_amd64")
- absolutePath = abs
- } else if runtime.GOARCH == "arm" {
- abs, _ := filepath.Abs("./gotty/gotty_linux_arm")
- absolutePath = abs
- } else if runtime.GOARCH == "arm64" {
- abs, _ := filepath.Abs("./gotty/ggotty_linux_arm64")
- absolutePath = abs
- } else {
- //Unsupported platform. Default use amd64
- abs, _ := filepath.Abs("./gotty/gotty_linux_amd64")
- absolutePath = abs
- }
- //Extract port number from listening addr
- tmp := strings.Split(handler.Port, ":")
- tmp = tmp[len(tmp)-1:]
- portOnly := strings.Join(tmp, "")
- log.Println("Starting WsTTY Adapter on: ", portOnly)
- //Start the gotty. This shoud be blocking by itself
- cmd := exec.Command(absolutePath, "-w", "-p", portOnly, "-a", "localhost", "--ws-origin", `\w*`, "bash", "--init-file", "bashstart")
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- if err := cmd.Start(); err != nil {
- //Fail to start gotty. Disable this module
- ioutil.WriteFile(".disabled", []byte(""), 0755)
- return
- }
- }
|