def channelOpen(self, foo): #global globalSession #globalSession = self # turn off local echo self.escapeMode = 1 c = session.SSHSessionClient() if options['escape']: c.dataReceived = self.handleInput else: c.dataReceived = self.write c.connectionLost = self.sendEOF frame.callback = c.dataReceived frame.canvas.focus_force() if options['subsystem']: self.conn.sendRequest(self, 'subsystem', \ common.NS(options['command'])) elif options['command']: if options['tty']: term = os.environ.get('TERM', 'xterm') #winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678') winSize = (25, 80, 0, 0) #struct.unpack('4H', winsz) ptyReqData = session.packRequest_pty_req(term, winSize, '') self.conn.sendRequest(self, 'pty-req', ptyReqData) self.conn.sendRequest(self, 'exec', \ common.NS(options['command'])) else: if not options['notty']: term = os.environ.get('TERM', 'xterm') #winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678') winSize = (25, 80, 0, 0) #struct.unpack('4H', winsz) ptyReqData = session.packRequest_pty_req(term, winSize, '') self.conn.sendRequest(self, 'pty-req', ptyReqData) self.conn.sendRequest(self, 'shell', '') self.conn.transport.transport.setTcpNoDelay(1)
def channelOpen(self, foo): # global globalSession # globalSession = self # turn off local echo self.escapeMode = 1 c = session.SSHSessionClient() if options["escape"]: c.dataReceived = self.handleInput else: c.dataReceived = self.write c.connectionLost = self.sendEOF frame.callback = c.dataReceived frame.canvas.focus_force() if options["subsystem"]: self.conn.sendRequest(self, b"subsystem", common.NS(options["command"])) elif options["command"]: if options["tty"]: term = os.environ.get("TERM", "xterm") # winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678') winSize = (25, 80, 0, 0) # struct.unpack('4H', winsz) ptyReqData = session.packRequest_pty_req(term, winSize, "") self.conn.sendRequest(self, b"pty-req", ptyReqData) self.conn.sendRequest(self, "exec", common.NS(options["command"])) else: if not options["notty"]: term = os.environ.get("TERM", "xterm") # winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678') winSize = (25, 80, 0, 0) # struct.unpack('4H', winsz) ptyReqData = session.packRequest_pty_req(term, winSize, "") self.conn.sendRequest(self, b"pty-req", ptyReqData) self.conn.sendRequest(self, b"shell", b"") self.conn.transport.transport.setTcpNoDelay(1)
def test_dataReceived(self): """ When data is received, it should be sent to the transport. """ client = session.SSHSessionClient() client.transport = StubTransport() client.dataReceived('test data') self.assertEquals(client.transport.buf, 'test data')
def newSessionClient(self, options): c = session.SSHSessionClient() if options['escape'] and not options['notty']: self.escapeMode = 1 c.dataReceived = self.handleInput else: c.dataReceived = self.write c.connectionLost = lambda x=None, s=self: s.sendEOF() return c
def channelOpen(self, foo): log.msg('session %s open' % self.id) self.conn.terminal.enter() c = session.SSHSessionClient() # TODO: figure out if this is right c.dataReceived = self.write c.connectionLost = self.sendEOF c.session = self self.conn.terminal.set_active_session(c) self.stdio = self.io_handler(c) self.allocatePty() self.conn.sendRequest(self, 'shell', '')
def channelOpen(self, foo): log.msg(f"session {self.id} open") if options["agent"]: d = self.conn.sendRequest(self, b"*****@*****.**", b"", wantReply=1) d.addBoth(lambda x: log.msg(x)) if options["noshell"]: return if (options["command"] and options["tty"]) or not options["notty"]: _enterRawMode() c = session.SSHSessionClient() if options["escape"] and not options["notty"]: self.escapeMode = 1 c.dataReceived = self.handleInput else: c.dataReceived = self.write c.connectionLost = lambda x: self.sendEOF() self.stdio = stdio.StandardIO(c) fd = 0 if options["subsystem"]: self.conn.sendRequest(self, b"subsystem", common.NS(options["command"])) elif options["command"]: if options["tty"]: term = os.environ["TERM"] winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, "12345678") winSize = struct.unpack("4H", winsz) ptyReqData = session.packRequest_pty_req(term, winSize, "") self.conn.sendRequest(self, b"pty-req", ptyReqData) signal.signal(signal.SIGWINCH, self._windowResized) self.conn.sendRequest(self, b"exec", common.NS(options["command"])) else: if not options["notty"]: term = os.environ["TERM"] winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, "12345678") winSize = struct.unpack("4H", winsz) ptyReqData = session.packRequest_pty_req(term, winSize, "") self.conn.sendRequest(self, b"pty-req", ptyReqData) signal.signal(signal.SIGWINCH, self._windowResized) self.conn.sendRequest(self, b"shell", b"")
def channelOpen(self, foo): log.msg('session {} open'.format(self.id)) if options['agent']: d = self.conn.sendRequest(self, b'*****@*****.**', b'', wantReply=1) d.addBoth(lambda x: log.msg(x)) if options['noshell']: return if (options['command'] and options['tty']) or not options['notty']: _enterRawMode() c = session.SSHSessionClient() if options['escape'] and not options['notty']: self.escapeMode = 1 c.dataReceived = self.handleInput else: c.dataReceived = self.write c.connectionLost = lambda x: self.sendEOF() self.stdio = stdio.StandardIO(c) fd = 0 if options['subsystem']: self.conn.sendRequest(self, b'subsystem', common.NS(options['command'])) elif options['command']: if options['tty']: term = os.environ['TERM'] winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678') winSize = struct.unpack('4H', winsz) ptyReqData = session.packRequest_pty_req(term, winSize, '') self.conn.sendRequest(self, b'pty-req', ptyReqData) signal.signal(signal.SIGWINCH, self._windowResized) self.conn.sendRequest(self, b'exec', common.NS(options['command'])) else: if not options['notty']: term = os.environ['TERM'] winsz = fcntl.ioctl(fd, tty.TIOCGWINSZ, '12345678') winSize = struct.unpack('4H', winsz) ptyReqData = session.packRequest_pty_req(term, winSize, '') self.conn.sendRequest(self, b'pty-req', ptyReqData) signal.signal(signal.SIGWINCH, self._windowResized) self.conn.sendRequest(self, b'shell', b'')
def channelOpen(self, ignore): log.msg('session %s open' % self.id) conn = self.conn def connectionLost(reason): log.msg('connection lost: %s' % reason) conn.console.session = None conn.console.writeHelp('Lost remote connection! %s' % reason) self.sendEOF() client = session.SSHSessionClient() client.connectionLost = connectionLost conn.console.session = self # tty voodoo magic (my head is officially f*****g hurting) term = os.environ['TERM'] winsz = fcntl.ioctl(0, tty.TIOCGWINSZ, '12345678') winSize = struct.unpack('4H', winsz) ptyReqData = session.packRequest_pty_req(term, winSize, '') conn.sendRequest(self, 'pty-req', ptyReqData) signal.signal(signal.SIGWINCH, self._windowResized) conn.sendRequest(self, 'shell', '')