MCPcopy
hub / github.com/netbirdio/netbird / StartSession

Method StartSession

client/wasm/internal/ssh/client.go:123–176  ·  view source on GitHub ↗

StartSession starts an SSH session with PTY

(cols, rows int)

Source from the content-addressed store, hash-verified

121
122// StartSession starts an SSH session with PTY
123func (c *Client) StartSession(cols, rows int) error {
124 if c.sshClient == nil {
125 return fmt.Errorf("SSH client not connected")
126 }
127
128 session, err := c.sshClient.NewSession()
129 if err != nil {
130 return fmt.Errorf("create session: %w", err)
131 }
132
133 c.mu.Lock()
134 defer c.mu.Unlock()
135 c.session = session
136
137 modes := ssh.TerminalModes{
138 ssh.ECHO: 1,
139 ssh.TTY_OP_ISPEED: 14400,
140 ssh.TTY_OP_OSPEED: 14400,
141 ssh.VINTR: 3,
142 ssh.VQUIT: 28,
143 ssh.VERASE: 127,
144 }
145
146 if err := session.RequestPty("xterm-256color", rows, cols, modes); err != nil {
147 closeWithLog(session, "session after PTY error")
148 return fmt.Errorf("PTY request: %w", err)
149 }
150
151 c.stdin, err = session.StdinPipe()
152 if err != nil {
153 closeWithLog(session, "session after stdin error")
154 return fmt.Errorf("get stdin: %w", err)
155 }
156
157 c.stdout, err = session.StdoutPipe()
158 if err != nil {
159 closeWithLog(session, "session after stdout error")
160 return fmt.Errorf("get stdout: %w", err)
161 }
162
163 c.stderr, err = session.StderrPipe()
164 if err != nil {
165 closeWithLog(session, "session after stderr error")
166 return fmt.Errorf("get stderr: %w", err)
167 }
168
169 if err := session.Shell(); err != nil {
170 closeWithLog(session, "session after shell error")
171 return fmt.Errorf("start shell: %w", err)
172 }
173
174 logrus.Info("SSH: Session started with PTY")
175 return nil
176}
177
178// Write sends data to the SSH session
179func (c *Client) Write(data []byte) (int, error) {

Callers 1

connectSSHFunction · 0.95

Calls 4

closeWithLogFunction · 0.85
ErrorfMethod · 0.80
LockMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected