diff --git a/jumpserver.py b/jumpserver.py index 69dadf2cd..f7b647d1b 100755 --- a/jumpserver.py +++ b/jumpserver.py @@ -24,6 +24,8 @@ if not cur_dir: sys.path.append('%s/webroot/AutoSa/' % cur_dir) os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings' +import django +django.setup() from UserManage.models import User, Logs, Pid from Assets.models import Assets @@ -88,18 +90,6 @@ def getwinsize(): return struct.unpack('HHHH', x)[0:2] -# def connect_db(user, passwd, db, host='127.0.0.1', port=3306): -# """This function connect db and return db and cursor""" -# db = MySQLdb.connect(host=host, -# port=port, -# user=user, -# passwd=passwd, -# db=db, -# charset='utf8') -# cursor = db.cursor() -# return db, cursor - - def run_cmd(cmd): """run command and return stdout""" pipe = subprocess.Popen(cmd, @@ -120,8 +110,7 @@ def connect(host, port, user, password): """Use pexpect module to connect other server.""" log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d')) if not os.path.isdir(log_date_dir): - os.mkdir(log_date_dir) - os.chmod(log_date_dir, 0777) + os.mkdir(log_date_dir, 0777) structtime_start = time.localtime() datetime_start = time.strftime('%Y%m%d%H%M%S', structtime_start) logtime_start = time.strftime('%Y/%m/%d %H:%M:%S', structtime_start) @@ -259,6 +248,13 @@ def exec_cmd_servers(username): cmd = raw_input('\033[1;32mCmd(s): \033[0m') if cmd in ['q', 'Q']: break + if not os.path.isdir(): + exec_log_dir = os.path.join(log_dir, 'exec_cmds') + os.mkdir(exec_log_dir, 0777) + filename = "%s/%s.log" % (exec_log_dir, time.strftime('%Y%m%d')) + f = open(filename, 'a') + f.write("DateTime: %s User: %s Host: %s Cmds: %s" % + (time.strftime('%Y/%m/%d %H:%M:%S'), username, hosts, cmd)) for host in hosts: remote_exec_cmd(host, username, cmd) diff --git a/webroot/AutoSa/log_handler.py b/webroot/AutoSa/log_handler.py index 9709e7d44..f7b3d10e6 100755 --- a/webroot/AutoSa/log_handler.py +++ b/webroot/AutoSa/log_handler.py @@ -9,6 +9,8 @@ cur_dir = os.path.dirname(__file__) sys.path.append('%s/webroot/AutoSa/' % cur_dir) os.environ['DJANGO_SETTINGS_MODULE'] = 'AutoSa.settings' +import django +django.setup() from UserManage.models import Logs, Pid @@ -24,7 +26,6 @@ def log_hanler(logid): print 'Handler % ok.' % filename - def set_finish(id): logs = Logs.objects.filter(id=id, finish=0) if logs: diff --git a/webroot/AutoSa/templates/addUser.html b/webroot/AutoSa/templates/addUser.html index 4d367438f..7630836ff 100644 --- a/webroot/AutoSa/templates/addUser.html +++ b/webroot/AutoSa/templates/addUser.html @@ -68,6 +68,12 @@