feat: add xterm frontend ui
This commit is contained in:
parent
55eacb59e9
commit
cb32637938
9 changed files with 325 additions and 16 deletions
|
|
@ -37,7 +37,6 @@ func FollowMaster(agent *tsnet.TSAgent) {
|
|||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Bytes()
|
||||
log.Info("Got bytes delimited by newline")
|
||||
|
||||
var msg CborMessage
|
||||
decoder := cbor.NewDecoder(bytes.NewReader(line))
|
||||
|
|
@ -49,14 +48,29 @@ func FollowMaster(agent *tsnet.TSAgent) {
|
|||
}
|
||||
|
||||
log.Debug("Received message from master: %s", msg)
|
||||
var sshPayload sshutil.SSHConnectPayload
|
||||
err = cbor.Unmarshal(msg.Payload, &sshPayload)
|
||||
if err != nil {
|
||||
log.Error("Unable to unmarshal SSH connect payload: %s", err)
|
||||
continue
|
||||
}
|
||||
switch msg.Op {
|
||||
case "ssh_conn":
|
||||
var sshPayload sshutil.SSHConnectPayload
|
||||
err = cbor.Unmarshal(msg.Payload, &sshPayload)
|
||||
if err != nil {
|
||||
log.Error("Unable to unmarshal SSH connect payload: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
sshutil.StartWebSSH(agent, sshPayload)
|
||||
sshutil.StartWebSSH(agent, sshPayload)
|
||||
continue
|
||||
|
||||
case "ssh_term":
|
||||
var sshPayload sshutil.SSHClosePayload
|
||||
err = cbor.Unmarshal(msg.Payload, &sshPayload)
|
||||
if err != nil {
|
||||
log.Error("Unable to unmarshal SSH close payload: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
sshutil.CloseWebSSH(agent, sshPayload)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// var msg RecvMessage
|
||||
|
|
|
|||
|
|
@ -18,6 +18,10 @@ type SSHConnectPayload struct {
|
|||
Port int `cbor:"port"`
|
||||
}
|
||||
|
||||
type SSHClosePayload struct {
|
||||
SessionId string `cbor:"sessionId"`
|
||||
}
|
||||
|
||||
func connectToTailscaleSSH(agent *tsnet.TSAgent, params SSHConnectPayload) (*ssh.Client, error) {
|
||||
log := util.GetLogger()
|
||||
addr := strings.Join([]string{params.Hostname, ":", strconv.Itoa(params.Port)}, "")
|
||||
|
|
@ -136,3 +140,27 @@ func StartWebSSH(agent *tsnet.TSAgent, params SSHConnectPayload) {
|
|||
RemoveSession(params.SessionId)
|
||||
}()
|
||||
}
|
||||
|
||||
func CloseWebSSH(agent *tsnet.TSAgent, params SSHClosePayload) {
|
||||
log := util.GetLogger()
|
||||
|
||||
if agent == nil {
|
||||
log.Error("tsnet.TSAgent is not initialized correctly")
|
||||
return
|
||||
}
|
||||
|
||||
if params.SessionId == "" {
|
||||
log.Error("Invalid SSH close parameters: %v", params)
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug("Closing SSH session for session ID: %s", params.SessionId)
|
||||
ctx, ok := lookupSession(params.SessionId)
|
||||
if !ok {
|
||||
log.Info("No active SSH session found for session ID: %s", params.SessionId)
|
||||
return
|
||||
}
|
||||
|
||||
RemoveSession(ctx.ID)
|
||||
log.Info("SSH session for %s closed", params.SessionId)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue