def _create(self, rows=24, cols=80):
pid, fd = pty.fork()
if pid == 0:
if os.getuid() == 0:
cmd = ['/bin/login']
else:
# The prompt has to end with a newline character.
sys.stdout.write(socket.gethostname() + ' login: \n')
login = sys.stdin.readline().strip()
cmd = [
'ssh',
'-oPreferredAuthentications=keyboard-interactive,password',
'-oNoHostAuthenticationForLocalhost=yes',
'-oLogLevel=FATAL',
'-F/dev/null',
'-l', login, 'localhost',
]
env = {
'COLUMNS': str(cols),
'LINES': str(rows),
'PATH': os.environ['PATH'],
'TERM': 'linux',
}
os.execvpe(cmd[0], cmd, env)
else:
fcntl.fcntl(fd, fcntl.F_SETFL, os.O_NONBLOCK)
fcntl.ioctl(fd, termios.TIOCSWINSZ,
struct.pack('HHHH', rows, cols, 0, 0))
TermSocketHandler.clients[fd] = {
'client': self,
'pid': pid,
'terminal': Terminal(rows, cols)
}
return fd
评论列表
文章目录