witty/main.go

84 lines
1.6 KiB
Go
Raw Normal View History

2022-01-04 21:41:41 +01:00
package main
import (
2022-01-22 03:42:22 +01:00
"flag"
"fmt"
"log"
2022-01-05 18:38:52 +01:00
"os"
2022-01-22 15:29:01 +01:00
"github.com/syssecfsu/witty/term_conn"
2022-01-21 15:36:31 +01:00
"github.com/syssecfsu/witty/web"
2022-01-04 21:41:41 +01:00
)
2022-01-05 03:21:21 +01:00
func main() {
2022-01-22 03:42:22 +01:00
if len(os.Args) < 2 {
2022-01-22 15:29:01 +01:00
fmt.Println("witty (adduser|deluser|replay|run)")
2022-01-22 03:42:22 +01:00
return
}
var naked bool
runCmd := flag.NewFlagSet("run", flag.ExitOnError)
runCmd.BoolVar(&naked, "n", false, "Run WiTTY without user authentication")
runCmd.BoolVar(&naked, "naked", false, "Run WiTTY without user authentication")
2022-01-22 15:29:01 +01:00
var wait uint
replayCmd := flag.NewFlagSet("replay", flag.ExitOnError)
replayCmd.UintVar(&wait, "w", 2000, "Max wait time between outputs")
replayCmd.UintVar(&wait, "wait", 2000, "Max wait time between outputs")
2022-01-22 03:42:22 +01:00
switch os.Args[1] {
case "adduser":
if len(os.Args) != 3 {
fmt.Println("witty adduser <username>")
return
}
web.AddUser(os.Args[2])
case "deluser":
if len(os.Args) != 3 {
fmt.Println("witty deluser <username>")
return
}
web.DelUser(os.Args[2])
2022-01-22 15:29:01 +01:00
case "listusers":
web.ListUsers()
case "replay":
replayCmd.Parse(os.Args[2:])
if len(replayCmd.Args()) != 1 {
fmt.Println("witty replay <recorded>")
return
}
term_conn.Replay(replayCmd.Arg(0), wait)
2022-01-22 03:42:22 +01:00
case "run":
2022-01-22 15:29:01 +01:00
fp, err := os.OpenFile("witty.log", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err == nil {
defer fp.Close()
log.SetOutput(fp)
}
2022-01-22 03:42:22 +01:00
runCmd.Parse(os.Args[2:])
var cmdToExec []string
args := runCmd.Args()
if len(args) > 0 {
cmdToExec = args
} else {
cmdToExec = []string{"bash"}
}
web.StartWeb(fp, cmdToExec, naked)
2022-01-07 02:21:11 +01:00
2022-01-22 03:42:22 +01:00
default:
2022-01-22 15:29:01 +01:00
fmt.Println("witty (adduser|deluser|replay|run)")
2022-01-22 03:42:22 +01:00
return
2022-01-07 02:21:11 +01:00
}
2022-01-05 03:21:21 +01:00
}