|
|
@ -22,7 +22,7 @@ cur_dir = os.path.dirname(__file__)
|
|
|
|
sys.path.append('%s/webroot/AutoSa/' % cur_dir)
|
|
|
|
sys.path.append('%s/webroot/AutoSa/' % cur_dir)
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings'
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings'
|
|
|
|
|
|
|
|
|
|
|
|
from UserManage.models import User
|
|
|
|
from UserManage.models import User,Logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cf = ConfigParser.ConfigParser()
|
|
|
|
cf = ConfigParser.ConfigParser()
|
|
|
@ -40,8 +40,6 @@ assets_user_table = cf.get('jumpserver', 'assets_user_table')
|
|
|
|
key = cf.get('jumpserver', 'key')
|
|
|
|
key = cf.get('jumpserver', 'key')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PyCrypt(object):
|
|
|
|
class PyCrypt(object):
|
|
|
|
"""It's used to encrypt and decrypt password."""
|
|
|
|
"""It's used to encrypt and decrypt password."""
|
|
|
|
def __init__(self, key):
|
|
|
|
def __init__(self, key):
|
|
|
@ -120,11 +118,16 @@ def connect(host, port, user, password):
|
|
|
|
log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d'))
|
|
|
|
log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d'))
|
|
|
|
if not os.path.isdir(log_date_dir):
|
|
|
|
if not os.path.isdir(log_date_dir):
|
|
|
|
os.mkdir(log_date_dir)
|
|
|
|
os.mkdir(log_date_dir)
|
|
|
|
logfile = open("%s/%s_%s_%s" % (log_date_dir, host, user, time.strftime('%Y%m%d%H%M%S')), 'a')
|
|
|
|
structtime_now = time.localtime()
|
|
|
|
db, cursor = connect_db(db_user, db_password, db_db, db_host, db_port)
|
|
|
|
datetime_now = time.strftime('%Y%m%d%H%M%S', structtime_now)
|
|
|
|
cursor.execute('insert into logs (Fuser, Fhost, Flogfile, Fstart_time) value (%s, %s, %s, UNIX_TIMESTAMP())'
|
|
|
|
logtime_now = time.strftime('%Y/%m/%d %H:%M:%S', structtime_now)
|
|
|
|
% (user, host, logfile))
|
|
|
|
timestamp_now = int(time.mktime(structtime_now))
|
|
|
|
logfile.write('\n%s\n' % time.strftime('%Y/%m/%d %H:%M:%S'))
|
|
|
|
|
|
|
|
|
|
|
|
logfile_name = "%s/%s_%s_%s" % (log_date_dir, host, user, datetime_now)
|
|
|
|
|
|
|
|
logfile = open(logfile_name, 'a')
|
|
|
|
|
|
|
|
log = Logs(user=user, host=host, logfile=logfile_name, start_time=timestamp_now)
|
|
|
|
|
|
|
|
log.save()
|
|
|
|
|
|
|
|
logfile.write('\n%s\n' % logtime_now)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
global foo
|
|
|
|
global foo
|
|
|
|
foo = pxssh.pxssh()
|
|
|
|
foo = pxssh.pxssh()
|
|
|
@ -133,13 +136,18 @@ def connect(host, port, user, password):
|
|
|
|
foo.sendline('')
|
|
|
|
foo.sendline('')
|
|
|
|
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
|
|
|
|
signal.signal(signal.SIGWINCH, sigwinch_passthrough)
|
|
|
|
foo.interact(escape_character=chr(28))
|
|
|
|
foo.interact(escape_character=chr(28))
|
|
|
|
cursor.execute('update logs set Ffindsh=True, Fend_time=UNIX_TIMESTAMP() where Flogfile=%s' % logfile)
|
|
|
|
log.finish = 1
|
|
|
|
|
|
|
|
log.end_time = int(time.time())
|
|
|
|
|
|
|
|
log.save()
|
|
|
|
except pxssh.ExceptionPxssh as e:
|
|
|
|
except pxssh.ExceptionPxssh as e:
|
|
|
|
print('登录失败: %s' % e)
|
|
|
|
print('登录失败: %s' % e)
|
|
|
|
cursor.execute('update logs set Ffindsh=2 where Flogfile=%s' % logfile)
|
|
|
|
log.finish = 2
|
|
|
|
|
|
|
|
log.save()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
foo.logout()
|
|
|
|
foo.logout()
|
|
|
|
cursor.execute('update logs set Ffindsh=True, Fend_time=UNIX_TIMESTAMP() where Flogfile=%s ' % logfile)
|
|
|
|
log.finish = 1
|
|
|
|
|
|
|
|
log.end_time = int(time.time())
|
|
|
|
|
|
|
|
log.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ip_all_select(username):
|
|
|
|
def ip_all_select(username):
|
|
|
|