diff --git a/.idea/jumpserver.iml b/.idea/jumpserver.iml index 94e54876c..9dcd47829 100644 --- a/.idea/jumpserver.iml +++ b/.idea/jumpserver.iml @@ -2,7 +2,7 @@ - + diff --git a/jumpserver.py b/jumpserver.py index d4754b33f..92e0e7082 100755 --- a/jumpserver.py +++ b/jumpserver.py @@ -16,6 +16,7 @@ from Crypto.Cipher import AES from binascii import b2a_hex, a2b_hex import ConfigParser import paramiko +import pxssh base_dir = "/opt/jumpserver/" cf = ConfigParser.ConfigParser() @@ -110,38 +111,20 @@ def connect(host, port, user, password): os.mkdir(log_date_dir) logfile = open("%s/%s_%s" % (log_date_dir, host, user), 'a') logfile.write('\n\n%s\n\n' % time.strftime('%Y%m%d_%H%M%S')) - cmd = 'ssh -q -p %s %s@%s' % (port, user, host) - global foo - foo = pexpect.spawn('/bin/bash', ['-c', cmd]) - foo.logfile = logfile - while True: - index = foo.expect(['continue', - 'assword', - pexpect.EOF, - pexpect.TIMEOUT], timeout=3) - if index == 0: - foo.sendline('yes') - continue - elif index == 1: - foo.sendline(password) - - index = foo.expect(['assword', - '.*', - pexpect.EOF, - pexpect.TIMEOUT], timeout=3) - if index == 1: - signal.signal(signal.SIGWINCH, sigwinch_passthrough) - size = getwinsize() - foo.setwinsize(size[0], size[1]) - foo.interact() - break - elif index == 0: - print "Password error." - break - else: - print "Login failed, please contact system administrator!" - break - foo.terminate(force=True) + try: + global foo + foo = pxssh.pxssh() + foo.login(host, user, password, port=port, auto_prompt_reset=False) + foo.logfile = logfile + foo.sendline('') + signal.signal(signal.SIGWINCH, sigwinch_passthrough) + size = getwinsize() + foo.setwinsize(size[0], size[1]) + foo.interact() + except pxssh.ExceptionPxssh as e: + print('密码错误: %s' % e) + except KeyboardInterrupt: + foo.logout() def ip_all_select(username): diff --git a/pip-requirement.txt b/pip-requirement.txt new file mode 100644 index 000000000..617685d43 --- /dev/null +++ b/pip-requirement.txt @@ -0,0 +1 @@ +pexpect == 3.3 \ No newline at end of file