操作出错时,页面显示更详细的错误信息,方便定位问题。

pull/32/head
Apex Liu 2017-04-29 21:32:53 +08:00
parent 3c3703d9a9
commit 1b9cf00c4d
15 changed files with 4823 additions and 4832 deletions

View File

@ -133,12 +133,12 @@ class ModifyPwd(TPBaseUserAuthJsonHandler):
if args is not None: if args is not None:
args = json.loads(args) args = json.loads(args)
else: else:
return self.write_json(-11, '参数错误') return self.write_json(-1, '参数错误')
_old_pwd = args['o_pwd'] _old_pwd = args['o_pwd']
_new_pwd = args['n_pwd'] _new_pwd = args['n_pwd']
if _old_pwd is None or _new_pwd is None: if _old_pwd is None or _new_pwd is None:
return self.write_json(-12, '参数错误') return self.write_json(-2, '参数错误')
user_info = self.get_current_user() user_info = self.get_current_user()
try: try:
@ -146,7 +146,7 @@ class ModifyPwd(TPBaseUserAuthJsonHandler):
if 0 == ret: if 0 == ret:
return self.write_json(0) return self.write_json(0)
else: else:
return self.write_json(-14, '数据库操作错误errcode{}'.format(ret)) return self.write_json(ret)
except: except:
log.e('modify password failed.') log.e('modify password failed.')
return self.write_json(-13, '发生异常') return self.write_json(-4, '发生异常')

View File

@ -306,6 +306,9 @@ class AddHost(TPBaseUserAuthJsonHandler):
ret = host.add_host(args) ret = host.add_host(args)
if ret > 0: if ret > 0:
return self.write_json(0) return self.write_json(0)
else:
if ret == -100:
return self.write_json(-100, '')
else: else:
return self.write_json(-2, '数据库操作失败errcode:{}'.format(ret)) return self.write_json(-2, '数据库操作失败errcode:{}'.format(ret))
except: except:
@ -484,10 +487,13 @@ class DeleteCert(TPBaseUserAuthJsonHandler):
if ret: if ret:
return self.write_json(0) return self.write_json(0)
else: else:
return self.write_json(-2, '数据库操作失败errcode:{}'.format(ret)) if ret == -2:
return self.write_json(-2, '')
else:
return self.write_json(-3, '数据库操作失败errcode:{}'.format(ret))
except: except:
log.e('add cert failed.\n') log.e('add cert failed.\n')
return self.write_json(-3, '发生异常') return self.write_json(-4, '发生异常')
class UpdateCert(TPBaseUserAuthJsonHandler): class UpdateCert(TPBaseUserAuthJsonHandler):
@ -521,7 +527,6 @@ class UpdateCert(TPBaseUserAuthJsonHandler):
return self.write_json(0) return self.write_json(0)
else: else:
return self.write_json(-4, '数据库操作失败errcode:{}'.format(ret)) return self.write_json(-4, '数据库操作失败errcode:{}'.format(ret))
return
except: except:
log.e('update cert failed.\n') log.e('update cert failed.\n')
return self.write_json(-5, '发生异常') return self.write_json(-5, '发生异常')
@ -582,10 +587,13 @@ class DeleteGroup(TPBaseUserAuthJsonHandler):
if ret == 0: if ret == 0:
return self.write_json(0) return self.write_json(0)
else: else:
return self.write_json(-2, '数据库操作失败errcode:{}'.format(ret)) if ret == -2:
return self.write_json(-2, '')
else:
return self.write_json(-3, '数据库操作失败errcode:{}'.format(ret))
except: except:
log.e('delete group failed.\n') log.e('delete group failed.\n')
return self.write_json(-3, '发生异常') return self.write_json(-4, '发生异常')
class AddHostToGroup(TPBaseUserAuthJsonHandler): class AddHostToGroup(TPBaseUserAuthJsonHandler):

View File

@ -96,7 +96,7 @@ class AddUser(TPBaseUserAuthJsonHandler):
if 0 == ret: if 0 == ret:
return self.write_json(0) return self.write_json(0)
else: else:
return self.write_json(-2, 'database op failed. errcode={}'.format(ret)) return self.write_json(ret, 'database op failed. errcode={}'.format(ret))
except: except:
log.e('add user failed.\n') log.e('add user failed.\n')
return self.write_json(-3, 'got exception.') return self.write_json(-3, 'got exception.')

View File

@ -50,12 +50,12 @@ def modify_pwd(old_pwd, new_pwd, user_id):
sql = 'SELECT `account_pwd` FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id)) sql = 'SELECT `account_pwd` FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
db_ret = db.query(sql) db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 1: if db_ret is None or len(db_ret) != 1:
return -2 return -100
if not sec_verify_password(old_pwd, db_ret[0][0]): if not sec_verify_password(old_pwd, db_ret[0][0]):
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下 # 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
if db_ret[0][0] != hashlib.sha256(old_pwd.encode()).hexdigest(): if db_ret[0][0] != hashlib.sha256(old_pwd.encode()).hexdigest():
return -2 return -101
_new_sec_password = sec_generate_password(new_pwd) _new_sec_password = sec_generate_password(new_pwd)
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id)) sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id))
@ -63,7 +63,7 @@ def modify_pwd(old_pwd, new_pwd, user_id):
if db_ret: if db_ret:
return 0 return 0
else: else:
return -3 return -102
def get_user_list(with_admin=False): def get_user_list(with_admin=False):
@ -126,7 +126,7 @@ def add_user(user_name, user_pwd, user_desc):
sql = 'SELECT `account_id` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, user_name) sql = 'SELECT `account_id` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, user_name)
db_ret = db.query(sql) db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 0: if db_ret is None or len(db_ret) != 0:
return -2 return -100
sec_password = sec_generate_password(user_pwd) sec_password = sec_generate_password(user_pwd)
sql = 'INSERT INTO `{}account` (`account_type`, `account_name`, `account_pwd`, `account_status`,' \ sql = 'INSERT INTO `{}account` (`account_type`, `account_name`, `account_pwd`, `account_status`,' \
@ -134,7 +134,7 @@ def add_user(user_name, user_pwd, user_desc):
ret = db.exec(sql) ret = db.exec(sql)
if ret: if ret:
return 0 return 0
return -3 return -101
def alloc_host(user_name, host_list): def alloc_host(user_name, host_list):

View File

@ -209,8 +209,12 @@ ywl.on_init = function (cb_stack, cb_args) {
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, ywl.ajax_post_json('/host/delete-host', {host_list: host_list},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
g_host_table.reload(); g_host_table.reload();
ywl.notify_success('删除主机操作成功!'); ywl.notify_success('删除主机操作成功!');
} else {
ywl.notify_error('删除主机操作失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('网络故障,删除主机操作失败!'); ywl.notify_error('网络故障,删除主机操作失败!');
@ -344,12 +348,16 @@ ywl.on_host_table_created = function (tbl) {
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/lock-host', {host_id: host_id, lock: host_lock}, ywl.ajax_post_json('/host/lock-host', {host_id: host_id, lock: host_lock},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
var update_args = {host_lock: host_lock}; var update_args = {host_lock: host_lock};
tbl.update_row(row_id, update_args); tbl.update_row(row_id, update_args);
ywl.notify_success('操作成功'); ywl.notify_success('锁定主机操作成功!');
} else {
ywl.notify_error('锁定主机操作失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('操作失败'); ywl.notify_error('网络故障,锁定主机操作失败');
} }
); );
}; };
@ -370,11 +378,15 @@ ywl.on_host_table_created = function (tbl) {
host_list.push(host_id); host_list.push(host_id);
ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, ywl.ajax_post_json('/host/delete-host', {host_list: host_list},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
tbl.remove_row(row_id); tbl.remove_row(row_id);
ywl.notify_success('操作成功'); ywl.notify_success('删除主机操作成功!');
} else {
ywl.notify_error('删除主机操作失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('操作失败'); ywl.notify_error('网络故障,删除主机操作失败');
} }
); );
}; };
@ -802,6 +814,7 @@ ywl.create_host_edit_dlg = function (tbl) {
}; };
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: args}, ywl.ajax_post_json('/host/update', {host_id: host_id, kv: args},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
var update_args = { var update_args = {
host_ip: dlg_edit_host.ip, host_ip: dlg_edit_host.ip,
group_name: dlg_edit_host.group_name, group_name: dlg_edit_host.group_name,
@ -813,11 +826,14 @@ ywl.create_host_edit_dlg = function (tbl) {
}; };
dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args); dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args);
ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 的认证信息已保存!'); ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已保存!');
dlg_edit_host.hide(); dlg_edit_host.hide();
} else {
ywl.notify_error('主机 ' + self.host_ip + ' 信息更新失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('主机 ' + self.host_ip + ' 更新失败!', ''); ywl.notify_error('网络故障,主机 ' + self.host_ip + ' 信息更新失败!');
} }
); );
}; };
@ -837,22 +853,22 @@ ywl.create_host_edit_dlg = function (tbl) {
ywl.ajax_post_json('/host/add-host', args, ywl.ajax_post_json('/host/add-host', args,
function (ret) { function (ret) {
if (ret.code === 0) { if (ret.code === TPE_OK) {
dlg_edit_host.tbl.reload(); dlg_edit_host.tbl.reload();
ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已添加!'); ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已添加!');
dlg_edit_host.hide(); dlg_edit_host.hide();
} }
else { else {
if (ret.code === -100) { if (ret.code === -100) {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已经添加,请不要重复添加主机!', ''); ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已存在,请不要重复添加主机!');
} else { } else {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.code, ''); ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.message);
} }
} }
}, },
function () { function () {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!', ''); ywl.notify_error('网络故障,主机 ' + dlg_edit_host.ip + ' 信息保存失败!', '');
} }
); );
}; };
@ -895,9 +911,15 @@ ywl.create_host_user_edit_dlg = function (tbl) {
html.push('</li></ul></div>'); html.push('</li></ul></div>');
return html.join(''); return html.join('');
}; };
dlg_user_edit_host.sync_user_info = function (host_id) { dlg_user_edit_host.sync_user_info = function (host_id) {
ywl.ajax_post_json('/host/sys-user/list', {host_id: host_id}, ywl.ajax_post_json('/host/sys-user/list', {host_id: host_id},
function (ret) { function (ret) {
if (ret.code !== TPE_OK) {
ywl.notify_error('获取主机用户列表失败:' + ret.message);
return;
}
var data = ret.data; var data = ret.data;
dlg_user_edit_host.auth_list = data; dlg_user_edit_host.auth_list = data;
@ -951,18 +973,15 @@ ywl.create_host_user_edit_dlg = function (tbl) {
var host_auth_id = parseInt($(this).attr("auth-id")); var host_auth_id = parseInt($(this).attr("auth-id"));
ywl.ajax_post_json('/host/sys-user/delete', {host_auth_id: host_auth_id}, ywl.ajax_post_json('/host/sys-user/delete', {host_auth_id: host_auth_id},
function (ret) { function (ret) {
//console.log("ret,", ret);
if (ret.code === TPE_OK) { if (ret.code === TPE_OK) {
ywl.notify_success('系统用户删除成功'); ywl.notify_success('系统用户删除成功!');
// var host_id = parseInt(dlg_user_edit_host.host_id);
g_dlg_edit_host_user.sync_user_info(host_id); g_dlg_edit_host_user.sync_user_info(host_id);
} else { } else {
ywl.notify_error('系统用户删除失败' + ret.code); ywl.notify_error('系统用户删除失败' + ret.message);
} }
}, },
function () { function () {
ywl.notify_error('系统用户删除失败!'); ywl.notify_error('网络故障:系统用户删除失败!');
} }
); );
}); });
@ -1349,21 +1368,19 @@ ywl.create_sys_user = function (tbl) {
cert_id: cert_id, cert_id: cert_id,
user_param: dlg_sys_user.user_param user_param: dlg_sys_user.user_param
}; };
//console.log("args:", args);
ywl.ajax_post_json('/host/sys-user/update', {host_auth_id: host_auth_id, kv: args}, ywl.ajax_post_json('/host/sys-user/update', {host_auth_id: host_auth_id, kv: args},
function (ret) { function (ret) {
//console.log("ret,", ret); if (ret.code === TPE_OK) {
if (ret.code === 0) { ywl.notify_success('系统用户信息更新成功!');
ywl.notify_success('系统用户信息更新成功');
g_dlg_edit_host_user.sync_user_info(host_id); g_dlg_edit_host_user.sync_user_info(host_id);
dlg_sys_user.hide(); dlg_sys_user.hide();
} else { } else {
ywl.notify_error('系统用户信息更新失败' + ret.code); ywl.notify_error('系统用户信息更新失败' + ret.message);
} }
}, },
function () { function () {
ywl.notify_error('系统用户信息更新失败'); ywl.notify_error('网络故障,系统用户信息更新失败');
} }
); );
}; };
@ -1394,15 +1411,15 @@ ywl.create_sys_user = function (tbl) {
ywl.ajax_post_json('/host/sys-user/add', args, ywl.ajax_post_json('/host/sys-user/add', args,
function (ret) { function (ret) {
if (ret.code === TPE_OK) { if (ret.code === TPE_OK) {
ywl.notify_success('系统用户添加成功'); ywl.notify_success('系统用户添加成功');
g_dlg_edit_host_user.sync_user_info(host_id); g_dlg_edit_host_user.sync_user_info(host_id);
dlg_sys_user.hide(); dlg_sys_user.hide();
} else { } else {
ywl.notify_error('系统用户添加失败' + ret.code); ywl.notify_error('系统用户添加失败' + ret.message);
} }
}, },
function () { function () {
ywl.notify_error('系统用户信息更新失败'); ywl.notify_error('网络故障,系统用户信息更新失败');
} }
); );
}; };
@ -1461,17 +1478,21 @@ ywl.create_batch_join_group_dlg = function (tbl) {
ywl.ajax_post_json('/host/add-host-to-group', {host_list: data_list, group_id: group_id}, ywl.ajax_post_json('/host/add-host-to-group', {host_list: data_list, group_id: group_id},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
var update_args = {group_name: group_name}; var update_args = {group_name: group_name};
for (var i = 0; i < batch_join_dlg.host_list.length; i++) { for (var i = 0; i < batch_join_dlg.host_list.length; i++) {
var row_id = batch_join_dlg.host_list[i].row_id; var row_id = batch_join_dlg.host_list[i].row_id;
batch_join_dlg.tbl.update_row(row_id, update_args); batch_join_dlg.tbl.update_row(row_id, update_args);
} }
ywl.notify_success("成功设定分组信息!"); ywl.notify_success("成功设定主机分组信息!");
batch_join_dlg.hide(); batch_join_dlg.hide();
} else {
ywl.notify_error("设定主机分组信息失败:" + ret.message);
}
}, },
function () { function () {
ywl.notify_error("设定分组信息失败!"); ywl.notify_error("网络故障,设定主机分组信息失败!");
} }
); );
}; };

View File

@ -1,13 +1,13 @@
/*! ywl v1.0.1, (c)2015 eomsoft.net */
"use strict"; "use strict";
var OS_TYPE_WINDOWS = 1; //var OS_TYPE_WINDOWS = 1;
var OS_TYPE_LINUX = 2; //var OS_TYPE_LINUX = 2;
var PROTOCOL_TYPE_RDP = 1; //var PROTOCOL_TYPE_RDP = 1;
var PROTOCOL_TYPE_SSH = 2; //var PROTOCOL_TYPE_SSH = 2;
var PROTOCOL_TYPE_TELNET = 3; //var PROTOCOL_TYPE_TELNET = 3;
var AUTH_TYPE_PASSWORD = 1; //var AUTH_TYPE_PASSWORD = 1;
var AUTH_TYPE_SSHKEY = 2; //var AUTH_TYPE_SSHKEY = 2;
var AUTH_NONE = 0; //var AUTH_NONE = 0;
var g_cert_list = {}; var g_cert_list = {};
var g_group_list = {}; var g_group_list = {};
var g_user_host_list = null; var g_user_host_list = null;
@ -108,7 +108,7 @@ ywl.create_host_table = function (cb_stack, cb_args) {
var host_auth_id = parseInt($(_user_objs).attr('user-check-box')); var host_auth_id = parseInt($(_user_objs).attr('user-check-box'));
// var data = {host_id: _row_data.host_id, row_id: _row_data.ywl_row_id}; // var data = {host_id: _row_data.host_id, row_id: _row_data.ywl_row_id};
if (typeof(user_dict[_row_data.ywl_row_id]) == "undefined") { if (typeof(user_dict[_row_data.ywl_row_id]) === "undefined") {
user_dict[_row_data.ywl_row_id] = []; user_dict[_row_data.ywl_row_id] = [];
} }
user_dict[_row_data.ywl_row_id].push(host_auth_id); user_dict[_row_data.ywl_row_id].push(host_auth_id);
@ -122,7 +122,7 @@ ywl.create_host_table = function (cb_stack, cb_args) {
var host_id = host_list[i].host_id; var host_id = host_list[i].host_id;
var row_id = host_list[i].row_id; var row_id = host_list[i].row_id;
var host_auth_list = user_dict[row_id]; var host_auth_list = user_dict[row_id];
if (typeof(host_auth_list) == "undefined") { if (typeof(host_auth_list) === "undefined") {
continue; continue;
} }
args[host_id] = host_auth_list; args[host_id] = host_auth_list;
@ -136,11 +136,15 @@ ywl.create_host_table = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/alloc-host-user', {host_list: args, user_name: ywl.page_options.user_name}, ywl.ajax_post_json('/user/alloc-host-user', {host_list: args, user_name: ywl.page_options.user_name},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
g_user_host_list.reload(); g_user_host_list.reload();
ywl.notify_success("主机授权操作成功!"); ywl.notify_success("主机授权操作成功!");
} else {
ywl.notify_error("主机授权操作失败:" + ret.message);
}
}, },
function () { function () {
ywl.notify_error("主机授权操作时发生错误!"); ywl.notify_error("网络故障,主机授权操作失败");
} }
); );
}); });
@ -249,11 +253,15 @@ ywl.create_user_host_table = function (cb_stack, cb_args) {
host_list.push(host_id); host_list.push(host_id);
ywl.ajax_post_json('/user/delete-host', {host_list: host_list, user_name: ywl.page_options.user_name}, ywl.ajax_post_json('/user/delete-host', {host_list: host_list, user_name: ywl.page_options.user_name},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
g_user_host_list.reload(); g_user_host_list.reload();
ywl.notify_success('成功回收主机授权!'); ywl.notify_success('成功回收主机授权!');
} else {
ywl.notify_error('回收主机授权失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('回收主机授权时发生错误!'); ywl.notify_error('网络故障,回收主机授权失败');
} }
); );
}; };
@ -283,7 +291,7 @@ ywl.create_user_host_table = function (cb_stack, cb_args) {
ywl.on_host_table_created = function (tbl) { ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) { tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'select_all') { if (col_key === 'select_all') {
// 选择 // 选择
$('#host-select-' + row_id).click(function () { $('#host-select-' + row_id).click(function () {
console.log('host-sel'); console.log('host-sel');
@ -310,14 +318,14 @@ ywl.on_host_table_created = function (tbl) {
//ywl.update_add_to_batch_btn(); //ywl.update_add_to_batch_btn();
}); });
} else if (col_key == 'host_id') { } else if (col_key === 'host_id') {
// 为主机描述绑定点击事件 // 为主机描述绑定点击事件
var _link = $(cell_obj).find(" [ywl-host-desc]"); var _link = $(cell_obj).find(" [ywl-host-desc]");
_link.click(function () { _link.click(function () {
var row_data = tbl.get_row(row_id); var row_data = tbl.get_row(row_id);
ywl.create_dlg_modify_host_desc(tbl, row_data.ywl_row_id, row_data.host_id, row_data.host_ip, row_data.host_desc).show(_link); ywl.create_dlg_modify_host_desc(tbl, row_data.ywl_row_id, row_data.host_id, row_data.host_ip, row_data.host_desc).show(_link);
}); });
} else if (col_key == 'auth_list') { } else if (col_key === 'auth_list') {
$('#user-check-box-row-' + row_id).click(function () { $('#user-check-box-row-' + row_id).click(function () {
var _checked = false; var _checked = false;
var _objs = $(this).parent().parent().parent().parent().find('[user-check-box]'); var _objs = $(this).parent().parent().parent().parent().find('[user-check-box]');
@ -334,7 +342,6 @@ ywl.on_host_table_created = function (tbl) {
} else { } else {
select.prop('checked', false); select.prop('checked', false);
} }
console.log("xxxxxxx");
}); });
} }
}; };
@ -348,7 +355,7 @@ ywl.on_host_table_created = function (tbl) {
var protocol = fields.protocol; var protocol = fields.protocol;
var ret = []; var ret = [];
if (auth_list.length == 0) { if (auth_list.length === 0) {
ret.push('<span class="badge badge-danger">尚未添加系统用户</span>'); ret.push('<span class="badge badge-danger">尚未添加系统用户</span>');
return ret.join(''); return ret.join('');
} }
@ -356,45 +363,45 @@ ywl.on_host_table_created = function (tbl) {
for (var i = 0; i < auth_list.length; i++) { for (var i = 0; i < auth_list.length; i++) {
var auth = auth_list[i]; var auth = auth_list[i];
ret.push('<div class="remote-action-group">'); ret.push('<div class="remote-action-group">');
if (protocol == PROTOCOL_TYPE_RDP) { if (protocol === PROTOCOL_TYPE_RDP) {
ret.push('<ul>'); ret.push('<ul>');
ret.push('<li class="remote-action-chk-protocol"><input type="checkbox" id=user-check-box-row-' + parseInt(row_id) + ' user-check-box=' + auth.host_auth_id + '"> RDP</label></li>'); ret.push('<li class="remote-action-chk-protocol"><input type="checkbox" id=user-check-box-row-' + parseInt(row_id) + ' user-check-box=' + auth.host_auth_id + '"> RDP</label></li>');
ret.push('<li class="remote-action-username">' + auth.user_name + '</li>'); ret.push('<li class="remote-action-username">' + auth.user_name + '</li>');
if (auth.auth_mode == AUTH_TYPE_PASSWORD) { if (auth.auth_mode === AUTH_TYPE_PASSWORD) {
ret.push('<li class="remote-action-password">密码</li>'); ret.push('<li class="remote-action-password">密码</li>');
} else if (auth.auth_mode == AUTH_TYPE_SSHKEY) { } else if (auth.auth_mode === AUTH_TYPE_SSHKEY) {
ret.push('<li class="remote-action-sshkey">私钥</li>'); ret.push('<li class="remote-action-sshkey">私钥</li>');
} else if (auth.auth_mode == AUTH_NONE) { } else if (auth.auth_mode === AUTH_NONE) {
ret.push('<li class="remote-action-noauth">无</li>'); ret.push('<li class="remote-action-noauth">无</li>');
} else { } else {
ret.push('<li class="remote-action-noauth">未知</li>'); ret.push('<li class="remote-action-noauth">未知</li>');
} }
ret.push('</ul>'); ret.push('</ul>');
} else if (protocol == PROTOCOL_TYPE_SSH) { } else if (protocol === PROTOCOL_TYPE_SSH) {
ret.push('<ul>'); ret.push('<ul>');
ret.push('<li class="remote-action-chk-protocol"><input type="checkbox" id=user-check-box-row-' + parseInt(row_id) + ' user-check-box=' + auth.host_auth_id + '"> SSH</label></li>'); ret.push('<li class="remote-action-chk-protocol"><input type="checkbox" id=user-check-box-row-' + parseInt(row_id) + ' user-check-box=' + auth.host_auth_id + '"> SSH</label></li>');
ret.push('<li class="remote-action-username">' + auth.user_name + '</li>'); ret.push('<li class="remote-action-username">' + auth.user_name + '</li>');
if (auth.auth_mode == AUTH_TYPE_PASSWORD) { if (auth.auth_mode === AUTH_TYPE_PASSWORD) {
ret.push('<li class="remote-action-password">密码</li>'); ret.push('<li class="remote-action-password">密码</li>');
} else if (auth.auth_mode == AUTH_TYPE_SSHKEY) { } else if (auth.auth_mode === AUTH_TYPE_SSHKEY) {
ret.push('<li class="remote-action-sshkey">私钥</li>'); ret.push('<li class="remote-action-sshkey">私钥</li>');
} else if (auth.auth_mode == AUTH_NONE) { } else if (auth.auth_mode === AUTH_NONE) {
ret.push('<li class="remote-action-noauth">无</li>'); ret.push('<li class="remote-action-noauth">无</li>');
} else { } else {
ret.push('<li class="remote-action-noauth">未知</li>'); ret.push('<li class="remote-action-noauth">未知</li>');
} }
ret.push('</ul>'); ret.push('</ul>');
} else if (protocol == PROTOCOL_TYPE_TELNET) { } else if (protocol === PROTOCOL_TYPE_TELNET) {
ret.push('<ul>'); ret.push('<ul>');
ret.push('<li class="remote-action-chk-protocol"><input type="checkbox" id=user-check-box-row-' + parseInt(row_id) + ' user-check-box=' + auth.host_auth_id + '"> TELNET</label></li>'); ret.push('<li class="remote-action-chk-protocol"><input type="checkbox" id=user-check-box-row-' + parseInt(row_id) + ' user-check-box=' + auth.host_auth_id + '"> TELNET</label></li>');
ret.push('<li class="remote-action-username">' + auth.user_name + '</li>'); ret.push('<li class="remote-action-username">' + auth.user_name + '</li>');
if (auth.auth_mode == AUTH_TYPE_PASSWORD) { if (auth.auth_mode === AUTH_TYPE_PASSWORD) {
ret.push('<li class="remote-action-password">密码</li>'); ret.push('<li class="remote-action-password">密码</li>');
} else if (auth.auth_mode == AUTH_TYPE_SSHKEY) { } else if (auth.auth_mode === AUTH_TYPE_SSHKEY) {
ret.push('<li class="remote-action-sshkey">私钥</li>'); ret.push('<li class="remote-action-sshkey">私钥</li>');
} else if (auth.auth_mode == AUTH_NONE) { } else if (auth.auth_mode === AUTH_NONE) {
ret.push('<li class="remote-action-noauth">无</li>'); ret.push('<li class="remote-action-noauth">无</li>');
} else { } else {
ret.push('<li class="remote-action-noauth">未知</li>'); ret.push('<li class="remote-action-noauth">未知</li>');
@ -483,7 +490,7 @@ ywl.on_user_host_table_header_created = function (tbl) {
ywl.on_user_host_table_created = function (tbl) { ywl.on_user_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) { tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'select_all') { if (col_key === 'select_all') {
// 选择 // 选择
$('#user-host-select-' + row_id).click(function () { $('#user-host-select-' + row_id).click(function () {
var _all_checked = true; var _all_checked = true;
@ -505,14 +512,14 @@ ywl.on_user_host_table_created = function (tbl) {
//ywl.update_add_to_batch_btn(); //ywl.update_add_to_batch_btn();
}); });
} else if (col_key == 'host_id') { } else if (col_key === 'host_id') {
// 为主机描述绑定点击事件 // 为主机描述绑定点击事件
var _link = $(cell_obj).find(" [ywl-host-desc]"); var _link = $(cell_obj).find(" [ywl-host-desc]");
_link.click(function () { _link.click(function () {
var row_data = tbl.get_row(row_id); var row_data = tbl.get_row(row_id);
ywl.create_dlg_modify_host_desc(tbl, row_data.ywl_row_id, row_data.host_id, row_data.host_ip, row_data.host_desc).show(_link); ywl.create_dlg_modify_host_desc(tbl, row_data.ywl_row_id, row_data.host_id, row_data.host_ip, row_data.host_desc).show(_link);
}); });
} else if (col_key == 'action') { } else if (col_key === 'action') {
var row_data = tbl.get_row(row_id); var row_data = tbl.get_row(row_id);
$(cell_obj).find('[ywl-btn-delete]').click(function () { $(cell_obj).find('[ywl-btn-delete]').click(function () {
var host_id = row_data.host_id; var host_id = row_data.host_id;
@ -521,11 +528,15 @@ ywl.on_user_host_table_created = function (tbl) {
host_list.push(host_id); host_list.push(host_id);
ywl.ajax_post_json('/user/delete-host', {host_list: host_list, user_name: ywl.page_options.user_name}, ywl.ajax_post_json('/user/delete-host', {host_list: host_list, user_name: ywl.page_options.user_name},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
tbl.remove_row(row_id); tbl.remove_row(row_id);
ywl.notify_success('回收授权成功!'); ywl.notify_success('回收授权成功!');
} else {
ywl.notify_error('回收授权失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('回收授权失败!'); ywl.notify_error('网络故障,回收授权失败!');
} }
); );
}; };
@ -537,43 +548,38 @@ ywl.on_user_host_table_created = function (tbl) {
fn_yes: _fn_sure fn_yes: _fn_sure
}); });
}); });
} else if (col_key == 'auth_list') { } else if (col_key === 'auth_list') {
$(cell_obj).find('[data-remove]').click(function () { $(cell_obj).find('[data-remove]').click(function () {
var row_data = tbl.get_row(row_id); var row_data = tbl.get_row(row_id);
var auth_id = parseInt($(this).attr('data-remove')); var auth_id = parseInt($(this).attr('data-remove'));
// var host_id = row_data.host_id;
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
var auth_id_list = []; var auth_id_list = [];
auth_id_list.push(auth_id); auth_id_list.push(auth_id);
ywl.ajax_post_json('/user/delete-host-user', {auth_id_list: auth_id_list, user_name: ywl.page_options.user_name}, ywl.ajax_post_json('/user/delete-host-user', {auth_id_list: auth_id_list, user_name: ywl.page_options.user_name},
function (ret) { function (ret) {
if (ret.code == 0) { if (ret.code === TPE_OK) {
var auth_list = []; var auth_list = [];
for (var i = 0; i < row_data.auth_list.length; i++) { for (var i = 0; i < row_data.auth_list.length; i++) {
var auth = row_data.auth_list[i]; var auth = row_data.auth_list[i];
if (auth.auth_id == auth_id) { if (auth.auth_id !== auth_id) {
continue;
} else {
auth_list.push(auth); auth_list.push(auth);
} }
} }
console.log('auth_list', auth_list);
if (auth_list.length == 0) { if (auth_list.length === 0) {
tbl.remove_row(row_id); tbl.remove_row(row_id);
} else { } else {
tbl.update_row(row_id, {auth_list: auth_list}); tbl.update_row(row_id, {auth_list: auth_list});
} }
ywl.notify_success('删除成功'); ywl.notify_success('回收授权成功!');
} else { } else {
ywl.notify_error('删除成功失败' + ret.code); ywl.notify_error('回收授权失败:' + ret.message);
} }
console.log('row_data', row_data);
// tbl.remove_row(row_id);
}, },
function () { function () {
ywl.notify_error('删除成功失败'); ywl.notify_error('网络故障,回收授权失败!');
} }
); );
}; };
@ -595,7 +601,7 @@ ywl.on_user_host_table_created = function (tbl) {
var protocol = fields.protocol; var protocol = fields.protocol;
var ret = []; var ret = [];
if (auth_list.length == 0) { if (auth_list.length === 0) {
ret.push('<span class="badge badge-danger">尚未添加系统用户</span>'); ret.push('<span class="badge badge-danger">尚未添加系统用户</span>');
return ret.join(''); return ret.join('');
} }
@ -609,11 +615,11 @@ ywl.on_user_host_table_created = function (tbl) {
ret.push('<ul>'); ret.push('<ul>');
ret.push('<li class="remote-action-chk-protocol">RDP</li>'); ret.push('<li class="remote-action-chk-protocol">RDP</li>');
ret.push('<li class="remote-action-username">' + auth.user_name + '</li>'); ret.push('<li class="remote-action-username">' + auth.user_name + '</li>');
if (auth.auth_mode == AUTH_TYPE_PASSWORD) { if (auth.auth_mode === AUTH_TYPE_PASSWORD) {
ret.push('<li class="remote-action-password">密码</li>'); ret.push('<li class="remote-action-password">密码</li>');
} else if (auth.auth_mode == AUTH_TYPE_SSHKEY) { } else if (auth.auth_mode === AUTH_TYPE_SSHKEY) {
ret.push('<li class="remote-action-sshkey">私钥</li>'); ret.push('<li class="remote-action-sshkey">私钥</li>');
} else if (auth.auth_mode == AUTH_NONE) { } else if (auth.auth_mode === AUTH_NONE) {
ret.push('<li class="remote-action-noauth">无</li>'); ret.push('<li class="remote-action-noauth">无</li>');
} else { } else {
ret.push('<li class="remote-action-noauth">未知</li>'); ret.push('<li class="remote-action-noauth">未知</li>');
@ -624,11 +630,11 @@ ywl.on_user_host_table_created = function (tbl) {
ret.push('<ul>'); ret.push('<ul>');
ret.push('<li class="remote-action-chk-protocol">SSH</li>'); ret.push('<li class="remote-action-chk-protocol">SSH</li>');
ret.push('<li class="remote-action-username">' + auth.user_name + '</li>'); ret.push('<li class="remote-action-username">' + auth.user_name + '</li>');
if (auth.auth_mode == AUTH_TYPE_PASSWORD) { if (auth.auth_mode === AUTH_TYPE_PASSWORD) {
ret.push('<li class="remote-action-password">密码</li>'); ret.push('<li class="remote-action-password">密码</li>');
} else if (auth.auth_mode == AUTH_TYPE_SSHKEY) { } else if (auth.auth_mode === AUTH_TYPE_SSHKEY) {
ret.push('<li class="remote-action-sshkey">私钥</li>'); ret.push('<li class="remote-action-sshkey">私钥</li>');
} else if (auth.auth_mode == AUTH_NONE) { } else if (auth.auth_mode === AUTH_NONE) {
ret.push('<li class="remote-action-noauth">无</li>'); ret.push('<li class="remote-action-noauth">无</li>');
} else { } else {
ret.push('<li class="remote-action-noauth">未知</li>'); ret.push('<li class="remote-action-noauth">未知</li>');
@ -640,11 +646,11 @@ ywl.on_user_host_table_created = function (tbl) {
ret.push('<ul>'); ret.push('<ul>');
ret.push('<li class="remote-action-chk-protocol">TELENT</li>'); ret.push('<li class="remote-action-chk-protocol">TELENT</li>');
ret.push('<li class="remote-action-username">' + auth.user_name + '</li>'); ret.push('<li class="remote-action-username">' + auth.user_name + '</li>');
if (auth.auth_mode == AUTH_TYPE_PASSWORD) { if (auth.auth_mode === AUTH_TYPE_PASSWORD) {
ret.push('<li class="remote-action-password">密码</li>'); ret.push('<li class="remote-action-password">密码</li>');
} else if (auth.auth_mode == AUTH_TYPE_SSHKEY) { } else if (auth.auth_mode === AUTH_TYPE_SSHKEY) {
ret.push('<li class="remote-action-sshkey">私钥</li>'); ret.push('<li class="remote-action-sshkey">私钥</li>');
} else if (auth.auth_mode == AUTH_NONE) { } else if (auth.auth_mode === AUTH_NONE) {
ret.push('<li class="remote-action-noauth">无</li>'); ret.push('<li class="remote-action-noauth">无</li>');
} else { } else {
ret.push('<li class="remote-action-noauth">未知</li>'); ret.push('<li class="remote-action-noauth">未知</li>');
@ -738,7 +744,6 @@ ywl.create_table_filter_user_name = function (tbl) {
_tblf_st.init = function (cb_stack) { _tblf_st.init = function (cb_stack) {
return; return;
}; };
return _tblf_st; return _tblf_st;

View File

@ -84,16 +84,16 @@ ywl.on_host_table_created = function (tbl) {
function (ret) { function (ret) {
if (ret.code === TPE_OK) { if (ret.code === TPE_OK) {
tbl.remove_row(row_id); tbl.remove_row(row_id);
ywl.notify_success('删除成功!'); ywl.notify_success('密钥删除成功!');
} else if (ret.code === -2) { } else if (ret.code === -2) {
ywl.notify_error('不能删除,有主机使用了此密钥!'); ywl.notify_error('不能删除,有主机使用了此密钥!');
} else { } else {
ywl.notify_error('删除失败!错误代码:'+ret.code); ywl.notify_error('密钥删除失败:' + ret.message);
} }
}, },
function () { function () {
ywl.notify_error('网络通讯失败!'); ywl.notify_error('网络故障,密钥删除失败!');
} }
); );
}; };
@ -200,13 +200,17 @@ ywl.create_cert_info_dlg = function (tbl) {
if (cert_info_dlg.update === 1) { if (cert_info_dlg.update === 1) {
ywl.ajax_post_json('/host/update-cert', {cert_id: cert_info_dlg.cert_id, cert_name: cert_info_dlg.cert_name, cert_pub: cert_info_dlg.cert_pub, cert_pri: cert_info_dlg.cert_pri}, ywl.ajax_post_json('/host/update-cert', {cert_id: cert_info_dlg.cert_id, cert_name: cert_info_dlg.cert_name, cert_pub: cert_info_dlg.cert_pub, cert_pri: cert_info_dlg.cert_pri},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
var update_args = {cert_id: cert_info_dlg.cert_id, cert_name: cert_info_dlg.cert_name}; var update_args = {cert_id: cert_info_dlg.cert_id, cert_name: cert_info_dlg.cert_name};
cert_info_dlg.tbl.update_row(cert_info_dlg.row_id, update_args); cert_info_dlg.tbl.update_row(cert_info_dlg.row_id, update_args);
ywl.notify_success('密钥更新成功!'); ywl.notify_success('密钥更新成功!');
cert_info_dlg.hide(); cert_info_dlg.hide();
} else {
ywl.notify_error('密钥更新失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('密钥更新失败!'); ywl.notify_error('网络故障,密钥更新失败!');
} }
); );
} else { } else {
@ -219,12 +223,12 @@ ywl.create_cert_info_dlg = function (tbl) {
} else if (ret.code === TPE_NO_CORE_SERVER) { } else if (ret.code === TPE_NO_CORE_SERVER) {
ywl.notify_error('错误,没有启动核心服务!'); ywl.notify_error('错误,没有启动核心服务!');
} else { } else {
ywl.notify_error('密钥添加失败code:' + ret.code); ywl.notify_error('密钥添加失败' + ret.message);
} }
}, },
function (ret) { function (ret) {
ywl.notify_error('密钥添加失败!'); ywl.notify_error('网络故障,密钥添加失败!');
} }
); );
} }
@ -237,65 +241,7 @@ ywl.create_cert_info_dlg = function (tbl) {
} }
cert_info_dlg.post(); cert_info_dlg.post();
// if (cert_info_dlg.update == 0) {
// cert_info_dlg.on_get_enc_pri();
// } else {
// if (cert_info_dlg.cert_pri.length > 0)
// cert_info_dlg.on_get_enc_pri();
// else
// cert_info_dlg.post();
// }
}); });
//
// cert_info_dlg.on_get_enc_pri = function () {
// ywl.ajax_post_json('/auth/get-enc-data', {pwd: cert_info_dlg.cert_pri},
// function (ret) {
// var data = ret.data;
// if (data.code == 0) {
//// var temp_password = data.data;
//
// cert_info_dlg.cert_pri = data.data;
//
// cert_info_dlg.post();
//
//
//// $("#dlg-cert-pri").val(temp_password);
//// ywl.notify_success('成功得到私钥加密字符串');
// } else {
// ywl.notify_error('获取加密私钥失败! [' + data.code + ']');
// }
//
// },
// function () {
// ywl.notify_error('获取加密私钥失败');
// }
// );
//
// };
// $(cert_info_dlg.dom_id + " #btn-get-enc-data").click(function () {
// var temp_dlg_cer__pri = $("#temp-dlg-cert-pri").val();
// if (temp_dlg_cer__pri == '') {
// ywl.notify_error('私钥不能为空!');
// return;
// }
// ywl.ajax_post_json('/auth/get-enc-data', {pwd: temp_dlg_cer__pri},
// function (ret) {
// var data = ret.data;
// if (data.code == 0) {
// var temp_password = data.data;
// $("#dlg-cert-pri").val(temp_password);
// ywl.notify_success('成功得到私钥加密字符串');
// } else {
// ywl.notify_error('获取加密私钥失败 ' + data.code);
// }
//
// },
// function () {
// ywl.notify_error('获取加密私钥失败');
// }
// );
// });
return cert_info_dlg return cert_info_dlg
}; };

View File

@ -218,19 +218,23 @@ ywl.create_dlg_modify_host_desc = function (tbl, row_id, host_id, host_ip,host_d
var dlg_dom_id = "[ywl-dlg='modify-host-desc']"; var dlg_dom_id = "[ywl-dlg='modify-host-desc']";
var val = $(dlg_dom_id + " input[ywl-input='desc']").val(); var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val == self.host_desc) { if (val === self.host_desc) {
self._destroy(); self._destroy();
return; return;
} }
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}}, ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
self._table_ctrl.update_row(row_id, {host_desc: val}); self._table_ctrl.update_row(row_id, {host_desc: val});
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!'); ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
} else {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存:' + ret.message);
}
self._destroy(); self._destroy();
}, },
function () { function () {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存!', ''); ywl.notify_error('网络故障,主机 ' + self.host_ip + ' 的描述修改未能成功保存!');
self._destroy(); self._destroy();
} }
); );
@ -321,19 +325,23 @@ ywl.create_dlg_show_rdp_advance = function(row_data) {
var dlg_dom_id = '[data-dlg="show-rdp-advance"]'; var dlg_dom_id = '[data-dlg="show-rdp-advance"]';
var val = $(dlg_dom_id + " input[ywl-input='desc']").val(); var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val == self.host_desc) { if (val === self.host_desc) {
self._destroy(); self._destroy();
return; return;
} }
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}}, ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
self._table_ctrl.update_row(row_id, {host_desc: val}); self._table_ctrl.update_row(row_id, {host_desc: val});
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!'); ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
} else {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存:' + ret.message);
}
self._destroy(); self._destroy();
}, },
function () { function () {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存!', ''); ywl.notify_error('网络故障,主机 ' + self.host_ip + ' 的描述修改未能成功保存!');
self._destroy(); self._destroy();
} }
); );
@ -379,7 +387,6 @@ ywl.create_dlg_show_rdp_advance = function(row_data) {
' </div>', ' </div>',
' <hr style="margin:3px 0;"/><div style="margin-top:10px;text-align:right;">', ' <hr style="margin:3px 0;"/><div style="margin-top:10px;text-align:right;">',
' <a href="javascript:;" class="btn btn-success btn-sm" data-action="ok"><i class="fa fa-check fa-fw"></i> 确定连接</a>', ' <a href="javascript:;" class="btn btn-success btn-sm" data-action="ok"><i class="fa fa-check fa-fw"></i> 确定连接</a>',
' <a href="javascript:;" class="btn btn-default btn-sm" data-actioin="cancel"><i class="fa fa-times fa-fw"></i> 取消</a>', ' <a href="javascript:;" class="btn btn-default btn-sm" data-actioin="cancel"><i class="fa fa-times fa-fw"></i> 取消</a>',

View File

@ -176,21 +176,21 @@ ywl.create_table = function (table_options) {
// 根据数据源的设定加载数据 // 根据数据源的设定加载数据
if (_tbl.options.data_source) { if (_tbl.options.data_source) {
if (_tbl.options.data_source.type == 'none') { if (_tbl.options.data_source.type === 'none') {
// 外部直接调用set_data()方法来设置数据,无需本控件主动获取 // 外部直接调用set_data()方法来设置数据,无需本控件主动获取
} else if (_tbl.options.data_source.type == 'callback') { } else if (_tbl.options.data_source.type === 'callback') {
// 调用一个函数来加载数据 // 调用一个函数来加载数据
//cb_stack.add(self.load_end); //cb_stack.add(self.load_end);
//cb_stack.add(self.set_data); //cb_stack.add(self.set_data);
_tbl.options.data_source.fn(cb_stack, {table: _tbl, filter: _filter, order: _order, limit: _limit}); _tbl.options.data_source.fn(cb_stack, {table: _tbl, filter: _filter, order: _order, limit: _limit});
} else if (_tbl.options.data_source.type == 'ajax-post') { } else if (_tbl.options.data_source.type === 'ajax-post') {
var _url = _tbl.options.data_source.url; var _url = _tbl.options.data_source.url;
ywl.ajax_post_json(_url, {filter: _filter, order: _order, limit: _limit}, ywl.ajax_post_json(_url, {filter: _filter, order: _order, limit: _limit},
function (ret) { function (ret) {
log.d('ajax-return:', ret); log.d('ajax-return:', ret);
if (ret.code != 0) { if (ret.code !== TPE_OK) {
ywl.notify_error(''); ywl.notify_error('');
} else { } else {
//self.total = ret.data.total; //self.total = ret.data.total;

View File

@ -69,7 +69,7 @@ ywl.on_init = function (cb_stack, cb_args) {
ywl.on_host_table_created = function (tbl) { ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) { tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'action') { if (col_key === 'action') {
var row_data = tbl.get_row(row_id); var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data); //console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () { $(cell_obj).find('[ywl-btn-edit]').click(function () {
@ -80,18 +80,18 @@ ywl.on_host_table_created = function (tbl) {
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-group', {group_id: group_id}, ywl.ajax_post_json('/host/delete-group', {group_id: group_id},
function (ret) { function (ret) {
if (ret.code == 0) { if (ret.code === TPE_OK) {
tbl.remove_row(row_id); tbl.remove_row(row_id);
ywl.notify_success('删除分组成功!'); ywl.notify_success('删除分组成功!');
} else if (ret.code == -2) { } else if (ret.code === -2) {
ywl.notify_error('不能删除,此分组中已经包含了主机。如果您一定要删除此分组,请先将此分组中的主机设定为其他分组,然后才能删除'); ywl.notify_error('因为有主机隶属此分组,因此不能删除此分组。请先将此分组中的主机设定为其他分组,然后重试');
} else { } else {
ywl.notify_error('删除分组失败!'); ywl.notify_error('删除分组失败:' + ret.message);
} }
}, },
function (ret) { function () {
ywl.notify_error('删除分组失败!'); ywl.notify_error('网络故障,删除分组失败!');
} }
); );
}; };
@ -166,24 +166,32 @@ ywl.create_group_info_dlg = function (tbl) {
if (group_info_dlg.update == 1) { if (group_info_dlg.update == 1) {
ywl.ajax_post_json('/host/update-group', {group_id: group_info_dlg.group_id, group_name: group_info_dlg.group_name}, ywl.ajax_post_json('/host/update-group', {group_id: group_info_dlg.group_id, group_name: group_info_dlg.group_name},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
var update_args = {id: group_info_dlg.group_id, group_name: group_info_dlg.group_name}; var update_args = {id: group_info_dlg.group_id, group_name: group_info_dlg.group_name};
group_info_dlg.tbl.update_row(group_info_dlg.row_id, update_args); group_info_dlg.tbl.update_row(group_info_dlg.row_id, update_args);
ywl.notify_success('更新分组信息成功!'); ywl.notify_success('更新分组信息成功!');
group_info_dlg.hide(); group_info_dlg.hide();
} else {
ywl.notify_error('更新分组失败:' + ret.message);
}
}, },
function (ret) { function () {
ywl.notify_error('更新分组信息失败!'); ywl.notify_error('网络故障,更新分组信息失败!');
} }
); );
} else { } else {
ywl.ajax_post_json('/host/add-group', {group_name: group_info_dlg.group_name}, ywl.ajax_post_json('/host/add-group', {group_name: group_info_dlg.group_name},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
group_info_dlg.tbl.reload(); group_info_dlg.tbl.reload();
ywl.notify_success('分组创建成功!'); ywl.notify_success('创建分组成功!');
group_info_dlg.hide(); group_info_dlg.hide();
} else {
ywl.notify_error('创建分组失败:' + ret.message);
}
}, },
function (ret) { function () {
ywl.notify_error('分组创建失败!'); ywl.notify_error('网络故障,创建分组失败!');
} }
); );
} }

View File

@ -96,19 +96,24 @@ ywl.on_init = function (cb_stack, cb_args) {
log_list.push(_row_data.id); log_list.push(_row_data.id);
} }
}); });
if (log_list.length === 0) { if (log_list.length === 0) {
ywl.notify_error('请选择要批量删除的日志'); ywl.notify_error('请选择要批量删除的日志');
return; return;
} }
;
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json_time_out('/log/delete-log', {log_list: log_list}, 1000 * 30, ywl.ajax_post_json_time_out('/log/delete-log', {log_list: log_list}, 1000 * 30,
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
host_table.reload(); host_table.reload();
ywl.notify_success('操作成功'); ywl.notify_success('删除日志成功!');
} else {
ywl.notify_error('删除日志失败!');
}
}, },
function () { function () {
ywl.notify_error('操作失败'); ywl.notify_error('网络故障,删除日志失败!');
} }
); );
}; };
@ -139,7 +144,7 @@ ywl.on_host_table_header_created = function (tbl) {
ywl.on_host_table_created = function (tbl) { ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) { tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'select_all') { if (col_key === 'select_all') {
// 选择 // 选择
$('#host-select-' + row_id).click(function () { $('#host-select-' + row_id).click(function () {
var _all_checked = true; var _all_checked = true;
@ -210,7 +215,6 @@ ywl.on_host_table_created = function (tbl) {
switch (fields.ret_code) { switch (fields.ret_code) {
case 0: case 0:
return '<span class="badge badge-warning">使用中</span>' return '<span class="badge badge-warning">使用中</span>'
// return '-';
case 9999: case 9999:
return '<span class="badge badge-success">成功</span>'; return '<span class="badge badge-success">成功</span>';
case 1: case 1:
@ -235,27 +239,17 @@ ywl.on_host_table_created = function (tbl) {
msg = '错误重置'; msg = '错误重置';
break; break;
default: default:
//return '<span class="badge badge-danger">' + fields.ret_code + '</span>';
msg = fields.ret_code; msg = fields.ret_code;
} }
return '<span class="badge badge-danger">' + msg + '</span>'; return '<span class="badge badge-danger">' + msg + '</span>';
// if (fields.ret_code == 0) {
//
// } else if (fields.ret_code == 9999) {
// return '<span class="badge badge-success">成功</span>';
// } else {
// return '<span class="badge badge-danger">' + fields.ret_code + '</span>';
// }
}; };
render.begin_time = function (row_id, fields) { render.begin_time = function (row_id, fields) {
return '<span class="badge badge-primary mono">' + format_datetime(utc_to_local(fields.begin_time)) + ' </span>'; return '<span class="badge badge-primary mono">' + format_datetime(utc_to_local(fields.begin_time)) + ' </span>';
}; };
render.cost_time = function (row_id, fields) { render.cost_time = function (row_id, fields) {
if (fields.ret_code == 0) { if (fields.ret_code === 0) {
return '<span class="badge badge-warning">使用中</span>'; return '<span class="badge badge-warning">使用中</span>';
} else { } else {
return '<span class="badge badge-success">' + second2str(fields.cost_time) + '</span>'; return '<span class="badge badge-success">' + second2str(fields.cost_time) + '</span>';
@ -265,18 +259,7 @@ ywl.on_host_table_created = function (tbl) {
//return '<span class="badge badge-success mono">' + fields.host_ip + ':' + fields.host_port + '</span>'; //return '<span class="badge badge-success mono">' + fields.host_ip + ':' + fields.host_port + '</span>';
return '<span class="mono">' + fields.host_ip + ':' + fields.host_port + '</span>'; return '<span class="mono">' + fields.host_ip + ':' + fields.host_port + '</span>';
}; };
// render.auth_type = function (row_id, fields) {
// switch (fields.auth_type) {
// case 0:
// return '<span class="badge badge-danger">无认证</span>';
// case 1:
// return '<span class="badge badge-primary">用户名/密码</span>';
// case 2:
// return '<span class="badge badge-success">SSH密钥</span>';
// default:
// return '<span class="badge badge-danger">未知</span>';
// }
// };
render.protocol = function (row_id, fields) { render.protocol = function (row_id, fields) {
switch (fields.protocol) { switch (fields.protocol) {
case 1: case 1:
@ -332,7 +315,7 @@ ywl.create_table_filter_user_list = function (tbl, selector, on_created) {
}; };
_tblf_st.reset = function (cb_stack, cb_args) { _tblf_st.reset = function (cb_stack, cb_args) {
if (_tblf_st.filter_value == _tblf_st.filter_default) { if (_tblf_st.filter_value === _tblf_st.filter_default) {
cb_stack.exec(); cb_stack.exec();
return; return;
} }

View File

@ -27,13 +27,13 @@ ywl.on_init = function (cb_stack, cb_args) {
} }
ywl.ajax_post_json('/auth/modify-pwd', {o_pwd: old_pwd, n_pwd: new_pwd_1, callback: 1}, ywl.ajax_post_json('/auth/modify-pwd', {o_pwd: old_pwd, n_pwd: new_pwd_1, callback: 1},
function (ret) { function (ret) {
if (ret.code == 0) { if (ret.code === TPE_OK) {
ywl.notify_success('密码修改成功!'); ywl.notify_success('密码修改成功!');
ywl.clear_input(); ywl.clear_input();
} else if (ret.code == -2) { } else if (ret.code === -101) {
ywl.notify_error('密码错误!'); ywl.notify_error('密码错误!');
} else { } else {
ywl.notify_error('密码修改失败errcode:'+ret.code); ywl.notify_error('密码修改失败'+ret.message);
} }
}, },

View File

@ -74,7 +74,7 @@ ywl.on_init = function (cb_stack, cb_args) {
ywl.on_host_table_created = function (tbl) { ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) { tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'action') { if (col_key === 'action') {
var row_data = tbl.get_row(row_id); var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data); //console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () { $(cell_obj).find('[ywl-btn-edit]').click(function () {
@ -88,10 +88,14 @@ ywl.on_host_table_created = function (tbl) {
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/reset-user', {user_id: user_id}, ywl.ajax_post_json('/user/reset-user', {user_id: user_id},
function (ret) { function (ret) {
ywl.notify_success('操作成功!'); if (ret.code === TPE_OK) {
ywl.notify_success('重置用户密码操作成功!');
} else {
ywl.notify_error('重置用户密码操作失败!');
}
}, },
function () { function () {
ywl.notify_error('操作失败!'); ywl.notify_error('网络故障,重置用户密码操作失败!');
} }
); );
}; };
@ -118,12 +122,16 @@ ywl.on_host_table_created = function (tbl) {
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/lock-user', {user_id: user_id, lock_status: user_lock}, ywl.ajax_post_json('/user/lock-user', {user_id: user_id, lock_status: user_lock},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
var update_args = {user_lock: user_lock}; var update_args = {user_lock: user_lock};
tbl.update_row(row_id, update_args); tbl.update_row(row_id, update_args);
ywl.notify_success('操作成功!'); ywl.notify_success('操作成功!');
} else {
ywl.notify_error('操作失败!');
}
}, },
function () { function () {
ywl.notify_error('操作失败!'); ywl.notify_error('网络故障,操作失败!');
} }
); );
}; };
@ -142,16 +150,16 @@ ywl.on_host_table_created = function (tbl) {
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/delete-user', {user_id: user_id}, ywl.ajax_post_json('/user/delete-user', {user_id: user_id},
function (ret) { function (ret) {
if (ret.code == 0) { if (ret.code === TPE_OK) {
tbl.remove_row(row_id); tbl.remove_row(row_id);
ywl.notify_success('删除用户成功!'); ywl.notify_success('删除用户成功!');
} else { } else {
ywl.notify_error('删除用户失败!'); ywl.notify_error('删除用户失败:' + ret.message);
} }
}, },
function (ret) { function () {
ywl.notify_error('删除用户失败!'); ywl.notify_error('网络故障,删除用户失败!');
} }
); );
}; };
@ -264,33 +272,37 @@ ywl.create_user_info_dlg = function (tbl) {
return true; return true;
}; };
user_info_dlg.post = function () { user_info_dlg.post = function () {
if (user_info_dlg.update == 1) { if (user_info_dlg.update === 1) {
ywl.ajax_post_json('/user/modify-user', {user_id: user_info_dlg.user_id, user_desc: user_info_dlg.user_desc}, ywl.ajax_post_json('/user/modify-user', {user_id: user_info_dlg.user_id, user_desc: user_info_dlg.user_desc},
function (ret) { function (ret) {
if (ret.code === TPE_OK) {
var update_args = {user_desc: user_info_dlg.user_desc}; var update_args = {user_desc: user_info_dlg.user_desc};
user_info_dlg.tbl.update_row(user_info_dlg.row_id, update_args); user_info_dlg.tbl.update_row(user_info_dlg.row_id, update_args);
ywl.notify_success('更新用户信息成功!'); ywl.notify_success('更新用户信息成功!');
user_info_dlg.hide(); user_info_dlg.hide();
} else {
ywl.notify_error('更新用户信息失败:' + ret.message);
}
}, },
function (ret) { function () {
ywl.notify_error('更新用户信息失败!'); ywl.notify_error('网络故障,更新用户信息失败!');
} }
); );
} else { } else {
ywl.ajax_post_json('/user/add-user', {user_name: user_info_dlg.user_name, user_desc: user_info_dlg.user_desc}, ywl.ajax_post_json('/user/add-user', {user_name: user_info_dlg.user_name, user_desc: user_info_dlg.user_desc},
function (ret) { function (ret) {
if (ret.code === 0) { if (ret.code === TPE_OK) {
user_info_dlg.tbl.reload(); user_info_dlg.tbl.reload();
ywl.notify_success('添加用户成功!'); ywl.notify_success('添加用户成功!');
user_info_dlg.hide(); user_info_dlg.hide();
} else if (ret.code == -2) { } else if (ret.code === -100) {
ywl.notify_error('已经存在同名用户!'); ywl.notify_error('已经存在同名用户!');
} else { } else {
ywl.notify_error('添加用户失败!'); ywl.notify_error('添加用户失败:' + ret.message);
} }
}, },
function (ret) { function () {
ywl.notify_error('添加用户失败!'); ywl.notify_error('网络故障,添加用户失败!');
} }
); );
} }

View File

@ -6,6 +6,7 @@ var PROTOCOL_TYPE_TELNET = 3;
var OS_TYPE_WINDOWS = 1; var OS_TYPE_WINDOWS = 1;
var OS_TYPE_LINUX = 2; var OS_TYPE_LINUX = 2;
var AUTH_TYPE_PASSWORD = 1; var AUTH_TYPE_PASSWORD = 1;
var AUTH_TYPE_SSHKEY = 2; var AUTH_TYPE_SSHKEY = 2;
var AUTH_NONE = 0; var AUTH_NONE = 0;

View File

@ -99,7 +99,7 @@
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'create_db'}, ywl.ajax_post_json('/maintenance/rpc', {cmd: 'create_db'},
function (ret) { function (ret) {
console.log('create-db:', ret); console.log('create-db:', ret);
if (ret.code == 0) { if (ret.code === TPE_OK) {
var cb_stack = CALLBACK_STACK.create(); var cb_stack = CALLBACK_STACK.create();
cb_stack cb_stack
@ -118,7 +118,7 @@
ywl.get_task_ret = function (cb_stack, cb_args) { ywl.get_task_ret = function (cb_stack, cb_args) {
var task_id = cb_args.task_id || 0; var task_id = cb_args.task_id || 0;
if (task_id == 0) { if (task_id === 0) {
console.log('task-id', task_id); console.log('task-id', task_id);
return; return;
} }
@ -126,7 +126,7 @@
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'get_task_ret', 'tid': task_id}, ywl.ajax_post_json('/maintenance/rpc', {cmd: 'get_task_ret', 'tid': task_id},
function (ret) { function (ret) {
console.log('get_task_ret:', ret); console.log('get_task_ret:', ret);
if (ret.code == 0) { if (ret.code === TPE_OK) {
// show step progress. // show step progress.
var steps = ret.data.steps; var steps = ret.data.steps;
@ -136,12 +136,12 @@
var icon_class = ''; var icon_class = '';
var err_class = ''; var err_class = '';
for (var i = 0; i < steps.length; ++i) { for (var i = 0; i < steps.length; ++i) {
if (steps[i].stat == 0) if (steps[i].stat === 0)
icon_class = 'fa-check'; icon_class = 'fa-check';
else else
icon_class = 'fa-cog fa-spin'; icon_class = 'fa-cog fa-spin';
if (steps[i].code != 0) { if (steps[i].code !== 0) {
icon_class = 'fa-exclamation-circle'; icon_class = 'fa-exclamation-circle';
err_class = ' class="error"'; err_class = ' class="error"';
steps[i].msg += ' 失败!' steps[i].msg += ' 失败!'