mirror of https://github.com/tp4a/teleport
1. 修正部分数据库操作,避免新安装的版本会出现无法无法连接数据库的问题;
2. 优化安装向导页面,避免出现不知道下一步操作的困扰; 3. 日志页面,只有成功操作的连接才出现回放按钮,避免困扰;pull/32/head
parent
2ce6d4beda
commit
1be2d393c9
|
@ -57,8 +57,8 @@ class TPDatabase:
|
|||
return False
|
||||
|
||||
# 看看数据库中是否存在指定的数据表(如果不存在,可能是一个空数据库文件),则可能是一个新安装的系统
|
||||
# ret = self.query('SELECT COUNT(*) FROM `sqlite_master` WHERE `type`="table" AND `name`="{}account";'.format(self._table_prefix))
|
||||
ret = self.is_table_exists('{}group'.format(self._table_prefix))
|
||||
# ret = self.query('SELECT COUNT(*) FROM `sqlite_master` WHERE `type`="table" AND `name`="{}account";'.format(self._table_prefix))
|
||||
ret = self.is_table_exists('{}group'.format(self._table_prefix))
|
||||
if ret is None or not ret:
|
||||
log.w('database need create.\n')
|
||||
self.need_create = True
|
||||
|
@ -76,9 +76,9 @@ class TPDatabase:
|
|||
self.need_upgrade = True
|
||||
return True
|
||||
|
||||
# DO TEST
|
||||
# self.alter_table('ts_account', [['account_id', 'id'], ['account_type', 'type']])
|
||||
|
||||
# DO TEST
|
||||
# self.alter_table('ts_account', [['account_id', 'id'], ['account_type', 'type']])
|
||||
|
||||
return True
|
||||
|
||||
def is_table_exists(self, table_name):
|
||||
|
@ -128,6 +128,14 @@ class TPDatabase:
|
|||
if not os.path.exists(db_path):
|
||||
log.e('can not create folder `{}` to store database file.\n'.format(db_path))
|
||||
return False
|
||||
# 创建一个空数据文件,这样才能进行connect。
|
||||
if not os.path.exists(self.db_source['file']):
|
||||
try:
|
||||
with open(self.db_source['file'], 'w') as f:
|
||||
pass
|
||||
except:
|
||||
log.e('can not create db file `{}`.\n'.format(self.db_source['file']))
|
||||
return False
|
||||
|
||||
if create_and_init(self, step_begin, step_end):
|
||||
log.v('database created.\n')
|
||||
|
@ -154,54 +162,55 @@ class TPDatabase:
|
|||
fields_names: 如果为None,则不修改字段名,否则应该是一个list,其中每个元素是包含两个str的list,表示将此list第一个指定的字段改名为第二个指定的名称
|
||||
@return: None or Boolean
|
||||
"""
|
||||
# TODO: 此函数尚未完成
|
||||
if self.db_source['type'] == self.DB_TYPE_SQLITE:
|
||||
if not isinstance(table_names, list) and field_names is None:
|
||||
log.w('nothing to do.\n')
|
||||
return False
|
||||
|
||||
if isinstance(table_names, str):
|
||||
old_table_name = table_names
|
||||
new_table_name = table_names
|
||||
elif isinstance(table_names, list) and len(table_names) == 2:
|
||||
old_table_name = table_names[0]
|
||||
new_table_name = table_names[1]
|
||||
else:
|
||||
log.w('invalid param.\n')
|
||||
return False
|
||||
|
||||
if isinstance(field_names, list):
|
||||
for i in field_names:
|
||||
if not isinstance(i, list) or 2 != len(i):
|
||||
log.w('invalid param.\n')
|
||||
return False
|
||||
|
||||
if field_names is None:
|
||||
# 仅数据表改名
|
||||
return self.exec('ALTER TABLE `{}` RENAME TO `{}`;'.format(old_table_name, new_table_name))
|
||||
else:
|
||||
# sqlite不支持字段改名,所以需要通过临时表中转一下
|
||||
|
||||
# 先获取数据表的字段名列表
|
||||
ret = self.query('SELECT * FROM `sqlite_master` WHERE `type`="table" AND `name`="{}";'.format(old_table_name))
|
||||
log.w('-----\n')
|
||||
log.w(ret[0][4])
|
||||
log.w('\n')
|
||||
|
||||
# 先将数据表改名,成为一个临时表
|
||||
# tmp_table_name = '{}_sqlite_tmp'.format(old_table_name)
|
||||
# ret = self.exec('ALTER TABLE `{}` RENAME TO `{}`;'.format(old_table_name, tmp_table_name))
|
||||
# if ret is None or not ret:
|
||||
# return ret
|
||||
|
||||
pass
|
||||
elif self.db_source['type'] == self.DB_TYPE_MYSQL:
|
||||
log.e('mysql not supported yet.\n')
|
||||
return False
|
||||
else:
|
||||
log.e('Unknown database type.\n')
|
||||
return False
|
||||
|
||||
|
||||
if isinstance(table_names, str):
|
||||
old_table_name = table_names
|
||||
new_table_name = table_names
|
||||
elif isinstance(table_names, list) and len(table_names) == 2:
|
||||
old_table_name = table_names[0]
|
||||
new_table_name = table_names[1]
|
||||
else:
|
||||
log.w('invalid param.\n')
|
||||
return False
|
||||
|
||||
if isinstance(field_names, list):
|
||||
for i in field_names:
|
||||
if not isinstance(i, list) or 2 != len(i):
|
||||
log.w('invalid param.\n')
|
||||
return False
|
||||
|
||||
if field_names is None:
|
||||
# 仅数据表改名
|
||||
return self.exec('ALTER TABLE `{}` RENAME TO `{}`;'.format(old_table_name, new_table_name))
|
||||
else:
|
||||
# sqlite不支持字段改名,所以需要通过临时表中转一下
|
||||
|
||||
# 先获取数据表的字段名列表
|
||||
ret = self.query('SELECT * FROM `sqlite_master` WHERE `type`="table" AND `name`="{}";'.format(old_table_name))
|
||||
log.w('-----\n')
|
||||
log.w(ret[0][4])
|
||||
log.w('\n')
|
||||
|
||||
# 先将数据表改名,成为一个临时表
|
||||
# tmp_table_name = '{}_sqlite_tmp'.format(old_table_name)
|
||||
# ret = self.exec('ALTER TABLE `{}` RENAME TO `{}`;'.format(old_table_name, tmp_table_name))
|
||||
# if ret is None or not ret:
|
||||
# return ret
|
||||
|
||||
pass
|
||||
elif self.db_source['type'] == self.DB_TYPE_MYSQL:
|
||||
log.e('mysql not supported yet.\n')
|
||||
return False
|
||||
else:
|
||||
log.e('Unknown database type.\n')
|
||||
return False
|
||||
|
||||
|
||||
class TPDatabasePool:
|
||||
def __init__(self):
|
||||
self._locker = threading.RLock()
|
||||
|
@ -224,7 +233,8 @@ class TPDatabasePool:
|
|||
thread_id = threading.get_ident()
|
||||
if thread_id not in self._connections:
|
||||
_conn = self._do_connect()
|
||||
self._connections[thread_id] = _conn
|
||||
if _conn is not None:
|
||||
self._connections[thread_id] = _conn
|
||||
else:
|
||||
_conn = self._connections[thread_id]
|
||||
|
||||
|
@ -246,6 +256,10 @@ class TPSqlitePool(TPDatabasePool):
|
|||
self._db_file = db_file
|
||||
|
||||
def _do_connect(self):
|
||||
if not os.path.exists(self._db_file):
|
||||
log.e('[sqlite] can not connect, database file not exists.\n')
|
||||
return None
|
||||
|
||||
try:
|
||||
return sqlite3.connect(self._db_file)
|
||||
except:
|
||||
|
@ -259,6 +273,7 @@ class TPSqlitePool(TPDatabasePool):
|
|||
db_ret = cursor.fetchall()
|
||||
return db_ret
|
||||
except sqlite3.OperationalError:
|
||||
# log.e('_do_query() error.\n')
|
||||
return None
|
||||
finally:
|
||||
cursor.close()
|
||||
|
@ -270,6 +285,7 @@ class TPSqlitePool(TPDatabasePool):
|
|||
conn.commit()
|
||||
return True
|
||||
except sqlite3.OperationalError:
|
||||
# log.e('_do_exec() error.\n')
|
||||
return False
|
||||
finally:
|
||||
cursor.close()
|
||||
|
|
|
@ -50,9 +50,6 @@ controllers = [
|
|||
(r'/user', user.IndexHandler),
|
||||
(r'/user/list', user.GetListHandler),
|
||||
|
||||
# add another path to static-path
|
||||
|
||||
# todo: 重放数据路径是动态从core服务的json-rpc接口获取的,因此这里的数据获取方式需要改变
|
||||
#(r"/log/replay/(.*)", tornado.web.StaticFileHandler, {"path": os.path.join(cfg.data_path, 'replay')}),
|
||||
(r"/log/replay/(.*)", record.ReplayStaticFileHandler, {"path": os.path.join(cfg.data_path, 'replay')}),
|
||||
|
||||
|
|
|
@ -453,16 +453,8 @@ class ExportHostHandler(TPBaseAdminAuthHandler):
|
|||
|
||||
class GetCertList(TPBaseUserAuthJsonHandler):
|
||||
def post(self):
|
||||
# args = self.get_argument('args', None)
|
||||
# if args is not None:
|
||||
# args = json.loads(args)
|
||||
# # print('args', args)
|
||||
# else:
|
||||
# # ret = {'code':-1}
|
||||
# self.write_json(-1)
|
||||
# return
|
||||
_certs = host.get_cert_list()
|
||||
if _certs is None:
|
||||
if _certs is None or len(_certs) == 0:
|
||||
self.write_json(-1)
|
||||
return
|
||||
else:
|
||||
|
|
|
@ -78,7 +78,6 @@ class RpcThreadManage:
|
|||
'steps': self._threads[task_id]['steps']
|
||||
}
|
||||
if not self._threads[task_id]['running']:
|
||||
print('remove task-id', task_id)
|
||||
del self._threads[task_id]
|
||||
return ret
|
||||
else:
|
||||
|
@ -153,15 +152,12 @@ thread_mgr = RpcThreadManage()
|
|||
class RpcHandler(TPBaseAdminAuthJsonHandler):
|
||||
def post(self):
|
||||
args = self.get_argument('args', None)
|
||||
# print('args', args)
|
||||
if args is not None:
|
||||
args = json.loads(args)
|
||||
else:
|
||||
self.write_json(-1)
|
||||
return
|
||||
|
||||
# print(args)
|
||||
|
||||
cmd = args['cmd']
|
||||
if cmd == 'create_db':
|
||||
if not get_db().need_create:
|
||||
|
@ -176,7 +172,6 @@ class RpcHandler(TPBaseAdminAuthJsonHandler):
|
|||
return self.write_json(0, data={"task_id": task_id})
|
||||
|
||||
elif cmd == 'get_task_ret':
|
||||
# return self.write_json(-1)
|
||||
r = thread_mgr.get_task(args['tid'])
|
||||
if r is None:
|
||||
return self.write_json(0, data={'running': False, 'steps': []})
|
||||
|
|
|
@ -51,6 +51,8 @@ def get_all_host_info_list(_filter, order, limit, with_pwd=False):
|
|||
'{};'.format(db.table_prefix, db.table_prefix, _where)
|
||||
|
||||
db_ret = db.query(sql)
|
||||
if db_ret is None:
|
||||
return 0, list()
|
||||
total_count = db_ret[0][0]
|
||||
|
||||
# 修正分页数据
|
||||
|
@ -88,7 +90,7 @@ def get_all_host_info_list(_filter, order, limit, with_pwd=False):
|
|||
|
||||
db_ret = db.query(sql)
|
||||
if db_ret is None:
|
||||
return 0, None
|
||||
return 0, list()
|
||||
|
||||
ret = list()
|
||||
for item in db_ret:
|
||||
|
@ -310,9 +312,11 @@ def get_cert_list():
|
|||
sql = 'SELECT {} FROM `{}key` AS a;'.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix)
|
||||
db_ret = db.query(sql)
|
||||
|
||||
if db_ret is None:
|
||||
return None
|
||||
ret = list()
|
||||
|
||||
if db_ret is None:
|
||||
return ret
|
||||
|
||||
for item in db_ret:
|
||||
x = DbItem()
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
var g_assist = null;
|
||||
var g_host_table = null;
|
||||
var g_cert_list = {};
|
||||
var g_group_list = {};
|
||||
var g_cert_list = [];
|
||||
var g_group_list = [];
|
||||
var g_dlg_edit_host = null;
|
||||
var g_dlg_edit_host_user = null;
|
||||
var g_dlg_sys_user = null;
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
/**
|
||||
* Created by mi on 2016/7/4.
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
ywl.on_init = function (cb_stack, cb_args) {
|
||||
var dom_id = '#ywl_log_list';
|
||||
|
@ -36,7 +34,6 @@ ywl.on_init = function (cb_stack, cb_args) {
|
|||
fields: {id: 'id'}
|
||||
},
|
||||
{title: "ID", key: "id"},
|
||||
// {title: "Session", key: "session_id"},
|
||||
{title: "操作者", key: "account_name"},
|
||||
{title: "系统用户", key: "user_name"},
|
||||
{title: "协议", key: "protocol", render: 'protocol', fields: {protocol: 'protocol'}},
|
||||
|
@ -51,7 +48,7 @@ ywl.on_init = function (cb_stack, cb_args) {
|
|||
width: 160,
|
||||
header_align: 'left', cell_align: 'left',
|
||||
render: 'make_action_btn',
|
||||
fields: {ID: 'id', sys_type: 'sys_type', cost_time: 'cost_time', protocol: 'protocol'}
|
||||
fields: {ID: 'id', ret_code:'ret_code', sys_type: 'sys_type', cost_time: 'cost_time', protocol: 'protocol'}
|
||||
}
|
||||
],
|
||||
paging: {selector: dom_id + " [ywl-paging='log-list']", per_page: paging_normal},
|
||||
|
@ -164,16 +161,14 @@ ywl.on_host_table_created = function (tbl) {
|
|||
//ywl.update_add_to_batch_btn();
|
||||
});
|
||||
|
||||
} else if (col_key == 'action') {
|
||||
} else if (col_key === 'action') {
|
||||
var row_data = tbl.get_row(row_id);
|
||||
//console.log('row_data', row_data);
|
||||
|
||||
var protocol = parseInt(row_data.protocol);
|
||||
|
||||
if (protocol == 1) {
|
||||
if (protocol === PROTOCOL_TYPE_RDP) {
|
||||
$(cell_obj).find('[ywl-btn-record]').click(function () {
|
||||
var ip = window.location.hostname;//ywl.page_options.ts_server.ip;
|
||||
var port = parseInt(window.location.port);//ywl.page_options.ts_server.port;
|
||||
var ip = window.location.hostname;
|
||||
var port = parseInt(window.location.port);
|
||||
var url = 'http://' + ip + ':' + port + '/log/replay/rdp/' + row_data.id;
|
||||
var tail = 'log/replay/rdp/' + prefixInteger(row_data.id, 6);
|
||||
var args = {};
|
||||
|
@ -187,7 +182,7 @@ ywl.on_host_table_created = function (tbl) {
|
|||
ywl.notify_success('RDP 录像播放器成功启动!');
|
||||
},
|
||||
function (code, msg) {
|
||||
if (code == TPE_NO_ASSIST)
|
||||
if (code === TPE_NO_ASSIST)
|
||||
g_assist.alert_assist_not_found();
|
||||
else {
|
||||
ywl.notify_error(msg);
|
||||
|
@ -196,7 +191,7 @@ ywl.on_host_table_created = function (tbl) {
|
|||
});
|
||||
});
|
||||
}
|
||||
else if (protocol == 2) {
|
||||
else if (protocol === PROTOCOL_TYPE_SSH) {
|
||||
$(cell_obj).find('[ywl-btn-record]').click(function () {
|
||||
window.open('/log/record/' + parseInt(row_data.protocol) + '/' + row_data.id);
|
||||
});
|
||||
|
@ -214,8 +209,8 @@ ywl.on_host_table_created = function (tbl) {
|
|||
var msg = '';
|
||||
switch (fields.ret_code) {
|
||||
case 0:
|
||||
// return '<span class="badge badge-warning">正在使用中</span>'
|
||||
return '-';
|
||||
return '<span class="badge badge-warning">使用中</span>'
|
||||
// return '-';
|
||||
case 9999:
|
||||
return '<span class="badge badge-success">成功</span>';
|
||||
case 1:
|
||||
|
@ -261,7 +256,7 @@ ywl.on_host_table_created = function (tbl) {
|
|||
|
||||
render.cost_time = function (row_id, fields) {
|
||||
if (fields.ret_code == 0) {
|
||||
return '<span class="badge badge-warning">正在使用中</span>';
|
||||
return '<span class="badge badge-warning">使用中</span>';
|
||||
} else {
|
||||
return '<span class="badge badge-success">' + second2str(fields.cost_time) + '</span>';
|
||||
}
|
||||
|
@ -302,19 +297,17 @@ ywl.on_host_table_created = function (tbl) {
|
|||
|
||||
render.make_action_btn = function (row_id, fields) {
|
||||
var ret = [];
|
||||
if (fields.protocol == 1) {
|
||||
if (fields.protocol === PROTOCOL_TYPE_RDP) {
|
||||
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" protocol=' + fields.protocol + ' ywl-btn-record="' + fields.ID + '">录像查看</a> ');
|
||||
} else if (fields.protocol == 2) {
|
||||
if (fields.cost_time > 0) {
|
||||
} else if (fields.protocol === PROTOCOL_TYPE_SSH) {
|
||||
if (fields.ret_code === 9999 && fields.cost_time > 0) {
|
||||
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" protocol=' + fields.protocol + ' ywl-btn-record="' + fields.ID + '">录像查看</a> ');
|
||||
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" protocol=' + fields.protocol + ' ywl-btn-log="' + fields.ID + '">日志查看</a> ');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret.join('');
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -378,7 +371,6 @@ ywl.create_table_filter_user_list = function (tbl, selector, on_created) {
|
|||
_tblf_st._on_select = function () {
|
||||
var user_name = $(this).html();
|
||||
|
||||
|
||||
var cb_stack = CALLBACK_STACK.create();
|
||||
cb_stack
|
||||
.add(_tblf_st._table_ctrl.load_data)
|
||||
|
@ -392,4 +384,3 @@ ywl.create_table_filter_user_list = function (tbl, selector, on_created) {
|
|||
|
||||
return _tblf_st;
|
||||
};
|
||||
|
||||
|
|
|
@ -68,6 +68,11 @@
|
|||
<div id="steps-detail" class="steps-detail"></div>
|
||||
</div>
|
||||
|
||||
<div id="step2" style="display:none;">
|
||||
<hr/>
|
||||
<h2>已完成!</h2>
|
||||
<p>是的,没有第二步了,安装配置已经完成了!刷新页面即可进入Teleport主界面啦~~</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
@ -157,6 +162,7 @@
|
|||
|
||||
|
||||
if (!ret.data.running) {
|
||||
$('#step2').show('fast');
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue