mirror of https://github.com/tp4a/teleport
修正bug#56,自动解锁后,该用户的状态在管理员查看时仍然显示为临时锁定。
parent
98f4c9fe92
commit
5af312cb16
|
@ -62,8 +62,11 @@ class TPStats(object):
|
||||||
|
|
||||||
# 每 5秒 采集一次系统状态统计数据
|
# 每 5秒 采集一次系统状态统计数据
|
||||||
tp_cron().add_job('sys_status', self._check_sys_stats, first_interval_seconds=self._INTERVAL, interval_seconds=self._INTERVAL)
|
tp_cron().add_job('sys_status', self._check_sys_stats, first_interval_seconds=self._INTERVAL, interval_seconds=self._INTERVAL)
|
||||||
# 每 一小时 重新查询一次数据库,得到用户数/主机数/账号数/连接数,避免统计数量出现偏差
|
# 每 1小时 重新查询一次数据库,得到用户数/主机数/账号数/连接数,避免统计数量出现偏差
|
||||||
tp_cron().add_job('query_counter', self._query_counter, first_interval_seconds=60 * 60, interval_seconds=60 * 60)
|
tp_cron().add_job('query_counter', self._query_counter, first_interval_seconds=60 * 60, interval_seconds=60 * 60)
|
||||||
|
# 每 1分钟 检查一下临时锁定用户是否可以自动解锁了
|
||||||
|
tp_cron().add_job('check_temp_locked_user', self._check_temp_locked_user, interval_seconds=60)
|
||||||
|
|
||||||
tp_wss().register_get_sys_status_callback(self.get_sys_stats)
|
tp_wss().register_get_sys_status_callback(self.get_sys_stats)
|
||||||
tp_wss().register_get_stat_counter_callback(self.get_counter_stats)
|
tp_wss().register_get_stat_counter_callback(self.get_counter_stats)
|
||||||
|
|
||||||
|
@ -116,6 +119,9 @@ class TPStats(object):
|
||||||
self._counter_stats = c
|
self._counter_stats = c
|
||||||
tp_wss().send_message('stat_counter', self._counter_stats)
|
tp_wss().send_message('stat_counter', self._counter_stats)
|
||||||
|
|
||||||
|
def _check_temp_locked_user(self):
|
||||||
|
stats.update_temp_locked_user_state()
|
||||||
|
|
||||||
def get_sys_stats(self):
|
def get_sys_stats(self):
|
||||||
return self._sys_stats
|
return self._sys_stats
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
from app.const import *
|
from app.const import *
|
||||||
from app.base.db import get_db
|
from app.base.db import get_db
|
||||||
|
from app.base.configs import tp_cfg
|
||||||
|
from app.base.utils import tp_timestamp_utc_now
|
||||||
|
|
||||||
|
|
||||||
def get_basic_stats():
|
def get_basic_stats():
|
||||||
|
@ -44,43 +46,14 @@ def get_basic_stats():
|
||||||
return TPE_OK, ret
|
return TPE_OK, ret
|
||||||
|
|
||||||
|
|
||||||
# def get_logs(sql_filter, sql_order, sql_limit):
|
def update_temp_locked_user_state():
|
||||||
# s = SQL(get_db())
|
sys_cfg = tp_cfg().sys
|
||||||
# s.select_from('syslog', ['id', 'user_name', 'user_surname', 'client_ip', 'code', 'log_time', 'message'], alt_name='l')
|
if sys_cfg.login.lock_timeout == 0:
|
||||||
#
|
return
|
||||||
# str_where = ''
|
|
||||||
# _where = list()
|
_lock_time = tp_timestamp_utc_now() - (sys_cfg.login.lock_timeout * 60)
|
||||||
#
|
db = get_db()
|
||||||
# if len(sql_filter) > 0:
|
|
||||||
# for k in sql_filter:
|
sql = 'UPDATE `{}user` SET state={new_state}, lock_time=0, fail_count=0 WHERE (state={old_state} AND lock_time<{lock_time});' \
|
||||||
# if k == 'log_user_name':
|
''.format(db.table_prefix, new_state=TP_STATE_NORMAL, old_state=TP_STATE_LOCKED, lock_time=_lock_time)
|
||||||
# _where.append('l.user_name="{}"'.format(sql_filter[k]))
|
db.exec(sql)
|
||||||
# # elif k == 'search_record':
|
|
||||||
# # _where.append('(h.name LIKE "%{}%" OR h.ip LIKE "%{}%" OR h.router_addr LIKE "%{}%" OR h.desc LIKE "%{}%" OR h.cid LIKE "%{}%")'.format(sql_filter[k], sql_filter[k], sql_filter[k], sql_filter[k], sql_filter[k]))
|
|
||||||
#
|
|
||||||
# if len(_where) > 0:
|
|
||||||
# str_where = '( {} )'.format(' AND '.join(_where))
|
|
||||||
#
|
|
||||||
# s.where(str_where)
|
|
||||||
#
|
|
||||||
# if sql_order is not None:
|
|
||||||
# _sort = False if not sql_order['asc'] else True
|
|
||||||
# if 'log_time' == sql_order['name']:
|
|
||||||
# s.order_by('l.log_time', _sort)
|
|
||||||
# # elif 'name' == sql_order['name']:
|
|
||||||
# # s.order_by('h.name', _sort)
|
|
||||||
# # elif 'os_type' == sql_order['name']:
|
|
||||||
# # s.order_by('h.os_type', _sort)
|
|
||||||
# # elif 'cid' == sql_order['name']:
|
|
||||||
# # s.order_by('h.cid', _sort)
|
|
||||||
# # elif 'state' == sql_order['name']:
|
|
||||||
# # s.order_by('h.state', _sort)
|
|
||||||
# else:
|
|
||||||
# log.e('unknown order field: {}\n'.format(sql_order['name']))
|
|
||||||
# return TPE_PARAM, s.total_count, s.recorder
|
|
||||||
#
|
|
||||||
# if len(sql_limit) > 0:
|
|
||||||
# s.limit(sql_limit['page_index'], sql_limit['per_page'])
|
|
||||||
#
|
|
||||||
# err = s.query()
|
|
||||||
# return err, s.total_count, s.recorder
|
|
||||||
|
|
Loading…
Reference in New Issue