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

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

@ -1,152 +1,152 @@
# -*- coding: utf-8 -*-
import json
from eom_app.app.const import *
from eom_app.app.configs import app_cfg
from eom_app.module import user
from eom_common.eomcore.logger import *
from .base import TPBaseHandler, TPBaseUserAuthHandler, TPBaseJsonHandler, TPBaseUserAuthJsonHandler
from eom_app.app.util import gen_captcha
class LoginHandler(TPBaseHandler):
def get(self):
_user = self.get_current_user()
_ref = self.get_argument('ref', '/')
if _user['is_login']:
self.redirect(_ref)
return
if _user['id'] == 0:
user_name = ''
else:
user_name = _user['name']
param = {
'ref': _ref,
'user_name': user_name
}
self.render('auth/login.mako', page_param=json.dumps(param))
class VerifyUser(TPBaseJsonHandler):
def post(self):
code = self.get_session('captcha')
if code is None:
return self.write_json(-1, '验证码已失效')
self.del_session('captcha')
args = self.get_argument('args', None)
if args is not None:
args = json.loads(args)
captcha = args['captcha']
username = args['username']
userpwd = args['userpwd']
remember = args['remember']
else:
return self.write_json(-1, '参数错误')
if code.lower() != captcha.lower():
return self.write_json(-1, '验证码错误')
try:
user_id, account_type, nickname, locked = user.verify_user(username, userpwd)
if locked == 1:
return self.write_json(-1, '账号被锁定,请联系管理员!')
if user_id == 0:
if app_cfg().app_mode == APP_MODE_MAINTENANCE:
return self.write_json(-2, '系统维护中,请稍候再试!')
else:
return self.write_json(-1, '用户名/密码错误!')
_user = self.get_session('user')
if _user is None:
_user = dict()
_user['id'] = 0
_user['name'] = 'guest'
_user['nick_name'] = '访客'
_user['status'] = 0
_user['phone_num'] = '110'
_user['type'] = 0
_user['permission'] = 0
_user['is_login'] = False
_user['id'] = user_id
_user['is_login'] = True
_user['name'] = username
_user['nick_name'] = nickname
_user['type'] = account_type
if remember:
self.set_session('user', _user, 12*60*60)
else:
self.set_session('user', _user)
return self.write_json(0)
except:
log.e('can not set session.')
return self.write_json(-1, '发生异常,无法登录!')
class LogoutHandler(TPBaseUserAuthHandler):
def get(self):
_user = self.get_current_user()
_user['is_login'] = False
self.set_session('user', _user)
self.redirect('/auth/login')
class GetCaptchaHandler(TPBaseHandler):
def get(self):
code, img_data = gen_captcha()
self.set_session('captcha', code)
self.set_header('Content-Type', 'image/jpeg')
self.write(img_data)
class VerifyCaptchaHandler(TPBaseJsonHandler):
def post(self):
code = self.get_session('captcha')
if code is None:
return self.write_json(-1, '验证码已失效')
args = self.get_argument('args', None)
if args is not None:
args = json.loads(args)
captcha = args['captcha']
else:
return self.write_json(-1, '参数错误')
if code.lower() != captcha.lower():
return self.write_json(-1, '验证码错误')
return self.write_json(0)
class ModifyPwd(TPBaseUserAuthJsonHandler):
def post(self):
args = self.get_argument('args', None)
if args is not None:
args = json.loads(args)
else:
return self.write_json(-11, '参数错误')
_old_pwd = args['o_pwd']
_new_pwd = args['n_pwd']
if _old_pwd is None or _new_pwd is None:
return self.write_json(-12, '参数错误')
user_info = self.get_current_user()
try:
ret = user.modify_pwd(_old_pwd, _new_pwd, user_info['id'])
if 0 == ret:
return self.write_json(0)
else:
return self.write_json(-14, '数据库操作错误errcode{}'.format(ret))
except:
log.e('modify password failed.')
return self.write_json(-13, '发生异常')
# -*- coding: utf-8 -*-
import json
from eom_app.app.const import *
from eom_app.app.configs import app_cfg
from eom_app.module import user
from eom_common.eomcore.logger import *
from .base import TPBaseHandler, TPBaseUserAuthHandler, TPBaseJsonHandler, TPBaseUserAuthJsonHandler
from eom_app.app.util import gen_captcha
class LoginHandler(TPBaseHandler):
def get(self):
_user = self.get_current_user()
_ref = self.get_argument('ref', '/')
if _user['is_login']:
self.redirect(_ref)
return
if _user['id'] == 0:
user_name = ''
else:
user_name = _user['name']
param = {
'ref': _ref,
'user_name': user_name
}
self.render('auth/login.mako', page_param=json.dumps(param))
class VerifyUser(TPBaseJsonHandler):
def post(self):
code = self.get_session('captcha')
if code is None:
return self.write_json(-1, '验证码已失效')
self.del_session('captcha')
args = self.get_argument('args', None)
if args is not None:
args = json.loads(args)
captcha = args['captcha']
username = args['username']
userpwd = args['userpwd']
remember = args['remember']
else:
return self.write_json(-1, '参数错误')
if code.lower() != captcha.lower():
return self.write_json(-1, '验证码错误')
try:
user_id, account_type, nickname, locked = user.verify_user(username, userpwd)
if locked == 1:
return self.write_json(-1, '账号被锁定,请联系管理员!')
if user_id == 0:
if app_cfg().app_mode == APP_MODE_MAINTENANCE:
return self.write_json(-2, '系统维护中,请稍候再试!')
else:
return self.write_json(-1, '用户名/密码错误!')
_user = self.get_session('user')
if _user is None:
_user = dict()
_user['id'] = 0
_user['name'] = 'guest'
_user['nick_name'] = '访客'
_user['status'] = 0
_user['phone_num'] = '110'
_user['type'] = 0
_user['permission'] = 0
_user['is_login'] = False
_user['id'] = user_id
_user['is_login'] = True
_user['name'] = username
_user['nick_name'] = nickname
_user['type'] = account_type
if remember:
self.set_session('user', _user, 12*60*60)
else:
self.set_session('user', _user)
return self.write_json(0)
except:
log.e('can not set session.')
return self.write_json(-1, '发生异常,无法登录!')
class LogoutHandler(TPBaseUserAuthHandler):
def get(self):
_user = self.get_current_user()
_user['is_login'] = False
self.set_session('user', _user)
self.redirect('/auth/login')
class GetCaptchaHandler(TPBaseHandler):
def get(self):
code, img_data = gen_captcha()
self.set_session('captcha', code)
self.set_header('Content-Type', 'image/jpeg')
self.write(img_data)
class VerifyCaptchaHandler(TPBaseJsonHandler):
def post(self):
code = self.get_session('captcha')
if code is None:
return self.write_json(-1, '验证码已失效')
args = self.get_argument('args', None)
if args is not None:
args = json.loads(args)
captcha = args['captcha']
else:
return self.write_json(-1, '参数错误')
if code.lower() != captcha.lower():
return self.write_json(-1, '验证码错误')
return self.write_json(0)
class ModifyPwd(TPBaseUserAuthJsonHandler):
def post(self):
args = self.get_argument('args', None)
if args is not None:
args = json.loads(args)
else:
return self.write_json(-1, '参数错误')
_old_pwd = args['o_pwd']
_new_pwd = args['n_pwd']
if _old_pwd is None or _new_pwd is None:
return self.write_json(-2, '参数错误')
user_info = self.get_current_user()
try:
ret = user.modify_pwd(_old_pwd, _new_pwd, user_info['id'])
if 0 == ret:
return self.write_json(0)
else:
return self.write_json(ret)
except:
log.e('modify password failed.')
return self.write_json(-4, '发生异常')

View File

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

View File

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

View File

@ -1,328 +1,328 @@
# -*- coding: utf-8 -*-
import hashlib
from eom_app.app.configs import app_cfg
from eom_app.app.const import *
from eom_app.app.db import get_db, DbItem
from eom_app.app.util import sec_generate_password, sec_verify_password
def verify_user(name, password):
cfg = app_cfg()
db = get_db()
sql = 'SELECT `account_id`, `account_type`, `account_name`, `account_pwd`, `account_lock` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, name)
db_ret = db.query(sql)
if db_ret is None:
# 特别地,如果无法取得数据库连接,有可能是新安装的系统,尚未建立数据库,此时应该处于维护模式
# 因此可以特别地处理用户验证用户名admin密码admin可以登录为管理员
if cfg.app_mode == APP_MODE_MAINTENANCE:
if name == 'admin' and password == 'admin':
return 1, 100, 'admin', 0
return 0, 0, '', 0
if len(db_ret) != 1:
return 0, 0, '', 0
user_id = db_ret[0][0]
account_type = db_ret[0][1]
name = db_ret[0][2]
locked = db_ret[0][4]
if locked == 1:
return 0, 0, '', locked
if not sec_verify_password(password, db_ret[0][3]):
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
if db_ret[0][3] != hashlib.sha256(password.encode()).hexdigest():
return 0, 0, '', locked
else:
# 发现此用户的密码散列格式还是旧的,更新成新的吧!
_new_sec_password = sec_generate_password(password)
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id))
db.exec(sql)
return user_id, account_type, name, locked
def modify_pwd(old_pwd, new_pwd, user_id):
db = get_db()
sql = 'SELECT `account_pwd` FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 1:
return -2
if not sec_verify_password(old_pwd, db_ret[0][0]):
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
if db_ret[0][0] != hashlib.sha256(old_pwd.encode()).hexdigest():
return -2
_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))
db_ret = db.exec(sql)
if db_ret:
return 0
else:
return -3
def get_user_list(with_admin=False):
db = get_db()
ret = list()
field_a = ['account_id', 'account_type', 'account_name', 'account_status', 'account_lock', 'account_desc']
if with_admin:
where = ''
else:
where = 'WHERE `a`.`account_type`<100'
sql = 'SELECT {} FROM `{}account` as a {} ORDER BY `account_name`;'.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix, where)
db_ret = db.query(sql)
if db_ret is None:
return ret
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
h = dict()
h['user_id'] = x.a_account_id
h['user_type'] = x.a_account_type
h['user_name'] = x.a_account_name
h['user_status'] = x.a_account_status
h['user_lock'] = x.a_account_lock
h['user_desc'] = x.a_account_desc
ret.append(h)
return ret
def delete_user(user_id):
db = get_db()
sql = 'DELETE FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
return db.exec(sql)
def lock_user(user_id, lock_status):
db = get_db()
sql = 'UPDATE `{}account` SET `account_lock`={} WHERE `account_id`={};'.format(db.table_prefix, lock_status, int(user_id))
return db.exec(sql)
def reset_user(user_id):
db = get_db()
_new_sec_password = sec_generate_password('123456')
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={};'.format(db.table_prefix, _new_sec_password, int(user_id))
return db.exec(sql)
def modify_user(user_id, user_desc):
db = get_db()
sql = 'UPDATE `{}account` SET `account_desc`="{}" WHERE `account_id`={};'.format(db.table_prefix, user_desc, int(user_id))
return db.exec(sql)
def add_user(user_name, user_pwd, user_desc):
db = get_db()
sql = 'SELECT `account_id` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, user_name)
db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 0:
return -2
sec_password = sec_generate_password(user_pwd)
sql = 'INSERT INTO `{}account` (`account_type`, `account_name`, `account_pwd`, `account_status`,' \
'`account_lock`,`account_desc`) VALUES (1,"{}","{}",0,0,"{}")'.format(db.table_prefix, user_name, sec_password, user_desc)
ret = db.exec(sql)
if ret:
return 0
return -3
def alloc_host(user_name, host_list):
db = get_db()
field_a = ['host_id']
sql = 'SELECT {} FROM `{}auth` AS a WHERE `account_name`="{}";'.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix, user_name)
db_ret = db.query(sql)
ret = dict()
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
host_id = int(x.a_host_id)
ret[host_id] = host_id
a_list = list()
for item in host_list:
if item in ret:
pass
else:
a_list.append(item)
try:
for item in a_list:
host_id = int(item)
sql = 'INSERT INTO `{}auth` (`account_name`, `host_id`) VALUES ("{}", {});'.format(db.table_prefix, user_name, host_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def alloc_host_user(user_name, host_auth_dict):
db = get_db()
field_a = ['host_id', 'host_auth_id']
sql = 'SELECT {} FROM `{}auth` AS a WHERE `account_name`="{}";'.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix, user_name)
db_ret = db.query(sql)
ret = dict()
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
host_id = int(x.a_host_id)
host_auth_id = int(x.a_host_auth_id)
if host_id not in ret:
ret[host_id] = dict()
temp = ret[host_id]
temp[host_auth_id] = host_id
ret[host_id] = temp
add_dict = dict()
for k, v in host_auth_dict.items():
host_id = int(k)
auth_id_list = v
for item in auth_id_list:
host_auth_id = int(item)
if host_id not in ret:
add_dict[host_auth_id] = host_id
continue
temp = ret[host_id]
if host_auth_id not in temp:
add_dict[host_auth_id] = host_id
continue
try:
for k, v in add_dict.items():
host_auth_id = int(k)
host_id = int(v)
sql = 'INSERT INTO `{}auth` (`account_name`, `host_id`, `host_auth_id`) VALUES ("{}", {}, {});'.format(db.table_prefix, user_name, host_id, host_auth_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def delete_host(user_name, host_list):
db = get_db()
try:
for item in host_list:
host_id = int(item)
sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `host_id`={};'.format(db.table_prefix, user_name, host_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def delete_host_user(user_name, auth_id_list):
db = get_db()
try:
for item in auth_id_list:
auth_id = int(item)
sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `auth_id`={};'.format(db.table_prefix, user_name, auth_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def get_log_list(_filter, limit):
db = get_db()
_where = ''
if len(_filter) > 0:
_where = 'WHERE ( '
need_and = False
for k in _filter:
if k == 'account_name':
if need_and:
_where += ' AND'
_where += ' `a`.`account_name`="{}"'.format(_filter[k])
need_and = True
if k == 'user_name':
if need_and:
_where += ' AND'
_where += ' `a`.`account_name`="{}"'.format(_filter[k])
need_and = True
elif k == 'search':
# 查找限于主机ID和IP地址前者是数字只能精确查找后者可以模糊匹配
# 因此,先判断搜索项能否转换为数字。
if need_and:
_where += ' AND '
_where += '('
_where += '`a`.`host_ip` LIKE "%{}%" )'.format(_filter[k])
need_and = True
_where += ')'
# http://www.jb51.net/article/46015.htm
field_a = ['id', 'session_id', 'account_name', 'host_ip', 'host_port', 'auth_type', 'sys_type', 'user_name', 'ret_code',
'begin_time', 'end_time', 'log_time', 'protocol']
sql = 'SELECT COUNT(*) FROM `{}log` AS a {};'.format(db.table_prefix, _where)
db_ret = db.query(sql)
total_count = db_ret[0][0]
# 修正分页数据
_limit = ''
if len(limit) > 0:
_page_index = limit['page_index']
_per_page = limit['per_page']
_limit = 'LIMIT {},{}'.format(_page_index * _per_page, (_page_index + 1) * _per_page)
if _page_index * _per_page >= total_count:
_page_index = int(total_count / _per_page)
_limit = 'LIMIT {},{}'.format(_page_index * _per_page, (_page_index + 1) * _per_page)
sql = 'SELECT {} FROM `{}log` AS a {} ORDER BY `begin_time` DESC {};'.format(','.join(['a.{}'.format(i) for i in field_a]), db.table_prefix, _where, _limit)
db_ret = db.query(sql)
ret = list()
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
h = dict()
h['id'] = x.a_id
h['session_id'] = x.a_session_id
h['account_name'] = x.a_account_name
h['host_ip'] = x.a_host_ip
h['host_port'] = x.a_host_port
h['auth_type'] = x.a_auth_type
h['sys_type'] = x.a_sys_type
h['user_name'] = x.a_user_name
h['ret_code'] = x.a_ret_code
cost_time = (x.a_end_time - x.a_begin_time)
if cost_time < 0:
cost_time = 0
h['cost_time'] = cost_time
h['begin_time'] = x.a_begin_time
if x.a_protocol is not None:
h['protocol'] = x.a_protocol
else:
if x.a_sys_type == 1:
h['protocol'] = 1
else:
h['protocol'] = 2
ret.append(h)
return total_count, ret
# -*- coding: utf-8 -*-
import hashlib
from eom_app.app.configs import app_cfg
from eom_app.app.const import *
from eom_app.app.db import get_db, DbItem
from eom_app.app.util import sec_generate_password, sec_verify_password
def verify_user(name, password):
cfg = app_cfg()
db = get_db()
sql = 'SELECT `account_id`, `account_type`, `account_name`, `account_pwd`, `account_lock` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, name)
db_ret = db.query(sql)
if db_ret is None:
# 特别地,如果无法取得数据库连接,有可能是新安装的系统,尚未建立数据库,此时应该处于维护模式
# 因此可以特别地处理用户验证用户名admin密码admin可以登录为管理员
if cfg.app_mode == APP_MODE_MAINTENANCE:
if name == 'admin' and password == 'admin':
return 1, 100, 'admin', 0
return 0, 0, '', 0
if len(db_ret) != 1:
return 0, 0, '', 0
user_id = db_ret[0][0]
account_type = db_ret[0][1]
name = db_ret[0][2]
locked = db_ret[0][4]
if locked == 1:
return 0, 0, '', locked
if not sec_verify_password(password, db_ret[0][3]):
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
if db_ret[0][3] != hashlib.sha256(password.encode()).hexdigest():
return 0, 0, '', locked
else:
# 发现此用户的密码散列格式还是旧的,更新成新的吧!
_new_sec_password = sec_generate_password(password)
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id))
db.exec(sql)
return user_id, account_type, name, locked
def modify_pwd(old_pwd, new_pwd, user_id):
db = get_db()
sql = 'SELECT `account_pwd` FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 1:
return -100
if not sec_verify_password(old_pwd, db_ret[0][0]):
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
if db_ret[0][0] != hashlib.sha256(old_pwd.encode()).hexdigest():
return -101
_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))
db_ret = db.exec(sql)
if db_ret:
return 0
else:
return -102
def get_user_list(with_admin=False):
db = get_db()
ret = list()
field_a = ['account_id', 'account_type', 'account_name', 'account_status', 'account_lock', 'account_desc']
if with_admin:
where = ''
else:
where = 'WHERE `a`.`account_type`<100'
sql = 'SELECT {} FROM `{}account` as a {} ORDER BY `account_name`;'.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix, where)
db_ret = db.query(sql)
if db_ret is None:
return ret
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
h = dict()
h['user_id'] = x.a_account_id
h['user_type'] = x.a_account_type
h['user_name'] = x.a_account_name
h['user_status'] = x.a_account_status
h['user_lock'] = x.a_account_lock
h['user_desc'] = x.a_account_desc
ret.append(h)
return ret
def delete_user(user_id):
db = get_db()
sql = 'DELETE FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
return db.exec(sql)
def lock_user(user_id, lock_status):
db = get_db()
sql = 'UPDATE `{}account` SET `account_lock`={} WHERE `account_id`={};'.format(db.table_prefix, lock_status, int(user_id))
return db.exec(sql)
def reset_user(user_id):
db = get_db()
_new_sec_password = sec_generate_password('123456')
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={};'.format(db.table_prefix, _new_sec_password, int(user_id))
return db.exec(sql)
def modify_user(user_id, user_desc):
db = get_db()
sql = 'UPDATE `{}account` SET `account_desc`="{}" WHERE `account_id`={};'.format(db.table_prefix, user_desc, int(user_id))
return db.exec(sql)
def add_user(user_name, user_pwd, user_desc):
db = get_db()
sql = 'SELECT `account_id` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, user_name)
db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 0:
return -100
sec_password = sec_generate_password(user_pwd)
sql = 'INSERT INTO `{}account` (`account_type`, `account_name`, `account_pwd`, `account_status`,' \
'`account_lock`,`account_desc`) VALUES (1,"{}","{}",0,0,"{}")'.format(db.table_prefix, user_name, sec_password, user_desc)
ret = db.exec(sql)
if ret:
return 0
return -101
def alloc_host(user_name, host_list):
db = get_db()
field_a = ['host_id']
sql = 'SELECT {} FROM `{}auth` AS a WHERE `account_name`="{}";'.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix, user_name)
db_ret = db.query(sql)
ret = dict()
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
host_id = int(x.a_host_id)
ret[host_id] = host_id
a_list = list()
for item in host_list:
if item in ret:
pass
else:
a_list.append(item)
try:
for item in a_list:
host_id = int(item)
sql = 'INSERT INTO `{}auth` (`account_name`, `host_id`) VALUES ("{}", {});'.format(db.table_prefix, user_name, host_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def alloc_host_user(user_name, host_auth_dict):
db = get_db()
field_a = ['host_id', 'host_auth_id']
sql = 'SELECT {} FROM `{}auth` AS a WHERE `account_name`="{}";'.format(','.join(['`a`.`{}`'.format(i) for i in field_a]), db.table_prefix, user_name)
db_ret = db.query(sql)
ret = dict()
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
host_id = int(x.a_host_id)
host_auth_id = int(x.a_host_auth_id)
if host_id not in ret:
ret[host_id] = dict()
temp = ret[host_id]
temp[host_auth_id] = host_id
ret[host_id] = temp
add_dict = dict()
for k, v in host_auth_dict.items():
host_id = int(k)
auth_id_list = v
for item in auth_id_list:
host_auth_id = int(item)
if host_id not in ret:
add_dict[host_auth_id] = host_id
continue
temp = ret[host_id]
if host_auth_id not in temp:
add_dict[host_auth_id] = host_id
continue
try:
for k, v in add_dict.items():
host_auth_id = int(k)
host_id = int(v)
sql = 'INSERT INTO `{}auth` (`account_name`, `host_id`, `host_auth_id`) VALUES ("{}", {}, {});'.format(db.table_prefix, user_name, host_id, host_auth_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def delete_host(user_name, host_list):
db = get_db()
try:
for item in host_list:
host_id = int(item)
sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `host_id`={};'.format(db.table_prefix, user_name, host_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def delete_host_user(user_name, auth_id_list):
db = get_db()
try:
for item in auth_id_list:
auth_id = int(item)
sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `auth_id`={};'.format(db.table_prefix, user_name, auth_id)
ret = db.exec(sql)
if not ret:
return False
return True
except:
return False
def get_log_list(_filter, limit):
db = get_db()
_where = ''
if len(_filter) > 0:
_where = 'WHERE ( '
need_and = False
for k in _filter:
if k == 'account_name':
if need_and:
_where += ' AND'
_where += ' `a`.`account_name`="{}"'.format(_filter[k])
need_and = True
if k == 'user_name':
if need_and:
_where += ' AND'
_where += ' `a`.`account_name`="{}"'.format(_filter[k])
need_and = True
elif k == 'search':
# 查找限于主机ID和IP地址前者是数字只能精确查找后者可以模糊匹配
# 因此,先判断搜索项能否转换为数字。
if need_and:
_where += ' AND '
_where += '('
_where += '`a`.`host_ip` LIKE "%{}%" )'.format(_filter[k])
need_and = True
_where += ')'
# http://www.jb51.net/article/46015.htm
field_a = ['id', 'session_id', 'account_name', 'host_ip', 'host_port', 'auth_type', 'sys_type', 'user_name', 'ret_code',
'begin_time', 'end_time', 'log_time', 'protocol']
sql = 'SELECT COUNT(*) FROM `{}log` AS a {};'.format(db.table_prefix, _where)
db_ret = db.query(sql)
total_count = db_ret[0][0]
# 修正分页数据
_limit = ''
if len(limit) > 0:
_page_index = limit['page_index']
_per_page = limit['per_page']
_limit = 'LIMIT {},{}'.format(_page_index * _per_page, (_page_index + 1) * _per_page)
if _page_index * _per_page >= total_count:
_page_index = int(total_count / _per_page)
_limit = 'LIMIT {},{}'.format(_page_index * _per_page, (_page_index + 1) * _per_page)
sql = 'SELECT {} FROM `{}log` AS a {} ORDER BY `begin_time` DESC {};'.format(','.join(['a.{}'.format(i) for i in field_a]), db.table_prefix, _where, _limit)
db_ret = db.query(sql)
ret = list()
for item in db_ret:
x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a])
h = dict()
h['id'] = x.a_id
h['session_id'] = x.a_session_id
h['account_name'] = x.a_account_name
h['host_ip'] = x.a_host_ip
h['host_port'] = x.a_host_port
h['auth_type'] = x.a_auth_type
h['sys_type'] = x.a_sys_type
h['user_name'] = x.a_user_name
h['ret_code'] = x.a_ret_code
cost_time = (x.a_end_time - x.a_begin_time)
if cost_time < 0:
cost_time = 0
h['cost_time'] = cost_time
h['begin_time'] = x.a_begin_time
if x.a_protocol is not None:
h['protocol'] = x.a_protocol
else:
if x.a_sys_type == 1:
h['protocol'] = 1
else:
h['protocol'] = 2
ret.append(h)
return total_count, ret

View File

@ -209,8 +209,12 @@ ywl.on_init = function (cb_stack, cb_args) {
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-host', {host_list: host_list},
function (ret) {
g_host_table.reload();
ywl.notify_success('删除主机操作成功!');
if (ret.code === TPE_OK) {
g_host_table.reload();
ywl.notify_success('删除主机操作成功!');
} else {
ywl.notify_error('删除主机操作失败:' + ret.message);
}
},
function () {
ywl.notify_error('网络故障,删除主机操作失败!');
@ -344,12 +348,16 @@ ywl.on_host_table_created = function (tbl) {
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/lock-host', {host_id: host_id, lock: host_lock},
function (ret) {
var update_args = {host_lock: host_lock};
tbl.update_row(row_id, update_args);
ywl.notify_success('操作成功');
if (ret.code === TPE_OK) {
var update_args = {host_lock: host_lock};
tbl.update_row(row_id, update_args);
ywl.notify_success('锁定主机操作成功!');
} else {
ywl.notify_error('锁定主机操作失败:' + ret.message);
}
},
function () {
ywl.notify_error('操作失败');
ywl.notify_error('网络故障,锁定主机操作失败');
}
);
};
@ -370,11 +378,15 @@ ywl.on_host_table_created = function (tbl) {
host_list.push(host_id);
ywl.ajax_post_json('/host/delete-host', {host_list: host_list},
function (ret) {
tbl.remove_row(row_id);
ywl.notify_success('操作成功');
if (ret.code === TPE_OK) {
tbl.remove_row(row_id);
ywl.notify_success('删除主机操作成功!');
} else {
ywl.notify_error('删除主机操作失败:' + ret.message);
}
},
function () {
ywl.notify_error('操作失败');
ywl.notify_error('网络故障,删除主机操作失败');
}
);
};
@ -802,22 +814,26 @@ ywl.create_host_edit_dlg = function (tbl) {
};
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: args},
function (ret) {
var update_args = {
host_ip: dlg_edit_host.ip,
group_name: dlg_edit_host.group_name,
group_id: dlg_edit_host.group_id,
host_desc: dlg_edit_host.host_desc,
host_sys_type: dlg_edit_host.sys_type,
protocol: protocol,
host_port: host_port
};
if (ret.code === TPE_OK) {
var update_args = {
host_ip: dlg_edit_host.ip,
group_name: dlg_edit_host.group_name,
group_id: dlg_edit_host.group_id,
host_desc: dlg_edit_host.host_desc,
host_sys_type: dlg_edit_host.sys_type,
protocol: protocol,
host_port: host_port
};
dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args);
ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 的认证信息已保存!');
dlg_edit_host.hide();
dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args);
ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已保存!');
dlg_edit_host.hide();
} else {
ywl.notify_error('主机 ' + self.host_ip + ' 信息更新失败:' + ret.message);
}
},
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,
function (ret) {
if (ret.code === 0) {
if (ret.code === TPE_OK) {
dlg_edit_host.tbl.reload();
ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已添加!');
dlg_edit_host.hide();
}
else {
if (ret.code === -100) {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已经添加,请不要重复添加主机!', '');
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已存在,请不要重复添加主机!');
} else {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.code, '');
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.message);
}
}
},
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>');
return html.join('');
};
dlg_user_edit_host.sync_user_info = function (host_id) {
ywl.ajax_post_json('/host/sys-user/list', {host_id: host_id},
function (ret) {
if (ret.code !== TPE_OK) {
ywl.notify_error('获取主机用户列表失败:' + ret.message);
return;
}
var data = ret.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"));
ywl.ajax_post_json('/host/sys-user/delete', {host_auth_id: host_auth_id},
function (ret) {
//console.log("ret,", ret);
if (ret.code === TPE_OK) {
ywl.notify_success('系统用户删除成功');
// var host_id = parseInt(dlg_user_edit_host.host_id);
ywl.notify_success('系统用户删除成功!');
g_dlg_edit_host_user.sync_user_info(host_id);
} else {
ywl.notify_error('系统用户删除失败' + ret.code);
ywl.notify_error('系统用户删除失败' + ret.message);
}
},
function () {
ywl.notify_error('系统用户删除失败!');
ywl.notify_error('网络故障:系统用户删除失败!');
}
);
});
@ -1349,21 +1368,19 @@ ywl.create_sys_user = function (tbl) {
cert_id: cert_id,
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},
function (ret) {
//console.log("ret,", ret);
if (ret.code === 0) {
ywl.notify_success('系统用户信息更新成功');
if (ret.code === TPE_OK) {
ywl.notify_success('系统用户信息更新成功!');
g_dlg_edit_host_user.sync_user_info(host_id);
dlg_sys_user.hide();
} else {
ywl.notify_error('系统用户信息更新失败' + ret.code);
ywl.notify_error('系统用户信息更新失败' + ret.message);
}
},
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,
function (ret) {
if (ret.code === TPE_OK) {
ywl.notify_success('系统用户添加成功');
ywl.notify_success('系统用户添加成功');
g_dlg_edit_host_user.sync_user_info(host_id);
dlg_sys_user.hide();
} else {
ywl.notify_error('系统用户添加失败' + ret.code);
ywl.notify_error('系统用户添加失败' + ret.message);
}
},
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},
function (ret) {
var update_args = {group_name: group_name};
for (var i = 0; i < batch_join_dlg.host_list.length; i++) {
var row_id = batch_join_dlg.host_list[i].row_id;
batch_join_dlg.tbl.update_row(row_id, update_args);
}
if (ret.code === TPE_OK) {
var update_args = {group_name: group_name};
for (var i = 0; i < batch_join_dlg.host_list.length; i++) {
var row_id = batch_join_dlg.host_list[i].row_id;
batch_join_dlg.tbl.update_row(row_id, update_args);
}
ywl.notify_success("成功设定分组信息!");
batch_join_dlg.hide();
ywl.notify_success("成功设定主机分组信息!");
batch_join_dlg.hide();
} else {
ywl.notify_error("设定主机分组信息失败:" + ret.message);
}
},
function () {
ywl.notify_error("设定分组信息失败!");
ywl.notify_error("网络故障,设定主机分组信息失败!");
}
);
};

File diff suppressed because it is too large Load Diff

View File

@ -1,302 +1,248 @@
"use strict";
var g_cert_dlg_info = null;
ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_cert_list';
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var host_table_options = {
selector: dom_id + " [ywl-table='cert-list']",
data_source: {
type: 'ajax-post',
url: '/cert/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{title: "编号", key: "cert_id", width: 80},
{title: "密钥名称", key: "cert_name", width: 240, header_align: 'left', cell_align: 'left'},
{title: "公钥", key: "cert_pub", render: 'cert_pub', header_align: 'left', cell_align: 'left'},
//{title: "私钥", key: "cert_pri"},
{title: "操作", key: "action", width: 180, render: 'make_action_btn', fields: {id: 'cert_id'}}
],
paging: {selector: dom_id + " [ywl-paging='cert-list']", per_page: paging_normal},
// 可用的属性设置
//have_header: true or false
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
var host_table = ywl.create_table(host_table_options);
g_cert_dlg_info = ywl.create_cert_info_dlg(host_table);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#btn-add-cert").click(function () {
g_cert_dlg_info.create_show();
});
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
};
// 扩展/重载表格的功能
ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key === 'action') {
var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () {
g_cert_dlg_info.update_show(row_data.cert_name, row_data.cert_id, row_data.cert_pub, row_data.cert_pri, row_id);
});
$(cell_obj).find('[ywl-btn-delete]').click(function () {
var cert_id = row_data.cert_id;
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-cert', {cert_id: cert_id},
function (ret) {
if (ret.code === TPE_OK) {
tbl.remove_row(row_id);
ywl.notify_success('删除成功!');
} else if (ret.code === -2) {
ywl.notify_error('不能删除,有主机使用了此密钥!');
} else {
ywl.notify_error('删除失败!错误代码:'+ret.code);
}
},
function () {
ywl.notify_error('网络通讯失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack,
{
msg: '<p><strong>删除操作不可恢复!!</strong></p><p>您确定要删除此密钥吗?</p>',
fn_yes: _fn_sure
});
});
}
};
// 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作
tbl.on_render_created = function (render) {
render.make_action_btn = function (row_id, fields) {
var ret = [];
ret.push('<a href="javascript:;" class="btn btn-primary btn-success btn-group-sm" ywl-btn-edit="' + fields.id + '">编辑</a>&nbsp');
ret.push('<a href="javascript:;" class="btn btn-primary btn-danger btn-group-sm" ywl-btn-delete="' + fields.id + '">删除</a>');
return ret.join('');
};
render.cert_pub = function (row_id, fields) {
return '<textarea class="textarea-code textarea-resize-none cert_pub" readonly="readonly">' + fields.cert_pub + '</textarea>';
};
};
};
ywl.on_host_table_header_created = function (tbl) {
};
ywl.create_cert_info_dlg = function (tbl) {
var cert_info_dlg = {};
cert_info_dlg.dom_id = "#dialog_cert_info";
cert_info_dlg.update = 1;
cert_info_dlg.tbl = tbl;
cert_info_dlg.cert_name = '';
cert_info_dlg.cert_id = 0;
cert_info_dlg.cert_pub = 0;
cert_info_dlg.cert_pri = 0;
cert_info_dlg.row_id = 0;
cert_info_dlg.title = '';
cert_info_dlg.update_show = function (cert_name, cert_id, cert_pub, cert_pri, row_id) {
cert_info_dlg.update = 1;
cert_info_dlg.title = '编辑SSH密钥';
cert_info_dlg.init(cert_name, cert_id, cert_pub, cert_pri, row_id);
var msg = '如果您只是希望修改密钥名称,那么本区域可以忽略不填写!';
$(cert_info_dlg.dom_id + ' #dlg-cert-pub').attr('placeholder', msg);
$(cert_info_dlg.dom_id + ' #dlg-cert-pri').attr('placeholder', msg);
$(cert_info_dlg.dom_id).modal();
};
cert_info_dlg.create_show = function () {
cert_info_dlg.update = 0;
cert_info_dlg.title = '添加SSH密钥';
cert_info_dlg.init('', 0, '', '', 0);
$(cert_info_dlg.dom_id + ' #dlg-cert-pub').attr('placeholder', '');
$(cert_info_dlg.dom_id + ' #dlg-cert-pri').attr('placeholder', '');
$(cert_info_dlg.dom_id).modal();
};
cert_info_dlg.hide = function () {
$(cert_info_dlg.dom_id).modal('hide');
};
cert_info_dlg.init = function (cert_name, cert_id, cert_pub, cert_pri, row_id) {
cert_info_dlg.cert_name = cert_name;
cert_info_dlg.cert_id = cert_id;
cert_info_dlg.cert_pub = cert_pub;
cert_info_dlg.cert_pri = '';//cert_pri;
cert_info_dlg.row_id = row_id;
cert_info_dlg.init_dlg();
};
cert_info_dlg.init_dlg = function () {
$(cert_info_dlg.dom_id + ' #title').html(cert_info_dlg.title);
$(cert_info_dlg.dom_id + ' #dlg-cert-name').val(cert_info_dlg.cert_name);
$(cert_info_dlg.dom_id + ' #dlg-cert-pub').val(cert_info_dlg.cert_pub);
// $(cert_info_dlg.dom_id + ' #dlg-cert-pri').val(cert_info_dlg.cert_pri);
$(cert_info_dlg.dom_id + ' #dlg-cert-pri').val('');
};
cert_info_dlg.check_args = function () {
cert_info_dlg.cert_name = $(cert_info_dlg.dom_id + ' #dlg-cert-name').val();
cert_info_dlg.cert_pub = $(cert_info_dlg.dom_id + ' #dlg-cert-pub').val();
cert_info_dlg.cert_pri = $(cert_info_dlg.dom_id + ' #dlg-cert-pri').val();
if (cert_info_dlg.cert_name === '') {
ywl.notify_error('必须为密钥设置一个名称!');
return false;
}
if (cert_info_dlg.cert_pub === '') {
ywl.notify_error('必须填写公钥内容!');
return false;
}
if (cert_info_dlg.update === 0 && cert_info_dlg.cert_pri.length === 0) {
ywl.notify_error('添加密钥时,必须填写私钥内容!');
return false;
}
return true;
};
cert_info_dlg.post = function () {
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},
function (ret) {
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);
ywl.notify_success('密钥更新成功!');
cert_info_dlg.hide();
},
function () {
ywl.notify_error('密钥更新失败!');
}
);
} else {
ywl.ajax_post_json('/host/add-cert', {cert_name: cert_info_dlg.cert_name, cert_pub: cert_info_dlg.cert_pub, cert_pri: cert_info_dlg.cert_pri},
function (ret) {
if(ret.code === TPE_OK){
cert_info_dlg.tbl.reload();
ywl.notify_success('密钥添加成功!');
cert_info_dlg.hide();
}else if(ret.code === TPE_NO_CORE_SERVER){
ywl.notify_error('错误,没有启动核心服务!');
}else{
ywl.notify_error('密钥添加失败code:' + ret.code);
}
},
function (ret) {
ywl.notify_error('密钥添加失败!');
}
);
}
return true;
};
$(cert_info_dlg.dom_id + " #btn-save").click(function () {
if (!cert_info_dlg.check_args()) {
return;
}
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
};
"use strict";
var g_cert_dlg_info = null;
ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_cert_list';
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var host_table_options = {
selector: dom_id + " [ywl-table='cert-list']",
data_source: {
type: 'ajax-post',
url: '/cert/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{title: "编号", key: "cert_id", width: 80},
{title: "密钥名称", key: "cert_name", width: 240, header_align: 'left', cell_align: 'left'},
{title: "公钥", key: "cert_pub", render: 'cert_pub', header_align: 'left', cell_align: 'left'},
//{title: "私钥", key: "cert_pri"},
{title: "操作", key: "action", width: 180, render: 'make_action_btn', fields: {id: 'cert_id'}}
],
paging: {selector: dom_id + " [ywl-paging='cert-list']", per_page: paging_normal},
// 可用的属性设置
//have_header: true or false
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
var host_table = ywl.create_table(host_table_options);
g_cert_dlg_info = ywl.create_cert_info_dlg(host_table);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#btn-add-cert").click(function () {
g_cert_dlg_info.create_show();
});
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
};
// 扩展/重载表格的功能
ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key === 'action') {
var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () {
g_cert_dlg_info.update_show(row_data.cert_name, row_data.cert_id, row_data.cert_pub, row_data.cert_pri, row_id);
});
$(cell_obj).find('[ywl-btn-delete]').click(function () {
var cert_id = row_data.cert_id;
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-cert', {cert_id: cert_id},
function (ret) {
if (ret.code === TPE_OK) {
tbl.remove_row(row_id);
ywl.notify_success('密钥删除成功!');
} else if (ret.code === -2) {
ywl.notify_error('不能删除,有主机使用了此密钥!');
} else {
ywl.notify_error('密钥删除失败:' + ret.message);
}
},
function () {
ywl.notify_error('网络故障,密钥删除失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack,
{
msg: '<p><strong>删除操作不可恢复!!</strong></p><p>您确定要删除此密钥吗?</p>',
fn_yes: _fn_sure
});
});
}
};
// 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作
tbl.on_render_created = function (render) {
render.make_action_btn = function (row_id, fields) {
var ret = [];
ret.push('<a href="javascript:;" class="btn btn-primary btn-success btn-group-sm" ywl-btn-edit="' + fields.id + '">编辑</a>&nbsp');
ret.push('<a href="javascript:;" class="btn btn-primary btn-danger btn-group-sm" ywl-btn-delete="' + fields.id + '">删除</a>');
return ret.join('');
};
render.cert_pub = function (row_id, fields) {
return '<textarea class="textarea-code textarea-resize-none cert_pub" readonly="readonly">' + fields.cert_pub + '</textarea>';
};
};
};
ywl.on_host_table_header_created = function (tbl) {
};
ywl.create_cert_info_dlg = function (tbl) {
var cert_info_dlg = {};
cert_info_dlg.dom_id = "#dialog_cert_info";
cert_info_dlg.update = 1;
cert_info_dlg.tbl = tbl;
cert_info_dlg.cert_name = '';
cert_info_dlg.cert_id = 0;
cert_info_dlg.cert_pub = 0;
cert_info_dlg.cert_pri = 0;
cert_info_dlg.row_id = 0;
cert_info_dlg.title = '';
cert_info_dlg.update_show = function (cert_name, cert_id, cert_pub, cert_pri, row_id) {
cert_info_dlg.update = 1;
cert_info_dlg.title = '编辑SSH密钥';
cert_info_dlg.init(cert_name, cert_id, cert_pub, cert_pri, row_id);
var msg = '如果您只是希望修改密钥名称,那么本区域可以忽略不填写!';
$(cert_info_dlg.dom_id + ' #dlg-cert-pub').attr('placeholder', msg);
$(cert_info_dlg.dom_id + ' #dlg-cert-pri').attr('placeholder', msg);
$(cert_info_dlg.dom_id).modal();
};
cert_info_dlg.create_show = function () {
cert_info_dlg.update = 0;
cert_info_dlg.title = '添加SSH密钥';
cert_info_dlg.init('', 0, '', '', 0);
$(cert_info_dlg.dom_id + ' #dlg-cert-pub').attr('placeholder', '');
$(cert_info_dlg.dom_id + ' #dlg-cert-pri').attr('placeholder', '');
$(cert_info_dlg.dom_id).modal();
};
cert_info_dlg.hide = function () {
$(cert_info_dlg.dom_id).modal('hide');
};
cert_info_dlg.init = function (cert_name, cert_id, cert_pub, cert_pri, row_id) {
cert_info_dlg.cert_name = cert_name;
cert_info_dlg.cert_id = cert_id;
cert_info_dlg.cert_pub = cert_pub;
cert_info_dlg.cert_pri = '';//cert_pri;
cert_info_dlg.row_id = row_id;
cert_info_dlg.init_dlg();
};
cert_info_dlg.init_dlg = function () {
$(cert_info_dlg.dom_id + ' #title').html(cert_info_dlg.title);
$(cert_info_dlg.dom_id + ' #dlg-cert-name').val(cert_info_dlg.cert_name);
$(cert_info_dlg.dom_id + ' #dlg-cert-pub').val(cert_info_dlg.cert_pub);
// $(cert_info_dlg.dom_id + ' #dlg-cert-pri').val(cert_info_dlg.cert_pri);
$(cert_info_dlg.dom_id + ' #dlg-cert-pri').val('');
};
cert_info_dlg.check_args = function () {
cert_info_dlg.cert_name = $(cert_info_dlg.dom_id + ' #dlg-cert-name').val();
cert_info_dlg.cert_pub = $(cert_info_dlg.dom_id + ' #dlg-cert-pub').val();
cert_info_dlg.cert_pri = $(cert_info_dlg.dom_id + ' #dlg-cert-pri').val();
if (cert_info_dlg.cert_name === '') {
ywl.notify_error('必须为密钥设置一个名称!');
return false;
}
if (cert_info_dlg.cert_pub === '') {
ywl.notify_error('必须填写公钥内容!');
return false;
}
if (cert_info_dlg.update === 0 && cert_info_dlg.cert_pri.length === 0) {
ywl.notify_error('添加密钥时,必须填写私钥内容!');
return false;
}
return true;
};
cert_info_dlg.post = function () {
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},
function (ret) {
if (ret.code === TPE_OK) {
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);
ywl.notify_success('密钥更新成功!');
cert_info_dlg.hide();
} else {
ywl.notify_error('密钥更新失败:' + ret.message);
}
},
function () {
ywl.notify_error('网络故障,密钥更新失败!');
}
);
} else {
ywl.ajax_post_json('/host/add-cert', {cert_name: cert_info_dlg.cert_name, cert_pub: cert_info_dlg.cert_pub, cert_pri: cert_info_dlg.cert_pri},
function (ret) {
if (ret.code === TPE_OK) {
cert_info_dlg.tbl.reload();
ywl.notify_success('密钥添加成功!');
cert_info_dlg.hide();
} else if (ret.code === TPE_NO_CORE_SERVER) {
ywl.notify_error('错误,没有启动核心服务!');
} else {
ywl.notify_error('密钥添加失败:' + ret.message);
}
},
function (ret) {
ywl.notify_error('网络故障,密钥添加失败!');
}
);
}
return true;
};
$(cert_info_dlg.dom_id + " #btn-save").click(function () {
if (!cert_info_dlg.check_args()) {
return;
}
cert_info_dlg.post();
});
return cert_info_dlg
};

View File

@ -1,413 +1,420 @@
/*! ywl v1.0.1, (c)2015 eomsoft.net */
"use strict";
ywl.notify_error = function (message_, title_) {
var _title = title_ || '';
$.gritter.add({
//sticky:true,
class_name: 'gritter-error',
time: 10000,
title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title,
text: message_
});
};
ywl.notify_success = function (message_, title_) {
var _title = title_ || null;
if (_title !== null)
_title = '<i class="fa fa-check-square fa-fw"></i> ' + _title;
$.gritter.add({
//sticky:true,
class_name: 'gritter-success',
time: 10000,
title: _title,
text: message_
});
};
function get_host_group_by_id(gid) {
var _all = {id: 0, group_name: '全部'};
return _all;
}
function get_user_info_by_id(user_id) {
var _all = {id: 0, nickname: '未知'};
return _all;
}
function get_event_code_by_id(e_id) {
var _all = {id: 0, e_desc: '未知'};
var ret = ywl.assist.get_cache_by_id(CACHE_TYPE_EVENT_CODE, e_id);
if (ret == null)
return _all;
else
return ret;
}
function get_current_system_group() {
return get_system_group_by_id(0);
}
function get_system_group_by_id(gid) {
var _all = {id: 0, name: '全部'};
var ret = null;
$.each(system_group, function (i, group) {
if (group.id == gid) {
ret = group;
return false;
}
});
if (ret == null)
return _all;
else
return ret;
}
//function get_command_name_by_id(cmd_id) {
// return ywl.assist.get_cache_by_id(CACHE_TYPE_COMMAND, cmd_id);
//}
//function notify_error(message_, title_) {
// var _title = title_ || '';
// $.gritter.add({
// sticky: true,
// class_name: 'gritter-error',
// time: 10000,
// title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title,
// text: message_
// });
//}
//function notify_success(message_, title_) {
// var _title = title_ || null;
// if (_title !== null)
// _title = '<i class="fa fa-check-square fa-fw"></i> ' + _title;
// $.gritter.add({
// //sticky:true,
// class_name: 'gritter-success',
// time: 10000,
// title: _title,
// text: message_
// });
//}
// 切换一个dom节点显示与否
ywl.toggle_display = function (selector) {
var obj = $(selector);
if (typeof(obj) == 'undefined')
return;
if (obj.is(':hidden')) {
obj.show();
} else {
obj.hide();
}
};
//======================================================
// Dialog-box for confirm operation.
//======================================================
ywl.dlg_confirm = function (cb_stack, cb_args) {
var self = {};
self._cb_stack = cb_stack;
self._title = cb_args.title || '操作确认:';
self._msg = cb_args.msg || '';
self._btn_yes = cb_args.btn_yes || '确定';
self._btn_no = cb_args.btn_no || '取消';
self._fn_yes = cb_args.fn_yes || null;
self._fn_no = cb_args.fn_no || null;
self._dlg_id = _.uniqueId('dlg-confirm-');
self._cb_args = cb_args.cb_args || {};
self._make_message_box = function () {
var _html = [
'<div class="modal fade" id="' + self._dlg_id + '" tabindex="-1" role="dialog">',
'<div class="modal-dialog" role="document">',
'<div class="modal-content">',
'<div class="modal-header">',
'<h4 class="modal-title">' + self._title + '</h4>',
'</div>',
'<div class="modal-body">',
'<div>' + self._msg + '</div>',
'</div>',
'<div class="modal-footer">',
'<button type="button" class="btn btn-primary" id="dlg-btn-'+self._dlg_id+'-yes"><i class="fa fa-check fa-fw"></i> ' + self._btn_yes + '</button>',
'<button type="button" class="btn btn-default" id="dlg-btn-'+self._dlg_id+'-no"><i class="fa fa-close fa-fw"></i> ' + self._btn_no + '</button>',
'</div>',
'</div>',
'</div>',
'</div>'].join('\n');
$('body').append($(_html));
};
self._destroy = function () {
$('#' + self._dlg_id).remove();
};
self._on_btn_yes = function () {
$('#' + self._dlg_id).modal('hide');
if (_.isFunction(self._fn_yes)) {
self._cb_stack
.add(self._fn_yes, self._cb_args)
.exec();
}
};
self._on_btn_no = function () {
$('#' + self._dlg_id).modal('hide');
if (_.isFunction(self._fn_no)) {
self._cb_stack
.add(self._fn_no, self._cb_args)
.exec();
}
};
self.show = function () {
$('#dlg-btn-' + self._dlg_id + "-yes").click(self._on_btn_yes);
$('#dlg-btn-' + self._dlg_id + "-no").click(self._on_btn_no);
$('#' + self._dlg_id)
.modal()
//.on('hide.bs.modal', self._on_cancel)
.on('hidden.bs.modal', self._destroy);
};
self._make_message_box();
self.show();
};
//======================================================
// Dialog-box for modify host description
//======================================================
ywl.create_dlg_modify_host_desc = function (tbl, row_id, host_id, host_ip,host_desc) {
var self = {};
self.dlg_id = _.uniqueId('dlg-modify-host-desc-');
self._table_ctrl = tbl;
self.host_id = host_id;
self.host_ip = host_ip;
self.host_desc = host_desc;
self.show = function (pos_obj) {
self._make_dialog_box();
$('body')
.addClass('modal-open')
.append($('<div class="modal-backdrop fade in"></div>'))
.keydown(function (event) {
if (event.which == 27) {
self._destroy();
}
});
$('.modal-backdrop').click(function () {
self._destroy();
});
var t_obj = $('#' + self.dlg_id + ' .popover');
t_obj.css({
'top': pos_obj.offset().top + pos_obj.height() - 5,
'left': pos_obj.offset().left
}).show();
$('#' + self.dlg_id + " [ywl-input='desc']").focus();
};
self._save = function () {
var dlg_dom_id = "[ywl-dlg='modify-host-desc']";
var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val == self.host_desc) {
self._destroy();
return;
}
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
function (ret) {
self._table_ctrl.update_row(row_id, {host_desc: val});
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
self._destroy();
},
function () {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存!', '');
self._destroy();
}
);
};
self._destroy = function () {
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
$('#' + self.dlg_id).remove();
};
self._make_dialog_box = function () {
var _html = [
'<div class="popover-inline-edit" id="' + self.dlg_id + '">',
' <div class="popover fade bottom in" role="tooltip" ywl-dlg="modify-host-desc">',
' <div class="arrow" style="left:50px;"></div>',
' <h3 class="popover-title">为主机 ' + self.host_ip + ' 添加备注,以便识别</h3>',
' <div class="popover-content">',
' <div style="display:inline-block;float:right;">',
' <a href="javascript:;" class="btn btn-success btn-sm" ywl-btn="ok"><i class="glyphicon glyphicon-ok"></i></a>',
' <a href="javascript:;" class="btn btn-danger btn-sm" ywl-btn="cancel"><i class="glyphicon glyphicon-remove"></i></a>',
' </div>',
' <div style="padding-right:80px;">',
' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">',
' </div>',
' </div>',
' </div>',
'</div>'].join('\n');
$('body').append($(_html));
// “修改主机描述” 对话框上的两个按钮的点击事件
$('#' + self.dlg_id + " [ywl-btn='ok']").click(function () {
self._save();
});
$('#' + self.dlg_id + " [ywl-btn='cancel']").click(function () {
self._destroy();
});
// 绑定“修改主机描述” 对话框中的输入框的回车事件
$('#' + self.dlg_id + " [ywl-input='desc']").keydown(function (event) {
if (event.which == 13) {
self._save();
} else if (event.which == 27) {
self._destroy();
}
});
};
return self;
};
ywl.create_dlg_show_rdp_advance = function(row_data) {
var self = {};
self.dlg_id = _.uniqueId('dlg-rdp-advance-');
// self._table_ctrl = tbl;
// self.host_id = host_id;
// self.host_ip = host_ip;
// self.host_desc = host_desc;
self.show = function (pos_obj) {
self._make_dialog_box();
$('body')
.addClass('modal-open')
.append($('<div class="modal-backdrop fade in"></div>'))
.keydown(function (event) {
if (event.which == 27) {
self._destroy();
}
});
$('.modal-backdrop').click(function () {
self._destroy();
});
var t_obj = $('#' + self.dlg_id + ' .popover');
t_obj.css({
'top': pos_obj.offset().top + pos_obj.height() + 5,
'left': pos_obj.offset().left - 10
}).show();
//$('#' + self.dlg_id + " [ywl-input='desc']").focus();
};
self._save = function () {
var dlg_dom_id = '[data-dlg="show-rdp-advance"]';
var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val == self.host_desc) {
self._destroy();
return;
}
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
function (ret) {
self._table_ctrl.update_row(row_id, {host_desc: val});
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
self._destroy();
},
function () {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存!', '');
self._destroy();
}
);
};
self._destroy = function () {
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
$('#' + self.dlg_id).remove();
};
self._make_dialog_box = function () {
var _html = [
'<div class="xx-popover-inline-edit" id="' + self.dlg_id + '">',
' <div class="popover fade bottom in" role="tooltip" data-dlg="show-rdp-advance" style="width:300px;">',
' <div class="arrow" style="left:50px;"></div>',
' <h3 class="popover-title" style="font-weight:bold;">RDP连接选项仅本次连接有效</h3>',
' <div class="popover-content">',
// ' <div style="">',
// ' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">',
// ' </div>',
' <div style="">',
' <p style="margin:0;"><strong>分辨率:</strong></p>',
' <label class="radio-inline">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-small" value="overwrite">小 800x600',
' </label><br/>',
' <label class="radio-inline">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-middle" value="skip" checked="checked">中 1024x768',
' </label><br/>',
' <label class="radio-inline">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-large" value="error">大 1280x800',
' </label>',
' </div>',
' <div style="margin-top:5px;">',
' <p style="margin:0;"><strong>Console模式</strong></p>',
' <label>',
' <input type="checkbox" id="dlg-action-rdp-console"> 以Console模式运行',
' </label>',
' </div>',
' <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-default btn-sm" data-actioin="cancel"><i class="fa fa-times fa-fw"></i> 取消</a>',
' </div>',
' </div>',
' </div>',
'</div>'].join('\n');
$('body').append($(_html));
// “修改主机描述” 对话框上的两个按钮的点击事件
$('#' + self.dlg_id + " [data-action='ok']").click(function () {
self._save();
});
$('#' + self.dlg_id + " [data-action='cancel']").click(function () {
self._destroy();
});
// // 绑定“修改主机描述” 对话框中的输入框的回车事件
// $('#' + self.dlg_id + " [ywl-input='desc']").keydown(function (event) {
// if (event.which == 13) {
// self._save();
// } else if (event.which == 27) {
// self._destroy();
// }
// });
};
return self;
};
/*! ywl v1.0.1, (c)2015 eomsoft.net */
"use strict";
ywl.notify_error = function (message_, title_) {
var _title = title_ || '';
$.gritter.add({
//sticky:true,
class_name: 'gritter-error',
time: 10000,
title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title,
text: message_
});
};
ywl.notify_success = function (message_, title_) {
var _title = title_ || null;
if (_title !== null)
_title = '<i class="fa fa-check-square fa-fw"></i> ' + _title;
$.gritter.add({
//sticky:true,
class_name: 'gritter-success',
time: 10000,
title: _title,
text: message_
});
};
function get_host_group_by_id(gid) {
var _all = {id: 0, group_name: '全部'};
return _all;
}
function get_user_info_by_id(user_id) {
var _all = {id: 0, nickname: '未知'};
return _all;
}
function get_event_code_by_id(e_id) {
var _all = {id: 0, e_desc: '未知'};
var ret = ywl.assist.get_cache_by_id(CACHE_TYPE_EVENT_CODE, e_id);
if (ret == null)
return _all;
else
return ret;
}
function get_current_system_group() {
return get_system_group_by_id(0);
}
function get_system_group_by_id(gid) {
var _all = {id: 0, name: '全部'};
var ret = null;
$.each(system_group, function (i, group) {
if (group.id == gid) {
ret = group;
return false;
}
});
if (ret == null)
return _all;
else
return ret;
}
//function get_command_name_by_id(cmd_id) {
// return ywl.assist.get_cache_by_id(CACHE_TYPE_COMMAND, cmd_id);
//}
//function notify_error(message_, title_) {
// var _title = title_ || '';
// $.gritter.add({
// sticky: true,
// class_name: 'gritter-error',
// time: 10000,
// title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title,
// text: message_
// });
//}
//function notify_success(message_, title_) {
// var _title = title_ || null;
// if (_title !== null)
// _title = '<i class="fa fa-check-square fa-fw"></i> ' + _title;
// $.gritter.add({
// //sticky:true,
// class_name: 'gritter-success',
// time: 10000,
// title: _title,
// text: message_
// });
//}
// 切换一个dom节点显示与否
ywl.toggle_display = function (selector) {
var obj = $(selector);
if (typeof(obj) == 'undefined')
return;
if (obj.is(':hidden')) {
obj.show();
} else {
obj.hide();
}
};
//======================================================
// Dialog-box for confirm operation.
//======================================================
ywl.dlg_confirm = function (cb_stack, cb_args) {
var self = {};
self._cb_stack = cb_stack;
self._title = cb_args.title || '操作确认:';
self._msg = cb_args.msg || '';
self._btn_yes = cb_args.btn_yes || '确定';
self._btn_no = cb_args.btn_no || '取消';
self._fn_yes = cb_args.fn_yes || null;
self._fn_no = cb_args.fn_no || null;
self._dlg_id = _.uniqueId('dlg-confirm-');
self._cb_args = cb_args.cb_args || {};
self._make_message_box = function () {
var _html = [
'<div class="modal fade" id="' + self._dlg_id + '" tabindex="-1" role="dialog">',
'<div class="modal-dialog" role="document">',
'<div class="modal-content">',
'<div class="modal-header">',
'<h4 class="modal-title">' + self._title + '</h4>',
'</div>',
'<div class="modal-body">',
'<div>' + self._msg + '</div>',
'</div>',
'<div class="modal-footer">',
'<button type="button" class="btn btn-primary" id="dlg-btn-' + self._dlg_id + '-yes"><i class="fa fa-check fa-fw"></i> ' + self._btn_yes + '</button>',
'<button type="button" class="btn btn-default" id="dlg-btn-' + self._dlg_id + '-no"><i class="fa fa-close fa-fw"></i> ' + self._btn_no + '</button>',
'</div>',
'</div>',
'</div>',
'</div>'].join('\n');
$('body').append($(_html));
};
self._destroy = function () {
$('#' + self._dlg_id).remove();
};
self._on_btn_yes = function () {
$('#' + self._dlg_id).modal('hide');
if (_.isFunction(self._fn_yes)) {
self._cb_stack
.add(self._fn_yes, self._cb_args)
.exec();
}
};
self._on_btn_no = function () {
$('#' + self._dlg_id).modal('hide');
if (_.isFunction(self._fn_no)) {
self._cb_stack
.add(self._fn_no, self._cb_args)
.exec();
}
};
self.show = function () {
$('#dlg-btn-' + self._dlg_id + "-yes").click(self._on_btn_yes);
$('#dlg-btn-' + self._dlg_id + "-no").click(self._on_btn_no);
$('#' + self._dlg_id)
.modal()
//.on('hide.bs.modal', self._on_cancel)
.on('hidden.bs.modal', self._destroy);
};
self._make_message_box();
self.show();
};
//======================================================
// Dialog-box for modify host description
//======================================================
ywl.create_dlg_modify_host_desc = function (tbl, row_id, host_id, host_ip, host_desc) {
var self = {};
self.dlg_id = _.uniqueId('dlg-modify-host-desc-');
self._table_ctrl = tbl;
self.host_id = host_id;
self.host_ip = host_ip;
self.host_desc = host_desc;
self.show = function (pos_obj) {
self._make_dialog_box();
$('body')
.addClass('modal-open')
.append($('<div class="modal-backdrop fade in"></div>'))
.keydown(function (event) {
if (event.which == 27) {
self._destroy();
}
});
$('.modal-backdrop').click(function () {
self._destroy();
});
var t_obj = $('#' + self.dlg_id + ' .popover');
t_obj.css({
'top': pos_obj.offset().top + pos_obj.height() - 5,
'left': pos_obj.offset().left
}).show();
$('#' + self.dlg_id + " [ywl-input='desc']").focus();
};
self._save = function () {
var dlg_dom_id = "[ywl-dlg='modify-host-desc']";
var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val === self.host_desc) {
self._destroy();
return;
}
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
function (ret) {
if (ret.code === TPE_OK) {
self._table_ctrl.update_row(row_id, {host_desc: val});
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
} else {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存:' + ret.message);
}
self._destroy();
},
function () {
ywl.notify_error('网络故障,主机 ' + self.host_ip + ' 的描述修改未能成功保存!');
self._destroy();
}
);
};
self._destroy = function () {
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
$('#' + self.dlg_id).remove();
};
self._make_dialog_box = function () {
var _html = [
'<div class="popover-inline-edit" id="' + self.dlg_id + '">',
' <div class="popover fade bottom in" role="tooltip" ywl-dlg="modify-host-desc">',
' <div class="arrow" style="left:50px;"></div>',
' <h3 class="popover-title">为主机 ' + self.host_ip + ' 添加备注,以便识别</h3>',
' <div class="popover-content">',
' <div style="display:inline-block;float:right;">',
' <a href="javascript:;" class="btn btn-success btn-sm" ywl-btn="ok"><i class="glyphicon glyphicon-ok"></i></a>',
' <a href="javascript:;" class="btn btn-danger btn-sm" ywl-btn="cancel"><i class="glyphicon glyphicon-remove"></i></a>',
' </div>',
' <div style="padding-right:80px;">',
' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">',
' </div>',
' </div>',
' </div>',
'</div>'].join('\n');
$('body').append($(_html));
// “修改主机描述” 对话框上的两个按钮的点击事件
$('#' + self.dlg_id + " [ywl-btn='ok']").click(function () {
self._save();
});
$('#' + self.dlg_id + " [ywl-btn='cancel']").click(function () {
self._destroy();
});
// 绑定“修改主机描述” 对话框中的输入框的回车事件
$('#' + self.dlg_id + " [ywl-input='desc']").keydown(function (event) {
if (event.which == 13) {
self._save();
} else if (event.which == 27) {
self._destroy();
}
});
};
return self;
};
ywl.create_dlg_show_rdp_advance = function (row_data) {
var self = {};
self.dlg_id = _.uniqueId('dlg-rdp-advance-');
// self._table_ctrl = tbl;
// self.host_id = host_id;
// self.host_ip = host_ip;
// self.host_desc = host_desc;
self.show = function (pos_obj) {
self._make_dialog_box();
$('body')
.addClass('modal-open')
.append($('<div class="modal-backdrop fade in"></div>'))
.keydown(function (event) {
if (event.which == 27) {
self._destroy();
}
});
$('.modal-backdrop').click(function () {
self._destroy();
});
var t_obj = $('#' + self.dlg_id + ' .popover');
t_obj.css({
'top': pos_obj.offset().top + pos_obj.height() + 5,
'left': pos_obj.offset().left - 10
}).show();
//$('#' + self.dlg_id + " [ywl-input='desc']").focus();
};
self._save = function () {
var dlg_dom_id = '[data-dlg="show-rdp-advance"]';
var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val === self.host_desc) {
self._destroy();
return;
}
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
function (ret) {
if (ret.code === TPE_OK) {
self._table_ctrl.update_row(row_id, {host_desc: val});
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
} else {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存:' + ret.message);
}
self._destroy();
},
function () {
ywl.notify_error('网络故障,主机 ' + self.host_ip + ' 的描述修改未能成功保存!');
self._destroy();
}
);
};
self._destroy = function () {
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
$('#' + self.dlg_id).remove();
};
self._make_dialog_box = function () {
var _html = [
'<div class="xx-popover-inline-edit" id="' + self.dlg_id + '">',
' <div class="popover fade bottom in" role="tooltip" data-dlg="show-rdp-advance" style="width:300px;">',
' <div class="arrow" style="left:50px;"></div>',
' <h3 class="popover-title" style="font-weight:bold;">RDP连接选项仅本次连接有效</h3>',
' <div class="popover-content">',
// ' <div style="">',
// ' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">',
// ' </div>',
' <div style="">',
' <p style="margin:0;"><strong>分辨率:</strong></p>',
' <label class="radio-inline">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-small" value="overwrite">小 800x600',
' </label><br/>',
' <label class="radio-inline">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-middle" value="skip" checked="checked">中 1024x768',
' </label><br/>',
' <label class="radio-inline">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-large" value="error">大 1280x800',
' </label>',
' </div>',
' <div style="margin-top:5px;">',
' <p style="margin:0;"><strong>Console模式</strong></p>',
' <label>',
' <input type="checkbox" id="dlg-action-rdp-console"> 以Console模式运行',
' </label>',
' </div>',
' <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-default btn-sm" data-actioin="cancel"><i class="fa fa-times fa-fw"></i> 取消</a>',
' </div>',
' </div>',
' </div>',
'</div>'].join('\n');
$('body').append($(_html));
// “修改主机描述” 对话框上的两个按钮的点击事件
$('#' + self.dlg_id + " [data-action='ok']").click(function () {
self._save();
});
$('#' + self.dlg_id + " [data-action='cancel']").click(function () {
self._destroy();
});
// // 绑定“修改主机描述” 对话框中的输入框的回车事件
// $('#' + self.dlg_id + " [ywl-input='desc']").keydown(function (event) {
// if (event.which == 13) {
// self._save();
// } else if (event.which == 27) {
// self._destroy();
// }
// });
};
return self;
};

File diff suppressed because it is too large Load Diff

View File

@ -3,198 +3,206 @@
*/
var g_gourp_dlg_info = null;
ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_group_list';
var dom_id = '#ywl_group_list';
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var host_table_options = {
selector: dom_id + " [ywl-table='group-list']",
data_source: {
type: 'ajax-post',
url: '/group/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{title: "分组ID", key: "id", width: 80},
{title: "分组名称", key: "group_name", header_align: 'left', cell_align: 'left'},
{title: "操作", key: "action", width: 240, render: 'make_action_btn', fields: {id: 'group_id'}}
],
paging: {selector: dom_id + " [ywl-paging='group-list']", per_page: paging_normal},
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var host_table_options = {
selector: dom_id + " [ywl-table='group-list']",
data_source: {
type: 'ajax-post',
url: '/group/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{title: "分组ID", key: "id", width: 80},
{title: "分组名称", key: "group_name", header_align: 'left', cell_align: 'left'},
{title: "操作", key: "action", width: 240, render: 'make_action_btn', fields: {id: 'group_id'}}
],
paging: {selector: dom_id + " [ywl-paging='group-list']", per_page: paging_normal},
// 可用的属性设置
//have_header: true or false
// 可用的属性设置
//have_header: true or false
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
var host_table = ywl.create_table(host_table_options);
g_gourp_dlg_info = ywl.create_group_info_dlg(host_table);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#btn-add-group").click(function () {
g_gourp_dlg_info.create_show();
});
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
var host_table = ywl.create_table(host_table_options);
g_gourp_dlg_info = ywl.create_group_info_dlg(host_table);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#btn-add-group").click(function () {
g_gourp_dlg_info.create_show();
});
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
};
// 扩展/重载表格的功能
ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'action') {
var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () {
g_gourp_dlg_info.update_show(row_data.group_name, row_data.id, row_id);
});
$(cell_obj).find('[ywl-btn-delete]').click(function () {
var group_id = row_data.id;
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-group', {group_id: group_id},
function (ret) {
if (ret.code == 0) {
tbl.remove_row(row_id);
ywl.notify_success('删除分组成功!');
} else if (ret.code == -2) {
ywl.notify_error('不能删除,此分组中已经包含了主机。如果您一定要删除此分组,请先将此分组中的主机设定为其他分组,然后才能删除');
} else {
ywl.notify_error('删除分组失败!');
}
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key === 'action') {
var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () {
g_gourp_dlg_info.update_show(row_data.group_name, row_data.id, row_id);
});
$(cell_obj).find('[ywl-btn-delete]').click(function () {
var group_id = row_data.id;
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-group', {group_id: group_id},
function (ret) {
if (ret.code === TPE_OK) {
tbl.remove_row(row_id);
ywl.notify_success('删除分组成功!');
} else if (ret.code === -2) {
ywl.notify_error('因为有主机隶属此分组,因此不能删除此分组。请先将此分组中的主机设定为其他分组,然后重试');
} else {
ywl.notify_error('删除分组失败:' + ret.message);
}
},
function (ret) {
ywl.notify_error('删除分组失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
},
function () {
ywl.notify_error('网络故障,删除分组失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack,
{
msg: '<p><strong>注意:移除操作不可恢复!!</strong></p><p>您确定要删除此分组吗?</p>',
fn_yes: _fn_sure
});
ywl.dlg_confirm(cb_stack,
{
msg: '<p><strong>注意:移除操作不可恢复!!</strong></p><p>您确定要删除此分组吗?</p>',
fn_yes: _fn_sure
});
});
});
}
};
}
};
// 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作
tbl.on_render_created = function (render) {
render.make_action_btn = function (row_id, fields) {
var ret = [];
ret.push('<a href="javascript:;" class="btn btn-primary btn-success btn-group-sm" ywl-btn-edit="' + fields.id + '">编辑</a>&nbsp');
ret.push('<a href="javascript:;" class="btn btn-primary btn-danger btn-group-sm" ywl-btn-delete="' + fields.id + '">删除</a>');
return ret.join('');
}
// 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作
tbl.on_render_created = function (render) {
render.make_action_btn = function (row_id, fields) {
var ret = [];
ret.push('<a href="javascript:;" class="btn btn-primary btn-success btn-group-sm" ywl-btn-edit="' + fields.id + '">编辑</a>&nbsp');
ret.push('<a href="javascript:;" class="btn btn-primary btn-danger btn-group-sm" ywl-btn-delete="' + fields.id + '">删除</a>');
return ret.join('');
}
};
};
};
ywl.on_host_table_header_created = function (tbl) {
};
ywl.create_group_info_dlg = function (tbl) {
var group_info_dlg = {};
group_info_dlg.dom_id = "#dialog_group_info";
group_info_dlg.update = 1;
group_info_dlg.tbl = tbl;
group_info_dlg.group_name = '';
group_info_dlg.group_id = 0;
group_info_dlg.row_id = 0;
var group_info_dlg = {};
group_info_dlg.dom_id = "#dialog_group_info";
group_info_dlg.update = 1;
group_info_dlg.tbl = tbl;
group_info_dlg.group_name = '';
group_info_dlg.group_id = 0;
group_info_dlg.row_id = 0;
group_info_dlg.update_show = function (group_name, group_id, row_id) {
group_info_dlg.update = 1;
group_info_dlg.init(group_name, group_id, row_id);
$(group_info_dlg.dom_id).modal();
};
group_info_dlg.create_show = function () {
group_info_dlg.update = 0;
group_info_dlg.init('', 0, 0);
$(group_info_dlg.dom_id).modal();
};
group_info_dlg.update_show = function (group_name, group_id, row_id) {
group_info_dlg.update = 1;
group_info_dlg.init(group_name, group_id, row_id);
$(group_info_dlg.dom_id).modal();
};
group_info_dlg.create_show = function () {
group_info_dlg.update = 0;
group_info_dlg.init('', 0, 0);
$(group_info_dlg.dom_id).modal();
};
group_info_dlg.hide = function() {
$(group_info_dlg.dom_id).modal('hide');
};
group_info_dlg.hide = function () {
$(group_info_dlg.dom_id).modal('hide');
};
group_info_dlg.init = function (group_name, group_id, row_id) {
group_info_dlg.group_name = group_name;
group_info_dlg.group_id = group_id;
group_info_dlg.row_id = row_id;
group_info_dlg.init_dlg();
};
group_info_dlg.init_dlg = function () {
$(group_info_dlg.dom_id + ' #group_name').val(group_info_dlg.group_name);
};
group_info_dlg.init = function (group_name, group_id, row_id) {
group_info_dlg.group_name = group_name;
group_info_dlg.group_id = group_id;
group_info_dlg.row_id = row_id;
group_info_dlg.init_dlg();
};
group_info_dlg.init_dlg = function () {
$(group_info_dlg.dom_id + ' #group_name').val(group_info_dlg.group_name);
};
group_info_dlg.check_args = function () {
group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val();
return true;
};
group_info_dlg.post = function () {
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},
function (ret) {
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);
ywl.notify_success('更新分组信息成功!');
group_info_dlg.hide();
},
function (ret) {
ywl.notify_error('更新分组信息失败!');
}
);
} else {
ywl.ajax_post_json('/host/add-group', {group_name: group_info_dlg.group_name},
function (ret) {
group_info_dlg.tbl.reload();
ywl.notify_success('分组创建成功!');
group_info_dlg.hide();
},
function (ret) {
ywl.notify_error('分组创建失败!');
}
);
}
//group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val();
return true;
};
$(group_info_dlg.dom_id + " #btn-save").click(function () {
if (!group_info_dlg.check_args()) {
return;
}
group_info_dlg.post();
});
return group_info_dlg
group_info_dlg.check_args = function () {
group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val();
return true;
};
group_info_dlg.post = function () {
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},
function (ret) {
if (ret.code === TPE_OK) {
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);
ywl.notify_success('更新分组信息成功!');
group_info_dlg.hide();
} else {
ywl.notify_error('更新分组失败:' + ret.message);
}
},
function () {
ywl.notify_error('网络故障,更新分组信息失败!');
}
);
} else {
ywl.ajax_post_json('/host/add-group', {group_name: group_info_dlg.group_name},
function (ret) {
if (ret.code === TPE_OK) {
group_info_dlg.tbl.reload();
ywl.notify_success('创建分组成功!');
group_info_dlg.hide();
} else {
ywl.notify_error('创建分组失败:' + ret.message);
}
},
function () {
ywl.notify_error('网络故障,创建分组失败!');
}
);
}
//group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val();
return true;
};
$(group_info_dlg.dom_id + " #btn-save").click(function () {
if (!group_info_dlg.check_args()) {
return;
}
group_info_dlg.post();
});
return group_info_dlg
}

View File

@ -1,386 +1,369 @@
"use strict";
ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_log_list';
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var disk_rate = parseInt(ywl.page_options.free_size * 100 / ywl.page_options.total_size);
$('#disk-status').text('日志磁盘大小:' + size2str(ywl.page_options.total_size, 2) + ',剩余空间:' + size2str(ywl.page_options.free_size, 2) + ',空闲' + disk_rate + '%');
if (disk_rate < 10) {
$('#disk-status').removeClass().addClass('badge badge-danger');
} else if (disk_rate < 30) {
$('#disk-status').removeClass().addClass('badge badge-warning');
} else {
$('#disk-status').removeClass().addClass('badge badge-ignore');
}
var host_table_options = {
selector: dom_id + " [ywl-table='log-list']",
data_source: {
type: 'ajax-post',
url: '/log/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{
title: '<input type="checkbox" id="host-select-all" value="">',
key: 'select_all',
sort: false,
width: 24,
render: 'make_check_box',
fields: {id: 'id'}
},
{title: "ID", key: "id"},
{title: "操作者", key: "account_name"},
{title: "系统用户", key: "user_name"},
{title: "协议", key: "protocol", render: 'protocol', fields: {protocol: 'protocol'}},
{title: "系统", key: "sys_type", width: 40, render: 'sys_type', fields: {sys_type: 'sys_type'}},
{title: "远程主机地址", key: "host_ip", render: 'server_info', fields: {host_ip: 'host_ip', host_port: 'host_port'}},
{title: "开始时间", key: "begin_time", width: 160, render: 'begin_time', fields: {begin_time: 'begin_time'}},
{title: "耗时", key: "cost_time", render: 'cost_time', fields: {cost_time: 'cost_time', ret_code: 'ret_code'}},
{title: "状态", key: "ret_code", render: 'ret_code', fields: {ret_code: 'ret_code'}},
{
title: "操作",
key: "action",
width: 160,
header_align: 'left', cell_align: 'left',
render: 'make_action_btn',
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},
// 可用的属性设置
//have_header: true or false
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
var host_table = ywl.create_table(host_table_options);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#delete-log").click(function () {
var log_list = [];
var _objs = $(host_table.selector + " tbody tr td [data-check-box]");
$.each(_objs, function (i, _obj) {
if ($(_obj).is(':checked')) {
var _row_data = host_table.get_row(_obj);
log_list.push(_row_data.id);
}
});
if (log_list.length === 0) {
ywl.notify_error('请选择要批量删除的日志');
return;
}
;
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json_time_out('/log/delete-log', {log_list: log_list},1000*30,
function (ret) {
host_table.reload();
ywl.notify_success('操作成功');
},
function () {
ywl.notify_error('操作失败');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack, {
msg: '<p>您确定要删除选定的日志吗?此操作不可恢复!!</p>',
fn_yes: _fn_sure
});
});
ywl.create_table_filter_user_list(host_table, dom_id + " [ywl-filter='user-name']");
ywl.create_table_filter_search_box(host_table, dom_id + " [ywl-filter='search']");
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
};
ywl.on_host_table_header_created = function (tbl) {
$('#host-select-all').click(function () {
var _is_selected = $(this).is(':checked');
$(tbl.selector + ' tbody').find('[data-check-box]').prop('checked', _is_selected);
});
};
// 扩展/重载表格的功能
ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'select_all') {
// 选择
$('#host-select-' + row_id).click(function () {
var _all_checked = true;
var _objs = $(tbl.selector + ' tbody').find('[data-check-box]');
$.each(_objs, function (i, _obj) {
if (!$(_obj).is(':checked')) {
_all_checked = false;
return false;
}
});
var select_all_dom = $('#host-select-all');
if (_all_checked) {
select_all_dom.prop('checked', true);
} else {
select_all_dom.prop('checked', false);
}
//ywl.update_add_to_batch_btn();
});
} else if (col_key === 'action') {
var row_data = tbl.get_row(row_id);
var protocol = parseInt(row_data.protocol);
if (protocol === PROTOCOL_TYPE_RDP) {
$(cell_obj).find('[ywl-btn-record]').click(function () {
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 = {};
args.id = parseInt(row_data.id);
args.host = ip;
args.port = port;
args.tail = tail;
args.url = url;
start_rdp_replay(args,
function () {
ywl.notify_success('RDP 录像播放器成功启动!');
},
function (code, msg) {
if (code === TPE_NO_ASSIST)
g_assist.alert_assist_not_found();
else {
ywl.notify_error(msg);
console.log('error:', msg)
}
});
});
}
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);
});
$(cell_obj).find('[ywl-btn-log]').click(function () {
window.open('/log/command-log/' + parseInt(row_data.protocol) + '/' + row_data.id);
});
}
}
};
// 重载表格渲染器的部分渲染方式加入本页面相关特殊操作f成功
tbl.on_render_created = function (render) {
render.ret_code = function (row_id, fields) {
var msg = '';
switch (fields.ret_code) {
case 0:
return '<span class="badge badge-warning">使用中</span>'
// return '-';
case 9999:
return '<span class="badge badge-success">成功</span>';
case 1:
msg = '认证失败';
break;
case 2:
msg = '连接失败';
break;
case 3:
msg = '私钥错误';
break;
case 4:
msg = '内部错误';
break;
case 5:
msg = '协议不支持';
break;
case 6:
msg = '通讯错误';
break;
case 7:
msg = '错误重置';
break;
default:
//return '<span class="badge badge-danger">' + fields.ret_code + '</span>';
msg = fields.ret_code;
}
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) {
return '<span class="badge badge-primary mono">' + format_datetime(utc_to_local(fields.begin_time)) + ' </span>';
};
render.cost_time = function (row_id, fields) {
if (fields.ret_code == 0) {
return '<span class="badge badge-warning">使用中</span>';
} else {
return '<span class="badge badge-success">' + second2str(fields.cost_time) + '</span>';
}
};
render.server_info = function (row_id, fields) {
//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>';
};
// 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) {
switch (fields.protocol) {
case 1:
return '<span class="badge badge-primary">RDP</span>';
case 2:
return '<span class="badge badge-success">SSH</span>';
case 3:
return '<span class="badge badge-success">TELNET</span>';
default:
return '<span class="badge badge-danger">未知</span>';
}
};
render.make_check_box = function (row_id, fields) {
return '<span><input type="checkbox" data-check-box="' + fields.id + '" id="host-select-' + row_id + '"></span>';
};
render.make_action_btn = function (row_id, fields) {
var ret = [];
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>&nbsp');
} 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>&nbsp');
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" protocol=' + fields.protocol + ' ywl-btn-log="' + fields.ID + '">日志查看</a>&nbsp');
}
}
return ret.join('');
}
};
};
ywl.create_table_filter_user_list = function (tbl, selector, on_created) {
var _tblf_st = {};
// 此表格绑定的DOM对象的ID用于JQuery的选择器
_tblf_st.selector = selector;
// 此过滤器绑定的表格控件
_tblf_st._table_ctrl = tbl;
_tblf_st._table_ctrl.append_filter_ctrl(_tblf_st);
// 过滤器内容
_tblf_st.filter_name = 'user_name';
_tblf_st.filter_default = '全部';
_tblf_st.filter_value = '';
_tblf_st.get_filter = function () {
var _ret = {};
_ret[_tblf_st.filter_name] = _tblf_st.filter_value;
return _ret;
};
_tblf_st.reset = function (cb_stack, cb_args) {
if (_tblf_st.filter_value == _tblf_st.filter_default) {
cb_stack.exec();
return;
}
cb_stack
.add(function (cb_stack) {
_tblf_st.filter_value = _tblf_st.filter_default;
$(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value);
cb_stack.exec();
});
};
_tblf_st.init = function (cb_stack) {
var node = '';
var user_list = ywl.page_options.user_list;
node += '<li><a href="javascript:;" ywl-user-id="0">全部</a></li>';
node += '<li role="separator" class="divider"></li>';
$.each(user_list, function (i, g) {
node += '<li><a href="javascript:;" ywl-user-id="' + g.user_id + '">' + g.user_name + '</a></li>';
});
_tblf_st.filter_value = _tblf_st.filter_default;
$(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value);
$(_tblf_st.selector + ' ul').empty().append($(node));
// 点击事件绑定
$(_tblf_st.selector + ' ul [ywl-user-id]').click(_tblf_st._on_select);
if (_.isFunction(on_created)) {
on_created(_tblf_st);
}
cb_stack.exec();
};
_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)
.add(function (cb_stack) {
_tblf_st.filter_value = user_name;
$(_tblf_st.selector + ' button span:first').html(user_name);
cb_stack.exec();
});
cb_stack.exec();
};
return _tblf_st;
};
"use strict";
ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_log_list';
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var disk_rate = parseInt(ywl.page_options.free_size * 100 / ywl.page_options.total_size);
$('#disk-status').text('日志磁盘大小:' + size2str(ywl.page_options.total_size, 2) + ',剩余空间:' + size2str(ywl.page_options.free_size, 2) + ',空闲' + disk_rate + '%');
if (disk_rate < 10) {
$('#disk-status').removeClass().addClass('badge badge-danger');
} else if (disk_rate < 30) {
$('#disk-status').removeClass().addClass('badge badge-warning');
} else {
$('#disk-status').removeClass().addClass('badge badge-ignore');
}
var host_table_options = {
selector: dom_id + " [ywl-table='log-list']",
data_source: {
type: 'ajax-post',
url: '/log/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{
title: '<input type="checkbox" id="host-select-all" value="">',
key: 'select_all',
sort: false,
width: 24,
render: 'make_check_box',
fields: {id: 'id'}
},
{title: "ID", key: "id"},
{title: "操作者", key: "account_name"},
{title: "系统用户", key: "user_name"},
{title: "协议", key: "protocol", render: 'protocol', fields: {protocol: 'protocol'}},
{title: "系统", key: "sys_type", width: 40, render: 'sys_type', fields: {sys_type: 'sys_type'}},
{title: "远程主机地址", key: "host_ip", render: 'server_info', fields: {host_ip: 'host_ip', host_port: 'host_port'}},
{title: "开始时间", key: "begin_time", width: 160, render: 'begin_time', fields: {begin_time: 'begin_time'}},
{title: "耗时", key: "cost_time", render: 'cost_time', fields: {cost_time: 'cost_time', ret_code: 'ret_code'}},
{title: "状态", key: "ret_code", render: 'ret_code', fields: {ret_code: 'ret_code'}},
{
title: "操作",
key: "action",
width: 160,
header_align: 'left', cell_align: 'left',
render: 'make_action_btn',
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},
// 可用的属性设置
//have_header: true or false
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
var host_table = ywl.create_table(host_table_options);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#delete-log").click(function () {
var log_list = [];
var _objs = $(host_table.selector + " tbody tr td [data-check-box]");
$.each(_objs, function (i, _obj) {
if ($(_obj).is(':checked')) {
var _row_data = host_table.get_row(_obj);
log_list.push(_row_data.id);
}
});
if (log_list.length === 0) {
ywl.notify_error('请选择要批量删除的日志!');
return;
}
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json_time_out('/log/delete-log', {log_list: log_list}, 1000 * 30,
function (ret) {
if (ret.code === TPE_OK) {
host_table.reload();
ywl.notify_success('删除日志成功!');
} else {
ywl.notify_error('删除日志失败!');
}
},
function () {
ywl.notify_error('网络故障,删除日志失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack, {
msg: '<p>您确定要删除选定的日志吗?此操作不可恢复!!</p>',
fn_yes: _fn_sure
});
});
ywl.create_table_filter_user_list(host_table, dom_id + " [ywl-filter='user-name']");
ywl.create_table_filter_search_box(host_table, dom_id + " [ywl-filter='search']");
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
};
ywl.on_host_table_header_created = function (tbl) {
$('#host-select-all').click(function () {
var _is_selected = $(this).is(':checked');
$(tbl.selector + ' tbody').find('[data-check-box]').prop('checked', _is_selected);
});
};
// 扩展/重载表格的功能
ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key === 'select_all') {
// 选择
$('#host-select-' + row_id).click(function () {
var _all_checked = true;
var _objs = $(tbl.selector + ' tbody').find('[data-check-box]');
$.each(_objs, function (i, _obj) {
if (!$(_obj).is(':checked')) {
_all_checked = false;
return false;
}
});
var select_all_dom = $('#host-select-all');
if (_all_checked) {
select_all_dom.prop('checked', true);
} else {
select_all_dom.prop('checked', false);
}
//ywl.update_add_to_batch_btn();
});
} else if (col_key === 'action') {
var row_data = tbl.get_row(row_id);
var protocol = parseInt(row_data.protocol);
if (protocol === PROTOCOL_TYPE_RDP) {
$(cell_obj).find('[ywl-btn-record]').click(function () {
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 = {};
args.id = parseInt(row_data.id);
args.host = ip;
args.port = port;
args.tail = tail;
args.url = url;
start_rdp_replay(args,
function () {
ywl.notify_success('RDP 录像播放器成功启动!');
},
function (code, msg) {
if (code === TPE_NO_ASSIST)
g_assist.alert_assist_not_found();
else {
ywl.notify_error(msg);
console.log('error:', msg)
}
});
});
}
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);
});
$(cell_obj).find('[ywl-btn-log]').click(function () {
window.open('/log/command-log/' + parseInt(row_data.protocol) + '/' + row_data.id);
});
}
}
};
// 重载表格渲染器的部分渲染方式加入本页面相关特殊操作f成功
tbl.on_render_created = function (render) {
render.ret_code = function (row_id, fields) {
var msg = '';
switch (fields.ret_code) {
case 0:
return '<span class="badge badge-warning">使用中</span>'
case 9999:
return '<span class="badge badge-success">成功</span>';
case 1:
msg = '认证失败';
break;
case 2:
msg = '连接失败';
break;
case 3:
msg = '私钥错误';
break;
case 4:
msg = '内部错误';
break;
case 5:
msg = '协议不支持';
break;
case 6:
msg = '通讯错误';
break;
case 7:
msg = '错误重置';
break;
default:
msg = fields.ret_code;
}
return '<span class="badge badge-danger">' + msg + '</span>';
};
render.begin_time = function (row_id, fields) {
return '<span class="badge badge-primary mono">' + format_datetime(utc_to_local(fields.begin_time)) + ' </span>';
};
render.cost_time = function (row_id, fields) {
if (fields.ret_code === 0) {
return '<span class="badge badge-warning">使用中</span>';
} else {
return '<span class="badge badge-success">' + second2str(fields.cost_time) + '</span>';
}
};
render.server_info = function (row_id, fields) {
//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>';
};
render.protocol = function (row_id, fields) {
switch (fields.protocol) {
case 1:
return '<span class="badge badge-primary">RDP</span>';
case 2:
return '<span class="badge badge-success">SSH</span>';
case 3:
return '<span class="badge badge-success">TELNET</span>';
default:
return '<span class="badge badge-danger">未知</span>';
}
};
render.make_check_box = function (row_id, fields) {
return '<span><input type="checkbox" data-check-box="' + fields.id + '" id="host-select-' + row_id + '"></span>';
};
render.make_action_btn = function (row_id, fields) {
var ret = [];
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>&nbsp');
} 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>&nbsp');
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" protocol=' + fields.protocol + ' ywl-btn-log="' + fields.ID + '">日志查看</a>&nbsp');
}
}
return ret.join('');
}
};
};
ywl.create_table_filter_user_list = function (tbl, selector, on_created) {
var _tblf_st = {};
// 此表格绑定的DOM对象的ID用于JQuery的选择器
_tblf_st.selector = selector;
// 此过滤器绑定的表格控件
_tblf_st._table_ctrl = tbl;
_tblf_st._table_ctrl.append_filter_ctrl(_tblf_st);
// 过滤器内容
_tblf_st.filter_name = 'user_name';
_tblf_st.filter_default = '全部';
_tblf_st.filter_value = '';
_tblf_st.get_filter = function () {
var _ret = {};
_ret[_tblf_st.filter_name] = _tblf_st.filter_value;
return _ret;
};
_tblf_st.reset = function (cb_stack, cb_args) {
if (_tblf_st.filter_value === _tblf_st.filter_default) {
cb_stack.exec();
return;
}
cb_stack
.add(function (cb_stack) {
_tblf_st.filter_value = _tblf_st.filter_default;
$(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value);
cb_stack.exec();
});
};
_tblf_st.init = function (cb_stack) {
var node = '';
var user_list = ywl.page_options.user_list;
node += '<li><a href="javascript:;" ywl-user-id="0">全部</a></li>';
node += '<li role="separator" class="divider"></li>';
$.each(user_list, function (i, g) {
node += '<li><a href="javascript:;" ywl-user-id="' + g.user_id + '">' + g.user_name + '</a></li>';
});
_tblf_st.filter_value = _tblf_st.filter_default;
$(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value);
$(_tblf_st.selector + ' ul').empty().append($(node));
// 点击事件绑定
$(_tblf_st.selector + ' ul [ywl-user-id]').click(_tblf_st._on_select);
if (_.isFunction(on_created)) {
on_created(_tblf_st);
}
cb_stack.exec();
};
_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)
.add(function (cb_stack) {
_tblf_st.filter_value = user_name;
$(_tblf_st.selector + ' button span:first').html(user_name);
cb_stack.exec();
});
cb_stack.exec();
};
return _tblf_st;
};

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},
function (ret) {
if (ret.code == 0) {
if (ret.code === TPE_OK) {
ywl.notify_success('密码修改成功!');
ywl.clear_input();
} else if (ret.code == -2) {
} else if (ret.code === -101) {
ywl.notify_error('密码错误!');
} else {
ywl.notify_error('密码修改失败errcode:'+ret.code);
ywl.notify_error('密码修改失败'+ret.message);
}
},

View File

@ -5,302 +5,314 @@
var g_user_dlg_info = null;
ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_user_list';
var dom_id = '#ywl_user_list';
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var host_table_options = {
selector: dom_id + " [ywl-table='user-list']",
data_source: {
type: 'ajax-post',
url: '/user/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{title: "用户ID", key: "user_id", width: 80},
{title: "用户名", key: "user_name", width: 200},
{title: "用户描述", key: "user_desc"},
{title: "状态", key: "user_lock", width: 200, render: 'user_lock', fields: {user_lock: 'user_lock'}},
{title: "操作", key: "action", width: 380, render: 'make_action_btn', fields: {user_id: 'user_id', user_lock: 'user_lock'}}
],
paging: {selector: dom_id + " [ywl-paging='user-list']", per_page: paging_normal},
//===================================
// 创建页面控件对象
//===================================
// 表格数据
var host_table_options = {
selector: dom_id + " [ywl-table='user-list']",
data_source: {
type: 'ajax-post',
url: '/user/list'
},
column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [
{title: "用户ID", key: "user_id", width: 80},
{title: "用户名", key: "user_name", width: 200},
{title: "用户描述", key: "user_desc"},
{title: "状态", key: "user_lock", width: 200, render: 'user_lock', fields: {user_lock: 'user_lock'}},
{title: "操作", key: "action", width: 380, render: 'make_action_btn', fields: {user_id: 'user_id', user_lock: 'user_lock'}}
],
paging: {selector: dom_id + " [ywl-paging='user-list']", per_page: paging_normal},
// 可用的属性设置
//have_header: true or false
// 可用的属性设置
//have_header: true or false
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可用的回调函数
on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可重载的函数在on_created回调函数中重载
// on_render_created
// on_header_created
// on_paging_created
// on_data_loaded
// on_row_rendered
// on_table_rendered
// on_cell_created
// on_begin_load
// on_after_load
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
// 可用的函数
// load_data
// cancel_load
// set_data
// add_row
// remove_row
// get_row
// update_row
// clear
// reset_filter
};
var host_table = ywl.create_table(host_table_options);
g_user_dlg_info = ywl.create_user_info_dlg(host_table);
var host_table = ywl.create_table(host_table_options);
g_user_dlg_info = ywl.create_user_info_dlg(host_table);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#btn-add-user").click(function () {
g_user_dlg_info.create_show();
});
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
$(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#btn-add-user").click(function () {
g_user_dlg_info.create_show();
});
cb_stack
.add(host_table.load_data)
.add(host_table.init)
.exec();
};
// 扩展/重载表格的功能
ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'action') {
var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () {
g_user_dlg_info.update_show(row_data.user_name, row_data.user_desc, row_data.user_id, row_id);
});
tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key === 'action') {
var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () {
g_user_dlg_info.update_show(row_data.user_name, row_data.user_desc, row_data.user_id, row_id);
});
$(cell_obj).find('[ywl-btn-reset]').click(function () {
var user_id = row_data.user_id;
//var user_lock = row_data.user_lock;
var message = '此操作将用户密码重置为默认密码 <span class="mono h3">123456</span>,确定要执行吗?<br/><br/>提示:密码重置后,请通知用户立即修改默认密码!';
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/reset-user', {user_id: user_id},
function (ret) {
ywl.notify_success('操作成功!');
},
function () {
ywl.notify_error('操作失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
$(cell_obj).find('[ywl-btn-reset]').click(function () {
var user_id = row_data.user_id;
//var user_lock = row_data.user_lock;
var message = '此操作将用户密码重置为默认密码 <span class="mono h3">123456</span>,确定要执行吗?<br/><br/>提示:密码重置后,请通知用户立即修改默认密码!';
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/reset-user', {user_id: user_id},
function (ret) {
if (ret.code === TPE_OK) {
ywl.notify_success('重置用户密码操作成功!');
} else {
ywl.notify_error('重置用户密码操作失败!');
}
},
function () {
ywl.notify_error('网络故障,重置用户密码操作失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack,
{
msg: '<p>' + message + '</p>',
fn_yes: _fn_sure
});
});
ywl.dlg_confirm(cb_stack,
{
msg: '<p>' + message + '</p>',
fn_yes: _fn_sure
});
});
$(cell_obj).find('[ywl-btn-lock]').click(function () {
var user_id = row_data.user_id;
var user_lock = row_data.user_lock;
var message = '';
if (user_lock === 0) {
user_lock = 1;
message = '被锁定的用户将无法登陆系统,确认要锁定该用户吗?';
} else {
user_lock = 0;
message = '确认要解锁该用户吗?';
}
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/lock-user', {user_id: user_id, lock_status: user_lock},
function (ret) {
var update_args = {user_lock: user_lock};
tbl.update_row(row_id, update_args);
ywl.notify_success('操作成功!');
},
function () {
ywl.notify_error('操作失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
$(cell_obj).find('[ywl-btn-lock]').click(function () {
var user_id = row_data.user_id;
var user_lock = row_data.user_lock;
var message = '';
if (user_lock === 0) {
user_lock = 1;
message = '被锁定的用户将无法登陆系统,确认要锁定该用户吗?';
} else {
user_lock = 0;
message = '确认要解锁该用户吗?';
}
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/lock-user', {user_id: user_id, lock_status: user_lock},
function (ret) {
if (ret.code === TPE_OK) {
var update_args = {user_lock: user_lock};
tbl.update_row(row_id, update_args);
ywl.notify_success('操作成功!');
} else {
ywl.notify_error('操作失败!');
}
},
function () {
ywl.notify_error('网络故障,操作失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack,
{
msg: '<p>' + message + '</p>',
fn_yes: _fn_sure
});
ywl.dlg_confirm(cb_stack,
{
msg: '<p>' + message + '</p>',
fn_yes: _fn_sure
});
});
});
$(cell_obj).find('[ywl-btn-delete]').click(function () {
var user_id = row_data.user_id;
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/delete-user', {user_id: user_id},
function (ret) {
if (ret.code == 0) {
tbl.remove_row(row_id);
ywl.notify_success('删除用户成功!');
} else {
ywl.notify_error('删除用户失败!');
}
$(cell_obj).find('[ywl-btn-delete]').click(function () {
var user_id = row_data.user_id;
var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/user/delete-user', {user_id: user_id},
function (ret) {
if (ret.code === TPE_OK) {
tbl.remove_row(row_id);
ywl.notify_success('删除用户成功!');
} else {
ywl.notify_error('删除用户失败:' + ret.message);
}
},
function (ret) {
ywl.notify_error('删除用户失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
},
function () {
ywl.notify_error('网络故障,删除用户失败!');
}
);
};
var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack,
{
msg: '<p><strong>注意:移除操作不可恢复!!</strong></p><p>您确定要删除此用户吗?</p>',
fn_yes: _fn_sure
});
ywl.dlg_confirm(cb_stack,
{
msg: '<p><strong>注意:移除操作不可恢复!!</strong></p><p>您确定要删除此用户吗?</p>',
fn_yes: _fn_sure
});
});
$(cell_obj).find('[ywl-auth-allo]').click(function () {
window.open("/user/auth/" + row_data.user_name);
});
});
$(cell_obj).find('[ywl-auth-allo]').click(function () {
window.open("/user/auth/" + row_data.user_name);
});
}
};
}
};
// 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作
tbl.on_render_created = function (render) {
render.user_lock = function (row_id, fields) {
switch (fields.user_lock) {
case 0:
return '<span class="badge badge-success">允许访问</span>';
case 1:
return '<span class="badge badge-danger">禁止访问</span>';
default:
return '<span class="badge badge-danger">未知</span>';
}
};
render.make_action_btn = function (row_id, fields) {
var ret = [];
ret.push('<div class="btn-group btn-group-sm" role="group">');
// 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作
tbl.on_render_created = function (render) {
render.user_lock = function (row_id, fields) {
switch (fields.user_lock) {
case 0:
return '<span class="badge badge-success">允许访问</span>';
case 1:
return '<span class="badge badge-danger">禁止访问</span>';
default:
return '<span class="badge badge-danger">未知</span>';
}
};
render.make_action_btn = function (row_id, fields) {
var ret = [];
ret.push('<div class="btn-group btn-group-sm" role="group">');
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" ywl-auth-allo="' + fields.user_id + '"><i class="fa fa-trash-o fa-fw"></i> 授权</a>');
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" ywl-auth-allo="' + fields.user_id + '"><i class="fa fa-trash-o fa-fw"></i> 授权</a>');
ret.push('</div> &nbsp;<div class="btn-group btn-group-sm" role="group">');
ret.push('</div> &nbsp;<div class="btn-group btn-group-sm" role="group">');
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" ywl-btn-edit="' + fields.user_id + '"><i class="fa fa-edit fa-fw"></i> 编辑</a>');
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" ywl-btn-reset="' + fields.user_id + '"><i class="fa fa-circle-o fa-fw"></i> 重置密码</a>');
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" ywl-btn-edit="' + fields.user_id + '"><i class="fa fa-edit fa-fw"></i> 编辑</a>');
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" ywl-btn-reset="' + fields.user_id + '"><i class="fa fa-circle-o fa-fw"></i> 重置密码</a>');
ret.push('</div> &nbsp;<div class="btn-group btn-group-sm" role="group">');
if (fields.user_lock === 0)
ret.push('<a href="javascript:;" class="btn btn-sm btn-warning" ywl-btn-lock="' + fields.user_id + '"><i class="fa fa-lock fa-fw"></i> 锁定</a>');
else
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" ywl-btn-lock="' + fields.user_id + '"><i class="fa fa-unlock fa-fw"></i> 解锁</a>');
ret.push('</div> &nbsp;<div class="btn-group btn-group-sm" role="group">');
if (fields.user_lock === 0)
ret.push('<a href="javascript:;" class="btn btn-sm btn-warning" ywl-btn-lock="' + fields.user_id + '"><i class="fa fa-lock fa-fw"></i> 锁定</a>');
else
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" ywl-btn-lock="' + fields.user_id + '"><i class="fa fa-unlock fa-fw"></i> 解锁</a>');
ret.push('<a href="javascript:;" class="btn btn-sm btn-danger" ywl-btn-delete="' + fields.user_id + '"><i class="fa fa-trash-o fa-fw"></i> 移除</a>');
ret.push('</div>');
return ret.join('');
}
ret.push('<a href="javascript:;" class="btn btn-sm btn-danger" ywl-btn-delete="' + fields.user_id + '"><i class="fa fa-trash-o fa-fw"></i> 移除</a>');
ret.push('</div>');
return ret.join('');
}
};
};
};
ywl.on_host_table_header_created = function (tbl) {
};
ywl.create_user_info_dlg = function (tbl) {
var user_info_dlg = {};
user_info_dlg.dom_id = "#dialog_user_info";
user_info_dlg.update = 1;
user_info_dlg.tbl = tbl;
user_info_dlg.user_name = '';
user_info_dlg.user_id = 0;
user_info_dlg.row_id = 0;
user_info_dlg.user_desc = '';
var user_info_dlg = {};
user_info_dlg.dom_id = "#dialog_user_info";
user_info_dlg.update = 1;
user_info_dlg.tbl = tbl;
user_info_dlg.user_name = '';
user_info_dlg.user_id = 0;
user_info_dlg.row_id = 0;
user_info_dlg.user_desc = '';
user_info_dlg.update_show = function (user_name, user_desc, user_id, row_id) {
user_info_dlg.update = 1;
user_info_dlg.init(user_name, user_desc, user_id, row_id);
$('#dlg-notice').hide();
$(user_info_dlg.dom_id).modal();
};
user_info_dlg.create_show = function () {
user_info_dlg.update = 0;
user_info_dlg.init('', '', 0, 0);
$('#dlg-notice').show();
$(user_info_dlg.dom_id).modal();
};
user_info_dlg.update_show = function (user_name, user_desc, user_id, row_id) {
user_info_dlg.update = 1;
user_info_dlg.init(user_name, user_desc, user_id, row_id);
$('#dlg-notice').hide();
$(user_info_dlg.dom_id).modal();
};
user_info_dlg.create_show = function () {
user_info_dlg.update = 0;
user_info_dlg.init('', '', 0, 0);
$('#dlg-notice').show();
$(user_info_dlg.dom_id).modal();
};
user_info_dlg.hide = function() {
$(user_info_dlg.dom_id).modal('hide');
};
user_info_dlg.hide = function () {
$(user_info_dlg.dom_id).modal('hide');
};
user_info_dlg.init = function (user_name, user_desc, user_id, row_id) {
user_info_dlg.user_name = user_name;
user_info_dlg.user_desc = user_desc;
user_info_dlg.user_id = user_id;
user_info_dlg.row_id = row_id;
user_info_dlg.init_dlg();
};
user_info_dlg.init_dlg = function () {
$(user_info_dlg.dom_id + ' #user-name').val(user_info_dlg.user_name);
$(user_info_dlg.dom_id + ' #user-desc').val(user_info_dlg.user_desc);
if (user_info_dlg.update === 1) {
$(user_info_dlg.dom_id + ' #user-name').attr("disabled", "true");
} else {
$(user_info_dlg.dom_id + ' #user-name').removeAttr("disabled");
}
user_info_dlg.init = function (user_name, user_desc, user_id, row_id) {
user_info_dlg.user_name = user_name;
user_info_dlg.user_desc = user_desc;
user_info_dlg.user_id = user_id;
user_info_dlg.row_id = row_id;
user_info_dlg.init_dlg();
};
user_info_dlg.init_dlg = function () {
$(user_info_dlg.dom_id + ' #user-name').val(user_info_dlg.user_name);
$(user_info_dlg.dom_id + ' #user-desc').val(user_info_dlg.user_desc);
if (user_info_dlg.update === 1) {
$(user_info_dlg.dom_id + ' #user-name').attr("disabled", "true");
} else {
$(user_info_dlg.dom_id + ' #user-name').removeAttr("disabled");
}
};
};
user_info_dlg.check_args = function () {
user_info_dlg.user_name = $(user_info_dlg.dom_id + ' #user-name').val();
user_info_dlg.user_desc = $(user_info_dlg.dom_id + ' #user-desc').val();
return true;
};
user_info_dlg.post = function () {
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},
function (ret) {
var update_args = {user_desc: user_info_dlg.user_desc};
user_info_dlg.tbl.update_row(user_info_dlg.row_id, update_args);
ywl.notify_success('更新用户信息成功!');
user_info_dlg.hide();
},
function (ret) {
ywl.notify_error('更新用户信息失败!');
}
);
} else {
ywl.ajax_post_json('/user/add-user', {user_name: user_info_dlg.user_name, user_desc: user_info_dlg.user_desc},
function (ret) {
if (ret.code === 0) {
user_info_dlg.tbl.reload();
ywl.notify_success('添加用户成功!');
user_info_dlg.hide();
} else if (ret.code == -2) {
ywl.notify_error('已经存在同名用户!');
} else {
ywl.notify_error('添加用户失败!');
}
},
function (ret) {
ywl.notify_error('添加用户失败!');
}
);
}
return true;
};
$(user_info_dlg.dom_id + " #btn-save").click(function () {
if (!user_info_dlg.check_args()) {
return;
}
user_info_dlg.post();
});
return user_info_dlg
user_info_dlg.check_args = function () {
user_info_dlg.user_name = $(user_info_dlg.dom_id + ' #user-name').val();
user_info_dlg.user_desc = $(user_info_dlg.dom_id + ' #user-desc').val();
return true;
};
user_info_dlg.post = function () {
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},
function (ret) {
if (ret.code === TPE_OK) {
var update_args = {user_desc: user_info_dlg.user_desc};
user_info_dlg.tbl.update_row(user_info_dlg.row_id, update_args);
ywl.notify_success('更新用户信息成功!');
user_info_dlg.hide();
} else {
ywl.notify_error('更新用户信息失败:' + ret.message);
}
},
function () {
ywl.notify_error('网络故障,更新用户信息失败!');
}
);
} else {
ywl.ajax_post_json('/user/add-user', {user_name: user_info_dlg.user_name, user_desc: user_info_dlg.user_desc},
function (ret) {
if (ret.code === TPE_OK) {
user_info_dlg.tbl.reload();
ywl.notify_success('添加用户成功!');
user_info_dlg.hide();
} else if (ret.code === -100) {
ywl.notify_error('已经存在同名用户!');
} else {
ywl.notify_error('添加用户失败:' + ret.message);
}
},
function () {
ywl.notify_error('网络故障,添加用户失败!');
}
);
}
return true;
};
$(user_info_dlg.dom_id + " #btn-save").click(function () {
if (!user_info_dlg.check_args()) {
return;
}
user_info_dlg.post();
});
return user_info_dlg
};

View File

@ -1,166 +1,167 @@
"use strict";
var PROTOCOL_TYPE_RDP = 1;
var PROTOCOL_TYPE_SSH = 2;
var PROTOCOL_TYPE_TELNET = 3;
var OS_TYPE_WINDOWS = 1;
var OS_TYPE_LINUX = 2;
var AUTH_TYPE_PASSWORD = 1;
var AUTH_TYPE_SSHKEY = 2;
var AUTH_NONE = 0;
//var USER_TYPE_TEAM_MEMBER = 1;
//var USER_TYPE_TEAM_LEADER = 9;
//var USER_TYPE_SYS_ADMIN = 99;
//var AGENT_STAT_ONLINE = 1;
//var AGENT_STAT_OFFLINE = 0;
//var AGENT_STAT_NOT_ACTIVE = 2;
var HOST_STAT_NOT_ACTIVE = 0;
var HOST_STAT_ACTIVE = 2;
var CACHE_TYPE_COMMAND = 1;
var CACHE_TYPE_TEAM_MEMBER = 2;
var CACHE_TYPE_TEAM = 3;
var CACHE_TYPE_COMMAND_VER = 4;
var CACHE_TYPE_GROUP = 5;
var CACHE_TYPE_COOKIE = 6;
var CACHE_TYPE_EVENT_CODE = 7;
var CACHE_TYPE_CONFIG = 8;
var KB = 1024;
var MB = 1048576;
var GB = 1073741824;
var TB = 1099511627776;
var PB = 1125899906842624;
var SECONDS_PER_DAY = 86400;
var SECONDS_PER_HOUR = 3600;
var SECONDS_PER_MINUTE = 60;
var system_group = [
{id: 0, name: '全部'},
{id: -1},
{id: 1, name: 'Windows'},
{id: -1},
{id: 2, name: 'Linux'}
];
var paging_normal = {
use_cookie: true,
default_select: '25',
selections: [
{name: '10', val: 10},
{name: "25", val: 25},
{name: "50", val: 50},
{name: "100", val: 100}]
};
var paging_big = {
use_cookie: false,
default_select: '100',
selections: [{name: "100", val: 100}]
};
//========================================================
// 错误值(请参考源代码/common/teleport/teleport_const.h
//========================================================
var TPE_OK = 0;
//-------------------------------------------------------
// 通用错误值
//-------------------------------------------------------
var TPE_NEED_MORE_DATA = 1; // 需要更多数据(不一定是错误)
// 100~299是通用错误值
var TPE_FAILED = 100; // 内部错误
var TPE_NETWORK = 101; // 网络错误
// HTTP请求相关错误
var TPE_HTTP_METHOD = 120; // 无效的请求方法不是GET/POST等或者错误的请求方法例如需要POST却使用GET方式请求
var TPE_HTTP_URL_ENCODE = 121; // URL编码错误无法解码
//#define TPE_HTTP_URI 122 // 无效的URI
var TPE_UNKNOWN_CMD = 124; // 未知的命令
var TPE_JSON_FORMAT = 125; // 错误的JSON格式需要JSON格式数据但是却无法按JSON格式解码
var TPE_PARAM = 126; // 参数错误
var TPE_DATA = 127; // 数据错误
// #define TPE_OPENFILE_ERROR 0x1007 // 无法打开文件
// #define TPE_GETTEMPPATH_ERROR 0x1007
var TPE_OPENFILE = 300; // 无法打开文件
//-------------------------------------------------------
// 助手程序专用错误值
//-------------------------------------------------------
var TPE_NO_ASSIST = 100000; // 未能检测到助手程序
var TPE_OLD_ASSIST = 100001; // 助手程序版本太低
var TPE_START_CLIENT = 100002; // 无法启动客户端程序(无法创建进程)
//-------------------------------------------------------
// 核心服务专用错误值
//-------------------------------------------------------
var TPE_NO_CORE_SERVER = 200000; // 未能检测到核心服务
function tp_error_msg(error_code) {
switch (error_code) {
case TPE_FAILED:
return '内部错误';
case TPE_NETWORK:
return '网络错误';
//-------------------------------------------------------
// HTTP请求相关错误
//-------------------------------------------------------
case TPE_HTTP_METHOD:
return '无效/错误的请求方法';
case TPE_HTTP_URL_ENCODE:
return 'URL编码错误无法解码';
case TPE_UNKNOWN_CMD:
return '未知命令';
case TPE_JSON_FORMAT:
return '错误的JSON格式数据';
case TPE_PARAM:
return '参数错误';
case TPE_DATA:
return '数据错误';
case TPE_OPENFILE:
return '无法打开文件';
//-------------------------------------------------------
// 助手程序专用错误值
//-------------------------------------------------------
case TPE_NO_ASSIST:
return '未能检测到助手程序';
case TPE_OLD_ASSIST:
return '助手程序版本太低';
case TPE_START_CLIENT:
return '无法启动客户端程序(无法创建进程)';
//-------------------------------------------------------
// 核心服务专用错误值
//-------------------------------------------------------
case TPE_NO_CORE_SERVER:
return '未能检测到核心服务';
default:
return '未知错误';
}
}
"use strict";
var PROTOCOL_TYPE_RDP = 1;
var PROTOCOL_TYPE_SSH = 2;
var PROTOCOL_TYPE_TELNET = 3;
var OS_TYPE_WINDOWS = 1;
var OS_TYPE_LINUX = 2;
var AUTH_TYPE_PASSWORD = 1;
var AUTH_TYPE_SSHKEY = 2;
var AUTH_NONE = 0;
//var USER_TYPE_TEAM_MEMBER = 1;
//var USER_TYPE_TEAM_LEADER = 9;
//var USER_TYPE_SYS_ADMIN = 99;
//var AGENT_STAT_ONLINE = 1;
//var AGENT_STAT_OFFLINE = 0;
//var AGENT_STAT_NOT_ACTIVE = 2;
var HOST_STAT_NOT_ACTIVE = 0;
var HOST_STAT_ACTIVE = 2;
var CACHE_TYPE_COMMAND = 1;
var CACHE_TYPE_TEAM_MEMBER = 2;
var CACHE_TYPE_TEAM = 3;
var CACHE_TYPE_COMMAND_VER = 4;
var CACHE_TYPE_GROUP = 5;
var CACHE_TYPE_COOKIE = 6;
var CACHE_TYPE_EVENT_CODE = 7;
var CACHE_TYPE_CONFIG = 8;
var KB = 1024;
var MB = 1048576;
var GB = 1073741824;
var TB = 1099511627776;
var PB = 1125899906842624;
var SECONDS_PER_DAY = 86400;
var SECONDS_PER_HOUR = 3600;
var SECONDS_PER_MINUTE = 60;
var system_group = [
{id: 0, name: '全部'},
{id: -1},
{id: 1, name: 'Windows'},
{id: -1},
{id: 2, name: 'Linux'}
];
var paging_normal = {
use_cookie: true,
default_select: '25',
selections: [
{name: '10', val: 10},
{name: "25", val: 25},
{name: "50", val: 50},
{name: "100", val: 100}]
};
var paging_big = {
use_cookie: false,
default_select: '100',
selections: [{name: "100", val: 100}]
};
//========================================================
// 错误值(请参考源代码/common/teleport/teleport_const.h
//========================================================
var TPE_OK = 0;
//-------------------------------------------------------
// 通用错误值
//-------------------------------------------------------
var TPE_NEED_MORE_DATA = 1; // 需要更多数据(不一定是错误)
// 100~299是通用错误值
var TPE_FAILED = 100; // 内部错误
var TPE_NETWORK = 101; // 网络错误
// HTTP请求相关错误
var TPE_HTTP_METHOD = 120; // 无效的请求方法不是GET/POST等或者错误的请求方法例如需要POST却使用GET方式请求
var TPE_HTTP_URL_ENCODE = 121; // URL编码错误无法解码
//#define TPE_HTTP_URI 122 // 无效的URI
var TPE_UNKNOWN_CMD = 124; // 未知的命令
var TPE_JSON_FORMAT = 125; // 错误的JSON格式需要JSON格式数据但是却无法按JSON格式解码
var TPE_PARAM = 126; // 参数错误
var TPE_DATA = 127; // 数据错误
// #define TPE_OPENFILE_ERROR 0x1007 // 无法打开文件
// #define TPE_GETTEMPPATH_ERROR 0x1007
var TPE_OPENFILE = 300; // 无法打开文件
//-------------------------------------------------------
// 助手程序专用错误值
//-------------------------------------------------------
var TPE_NO_ASSIST = 100000; // 未能检测到助手程序
var TPE_OLD_ASSIST = 100001; // 助手程序版本太低
var TPE_START_CLIENT = 100002; // 无法启动客户端程序(无法创建进程)
//-------------------------------------------------------
// 核心服务专用错误值
//-------------------------------------------------------
var TPE_NO_CORE_SERVER = 200000; // 未能检测到核心服务
function tp_error_msg(error_code) {
switch (error_code) {
case TPE_FAILED:
return '内部错误';
case TPE_NETWORK:
return '网络错误';
//-------------------------------------------------------
// HTTP请求相关错误
//-------------------------------------------------------
case TPE_HTTP_METHOD:
return '无效/错误的请求方法';
case TPE_HTTP_URL_ENCODE:
return 'URL编码错误无法解码';
case TPE_UNKNOWN_CMD:
return '未知命令';
case TPE_JSON_FORMAT:
return '错误的JSON格式数据';
case TPE_PARAM:
return '参数错误';
case TPE_DATA:
return '数据错误';
case TPE_OPENFILE:
return '无法打开文件';
//-------------------------------------------------------
// 助手程序专用错误值
//-------------------------------------------------------
case TPE_NO_ASSIST:
return '未能检测到助手程序';
case TPE_OLD_ASSIST:
return '助手程序版本太低';
case TPE_START_CLIENT:
return '无法启动客户端程序(无法创建进程)';
//-------------------------------------------------------
// 核心服务专用错误值
//-------------------------------------------------------
case TPE_NO_CORE_SERVER:
return '未能检测到核心服务';
default:
return '未知错误';
}
}

View File

@ -1,186 +1,186 @@
<%!
page_title_ = '配置TELEPORT服务'
%>
<%inherit file="../page_maintenance_base.mako"/>
<%block name="breadcrumb">
<ol class="breadcrumb">
<li><i class="fa fa-cog fa-fw"></i> ${self.attr.page_title_}</li>
</ol>
</%block>
<%block name="embed_css">
<style type="text/css">
.container {
background-color: #fff;
padding-bottom: 20px;
}
h1 {
font-size: 200%;
}
h2 {
font-size: 160%;
}
.steps-detail {
display: none;
margin: 10px;
padding: 10px;
border: 1px solid #b4b4b4;
background-color: #dcdcdc;
}
.steps-detail p {
padding-left: 5px;
margin: 2px 0 2px 1px;
}
.steps-detail p.error {
color: #ffffff;
margin: 2px 0 2px 0;
background-color: #cc3632;
border: 1px solid #9c2a26;
}
</style>
</%block>
## Begin Main Body.
<div class="page-content">
<div class="content_box">
<div class="container">
<h1>配置TELEPORT服务</h1>
<hr/>
<h2>第一步:创建数据表</h2>
<div>
<p>请选择要使用的数据库类型暂时仅支持sqlite其它类型开发中</p>
<input id="db-sqlite" type="radio" checked="checked" name="database" value="sqlite"/> <label for="db-sqlite">SQLite</label><br/>
<input id="db-mysql" type="radio" name="database" value="mysql" disabled="disabled"/> <label for="db-mysql">MySQL开发中暂不支持</label>
<div>
<button id="btn-create-db" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始创建</button>
</div>
<div id="steps-detail" class="steps-detail"></div>
</div>
<div id="step2" style="display:none;">
<hr/>
<h2>已完成!</h2>
<p>是的没有第二步了安装配置已经完成了刷新页面即可进入Teleport主界面啦~~</p>
</div>
</div>
</div>
</div>
<%block name="embed_js">
<script type="text/javascript">
"use strict";
ywl.on_init = function (cb_stack, cb_args) {
ywl.dom = {
btn_create_db: $('#btn-create-db'),
steps_detail: $('#steps-detail')
};
ywl.dom.btn_create_db.click(function () {
ywl.dom.btn_create_db.attr('disabled', 'disabled').hide();
ywl.dom.steps_detail.show();
console.log('create-db-click');
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'create_db'},
function (ret) {
console.log('create-db:', ret);
if (ret.code == 0) {
var cb_stack = CALLBACK_STACK.create();
cb_stack
.add(ywl.get_task_ret, {task_id: ret.data.task_id})
.add(ywl.delay_exec, {delay_ms: 500})
.exec();
}
},
function () {
ywl.show_message('error', '无法连接到服务器!');
}
);
});
ywl.get_task_ret = function (cb_stack, cb_args) {
var task_id = cb_args.task_id || 0;
if (task_id == 0) {
console.log('task-id', task_id);
return;
}
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'get_task_ret', 'tid': task_id},
function (ret) {
console.log('get_task_ret:', ret);
if (ret.code == 0) {
// show step progress.
var steps = ret.data.steps;
ywl.dom.steps_detail.empty();
var html = [];
var icon_class = '';
var err_class = '';
for (var i = 0; i < steps.length; ++i) {
if (steps[i].stat == 0)
icon_class = 'fa-check';
else
icon_class = 'fa-cog fa-spin';
if (steps[i].code != 0) {
icon_class = 'fa-exclamation-circle';
err_class = ' class="error"';
steps[i].msg += ' 失败!'
}
else {
err_class = '';
}
html.push('<p');
html.push(err_class);
html.push('><i class="fa ');
html.push(icon_class);
html.push('"></i> ');
html.push(steps[i].msg);
html.push('</p>')
}
ywl.dom.steps_detail.html(html.join(''));
if (!ret.data.running) {
$('#step2').show('fast');
return;
}
cb_stack
.add(ywl.get_task_ret, {task_id: task_id})
.add(ywl.delay_exec, {delay_ms: 500})
.exec();
}
},
function () {
ywl.show_message('error', '无法连接到服务器!');
}
);
};
cb_stack.exec();
};
</script>
</%block>
<%!
page_title_ = '配置TELEPORT服务'
%>
<%inherit file="../page_maintenance_base.mako"/>
<%block name="breadcrumb">
<ol class="breadcrumb">
<li><i class="fa fa-cog fa-fw"></i> ${self.attr.page_title_}</li>
</ol>
</%block>
<%block name="embed_css">
<style type="text/css">
.container {
background-color: #fff;
padding-bottom: 20px;
}
h1 {
font-size: 200%;
}
h2 {
font-size: 160%;
}
.steps-detail {
display: none;
margin: 10px;
padding: 10px;
border: 1px solid #b4b4b4;
background-color: #dcdcdc;
}
.steps-detail p {
padding-left: 5px;
margin: 2px 0 2px 1px;
}
.steps-detail p.error {
color: #ffffff;
margin: 2px 0 2px 0;
background-color: #cc3632;
border: 1px solid #9c2a26;
}
</style>
</%block>
## Begin Main Body.
<div class="page-content">
<div class="content_box">
<div class="container">
<h1>配置TELEPORT服务</h1>
<hr/>
<h2>第一步:创建数据表</h2>
<div>
<p>请选择要使用的数据库类型暂时仅支持sqlite其它类型开发中</p>
<input id="db-sqlite" type="radio" checked="checked" name="database" value="sqlite"/> <label for="db-sqlite">SQLite</label><br/>
<input id="db-mysql" type="radio" name="database" value="mysql" disabled="disabled"/> <label for="db-mysql">MySQL开发中暂不支持</label>
<div>
<button id="btn-create-db" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始创建</button>
</div>
<div id="steps-detail" class="steps-detail"></div>
</div>
<div id="step2" style="display:none;">
<hr/>
<h2>已完成!</h2>
<p>是的没有第二步了安装配置已经完成了刷新页面即可进入Teleport主界面啦~~</p>
</div>
</div>
</div>
</div>
<%block name="embed_js">
<script type="text/javascript">
"use strict";
ywl.on_init = function (cb_stack, cb_args) {
ywl.dom = {
btn_create_db: $('#btn-create-db'),
steps_detail: $('#steps-detail')
};
ywl.dom.btn_create_db.click(function () {
ywl.dom.btn_create_db.attr('disabled', 'disabled').hide();
ywl.dom.steps_detail.show();
console.log('create-db-click');
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'create_db'},
function (ret) {
console.log('create-db:', ret);
if (ret.code === TPE_OK) {
var cb_stack = CALLBACK_STACK.create();
cb_stack
.add(ywl.get_task_ret, {task_id: ret.data.task_id})
.add(ywl.delay_exec, {delay_ms: 500})
.exec();
}
},
function () {
ywl.show_message('error', '无法连接到服务器!');
}
);
});
ywl.get_task_ret = function (cb_stack, cb_args) {
var task_id = cb_args.task_id || 0;
if (task_id === 0) {
console.log('task-id', task_id);
return;
}
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'get_task_ret', 'tid': task_id},
function (ret) {
console.log('get_task_ret:', ret);
if (ret.code === TPE_OK) {
// show step progress.
var steps = ret.data.steps;
ywl.dom.steps_detail.empty();
var html = [];
var icon_class = '';
var err_class = '';
for (var i = 0; i < steps.length; ++i) {
if (steps[i].stat === 0)
icon_class = 'fa-check';
else
icon_class = 'fa-cog fa-spin';
if (steps[i].code !== 0) {
icon_class = 'fa-exclamation-circle';
err_class = ' class="error"';
steps[i].msg += ' 失败!'
}
else {
err_class = '';
}
html.push('<p');
html.push(err_class);
html.push('><i class="fa ');
html.push(icon_class);
html.push('"></i> ');
html.push(steps[i].msg);
html.push('</p>')
}
ywl.dom.steps_detail.html(html.join(''));
if (!ret.data.running) {
$('#step2').show('fast');
return;
}
cb_stack
.add(ywl.get_task_ret, {task_id: task_id})
.add(ywl.delay_exec, {delay_ms: 500})
.exec();
}
},
function () {
ywl.show_message('error', '无法连接到服务器!');
}
);
};
cb_stack.exec();
};
</script>
</%block>