|
|
@ -66,6 +66,7 @@ import termios
|
|
|
|
import signal
|
|
|
|
import signal
|
|
|
|
import MySQLdb
|
|
|
|
import MySQLdb
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
#Test user
|
|
|
|
#Test user
|
|
|
@ -81,6 +82,9 @@ db_password = 'redhat'
|
|
|
|
db_db = 'jump'
|
|
|
|
db_db = 'jump'
|
|
|
|
db_port = 3306
|
|
|
|
db_port = 3306
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_dir = '/tmp/logfile/'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sigwinch_passthrough (sig, data):
|
|
|
|
def sigwinch_passthrough (sig, data):
|
|
|
|
winsize = getwinsize()
|
|
|
|
winsize = getwinsize()
|
|
|
@ -129,8 +133,15 @@ def is_ip(ip):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def connect(host, port, user, password ):
|
|
|
|
def connect(host, port, user, password):
|
|
|
|
foo = pexpect.spawn('ssh -p %s %s@%s' % (port, user, host))
|
|
|
|
if not os.path.isdir(log_dir):
|
|
|
|
|
|
|
|
os.mkdir(log_dir)
|
|
|
|
|
|
|
|
logfile = open("%s/%s_%s_%s" % (log_dir, host, time.strftime('%Y%m%d'), user), 'a')
|
|
|
|
|
|
|
|
logfile.write('\n\n\n%s' % time.strftime('%Y%m%d_%H%M%S'))
|
|
|
|
|
|
|
|
#cmd = 'ssh -p %s %s@%s | tee -a %s' % (port, user, host, logfile)
|
|
|
|
|
|
|
|
cmd = 'ssh -p %s %s@%s' % (port, user, host)
|
|
|
|
|
|
|
|
foo = pexpect.spawn('/bin/bash', ['-c', cmd])
|
|
|
|
|
|
|
|
foo.logfile = logfile
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
index = foo.expect(['continue',
|
|
|
|
index = foo.expect(['continue',
|
|
|
|
'assword',
|
|
|
|
'assword',
|
|
|
@ -150,8 +161,9 @@ def connect(host, port, user, password ):
|
|
|
|
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
|
|
|
|
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
|
|
|
|
size = getwinsize()
|
|
|
|
size = getwinsize()
|
|
|
|
foo.setwinsize(size[0], size[1])
|
|
|
|
foo.setwinsize(size[0], size[1])
|
|
|
|
foo.interact()
|
|
|
|
|
|
|
|
print "Login success!"
|
|
|
|
print "Login success!"
|
|
|
|
|
|
|
|
foo.interact()
|
|
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print "Login failed, please contact system administrator!"
|
|
|
|
print "Login failed, please contact system administrator!"
|
|
|
@ -189,7 +201,6 @@ def sth_select(username='', ip=''):
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|
username = run_cmd('whoami')
|
|
|
|
username = run_cmd('whoami')
|
|
|
|
print username
|
|
|
|
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
option = raw_input("""
|
|
|
|
option = raw_input("""
|
|
|
|
Welcome Use JumpServer To Login.
|
|
|
|
Welcome Use JumpServer To Login.
|
|
|
|