mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: put terminal service into container refactor: separate main into terminal and websocket feat: create zsh using commander in home feat: pass backendUrl to container feat: pass token to ws server to cmd-hook feat: gen terminal access token for frontend feat: success to connect through traefik fix: handle invalid jwt feat: connect to session container via traefik
41 lines
624 B
Go
41 lines
624 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
|
|
"github.com/creack/pty"
|
|
)
|
|
|
|
type terminal struct {
|
|
cmd *exec.Cmd
|
|
pty *os.File
|
|
}
|
|
|
|
func newTerminal(token string) (*terminal, error) {
|
|
// Start a new shell in the home directory
|
|
cmd := exec.Command("/usr/bin/zsh")
|
|
cmd.Dir = os.Getenv("HOME")
|
|
cmd.Env = append(os.Environ(), "ZDOTDIR=/etc/zsh", "TOKEN="+token)
|
|
ptmx, err := pty.Start(cmd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &terminal{
|
|
cmd: cmd,
|
|
pty: ptmx,
|
|
}, nil
|
|
}
|
|
|
|
func (t *terminal) Close() error {
|
|
if t.pty != nil {
|
|
t.pty.Close()
|
|
}
|
|
if t.cmd != nil {
|
|
t.cmd.Process.Kill()
|
|
t.cmd.Wait()
|
|
}
|
|
return nil
|
|
}
|