修正数据库操作使用unix_timestamp()导致sqlite无法工作的问题。

pull/236/head
Apex Liu 2019-11-17 04:31:11 +08:00
parent 363be82945
commit 483aa810ee
4 changed files with 16 additions and 18 deletions

View File

@ -235,20 +235,12 @@ $assist.do_teleport = function (args, func_success, func_error) {
};
$assist.do_rdp_replay = function (rid, func_success, func_error) {
// ==================================================
// 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.
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.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);

View File

@ -160,6 +160,12 @@ def tp_second2human(n):
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):
return int(datetime.datetime.utcfromtimestamp(time.mktime(time.localtime(t))).timestamp())

View File

@ -11,7 +11,7 @@ from app.base.configs import tp_cfg
from app.base.controller import TPBaseHandler, TPBaseJsonHandler
from app.base.logger import *
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.const import *
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()
if args['valid_from'] == '':
args['valid_from'] = '1970-01-01'
args['valid_from'] = 0
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'] == '':
args['valid_to'] = '1970-01-01'
args['valid_to'] = 0
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()
except:
return self.write_json(TPE_PARAM)

View File

@ -362,8 +362,8 @@ def create_user(handler, user):
'`email`, `creator_id`, `create_time`, `last_login`, `last_chpass`, `valid_from`, `valid_to`, `desc`' \
') VALUES (' \
'{role}, "{username}", "{surname}", {user_type}, "{ldap_dn}", {auth_type}, "{password}", {state}, ' \
'"{email}", {creator_id}, {create_time}, {last_login}, {last_chpass}, unix_timestamp("{valid_from}"), '\
'unix_timestamp("{valid_to}"), "{desc}");' \
'"{email}", {creator_id}, {create_time}, {last_login}, {last_chpass}, {valid_from}, '\
'{valid_to}, "{desc}");' \
''.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,
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 ' \
'`username`="{username}", `surname`="{surname}", `auth_type`={auth_type}, ' \
'`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};' \
''.format(db.table_prefix,
username=args['username'], surname=args['surname'], auth_type=args['auth_type'], role=args['role'],