|
|
|
@ -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): |
|
|
|
|