mirror of
https://github.com/syssecfsu/witty.git
synced 2024-11-01 09:39:26 +01:00
add an option for command line
This commit is contained in:
parent
906991c297
commit
97791896e1
15
main.go
15
main.go
@ -155,6 +155,8 @@ func fromPtyStdout(ws *websocket.Conn, ptmx *os.File, done chan struct{}) {
|
|||||||
time.Sleep(closeGracePeriod)
|
time.Sleep(closeGracePeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cmdToExec string = "bash"
|
||||||
|
|
||||||
// handle websockets
|
// handle websockets
|
||||||
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
func wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ws, err := upgrader.Upgrade(w, r, nil)
|
ws, err := upgrader.Upgrade(w, r, nil)
|
||||||
@ -168,7 +170,7 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
log.Println("\n\nCreated the websocket")
|
log.Println("\n\nCreated the websocket")
|
||||||
|
|
||||||
ptmx, cmd, err := createPty("bash")
|
ptmx, cmd, err := createPty(cmdToExec)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Failed to create PTY: ", err)
|
log.Println("Failed to create PTY: ", err)
|
||||||
@ -235,6 +237,17 @@ func main() {
|
|||||||
gin.DefaultWriter = fp
|
gin.DefaultWriter = fp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse the arguments. User can pass the command to execute
|
||||||
|
// by default, we use bash, but macos users might want to use zsh
|
||||||
|
// you can also run single program, such as pstree, htop...
|
||||||
|
// but program might misbehave (htop seems to be fine)
|
||||||
|
args := os.Args
|
||||||
|
|
||||||
|
if len(args) > 1 {
|
||||||
|
cmdToExec = strings.Join(args[1:], " ")
|
||||||
|
log.Println(cmdToExec)
|
||||||
|
}
|
||||||
|
|
||||||
rt := gin.Default()
|
rt := gin.Default()
|
||||||
|
|
||||||
rt.SetTrustedProxies(nil)
|
rt.SetTrustedProxies(nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user