mirror of https://github.com/tp4a/teleport
修正数据库操作使用unix_timestamp()导致sqlite无法工作的问题。
parent
363be82945
commit
483aa810ee
|
@ -235,20 +235,12 @@ $assist.do_teleport = function (args, func_success, func_error) {
|
||||||
};
|
};
|
||||||
|
|
||||||
$assist.do_rdp_replay = function (rid, func_success, func_error) {
|
$assist.do_rdp_replay = function (rid, func_success, func_error) {
|
||||||
// ==================================================
|
// rid: (int) - record-id in database.
|
||||||
// args is dict with fields shown below:
|
|
||||||
// rid: (int) - record-id in database.
|
|
||||||
// user: (string) - who did the RDP connection.
|
|
||||||
// acc: (string) - account to login to remote RDP server.
|
|
||||||
// host: (string) - IP of the remote RDP server.
|
|
||||||
// start: (string) - when start the RDP connection, should be a UTC timestamp.
|
|
||||||
// ==================================================
|
|
||||||
|
|
||||||
// now make the args.
|
// now make the args.
|
||||||
var args = {rid: rid};
|
var args = {rid: rid};
|
||||||
args.web = $tp.web_server; // (string) - teleport server base address, like "http://127.0.0.1:7190", without end-slash.
|
args.web = $tp.web_server; // (string) - teleport server base address, like "http://127.0.0.1:7190", without end-slash.
|
||||||
args.sid = Cookies.get('_sid'); // (string) - current login user's session-id.
|
args.sid = Cookies.get('_sid'); // (string) - current login user's session-id.
|
||||||
// args.start = tp_format_datetime(tp_utc2local(args.start), 'yyyyMMdd-HHmmss'); // (string) - convert UTC timestamp to local human-readable string.
|
|
||||||
|
|
||||||
console.log('do-rdp-replay:', args);
|
console.log('do-rdp-replay:', args);
|
||||||
|
|
||||||
|
|
|
@ -160,6 +160,12 @@ def tp_second2human(n):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def tp_timestamp_from_str(t, fmt='%Y-%m-%d %H:%M:%S'):
|
||||||
|
_fmt = '%Y-%m-%d %H:%M:%S' if fmt is None else fmt
|
||||||
|
d = datetime.datetime.strptime(t, _fmt)
|
||||||
|
return int(d.timestamp())
|
||||||
|
|
||||||
|
|
||||||
def tp_timestamp_local_to_utc(t):
|
def tp_timestamp_local_to_utc(t):
|
||||||
return int(datetime.datetime.utcfromtimestamp(time.mktime(time.localtime(t))).timestamp())
|
return int(datetime.datetime.utcfromtimestamp(time.mktime(time.localtime(t))).timestamp())
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ from app.base.configs import tp_cfg
|
||||||
from app.base.controller import TPBaseHandler, TPBaseJsonHandler
|
from app.base.controller import TPBaseHandler, TPBaseJsonHandler
|
||||||
from app.base.logger import *
|
from app.base.logger import *
|
||||||
from app.base.session import tp_session
|
from app.base.session import tp_session
|
||||||
from app.base.utils import tp_check_strong_password, tp_gen_password
|
from app.base.utils import tp_check_strong_password, tp_gen_password, tp_timestamp_from_str
|
||||||
from app.logic.auth.oath import tp_oath_verify_code
|
from app.logic.auth.oath import tp_oath_verify_code
|
||||||
from app.const import *
|
from app.const import *
|
||||||
from app.logic.auth.oath import tp_oath_generate_secret, tp_oath_generate_qrcode
|
from app.logic.auth.oath import tp_oath_generate_secret, tp_oath_generate_qrcode
|
||||||
|
@ -590,13 +590,13 @@ class DoUpdateUserHandler(TPBaseJsonHandler):
|
||||||
args['wechat'] = args['wechat'].strip()
|
args['wechat'] = args['wechat'].strip()
|
||||||
|
|
||||||
if args['valid_from'] == '':
|
if args['valid_from'] == '':
|
||||||
args['valid_from'] = '1970-01-01'
|
args['valid_from'] = 0
|
||||||
else:
|
else:
|
||||||
args['valid_from'] = args['valid_from'].strip()
|
args['valid_from'] = tp_timestamp_from_str(args['valid_from'].strip(), '%Y-%m-%d %H:%M')
|
||||||
if args['valid_to'] == '':
|
if args['valid_to'] == '':
|
||||||
args['valid_to'] = '1970-01-01'
|
args['valid_to'] = 0
|
||||||
else:
|
else:
|
||||||
args['valid_to'] = args['valid_to'].strip()
|
args['valid_to'] = tp_timestamp_from_str(args['valid_to'].strip(), '%Y-%m-%d %H:%M')
|
||||||
args['desc'] = args['desc'].strip()
|
args['desc'] = args['desc'].strip()
|
||||||
except:
|
except:
|
||||||
return self.write_json(TPE_PARAM)
|
return self.write_json(TPE_PARAM)
|
||||||
|
|
|
@ -90,7 +90,7 @@ def login(handler, username, password=None, oath_code=None, check_bind_oath=Fals
|
||||||
msg = '登录失败,用户状态异常'
|
msg = '登录失败,用户状态异常'
|
||||||
syslog.sys_log(user_info, handler.request.remote_ip, TPE_FAILED, msg)
|
syslog.sys_log(user_info, handler.request.remote_ip, TPE_FAILED, msg)
|
||||||
return TPE_FAILED, None, msg
|
return TPE_FAILED, None, msg
|
||||||
elif current_unix_time < user_info['valid_from'] or (current_unix_time > user_info['valid_to'] and user_info['valid_to'] != 0):
|
elif current_unix_time < user_info['valid_from'] or (current_unix_time > user_info['valid_to'] and user_info['valid_to'] != 0):
|
||||||
msg = '登录失败,用户已过期'
|
msg = '登录失败,用户已过期'
|
||||||
syslog.sys_log(user_info, handler.request.remote_ip, TPE_FAILED, msg)
|
syslog.sys_log(user_info, handler.request.remote_ip, TPE_FAILED, msg)
|
||||||
return TPE_FAILED, None, msg
|
return TPE_FAILED, None, msg
|
||||||
|
@ -362,8 +362,8 @@ def create_user(handler, user):
|
||||||
'`email`, `creator_id`, `create_time`, `last_login`, `last_chpass`, `valid_from`, `valid_to`, `desc`' \
|
'`email`, `creator_id`, `create_time`, `last_login`, `last_chpass`, `valid_from`, `valid_to`, `desc`' \
|
||||||
') VALUES (' \
|
') VALUES (' \
|
||||||
'{role}, "{username}", "{surname}", {user_type}, "{ldap_dn}", {auth_type}, "{password}", {state}, ' \
|
'{role}, "{username}", "{surname}", {user_type}, "{ldap_dn}", {auth_type}, "{password}", {state}, ' \
|
||||||
'"{email}", {creator_id}, {create_time}, {last_login}, {last_chpass}, unix_timestamp("{valid_from}"), '\
|
'"{email}", {creator_id}, {create_time}, {last_login}, {last_chpass}, {valid_from}, '\
|
||||||
'unix_timestamp("{valid_to}"), "{desc}");' \
|
'{valid_to}, "{desc}");' \
|
||||||
''.format(db.table_prefix, role=user['role'], username=user['username'], surname=user['surname'],
|
''.format(db.table_prefix, role=user['role'], username=user['username'], surname=user['surname'],
|
||||||
user_type=user['type'], ldap_dn=user['ldap_dn'], auth_type=user['auth_type'], password=_password,
|
user_type=user['type'], ldap_dn=user['ldap_dn'], auth_type=user['auth_type'], password=_password,
|
||||||
state=TP_STATE_NORMAL, email=user['email'], creator_id=operator['id'], create_time=_time_now,
|
state=TP_STATE_NORMAL, email=user['email'], creator_id=operator['id'], create_time=_time_now,
|
||||||
|
@ -407,7 +407,7 @@ def update_user(handler, args):
|
||||||
sql = 'UPDATE `{}user` SET ' \
|
sql = 'UPDATE `{}user` SET ' \
|
||||||
'`username`="{username}", `surname`="{surname}", `auth_type`={auth_type}, ' \
|
'`username`="{username}", `surname`="{surname}", `auth_type`={auth_type}, ' \
|
||||||
'`role_id`={role}, `email`="{email}", `mobile`="{mobile}", `qq`="{qq}", ' \
|
'`role_id`={role}, `email`="{email}", `mobile`="{mobile}", `qq`="{qq}", ' \
|
||||||
'`wechat`="{wechat}", `valid_from`=unix_timestamp("{valid_from}"), `valid_to`=unix_timestamp("{valid_to}"), '\
|
'`wechat`="{wechat}", `valid_from`={valid_from}, `valid_to`={valid_to}, '\
|
||||||
'`desc`="{desc}" WHERE `id`={user_id};' \
|
'`desc`="{desc}" WHERE `id`={user_id};' \
|
||||||
''.format(db.table_prefix,
|
''.format(db.table_prefix,
|
||||||
username=args['username'], surname=args['surname'], auth_type=args['auth_type'], role=args['role'],
|
username=args['username'], surname=args['surname'], auth_type=args['auth_type'], role=args['role'],
|
||||||
|
|
Loading…
Reference in New Issue