mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: connect terminal service to backend
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
This commit is contained in:
1 parent
0b08a9a5d9
commit
5e81db2759
20 files changed
+281
-209
No files matched your search
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user