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

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

View File

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

View File

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

View File

@ -1,328 +1,328 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import hashlib import hashlib
from eom_app.app.configs import app_cfg from eom_app.app.configs import app_cfg
from eom_app.app.const import * from eom_app.app.const import *
from eom_app.app.db import get_db, DbItem from eom_app.app.db import get_db, DbItem
from eom_app.app.util import sec_generate_password, sec_verify_password from eom_app.app.util import sec_generate_password, sec_verify_password
def verify_user(name, password): def verify_user(name, password):
cfg = app_cfg() cfg = app_cfg()
db = get_db() 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) 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) db_ret = db.query(sql)
if db_ret is None: if db_ret is None:
# 特别地,如果无法取得数据库连接,有可能是新安装的系统,尚未建立数据库,此时应该处于维护模式 # 特别地,如果无法取得数据库连接,有可能是新安装的系统,尚未建立数据库,此时应该处于维护模式
# 因此可以特别地处理用户验证用户名admin密码admin可以登录为管理员 # 因此可以特别地处理用户验证用户名admin密码admin可以登录为管理员
if cfg.app_mode == APP_MODE_MAINTENANCE: if cfg.app_mode == APP_MODE_MAINTENANCE:
if name == 'admin' and password == 'admin': if name == 'admin' and password == 'admin':
return 1, 100, 'admin', 0 return 1, 100, 'admin', 0
return 0, 0, '', 0 return 0, 0, '', 0
if len(db_ret) != 1: if len(db_ret) != 1:
return 0, 0, '', 0 return 0, 0, '', 0
user_id = db_ret[0][0] user_id = db_ret[0][0]
account_type = db_ret[0][1] account_type = db_ret[0][1]
name = db_ret[0][2] name = db_ret[0][2]
locked = db_ret[0][4] locked = db_ret[0][4]
if locked == 1: if locked == 1:
return 0, 0, '', locked return 0, 0, '', locked
if not sec_verify_password(password, db_ret[0][3]): if not sec_verify_password(password, db_ret[0][3]):
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下 # 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
if db_ret[0][3] != hashlib.sha256(password.encode()).hexdigest(): if db_ret[0][3] != hashlib.sha256(password.encode()).hexdigest():
return 0, 0, '', locked return 0, 0, '', locked
else: else:
# 发现此用户的密码散列格式还是旧的,更新成新的吧! # 发现此用户的密码散列格式还是旧的,更新成新的吧!
_new_sec_password = sec_generate_password(password) _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)) sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id))
db.exec(sql) db.exec(sql)
return user_id, account_type, name, locked return user_id, account_type, name, locked
def modify_pwd(old_pwd, new_pwd, user_id): def modify_pwd(old_pwd, new_pwd, user_id):
db = get_db() db = get_db()
sql = 'SELECT `account_pwd` FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id)) sql = 'SELECT `account_pwd` FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
db_ret = db.query(sql) db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 1: if db_ret is None or len(db_ret) != 1:
return -2 return -100
if not sec_verify_password(old_pwd, db_ret[0][0]): if not sec_verify_password(old_pwd, db_ret[0][0]):
# 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下 # 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下
if db_ret[0][0] != hashlib.sha256(old_pwd.encode()).hexdigest(): if db_ret[0][0] != hashlib.sha256(old_pwd.encode()).hexdigest():
return -2 return -101
_new_sec_password = sec_generate_password(new_pwd) _new_sec_password = sec_generate_password(new_pwd)
sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id)) sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id))
db_ret = db.exec(sql) db_ret = db.exec(sql)
if db_ret: if db_ret:
return 0 return 0
else: else:
return -3 return -102
def get_user_list(with_admin=False): def get_user_list(with_admin=False):
db = get_db() db = get_db()
ret = list() ret = list()
field_a = ['account_id', 'account_type', 'account_name', 'account_status', 'account_lock', 'account_desc'] field_a = ['account_id', 'account_type', 'account_name', 'account_status', 'account_lock', 'account_desc']
if with_admin: if with_admin:
where = '' where = ''
else: else:
where = 'WHERE `a`.`account_type`<100' 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) 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) db_ret = db.query(sql)
if db_ret is None: if db_ret is None:
return ret return ret
for item in db_ret: for item in db_ret:
x = DbItem() x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a]) x.load(item, ['a_{}'.format(i) for i in field_a])
h = dict() h = dict()
h['user_id'] = x.a_account_id h['user_id'] = x.a_account_id
h['user_type'] = x.a_account_type h['user_type'] = x.a_account_type
h['user_name'] = x.a_account_name h['user_name'] = x.a_account_name
h['user_status'] = x.a_account_status h['user_status'] = x.a_account_status
h['user_lock'] = x.a_account_lock h['user_lock'] = x.a_account_lock
h['user_desc'] = x.a_account_desc h['user_desc'] = x.a_account_desc
ret.append(h) ret.append(h)
return ret return ret
def delete_user(user_id): def delete_user(user_id):
db = get_db() db = get_db()
sql = 'DELETE FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id)) sql = 'DELETE FROM `{}account` WHERE `account_id`={};'.format(db.table_prefix, int(user_id))
return db.exec(sql) return db.exec(sql)
def lock_user(user_id, lock_status): def lock_user(user_id, lock_status):
db = get_db() db = get_db()
sql = 'UPDATE `{}account` SET `account_lock`={} WHERE `account_id`={};'.format(db.table_prefix, lock_status, int(user_id)) sql = 'UPDATE `{}account` SET `account_lock`={} WHERE `account_id`={};'.format(db.table_prefix, lock_status, int(user_id))
return db.exec(sql) return db.exec(sql)
def reset_user(user_id): def reset_user(user_id):
db = get_db() db = get_db()
_new_sec_password = sec_generate_password('123456') _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)) sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={};'.format(db.table_prefix, _new_sec_password, int(user_id))
return db.exec(sql) return db.exec(sql)
def modify_user(user_id, user_desc): def modify_user(user_id, user_desc):
db = get_db() db = get_db()
sql = 'UPDATE `{}account` SET `account_desc`="{}" WHERE `account_id`={};'.format(db.table_prefix, user_desc, int(user_id)) sql = 'UPDATE `{}account` SET `account_desc`="{}" WHERE `account_id`={};'.format(db.table_prefix, user_desc, int(user_id))
return db.exec(sql) return db.exec(sql)
def add_user(user_name, user_pwd, user_desc): def add_user(user_name, user_pwd, user_desc):
db = get_db() db = get_db()
sql = 'SELECT `account_id` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, user_name) sql = 'SELECT `account_id` FROM `{}account` WHERE `account_name`="{}";'.format(db.table_prefix, user_name)
db_ret = db.query(sql) db_ret = db.query(sql)
if db_ret is None or len(db_ret) != 0: if db_ret is None or len(db_ret) != 0:
return -2 return -100
sec_password = sec_generate_password(user_pwd) sec_password = sec_generate_password(user_pwd)
sql = 'INSERT INTO `{}account` (`account_type`, `account_name`, `account_pwd`, `account_status`,' \ sql = 'INSERT INTO `{}account` (`account_type`, `account_name`, `account_pwd`, `account_status`,' \
'`account_lock`,`account_desc`) VALUES (1,"{}","{}",0,0,"{}")'.format(db.table_prefix, user_name, sec_password, user_desc) '`account_lock`,`account_desc`) VALUES (1,"{}","{}",0,0,"{}")'.format(db.table_prefix, user_name, sec_password, user_desc)
ret = db.exec(sql) ret = db.exec(sql)
if ret: if ret:
return 0 return 0
return -3 return -101
def alloc_host(user_name, host_list): def alloc_host(user_name, host_list):
db = get_db() db = get_db()
field_a = ['host_id'] 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) 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) db_ret = db.query(sql)
ret = dict() ret = dict()
for item in db_ret: for item in db_ret:
x = DbItem() x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a]) x.load(item, ['a_{}'.format(i) for i in field_a])
host_id = int(x.a_host_id) host_id = int(x.a_host_id)
ret[host_id] = host_id ret[host_id] = host_id
a_list = list() a_list = list()
for item in host_list: for item in host_list:
if item in ret: if item in ret:
pass pass
else: else:
a_list.append(item) a_list.append(item)
try: try:
for item in a_list: for item in a_list:
host_id = int(item) host_id = int(item)
sql = 'INSERT INTO `{}auth` (`account_name`, `host_id`) VALUES ("{}", {});'.format(db.table_prefix, user_name, host_id) sql = 'INSERT INTO `{}auth` (`account_name`, `host_id`) VALUES ("{}", {});'.format(db.table_prefix, user_name, host_id)
ret = db.exec(sql) ret = db.exec(sql)
if not ret: if not ret:
return False return False
return True return True
except: except:
return False return False
def alloc_host_user(user_name, host_auth_dict): def alloc_host_user(user_name, host_auth_dict):
db = get_db() db = get_db()
field_a = ['host_id', 'host_auth_id'] 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) 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) db_ret = db.query(sql)
ret = dict() ret = dict()
for item in db_ret: for item in db_ret:
x = DbItem() x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a]) x.load(item, ['a_{}'.format(i) for i in field_a])
host_id = int(x.a_host_id) host_id = int(x.a_host_id)
host_auth_id = int(x.a_host_auth_id) host_auth_id = int(x.a_host_auth_id)
if host_id not in ret: if host_id not in ret:
ret[host_id] = dict() ret[host_id] = dict()
temp = ret[host_id] temp = ret[host_id]
temp[host_auth_id] = host_id temp[host_auth_id] = host_id
ret[host_id] = temp ret[host_id] = temp
add_dict = dict() add_dict = dict()
for k, v in host_auth_dict.items(): for k, v in host_auth_dict.items():
host_id = int(k) host_id = int(k)
auth_id_list = v auth_id_list = v
for item in auth_id_list: for item in auth_id_list:
host_auth_id = int(item) host_auth_id = int(item)
if host_id not in ret: if host_id not in ret:
add_dict[host_auth_id] = host_id add_dict[host_auth_id] = host_id
continue continue
temp = ret[host_id] temp = ret[host_id]
if host_auth_id not in temp: if host_auth_id not in temp:
add_dict[host_auth_id] = host_id add_dict[host_auth_id] = host_id
continue continue
try: try:
for k, v in add_dict.items(): for k, v in add_dict.items():
host_auth_id = int(k) host_auth_id = int(k)
host_id = int(v) 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) 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) ret = db.exec(sql)
if not ret: if not ret:
return False return False
return True return True
except: except:
return False return False
def delete_host(user_name, host_list): def delete_host(user_name, host_list):
db = get_db() db = get_db()
try: try:
for item in host_list: for item in host_list:
host_id = int(item) host_id = int(item)
sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `host_id`={};'.format(db.table_prefix, user_name, host_id) sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `host_id`={};'.format(db.table_prefix, user_name, host_id)
ret = db.exec(sql) ret = db.exec(sql)
if not ret: if not ret:
return False return False
return True return True
except: except:
return False return False
def delete_host_user(user_name, auth_id_list): def delete_host_user(user_name, auth_id_list):
db = get_db() db = get_db()
try: try:
for item in auth_id_list: for item in auth_id_list:
auth_id = int(item) auth_id = int(item)
sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `auth_id`={};'.format(db.table_prefix, user_name, auth_id) sql = 'DELETE FROM `{}auth` WHERE `account_name`="{}" AND `auth_id`={};'.format(db.table_prefix, user_name, auth_id)
ret = db.exec(sql) ret = db.exec(sql)
if not ret: if not ret:
return False return False
return True return True
except: except:
return False return False
def get_log_list(_filter, limit): def get_log_list(_filter, limit):
db = get_db() db = get_db()
_where = '' _where = ''
if len(_filter) > 0: if len(_filter) > 0:
_where = 'WHERE ( ' _where = 'WHERE ( '
need_and = False need_and = False
for k in _filter: for k in _filter:
if k == 'account_name': if k == 'account_name':
if need_and: if need_and:
_where += ' AND' _where += ' AND'
_where += ' `a`.`account_name`="{}"'.format(_filter[k]) _where += ' `a`.`account_name`="{}"'.format(_filter[k])
need_and = True need_and = True
if k == 'user_name': if k == 'user_name':
if need_and: if need_and:
_where += ' AND' _where += ' AND'
_where += ' `a`.`account_name`="{}"'.format(_filter[k]) _where += ' `a`.`account_name`="{}"'.format(_filter[k])
need_and = True need_and = True
elif k == 'search': elif k == 'search':
# 查找限于主机ID和IP地址前者是数字只能精确查找后者可以模糊匹配 # 查找限于主机ID和IP地址前者是数字只能精确查找后者可以模糊匹配
# 因此,先判断搜索项能否转换为数字。 # 因此,先判断搜索项能否转换为数字。
if need_and: if need_and:
_where += ' AND ' _where += ' AND '
_where += '(' _where += '('
_where += '`a`.`host_ip` LIKE "%{}%" )'.format(_filter[k]) _where += '`a`.`host_ip` LIKE "%{}%" )'.format(_filter[k])
need_and = True need_and = True
_where += ')' _where += ')'
# http://www.jb51.net/article/46015.htm # 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', 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'] 'begin_time', 'end_time', 'log_time', 'protocol']
sql = 'SELECT COUNT(*) FROM `{}log` AS a {};'.format(db.table_prefix, _where) sql = 'SELECT COUNT(*) FROM `{}log` AS a {};'.format(db.table_prefix, _where)
db_ret = db.query(sql) db_ret = db.query(sql)
total_count = db_ret[0][0] total_count = db_ret[0][0]
# 修正分页数据 # 修正分页数据
_limit = '' _limit = ''
if len(limit) > 0: if len(limit) > 0:
_page_index = limit['page_index'] _page_index = limit['page_index']
_per_page = limit['per_page'] _per_page = limit['per_page']
_limit = 'LIMIT {},{}'.format(_page_index * _per_page, (_page_index + 1) * _per_page) _limit = 'LIMIT {},{}'.format(_page_index * _per_page, (_page_index + 1) * _per_page)
if _page_index * _per_page >= total_count: if _page_index * _per_page >= total_count:
_page_index = int(total_count / _per_page) _page_index = int(total_count / _per_page)
_limit = 'LIMIT {},{}'.format(_page_index * _per_page, (_page_index + 1) * _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) 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) db_ret = db.query(sql)
ret = list() ret = list()
for item in db_ret: for item in db_ret:
x = DbItem() x = DbItem()
x.load(item, ['a_{}'.format(i) for i in field_a]) x.load(item, ['a_{}'.format(i) for i in field_a])
h = dict() h = dict()
h['id'] = x.a_id h['id'] = x.a_id
h['session_id'] = x.a_session_id h['session_id'] = x.a_session_id
h['account_name'] = x.a_account_name h['account_name'] = x.a_account_name
h['host_ip'] = x.a_host_ip h['host_ip'] = x.a_host_ip
h['host_port'] = x.a_host_port h['host_port'] = x.a_host_port
h['auth_type'] = x.a_auth_type h['auth_type'] = x.a_auth_type
h['sys_type'] = x.a_sys_type h['sys_type'] = x.a_sys_type
h['user_name'] = x.a_user_name h['user_name'] = x.a_user_name
h['ret_code'] = x.a_ret_code h['ret_code'] = x.a_ret_code
cost_time = (x.a_end_time - x.a_begin_time) cost_time = (x.a_end_time - x.a_begin_time)
if cost_time < 0: if cost_time < 0:
cost_time = 0 cost_time = 0
h['cost_time'] = cost_time h['cost_time'] = cost_time
h['begin_time'] = x.a_begin_time h['begin_time'] = x.a_begin_time
if x.a_protocol is not None: if x.a_protocol is not None:
h['protocol'] = x.a_protocol h['protocol'] = x.a_protocol
else: else:
if x.a_sys_type == 1: if x.a_sys_type == 1:
h['protocol'] = 1 h['protocol'] = 1
else: else:
h['protocol'] = 2 h['protocol'] = 2
ret.append(h) ret.append(h)
return total_count, ret 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) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, ywl.ajax_post_json('/host/delete-host', {host_list: host_list},
function (ret) { function (ret) {
g_host_table.reload(); if (ret.code === TPE_OK) {
ywl.notify_success('删除主机操作成功!'); g_host_table.reload();
ywl.notify_success('删除主机操作成功!');
} else {
ywl.notify_error('删除主机操作失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('网络故障,删除主机操作失败!'); ywl.notify_error('网络故障,删除主机操作失败!');
@ -344,12 +348,16 @@ ywl.on_host_table_created = function (tbl) {
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/lock-host', {host_id: host_id, lock: host_lock}, ywl.ajax_post_json('/host/lock-host', {host_id: host_id, lock: host_lock},
function (ret) { function (ret) {
var update_args = {host_lock: host_lock}; if (ret.code === TPE_OK) {
tbl.update_row(row_id, update_args); var update_args = {host_lock: host_lock};
ywl.notify_success('操作成功'); tbl.update_row(row_id, update_args);
ywl.notify_success('锁定主机操作成功!');
} else {
ywl.notify_error('锁定主机操作失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('操作失败'); ywl.notify_error('网络故障,锁定主机操作失败');
} }
); );
}; };
@ -370,11 +378,15 @@ ywl.on_host_table_created = function (tbl) {
host_list.push(host_id); host_list.push(host_id);
ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, ywl.ajax_post_json('/host/delete-host', {host_list: host_list},
function (ret) { function (ret) {
tbl.remove_row(row_id); if (ret.code === TPE_OK) {
ywl.notify_success('操作成功'); tbl.remove_row(row_id);
ywl.notify_success('删除主机操作成功!');
} else {
ywl.notify_error('删除主机操作失败:' + ret.message);
}
}, },
function () { 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}, ywl.ajax_post_json('/host/update', {host_id: host_id, kv: args},
function (ret) { function (ret) {
var update_args = { if (ret.code === TPE_OK) {
host_ip: dlg_edit_host.ip, var update_args = {
group_name: dlg_edit_host.group_name, host_ip: dlg_edit_host.ip,
group_id: dlg_edit_host.group_id, group_name: dlg_edit_host.group_name,
host_desc: dlg_edit_host.host_desc, group_id: dlg_edit_host.group_id,
host_sys_type: dlg_edit_host.sys_type, host_desc: dlg_edit_host.host_desc,
protocol: protocol, host_sys_type: dlg_edit_host.sys_type,
host_port: host_port protocol: protocol,
}; host_port: host_port
};
dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args); dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args);
ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 的认证信息已保存!'); ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已保存!');
dlg_edit_host.hide(); dlg_edit_host.hide();
} else {
ywl.notify_error('主机 ' + self.host_ip + ' 信息更新失败:' + ret.message);
}
}, },
function () { function () {
ywl.notify_error('主机 ' + self.host_ip + ' 更新失败!', ''); ywl.notify_error('网络故障,主机 ' + self.host_ip + ' 信息更新失败!');
} }
); );
}; };
@ -837,22 +853,22 @@ ywl.create_host_edit_dlg = function (tbl) {
ywl.ajax_post_json('/host/add-host', args, ywl.ajax_post_json('/host/add-host', args,
function (ret) { function (ret) {
if (ret.code === 0) { if (ret.code === TPE_OK) {
dlg_edit_host.tbl.reload(); dlg_edit_host.tbl.reload();
ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已添加!'); ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已添加!');
dlg_edit_host.hide(); dlg_edit_host.hide();
} }
else { else {
if (ret.code === -100) { if (ret.code === -100) {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已经添加,请不要重复添加主机!', ''); ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已存在,请不要重复添加主机!');
} else { } else {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.code, ''); ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.message);
} }
} }
}, },
function () { function () {
ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!', ''); ywl.notify_error('网络故障,主机 ' + dlg_edit_host.ip + ' 信息保存失败!', '');
} }
); );
}; };
@ -895,9 +911,15 @@ ywl.create_host_user_edit_dlg = function (tbl) {
html.push('</li></ul></div>'); html.push('</li></ul></div>');
return html.join(''); return html.join('');
}; };
dlg_user_edit_host.sync_user_info = function (host_id) { dlg_user_edit_host.sync_user_info = function (host_id) {
ywl.ajax_post_json('/host/sys-user/list', {host_id: host_id}, ywl.ajax_post_json('/host/sys-user/list', {host_id: host_id},
function (ret) { function (ret) {
if (ret.code !== TPE_OK) {
ywl.notify_error('获取主机用户列表失败:' + ret.message);
return;
}
var data = ret.data; var data = ret.data;
dlg_user_edit_host.auth_list = data; dlg_user_edit_host.auth_list = data;
@ -951,18 +973,15 @@ ywl.create_host_user_edit_dlg = function (tbl) {
var host_auth_id = parseInt($(this).attr("auth-id")); var host_auth_id = parseInt($(this).attr("auth-id"));
ywl.ajax_post_json('/host/sys-user/delete', {host_auth_id: host_auth_id}, ywl.ajax_post_json('/host/sys-user/delete', {host_auth_id: host_auth_id},
function (ret) { function (ret) {
//console.log("ret,", ret);
if (ret.code === TPE_OK) { if (ret.code === TPE_OK) {
ywl.notify_success('系统用户删除成功'); ywl.notify_success('系统用户删除成功!');
// var host_id = parseInt(dlg_user_edit_host.host_id);
g_dlg_edit_host_user.sync_user_info(host_id); g_dlg_edit_host_user.sync_user_info(host_id);
} else { } else {
ywl.notify_error('系统用户删除失败' + ret.code); ywl.notify_error('系统用户删除失败' + ret.message);
} }
}, },
function () { function () {
ywl.notify_error('系统用户删除失败!'); ywl.notify_error('网络故障:系统用户删除失败!');
} }
); );
}); });
@ -1349,21 +1368,19 @@ ywl.create_sys_user = function (tbl) {
cert_id: cert_id, cert_id: cert_id,
user_param: dlg_sys_user.user_param user_param: dlg_sys_user.user_param
}; };
//console.log("args:", args);
ywl.ajax_post_json('/host/sys-user/update', {host_auth_id: host_auth_id, kv: args}, ywl.ajax_post_json('/host/sys-user/update', {host_auth_id: host_auth_id, kv: args},
function (ret) { function (ret) {
//console.log("ret,", ret); if (ret.code === TPE_OK) {
if (ret.code === 0) { ywl.notify_success('系统用户信息更新成功!');
ywl.notify_success('系统用户信息更新成功');
g_dlg_edit_host_user.sync_user_info(host_id); g_dlg_edit_host_user.sync_user_info(host_id);
dlg_sys_user.hide(); dlg_sys_user.hide();
} else { } else {
ywl.notify_error('系统用户信息更新失败' + ret.code); ywl.notify_error('系统用户信息更新失败' + ret.message);
} }
}, },
function () { function () {
ywl.notify_error('系统用户信息更新失败'); ywl.notify_error('网络故障,系统用户信息更新失败');
} }
); );
}; };
@ -1394,15 +1411,15 @@ ywl.create_sys_user = function (tbl) {
ywl.ajax_post_json('/host/sys-user/add', args, ywl.ajax_post_json('/host/sys-user/add', args,
function (ret) { function (ret) {
if (ret.code === TPE_OK) { if (ret.code === TPE_OK) {
ywl.notify_success('系统用户添加成功'); ywl.notify_success('系统用户添加成功');
g_dlg_edit_host_user.sync_user_info(host_id); g_dlg_edit_host_user.sync_user_info(host_id);
dlg_sys_user.hide(); dlg_sys_user.hide();
} else { } else {
ywl.notify_error('系统用户添加失败' + ret.code); ywl.notify_error('系统用户添加失败' + ret.message);
} }
}, },
function () { function () {
ywl.notify_error('系统用户信息更新失败'); ywl.notify_error('网络故障,系统用户信息更新失败');
} }
); );
}; };
@ -1461,17 +1478,21 @@ ywl.create_batch_join_group_dlg = function (tbl) {
ywl.ajax_post_json('/host/add-host-to-group', {host_list: data_list, group_id: group_id}, ywl.ajax_post_json('/host/add-host-to-group', {host_list: data_list, group_id: group_id},
function (ret) { function (ret) {
var update_args = {group_name: group_name}; if (ret.code === TPE_OK) {
for (var i = 0; i < batch_join_dlg.host_list.length; i++) { var update_args = {group_name: group_name};
var row_id = batch_join_dlg.host_list[i].row_id; for (var i = 0; i < batch_join_dlg.host_list.length; i++) {
batch_join_dlg.tbl.update_row(row_id, update_args); var row_id = batch_join_dlg.host_list[i].row_id;
} batch_join_dlg.tbl.update_row(row_id, update_args);
}
ywl.notify_success("成功设定分组信息!"); ywl.notify_success("成功设定主机分组信息!");
batch_join_dlg.hide(); batch_join_dlg.hide();
} else {
ywl.notify_error("设定主机分组信息失败:" + ret.message);
}
}, },
function () { function () {
ywl.notify_error("设定分组信息失败!"); ywl.notify_error("网络故障,设定主机分组信息失败!");
} }
); );
}; };

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,413 +1,420 @@
/*! ywl v1.0.1, (c)2015 eomsoft.net */ /*! ywl v1.0.1, (c)2015 eomsoft.net */
"use strict"; "use strict";
ywl.notify_error = function (message_, title_) { ywl.notify_error = function (message_, title_) {
var _title = title_ || ''; var _title = title_ || '';
$.gritter.add({ $.gritter.add({
//sticky:true, //sticky:true,
class_name: 'gritter-error', class_name: 'gritter-error',
time: 10000, time: 10000,
title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title, title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title,
text: message_ text: message_
}); });
}; };
ywl.notify_success = function (message_, title_) { ywl.notify_success = function (message_, title_) {
var _title = title_ || null; var _title = title_ || null;
if (_title !== null) if (_title !== null)
_title = '<i class="fa fa-check-square fa-fw"></i> ' + _title; _title = '<i class="fa fa-check-square fa-fw"></i> ' + _title;
$.gritter.add({ $.gritter.add({
//sticky:true, //sticky:true,
class_name: 'gritter-success', class_name: 'gritter-success',
time: 10000, time: 10000,
title: _title, title: _title,
text: message_ text: message_
}); });
}; };
function get_host_group_by_id(gid) { function get_host_group_by_id(gid) {
var _all = {id: 0, group_name: '全部'}; var _all = {id: 0, group_name: '全部'};
return _all; return _all;
} }
function get_user_info_by_id(user_id) { function get_user_info_by_id(user_id) {
var _all = {id: 0, nickname: '未知'}; var _all = {id: 0, nickname: '未知'};
return _all; return _all;
} }
function get_event_code_by_id(e_id) { function get_event_code_by_id(e_id) {
var _all = {id: 0, e_desc: '未知'}; var _all = {id: 0, e_desc: '未知'};
var ret = ywl.assist.get_cache_by_id(CACHE_TYPE_EVENT_CODE, e_id); var ret = ywl.assist.get_cache_by_id(CACHE_TYPE_EVENT_CODE, e_id);
if (ret == null) if (ret == null)
return _all; return _all;
else else
return ret; return ret;
} }
function get_current_system_group() { function get_current_system_group() {
return get_system_group_by_id(0); return get_system_group_by_id(0);
} }
function get_system_group_by_id(gid) { function get_system_group_by_id(gid) {
var _all = {id: 0, name: '全部'}; var _all = {id: 0, name: '全部'};
var ret = null; var ret = null;
$.each(system_group, function (i, group) { $.each(system_group, function (i, group) {
if (group.id == gid) { if (group.id == gid) {
ret = group; ret = group;
return false; return false;
} }
}); });
if (ret == null) if (ret == null)
return _all; return _all;
else else
return ret; return ret;
} }
//function get_command_name_by_id(cmd_id) { //function get_command_name_by_id(cmd_id) {
// return ywl.assist.get_cache_by_id(CACHE_TYPE_COMMAND, cmd_id); // return ywl.assist.get_cache_by_id(CACHE_TYPE_COMMAND, cmd_id);
//} //}
//function notify_error(message_, title_) { //function notify_error(message_, title_) {
// var _title = title_ || ''; // var _title = title_ || '';
// $.gritter.add({ // $.gritter.add({
// sticky: true, // sticky: true,
// class_name: 'gritter-error', // class_name: 'gritter-error',
// time: 10000, // time: 10000,
// title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title, // title: '<i class="fa fa-warning fa-fw"></i> 错误:' + _title,
// text: message_ // text: message_
// }); // });
//} //}
//function notify_success(message_, title_) { //function notify_success(message_, title_) {
// var _title = title_ || null; // var _title = title_ || null;
// if (_title !== null) // if (_title !== null)
// _title = '<i class="fa fa-check-square fa-fw"></i> ' + _title; // _title = '<i class="fa fa-check-square fa-fw"></i> ' + _title;
// $.gritter.add({ // $.gritter.add({
// //sticky:true, // //sticky:true,
// class_name: 'gritter-success', // class_name: 'gritter-success',
// time: 10000, // time: 10000,
// title: _title, // title: _title,
// text: message_ // text: message_
// }); // });
//} //}
// 切换一个dom节点显示与否 // 切换一个dom节点显示与否
ywl.toggle_display = function (selector) { ywl.toggle_display = function (selector) {
var obj = $(selector); var obj = $(selector);
if (typeof(obj) == 'undefined') if (typeof(obj) == 'undefined')
return; return;
if (obj.is(':hidden')) { if (obj.is(':hidden')) {
obj.show(); obj.show();
} else { } else {
obj.hide(); obj.hide();
} }
}; };
//====================================================== //======================================================
// Dialog-box for confirm operation. // Dialog-box for confirm operation.
//====================================================== //======================================================
ywl.dlg_confirm = function (cb_stack, cb_args) { ywl.dlg_confirm = function (cb_stack, cb_args) {
var self = {}; var self = {};
self._cb_stack = cb_stack; self._cb_stack = cb_stack;
self._title = cb_args.title || '操作确认:'; self._title = cb_args.title || '操作确认:';
self._msg = cb_args.msg || ''; self._msg = cb_args.msg || '';
self._btn_yes = cb_args.btn_yes || '确定'; self._btn_yes = cb_args.btn_yes || '确定';
self._btn_no = cb_args.btn_no || '取消'; self._btn_no = cb_args.btn_no || '取消';
self._fn_yes = cb_args.fn_yes || null; self._fn_yes = cb_args.fn_yes || null;
self._fn_no = cb_args.fn_no || null; self._fn_no = cb_args.fn_no || null;
self._dlg_id = _.uniqueId('dlg-confirm-'); self._dlg_id = _.uniqueId('dlg-confirm-');
self._cb_args = cb_args.cb_args || {}; self._cb_args = cb_args.cb_args || {};
self._make_message_box = function () { self._make_message_box = function () {
var _html = [ var _html = [
'<div class="modal fade" id="' + self._dlg_id + '" tabindex="-1" role="dialog">', '<div class="modal fade" id="' + self._dlg_id + '" tabindex="-1" role="dialog">',
'<div class="modal-dialog" role="document">', '<div class="modal-dialog" role="document">',
'<div class="modal-content">', '<div class="modal-content">',
'<div class="modal-header">', '<div class="modal-header">',
'<h4 class="modal-title">' + self._title + '</h4>', '<h4 class="modal-title">' + self._title + '</h4>',
'</div>', '</div>',
'<div class="modal-body">', '<div class="modal-body">',
'<div>' + self._msg + '</div>', '<div>' + self._msg + '</div>',
'</div>', '</div>',
'<div class="modal-footer">', '<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-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>', '<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>',
'</div>', '</div>',
'</div>'].join('\n'); '</div>'].join('\n');
$('body').append($(_html)); $('body').append($(_html));
}; };
self._destroy = function () { self._destroy = function () {
$('#' + self._dlg_id).remove(); $('#' + self._dlg_id).remove();
}; };
self._on_btn_yes = function () { self._on_btn_yes = function () {
$('#' + self._dlg_id).modal('hide'); $('#' + self._dlg_id).modal('hide');
if (_.isFunction(self._fn_yes)) { if (_.isFunction(self._fn_yes)) {
self._cb_stack self._cb_stack
.add(self._fn_yes, self._cb_args) .add(self._fn_yes, self._cb_args)
.exec(); .exec();
} }
}; };
self._on_btn_no = function () { self._on_btn_no = function () {
$('#' + self._dlg_id).modal('hide'); $('#' + self._dlg_id).modal('hide');
if (_.isFunction(self._fn_no)) { if (_.isFunction(self._fn_no)) {
self._cb_stack self._cb_stack
.add(self._fn_no, self._cb_args) .add(self._fn_no, self._cb_args)
.exec(); .exec();
} }
}; };
self.show = function () { self.show = function () {
$('#dlg-btn-' + self._dlg_id + "-yes").click(self._on_btn_yes); $('#dlg-btn-' + self._dlg_id + "-yes").click(self._on_btn_yes);
$('#dlg-btn-' + self._dlg_id + "-no").click(self._on_btn_no); $('#dlg-btn-' + self._dlg_id + "-no").click(self._on_btn_no);
$('#' + self._dlg_id) $('#' + self._dlg_id)
.modal() .modal()
//.on('hide.bs.modal', self._on_cancel) //.on('hide.bs.modal', self._on_cancel)
.on('hidden.bs.modal', self._destroy); .on('hidden.bs.modal', self._destroy);
}; };
self._make_message_box(); self._make_message_box();
self.show(); self.show();
}; };
//====================================================== //======================================================
// Dialog-box for modify host description // Dialog-box for modify host description
//====================================================== //======================================================
ywl.create_dlg_modify_host_desc = function (tbl, row_id, host_id, host_ip,host_desc) { ywl.create_dlg_modify_host_desc = function (tbl, row_id, host_id, host_ip, host_desc) {
var self = {}; var self = {};
self.dlg_id = _.uniqueId('dlg-modify-host-desc-'); self.dlg_id = _.uniqueId('dlg-modify-host-desc-');
self._table_ctrl = tbl; self._table_ctrl = tbl;
self.host_id = host_id; self.host_id = host_id;
self.host_ip = host_ip; self.host_ip = host_ip;
self.host_desc = host_desc; self.host_desc = host_desc;
self.show = function (pos_obj) { self.show = function (pos_obj) {
self._make_dialog_box(); self._make_dialog_box();
$('body') $('body')
.addClass('modal-open') .addClass('modal-open')
.append($('<div class="modal-backdrop fade in"></div>')) .append($('<div class="modal-backdrop fade in"></div>'))
.keydown(function (event) { .keydown(function (event) {
if (event.which == 27) { if (event.which == 27) {
self._destroy(); self._destroy();
} }
}); });
$('.modal-backdrop').click(function () { $('.modal-backdrop').click(function () {
self._destroy(); self._destroy();
}); });
var t_obj = $('#' + self.dlg_id + ' .popover'); var t_obj = $('#' + self.dlg_id + ' .popover');
t_obj.css({ t_obj.css({
'top': pos_obj.offset().top + pos_obj.height() - 5, 'top': pos_obj.offset().top + pos_obj.height() - 5,
'left': pos_obj.offset().left 'left': pos_obj.offset().left
}).show(); }).show();
$('#' + self.dlg_id + " [ywl-input='desc']").focus(); $('#' + self.dlg_id + " [ywl-input='desc']").focus();
}; };
self._save = function () { self._save = function () {
var dlg_dom_id = "[ywl-dlg='modify-host-desc']"; var dlg_dom_id = "[ywl-dlg='modify-host-desc']";
var val = $(dlg_dom_id + " input[ywl-input='desc']").val(); var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val == self.host_desc) { if (val === self.host_desc) {
self._destroy(); self._destroy();
return; return;
} }
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}}, ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
function (ret) { function (ret) {
self._table_ctrl.update_row(row_id, {host_desc: val}); if (ret.code === TPE_OK) {
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!'); self._table_ctrl.update_row(row_id, {host_desc: val});
self._destroy(); ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
}, } else {
function () { ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存:' + ret.message);
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存!', ''); }
self._destroy(); 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._destroy = function () {
}; $('body').removeClass('modal-open');
$('.modal-backdrop').remove();
self._make_dialog_box = function () {
var _html = [ $('#' + self.dlg_id).remove();
'<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>', self._make_dialog_box = function () {
' <h3 class="popover-title">为主机 ' + self.host_ip + ' 添加备注,以便识别</h3>', var _html = [
' <div class="popover-content">', '<div class="popover-inline-edit" id="' + self.dlg_id + '">',
' <div style="display:inline-block;float:right;">', ' <div class="popover fade bottom in" role="tooltip" ywl-dlg="modify-host-desc">',
' <a href="javascript:;" class="btn btn-success btn-sm" ywl-btn="ok"><i class="glyphicon glyphicon-ok"></i></a>', ' <div class="arrow" style="left:50px;"></div>',
' <a href="javascript:;" class="btn btn-danger btn-sm" ywl-btn="cancel"><i class="glyphicon glyphicon-remove"></i></a>', ' <h3 class="popover-title">为主机 ' + self.host_ip + ' 添加备注,以便识别</h3>',
' </div>', ' <div class="popover-content">',
' <div style="padding-right:80px;">', ' <div style="display:inline-block;float:right;">',
' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">', ' <a href="javascript:;" class="btn btn-success btn-sm" ywl-btn="ok"><i class="glyphicon glyphicon-ok"></i></a>',
' </div>', ' <a href="javascript:;" class="btn btn-danger btn-sm" ywl-btn="cancel"><i class="glyphicon glyphicon-remove"></i></a>',
' </div>', ' </div>',
' </div>', ' <div style="padding-right:80px;">',
'</div>'].join('\n'); ' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">',
' </div>',
$('body').append($(_html)); ' </div>',
' </div>',
// “修改主机描述” 对话框上的两个按钮的点击事件 '</div>'].join('\n');
$('#' + self.dlg_id + " [ywl-btn='ok']").click(function () {
self._save(); $('body').append($(_html));
});
$('#' + self.dlg_id + " [ywl-btn='cancel']").click(function () { // “修改主机描述” 对话框上的两个按钮的点击事件
self._destroy(); $('#' + self.dlg_id + " [ywl-btn='ok']").click(function () {
}); self._save();
// 绑定“修改主机描述” 对话框中的输入框的回车事件 });
$('#' + self.dlg_id + " [ywl-input='desc']").keydown(function (event) { $('#' + self.dlg_id + " [ywl-btn='cancel']").click(function () {
if (event.which == 13) { self._destroy();
self._save(); });
} else if (event.which == 27) { // 绑定“修改主机描述” 对话框中的输入框的回车事件
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 = {}; return self;
};
self.dlg_id = _.uniqueId('dlg-rdp-advance-');
// self._table_ctrl = tbl; ywl.create_dlg_show_rdp_advance = function (row_data) {
// self.host_id = host_id; var self = {};
// self.host_ip = host_ip;
// self.host_desc = host_desc; self.dlg_id = _.uniqueId('dlg-rdp-advance-');
// self._table_ctrl = tbl;
self.show = function (pos_obj) { // self.host_id = host_id;
self._make_dialog_box(); // self.host_ip = host_ip;
$('body') // self.host_desc = host_desc;
.addClass('modal-open')
.append($('<div class="modal-backdrop fade in"></div>')) self.show = function (pos_obj) {
.keydown(function (event) { self._make_dialog_box();
if (event.which == 27) { $('body')
self._destroy(); .addClass('modal-open')
} .append($('<div class="modal-backdrop fade in"></div>'))
}); .keydown(function (event) {
$('.modal-backdrop').click(function () { if (event.which == 27) {
self._destroy(); self._destroy();
}); }
});
var t_obj = $('#' + self.dlg_id + ' .popover'); $('.modal-backdrop').click(function () {
t_obj.css({ self._destroy();
'top': pos_obj.offset().top + pos_obj.height() + 5, });
'left': pos_obj.offset().left - 10
}).show(); var t_obj = $('#' + self.dlg_id + ' .popover');
t_obj.css({
//$('#' + self.dlg_id + " [ywl-input='desc']").focus(); 'top': pos_obj.offset().top + pos_obj.height() + 5,
}; 'left': pos_obj.offset().left - 10
}).show();
self._save = function () {
var dlg_dom_id = '[data-dlg="show-rdp-advance"]'; //$('#' + self.dlg_id + " [ywl-input='desc']").focus();
};
var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val == self.host_desc) { self._save = function () {
self._destroy(); var dlg_dom_id = '[data-dlg="show-rdp-advance"]';
return;
} var val = $(dlg_dom_id + " input[ywl-input='desc']").val();
if (val === self.host_desc) {
ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}}, self._destroy();
function (ret) { return;
self._table_ctrl.update_row(row_id, {host_desc: val}); }
ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
self._destroy(); ywl.ajax_post_json('/host/update', {host_id: host_id, kv: {host_desc: val}},
}, function (ret) {
function () { if (ret.code === TPE_OK) {
ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存!', ''); self._table_ctrl.update_row(row_id, {host_desc: val});
self._destroy(); ywl.notify_success('主机 ' + self.host_ip + ' 的描述已保存!');
} } else {
); ywl.notify_error('主机 ' + self.host_ip + ' 的描述修改未能成功保存:' + ret.message);
}
}; self._destroy();
},
self._destroy = function () { function () {
$('body').removeClass('modal-open'); ywl.notify_error('网络故障,主机 ' + self.host_ip + ' 的描述修改未能成功保存!');
$('.modal-backdrop').remove(); self._destroy();
}
$('#' + self.dlg_id).remove(); );
};
};
self._make_dialog_box = function () {
var _html = [ self._destroy = function () {
'<div class="xx-popover-inline-edit" id="' + self.dlg_id + '">', $('body').removeClass('modal-open');
' <div class="popover fade bottom in" role="tooltip" data-dlg="show-rdp-advance" style="width:300px;">', $('.modal-backdrop').remove();
' <div class="arrow" style="left:50px;"></div>',
' <h3 class="popover-title" style="font-weight:bold;">RDP连接选项仅本次连接有效</h3>', $('#' + self.dlg_id).remove();
' <div class="popover-content">', };
// ' <div style="">',
// ' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">', self._make_dialog_box = function () {
// ' </div>', var _html = [
'<div class="xx-popover-inline-edit" id="' + self.dlg_id + '">',
' <div style="">', ' <div class="popover fade bottom in" role="tooltip" data-dlg="show-rdp-advance" style="width:300px;">',
' <p style="margin:0;"><strong>分辨率:</strong></p>', ' <div class="arrow" style="left:50px;"></div>',
' <label class="radio-inline">', ' <h3 class="popover-title" style="font-weight:bold;">RDP连接选项仅本次连接有效</h3>',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-small" value="overwrite">小 800x600', ' <div class="popover-content">',
' </label><br/>', // ' <div style="">',
' <label class="radio-inline">', // ' <input type="text" ywl-input="desc" class="form-control" value="' + self.host_desc + '">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-middle" value="skip" checked="checked">中 1024x768', // ' </div>',
' </label><br/>',
' <label class="radio-inline">', ' <div style="">',
' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-large" value="error">大 1280x800', ' <p style="margin:0;"><strong>分辨率:</strong></p>',
' </label>', ' <label class="radio-inline">',
' </div>', ' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-small" value="overwrite">小 800x600',
' </label><br/>',
' <div style="margin-top:5px;">', ' <label class="radio-inline">',
' <p style="margin:0;"><strong>Console模式</strong></p>', ' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-middle" value="skip" checked="checked">中 1024x768',
' <label>', ' </label><br/>',
' <input type="checkbox" id="dlg-action-rdp-console"> 以Console模式运行', ' <label class="radio-inline">',
' </label>', ' <input type="radio" name="radio-rdp-size" id="dlg-action-rdp-size-large" value="error">大 1280x800',
' </div>', ' </label>',
' </div>',
' <div style="margin-top:5px;">',
' <hr style="margin:3px 0;"/><div style="margin-top:10px;text-align:right;">', ' <p style="margin:0;"><strong>Console模式</strong></p>',
' <a href="javascript:;" class="btn btn-success btn-sm" data-action="ok"><i class="fa fa-check fa-fw"></i> 确定连接</a>', ' <label>',
' <a href="javascript:;" class="btn btn-default btn-sm" data-actioin="cancel"><i class="fa fa-times fa-fw"></i> 取消</a>', ' <input type="checkbox" id="dlg-action-rdp-console"> 以Console模式运行',
' </div>', ' </label>',
' </div>', ' </div>',
' </div>',
'</div>'].join('\n');
' <hr style="margin:3px 0;"/><div style="margin-top:10px;text-align:right;">',
$('body').append($(_html)); ' <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>',
$('#' + self.dlg_id + " [data-action='ok']").click(function () { ' </div>',
self._save(); ' </div>',
}); '</div>'].join('\n');
$('#' + self.dlg_id + " [data-action='cancel']").click(function () {
self._destroy(); $('body').append($(_html));
});
// “修改主机描述” 对话框上的两个按钮的点击事件
// // 绑定“修改主机描述” 对话框中的输入框的回车事件 $('#' + self.dlg_id + " [data-action='ok']").click(function () {
// $('#' + self.dlg_id + " [ywl-input='desc']").keydown(function (event) { self._save();
// if (event.which == 13) { });
// self._save(); $('#' + self.dlg_id + " [data-action='cancel']").click(function () {
// } else if (event.which == 27) { self._destroy();
// self._destroy(); });
// }
// }); // // 绑定“修改主机描述” 对话框中的输入框的回车事件
// $('#' + self.dlg_id + " [ywl-input='desc']").keydown(function (event) {
}; // if (event.which == 13) {
// self._save();
return self; // } 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; var g_gourp_dlg_info = null;
ywl.on_init = function (cb_stack, cb_args) { ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_group_list'; var dom_id = '#ywl_group_list';
//=================================== //===================================
// 创建页面控件对象 // 创建页面控件对象
//=================================== //===================================
// 表格数据 // 表格数据
var host_table_options = { var host_table_options = {
selector: dom_id + " [ywl-table='group-list']", selector: dom_id + " [ywl-table='group-list']",
data_source: { data_source: {
type: 'ajax-post', type: 'ajax-post',
url: '/group/list' url: '/group/list'
}, },
column_default: {sort: false, header_align: 'center', cell_align: 'center'}, column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [ columns: [
{title: "分组ID", key: "id", width: 80}, {title: "分组ID", key: "id", width: 80},
{title: "分组名称", key: "group_name", header_align: 'left', cell_align: 'left'}, {title: "分组名称", key: "group_name", header_align: 'left', cell_align: 'left'},
{title: "操作", key: "action", width: 240, render: 'make_action_btn', fields: {id: 'group_id'}} {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}, 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_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载 // 可重载的函数在on_created回调函数中重载
// on_render_created // on_render_created
// on_header_created // on_header_created
// on_paging_created // on_paging_created
// on_data_loaded // on_data_loaded
// on_row_rendered // on_row_rendered
// on_table_rendered // on_table_rendered
// on_cell_created // on_cell_created
// on_begin_load // on_begin_load
// on_after_load // on_after_load
// 可用的函数 // 可用的函数
// load_data // load_data
// cancel_load // cancel_load
// set_data // set_data
// add_row // add_row
// remove_row // remove_row
// get_row // get_row
// update_row // update_row
// clear // clear
// reset_filter // reset_filter
}; };
var host_table = ywl.create_table(host_table_options); var host_table = ywl.create_table(host_table_options);
g_gourp_dlg_info = ywl.create_group_info_dlg(host_table); g_gourp_dlg_info = ywl.create_group_info_dlg(host_table);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload); $(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#btn-add-group").click(function () { $("#btn-add-group").click(function () {
g_gourp_dlg_info.create_show(); g_gourp_dlg_info.create_show();
}); });
cb_stack cb_stack
.add(host_table.load_data) .add(host_table.load_data)
.add(host_table.init) .add(host_table.init)
.exec(); .exec();
}; };
// 扩展/重载表格的功能 // 扩展/重载表格的功能
ywl.on_host_table_created = function (tbl) { ywl.on_host_table_created = function (tbl) {
tbl.on_cell_created = function (row_id, col_key, cell_obj) { tbl.on_cell_created = function (row_id, col_key, cell_obj) {
if (col_key == 'action') { if (col_key === 'action') {
var row_data = tbl.get_row(row_id); var row_data = tbl.get_row(row_id);
//console.log('row_data', row_data); //console.log('row_data', row_data);
$(cell_obj).find('[ywl-btn-edit]').click(function () { $(cell_obj).find('[ywl-btn-edit]').click(function () {
g_gourp_dlg_info.update_show(row_data.group_name, row_data.id, row_id); g_gourp_dlg_info.update_show(row_data.group_name, row_data.id, row_id);
}); });
$(cell_obj).find('[ywl-btn-delete]').click(function () { $(cell_obj).find('[ywl-btn-delete]').click(function () {
var group_id = row_data.id; var group_id = row_data.id;
var _fn_sure = function (cb_stack, cb_args) { var _fn_sure = function (cb_stack, cb_args) {
ywl.ajax_post_json('/host/delete-group', {group_id: group_id}, ywl.ajax_post_json('/host/delete-group', {group_id: group_id},
function (ret) { function (ret) {
if (ret.code == 0) { if (ret.code === TPE_OK) {
tbl.remove_row(row_id); tbl.remove_row(row_id);
ywl.notify_success('删除分组成功!'); ywl.notify_success('删除分组成功!');
} else if (ret.code == -2) { } else if (ret.code === -2) {
ywl.notify_error('不能删除,此分组中已经包含了主机。如果您一定要删除此分组,请先将此分组中的主机设定为其他分组,然后才能删除'); ywl.notify_error('因为有主机隶属此分组,因此不能删除此分组。请先将此分组中的主机设定为其他分组,然后重试');
} else { } else {
ywl.notify_error('删除分组失败!'); ywl.notify_error('删除分组失败:' + ret.message);
} }
}, },
function (ret) { function () {
ywl.notify_error('删除分组失败!'); ywl.notify_error('网络故障,删除分组失败!');
} }
); );
}; };
var cb_stack = CALLBACK_STACK.create(); var cb_stack = CALLBACK_STACK.create();
ywl.dlg_confirm(cb_stack, ywl.dlg_confirm(cb_stack,
{ {
msg: '<p><strong>注意:移除操作不可恢复!!</strong></p><p>您确定要删除此分组吗?</p>', msg: '<p><strong>注意:移除操作不可恢复!!</strong></p><p>您确定要删除此分组吗?</p>',
fn_yes: _fn_sure fn_yes: _fn_sure
}); });
}); });
} }
}; };
// 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作 // 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作
tbl.on_render_created = function (render) { tbl.on_render_created = function (render) {
render.make_action_btn = function (row_id, fields) { render.make_action_btn = function (row_id, fields) {
var ret = []; 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-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>'); ret.push('<a href="javascript:;" class="btn btn-primary btn-danger btn-group-sm" ywl-btn-delete="' + fields.id + '">删除</a>');
return ret.join(''); return ret.join('');
} }
}; };
}; };
ywl.on_host_table_header_created = function (tbl) { ywl.on_host_table_header_created = function (tbl) {
}; };
ywl.create_group_info_dlg = function (tbl) { ywl.create_group_info_dlg = function (tbl) {
var group_info_dlg = {}; var group_info_dlg = {};
group_info_dlg.dom_id = "#dialog_group_info"; group_info_dlg.dom_id = "#dialog_group_info";
group_info_dlg.update = 1; group_info_dlg.update = 1;
group_info_dlg.tbl = tbl; group_info_dlg.tbl = tbl;
group_info_dlg.group_name = ''; group_info_dlg.group_name = '';
group_info_dlg.group_id = 0; group_info_dlg.group_id = 0;
group_info_dlg.row_id = 0; group_info_dlg.row_id = 0;
group_info_dlg.update_show = function (group_name, group_id, row_id) { group_info_dlg.update_show = function (group_name, group_id, row_id) {
group_info_dlg.update = 1; group_info_dlg.update = 1;
group_info_dlg.init(group_name, group_id, row_id); group_info_dlg.init(group_name, group_id, row_id);
$(group_info_dlg.dom_id).modal(); $(group_info_dlg.dom_id).modal();
}; };
group_info_dlg.create_show = function () { group_info_dlg.create_show = function () {
group_info_dlg.update = 0; group_info_dlg.update = 0;
group_info_dlg.init('', 0, 0); group_info_dlg.init('', 0, 0);
$(group_info_dlg.dom_id).modal(); $(group_info_dlg.dom_id).modal();
}; };
group_info_dlg.hide = function() { group_info_dlg.hide = function () {
$(group_info_dlg.dom_id).modal('hide'); $(group_info_dlg.dom_id).modal('hide');
}; };
group_info_dlg.init = function (group_name, group_id, row_id) { group_info_dlg.init = function (group_name, group_id, row_id) {
group_info_dlg.group_name = group_name; group_info_dlg.group_name = group_name;
group_info_dlg.group_id = group_id; group_info_dlg.group_id = group_id;
group_info_dlg.row_id = row_id; group_info_dlg.row_id = row_id;
group_info_dlg.init_dlg(); group_info_dlg.init_dlg();
}; };
group_info_dlg.init_dlg = function () { group_info_dlg.init_dlg = function () {
$(group_info_dlg.dom_id + ' #group_name').val(group_info_dlg.group_name); $(group_info_dlg.dom_id + ' #group_name').val(group_info_dlg.group_name);
}; };
group_info_dlg.check_args = function () { group_info_dlg.check_args = function () {
group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val(); group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val();
return true; return true;
}; };
group_info_dlg.post = function () { group_info_dlg.post = function () {
if (group_info_dlg.update == 1) { if (group_info_dlg.update == 1) {
ywl.ajax_post_json('/host/update-group', {group_id: group_info_dlg.group_id, group_name: group_info_dlg.group_name}, ywl.ajax_post_json('/host/update-group', {group_id: group_info_dlg.group_id, group_name: group_info_dlg.group_name},
function (ret) { function (ret) {
var update_args = {id: group_info_dlg.group_id, group_name: group_info_dlg.group_name}; if (ret.code === TPE_OK) {
group_info_dlg.tbl.update_row(group_info_dlg.row_id, update_args); var update_args = {id: group_info_dlg.group_id, group_name: group_info_dlg.group_name};
ywl.notify_success('更新分组信息成功!'); group_info_dlg.tbl.update_row(group_info_dlg.row_id, update_args);
group_info_dlg.hide(); ywl.notify_success('更新分组信息成功!');
}, group_info_dlg.hide();
function (ret) { } else {
ywl.notify_error('更新分组信息失败!'); ywl.notify_error('更新分组失败:' + ret.message);
} }
); },
} else { function () {
ywl.ajax_post_json('/host/add-group', {group_name: group_info_dlg.group_name}, ywl.notify_error('网络故障,更新分组信息失败!');
function (ret) { }
group_info_dlg.tbl.reload(); );
ywl.notify_success('分组创建成功!'); } else {
group_info_dlg.hide(); ywl.ajax_post_json('/host/add-group', {group_name: group_info_dlg.group_name},
}, function (ret) {
function (ret) { if (ret.code === TPE_OK) {
ywl.notify_error('分组创建失败!'); group_info_dlg.tbl.reload();
} ywl.notify_success('创建分组成功!');
); group_info_dlg.hide();
} } else {
//group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val(); ywl.notify_error('创建分组失败:' + ret.message);
return true; }
}; },
$(group_info_dlg.dom_id + " #btn-save").click(function () { function () {
if (!group_info_dlg.check_args()) { ywl.notify_error('网络故障,创建分组失败!');
return; }
} );
group_info_dlg.post(); }
}); //group_info_dlg.group_name = $(group_info_dlg.dom_id + ' #group_name').val();
return group_info_dlg 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"; "use strict";
ywl.on_init = function (cb_stack, cb_args) { ywl.on_init = function (cb_stack, cb_args) {
var dom_id = '#ywl_log_list'; var dom_id = '#ywl_log_list';
//=================================== //===================================
// 创建页面控件对象 // 创建页面控件对象
//=================================== //===================================
// 表格数据 // 表格数据
var disk_rate = parseInt(ywl.page_options.free_size * 100 / ywl.page_options.total_size); 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 + '%'); $('#disk-status').text('日志磁盘大小:' + size2str(ywl.page_options.total_size, 2) + ',剩余空间:' + size2str(ywl.page_options.free_size, 2) + ',空闲' + disk_rate + '%');
if (disk_rate < 10) { if (disk_rate < 10) {
$('#disk-status').removeClass().addClass('badge badge-danger'); $('#disk-status').removeClass().addClass('badge badge-danger');
} else if (disk_rate < 30) { } else if (disk_rate < 30) {
$('#disk-status').removeClass().addClass('badge badge-warning'); $('#disk-status').removeClass().addClass('badge badge-warning');
} else { } else {
$('#disk-status').removeClass().addClass('badge badge-ignore'); $('#disk-status').removeClass().addClass('badge badge-ignore');
} }
var host_table_options = { var host_table_options = {
selector: dom_id + " [ywl-table='log-list']", selector: dom_id + " [ywl-table='log-list']",
data_source: { data_source: {
type: 'ajax-post', type: 'ajax-post',
url: '/log/list' url: '/log/list'
}, },
column_default: {sort: false, header_align: 'center', cell_align: 'center'}, column_default: {sort: false, header_align: 'center', cell_align: 'center'},
columns: [ columns: [
{ {
title: '<input type="checkbox" id="host-select-all" value="">', title: '<input type="checkbox" id="host-select-all" value="">',
key: 'select_all', key: 'select_all',
sort: false, sort: false,
width: 24, width: 24,
render: 'make_check_box', render: 'make_check_box',
fields: {id: 'id'} fields: {id: 'id'}
}, },
{title: "ID", key: "id"}, {title: "ID", key: "id"},
{title: "操作者", key: "account_name"}, {title: "操作者", key: "account_name"},
{title: "系统用户", key: "user_name"}, {title: "系统用户", key: "user_name"},
{title: "协议", key: "protocol", render: 'protocol', fields: {protocol: 'protocol'}}, {title: "协议", key: "protocol", render: 'protocol', fields: {protocol: 'protocol'}},
{title: "系统", key: "sys_type", width: 40, render: 'sys_type', fields: {sys_type: 'sys_type'}}, {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: "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: "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: "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: "ret_code", render: 'ret_code', fields: {ret_code: 'ret_code'}},
{ {
title: "操作", title: "操作",
key: "action", key: "action",
width: 160, width: 160,
header_align: 'left', cell_align: 'left', header_align: 'left', cell_align: 'left',
render: 'make_action_btn', render: 'make_action_btn',
fields: {ID: 'id', ret_code:'ret_code', sys_type: 'sys_type', cost_time: 'cost_time', protocol: 'protocol'} fields: {ID: 'id', ret_code: 'ret_code', sys_type: 'sys_type', cost_time: 'cost_time', protocol: 'protocol'}
} }
], ],
paging: {selector: dom_id + " [ywl-paging='log-list']", per_page: paging_normal}, paging: {selector: dom_id + " [ywl-paging='log-list']", per_page: paging_normal},
// 可用的属性设置 // 可用的属性设置
//have_header: true or false //have_header: true or false
// 可用的回调函数 // 可用的回调函数
on_created: ywl.on_host_table_created, on_created: ywl.on_host_table_created,
on_header_created: ywl.on_host_table_header_created on_header_created: ywl.on_host_table_header_created
// 可重载的函数在on_created回调函数中重载 // 可重载的函数在on_created回调函数中重载
// on_render_created // on_render_created
// on_header_created // on_header_created
// on_paging_created // on_paging_created
// on_data_loaded // on_data_loaded
// on_row_rendered // on_row_rendered
// on_table_rendered // on_table_rendered
// on_cell_created // on_cell_created
// on_begin_load // on_begin_load
// on_after_load // on_after_load
// 可用的函数 // 可用的函数
// load_data // load_data
// cancel_load // cancel_load
// set_data // set_data
// add_row // add_row
// remove_row // remove_row
// get_row // get_row
// update_row // update_row
// clear // clear
// reset_filter // reset_filter
}; };
var host_table = ywl.create_table(host_table_options); var host_table = ywl.create_table(host_table_options);
$(dom_id + " [ywl-filter='reload']").click(host_table.reload); $(dom_id + " [ywl-filter='reload']").click(host_table.reload);
$("#delete-log").click(function () { $("#delete-log").click(function () {
var log_list = []; var log_list = [];
var _objs = $(host_table.selector + " tbody tr td [data-check-box]"); var _objs = $(host_table.selector + " tbody tr td [data-check-box]");
$.each(_objs, function (i, _obj) { $.each(_objs, function (i, _obj) {
if ($(_obj).is(':checked')) { if ($(_obj).is(':checked')) {
var _row_data = host_table.get_row(_obj); var _row_data = host_table.get_row(_obj);
log_list.push(_row_data.id); log_list.push(_row_data.id);
} }
}); });
if (log_list.length === 0) {
ywl.notify_error('请选择要批量删除的日志'); if (log_list.length === 0) {
return; 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, var _fn_sure = function (cb_stack, cb_args) {
function (ret) { ywl.ajax_post_json_time_out('/log/delete-log', {log_list: log_list}, 1000 * 30,
host_table.reload(); function (ret) {
ywl.notify_success('操作成功'); if (ret.code === TPE_OK) {
}, host_table.reload();
function () { ywl.notify_success('删除日志成功!');
ywl.notify_error('操作失败'); } else {
} ywl.notify_error('删除日志失败!');
); }
}; },
var cb_stack = CALLBACK_STACK.create(); function () {
ywl.notify_error('网络故障,删除日志失败!');
ywl.dlg_confirm(cb_stack, { }
msg: '<p>您确定要删除选定的日志吗?此操作不可恢复!!</p>', );
fn_yes: _fn_sure };
}); var cb_stack = CALLBACK_STACK.create();
});
ywl.dlg_confirm(cb_stack, {
ywl.create_table_filter_user_list(host_table, dom_id + " [ywl-filter='user-name']"); msg: '<p>您确定要删除选定的日志吗?此操作不可恢复!!</p>',
fn_yes: _fn_sure
ywl.create_table_filter_search_box(host_table, dom_id + " [ywl-filter='search']"); });
});
cb_stack
.add(host_table.load_data) ywl.create_table_filter_user_list(host_table, dom_id + " [ywl-filter='user-name']");
.add(host_table.init)
.exec(); ywl.create_table_filter_search_box(host_table, dom_id + " [ywl-filter='search']");
};
ywl.on_host_table_header_created = function (tbl) { cb_stack
$('#host-select-all').click(function () { .add(host_table.load_data)
var _is_selected = $(this).is(':checked'); .add(host_table.init)
$(tbl.selector + ' tbody').find('[data-check-box]').prop('checked', _is_selected); .exec();
}); };
}; ywl.on_host_table_header_created = function (tbl) {
// 扩展/重载表格的功能 $('#host-select-all').click(function () {
ywl.on_host_table_created = function (tbl) { var _is_selected = $(this).is(':checked');
$(tbl.selector + ' tbody').find('[data-check-box]').prop('checked', _is_selected);
tbl.on_cell_created = function (row_id, col_key, cell_obj) { });
if (col_key == 'select_all') { };
// 选择 // 扩展/重载表格的功能
$('#host-select-' + row_id).click(function () { ywl.on_host_table_created = function (tbl) {
var _all_checked = true;
var _objs = $(tbl.selector + ' tbody').find('[data-check-box]'); tbl.on_cell_created = function (row_id, col_key, cell_obj) {
$.each(_objs, function (i, _obj) { if (col_key === 'select_all') {
if (!$(_obj).is(':checked')) { // 选择
_all_checked = false; $('#host-select-' + row_id).click(function () {
return false; var _all_checked = true;
} var _objs = $(tbl.selector + ' tbody').find('[data-check-box]');
}); $.each(_objs, function (i, _obj) {
if (!$(_obj).is(':checked')) {
var select_all_dom = $('#host-select-all'); _all_checked = false;
if (_all_checked) { return false;
select_all_dom.prop('checked', true); }
} else { });
select_all_dom.prop('checked', false);
} var select_all_dom = $('#host-select-all');
if (_all_checked) {
//ywl.update_add_to_batch_btn(); select_all_dom.prop('checked', true);
}); } else {
select_all_dom.prop('checked', false);
} else if (col_key === 'action') { }
var row_data = tbl.get_row(row_id);
var protocol = parseInt(row_data.protocol); //ywl.update_add_to_batch_btn();
});
if (protocol === PROTOCOL_TYPE_RDP) {
$(cell_obj).find('[ywl-btn-record]').click(function () { } else if (col_key === 'action') {
var ip = window.location.hostname; var row_data = tbl.get_row(row_id);
var port = parseInt(window.location.port); var protocol = parseInt(row_data.protocol);
var url = 'http://' + ip + ':' + port + '/log/replay/rdp/' + row_data.id;
var tail = 'log/replay/rdp/' + prefixInteger(row_data.id, 6); if (protocol === PROTOCOL_TYPE_RDP) {
var args = {}; $(cell_obj).find('[ywl-btn-record]').click(function () {
args.id = parseInt(row_data.id); var ip = window.location.hostname;
args.host = ip; var port = parseInt(window.location.port);
args.port = port; var url = 'http://' + ip + ':' + port + '/log/replay/rdp/' + row_data.id;
args.tail = tail; var tail = 'log/replay/rdp/' + prefixInteger(row_data.id, 6);
args.url = url; var args = {};
start_rdp_replay(args, args.id = parseInt(row_data.id);
function () { args.host = ip;
ywl.notify_success('RDP 录像播放器成功启动!'); args.port = port;
}, args.tail = tail;
function (code, msg) { args.url = url;
if (code === TPE_NO_ASSIST) start_rdp_replay(args,
g_assist.alert_assist_not_found(); function () {
else { ywl.notify_success('RDP 录像播放器成功启动!');
ywl.notify_error(msg); },
console.log('error:', msg) function (code, msg) {
} if (code === TPE_NO_ASSIST)
}); g_assist.alert_assist_not_found();
}); else {
} ywl.notify_error(msg);
else if (protocol === PROTOCOL_TYPE_SSH) { console.log('error:', msg)
$(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 () { else if (protocol === PROTOCOL_TYPE_SSH) {
window.open('/log/command-log/' + parseInt(row_data.protocol) + '/' + row_data.id); $(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: // 重载表格渲染器的部分渲染方式加入本页面相关特殊操作f成功
return '<span class="badge badge-warning">使用中</span>' tbl.on_render_created = function (render) {
// return '-'; render.ret_code = function (row_id, fields) {
case 9999: var msg = '';
return '<span class="badge badge-success">成功</span>'; switch (fields.ret_code) {
case 1: case 0:
msg = '认证失败'; return '<span class="badge badge-warning">使用中</span>'
break; case 9999:
case 2: return '<span class="badge badge-success">成功</span>';
msg = '连接失败'; case 1:
break; msg = '认证失败';
case 3: break;
msg = '私钥错误'; case 2:
break; msg = '连接失败';
case 4: break;
msg = '内部错误'; case 3:
break; msg = '私钥错误';
case 5: break;
msg = '协议不支持'; case 4:
break; msg = '内部错误';
case 6: break;
msg = '通讯错误'; case 5:
break; msg = '协议不支持';
case 7: break;
msg = '错误重置'; case 6:
break; msg = '通讯错误';
default: break;
//return '<span class="badge badge-danger">' + fields.ret_code + '</span>'; case 7:
msg = fields.ret_code; msg = '错误重置';
} break;
default:
return '<span class="badge badge-danger">' + msg + '</span>'; msg = fields.ret_code;
}
// if (fields.ret_code == 0) {
// return '<span class="badge badge-danger">' + msg + '</span>';
// } else if (fields.ret_code == 9999) { };
// return '<span class="badge badge-success">成功</span>'; render.begin_time = function (row_id, fields) {
// } else { return '<span class="badge badge-primary mono">' + format_datetime(utc_to_local(fields.begin_time)) + ' </span>';
// return '<span class="badge badge-danger">' + fields.ret_code + '</span>'; };
// }
render.cost_time = function (row_id, fields) {
}; if (fields.ret_code === 0) {
render.begin_time = function (row_id, fields) { return '<span class="badge badge-warning">使用中</span>';
return '<span class="badge badge-primary mono">' + format_datetime(utc_to_local(fields.begin_time)) + ' </span>'; } else {
}; return '<span class="badge badge-success">' + second2str(fields.cost_time) + '</span>';
}
render.cost_time = function (row_id, fields) { };
if (fields.ret_code == 0) { render.server_info = function (row_id, fields) {
return '<span class="badge badge-warning">使用中</span>'; //return '<span class="badge badge-success mono">' + fields.host_ip + ':' + fields.host_port + '</span>';
} else { return '<span class="mono">' + fields.host_ip + ':' + fields.host_port + '</span>';
return '<span class="badge badge-success">' + second2str(fields.cost_time) + '</span>'; };
}
}; render.protocol = function (row_id, fields) {
render.server_info = function (row_id, fields) { switch (fields.protocol) {
//return '<span class="badge badge-success mono">' + fields.host_ip + ':' + fields.host_port + '</span>'; case 1:
return '<span class="mono">' + fields.host_ip + ':' + fields.host_port + '</span>'; return '<span class="badge badge-primary">RDP</span>';
}; case 2:
// render.auth_type = function (row_id, fields) { return '<span class="badge badge-success">SSH</span>';
// switch (fields.auth_type) { case 3:
// case 0: return '<span class="badge badge-success">TELNET</span>';
// return '<span class="badge badge-danger">无认证</span>'; default:
// case 1: return '<span class="badge badge-danger">未知</span>';
// return '<span class="badge badge-primary">用户名/密码</span>'; }
// case 2: };
// return '<span class="badge badge-success">SSH密钥</span>';
// default: render.make_check_box = function (row_id, fields) {
// return '<span class="badge badge-danger">未知</span>'; return '<span><input type="checkbox" data-check-box="' + fields.id + '" id="host-select-' + row_id + '"></span>';
// } };
// };
render.protocol = function (row_id, fields) {
switch (fields.protocol) { render.make_action_btn = function (row_id, fields) {
case 1: var ret = [];
return '<span class="badge badge-primary">RDP</span>'; if (fields.protocol === PROTOCOL_TYPE_RDP) {
case 2: ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" protocol=' + fields.protocol + ' ywl-btn-record="' + fields.ID + '">录像查看</a>&nbsp');
return '<span class="badge badge-success">SSH</span>'; } else if (fields.protocol === PROTOCOL_TYPE_SSH) {
case 3: if (fields.ret_code === 9999 && fields.cost_time > 0) {
return '<span class="badge badge-success">TELNET</span>'; ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" protocol=' + fields.protocol + ' ywl-btn-record="' + fields.ID + '">录像查看</a>&nbsp');
default: ret.push('<a href="javascript:;" class="btn btn-sm btn-success" protocol=' + fields.protocol + ' ywl-btn-log="' + fields.ID + '">日志查看</a>&nbsp');
return '<span class="badge badge-danger">未知</span>'; }
} }
};
return ret.join('');
render.make_check_box = function (row_id, fields) { }
return '<span><input type="checkbox" data-check-box="' + fields.id + '" id="host-select-' + row_id + '"></span>'; };
}; };
ywl.create_table_filter_user_list = function (tbl, selector, on_created) {
render.make_action_btn = function (row_id, fields) { var _tblf_st = {};
var ret = [];
if (fields.protocol === PROTOCOL_TYPE_RDP) { // 此表格绑定的DOM对象的ID用于JQuery的选择器
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" protocol=' + fields.protocol + ' ywl-btn-record="' + fields.ID + '">录像查看</a>&nbsp'); _tblf_st.selector = selector;
} else if (fields.protocol === PROTOCOL_TYPE_SSH) { // 此过滤器绑定的表格控件
if (fields.ret_code === 9999 && fields.cost_time > 0) { _tblf_st._table_ctrl = tbl;
ret.push('<a href="javascript:;" class="btn btn-sm btn-primary" protocol=' + fields.protocol + ' ywl-btn-record="' + fields.ID + '">录像查看</a>&nbsp'); _tblf_st._table_ctrl.append_filter_ctrl(_tblf_st);
ret.push('<a href="javascript:;" class="btn btn-sm btn-success" protocol=' + fields.protocol + ' ywl-btn-log="' + fields.ID + '">日志查看</a>&nbsp');
} // 过滤器内容
} _tblf_st.filter_name = 'user_name';
_tblf_st.filter_default = '全部';
return ret.join(''); _tblf_st.filter_value = '';
}
}; _tblf_st.get_filter = function () {
}; var _ret = {};
_ret[_tblf_st.filter_name] = _tblf_st.filter_value;
ywl.create_table_filter_user_list = function (tbl, selector, on_created) { return _ret;
var _tblf_st = {}; };
// 此表格绑定的DOM对象的ID用于JQuery的选择器 _tblf_st.reset = function (cb_stack, cb_args) {
_tblf_st.selector = selector; if (_tblf_st.filter_value === _tblf_st.filter_default) {
// 此过滤器绑定的表格控件 cb_stack.exec();
_tblf_st._table_ctrl = tbl; return;
_tblf_st._table_ctrl.append_filter_ctrl(_tblf_st); }
// 过滤器内容 cb_stack
_tblf_st.filter_name = 'user_name'; .add(function (cb_stack) {
_tblf_st.filter_default = '全部'; _tblf_st.filter_value = _tblf_st.filter_default;
_tblf_st.filter_value = ''; $(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value);
cb_stack.exec();
_tblf_st.get_filter = function () { });
var _ret = {}; };
_ret[_tblf_st.filter_name] = _tblf_st.filter_value;
return _ret; _tblf_st.init = function (cb_stack) {
}; var node = '';
var user_list = ywl.page_options.user_list;
_tblf_st.reset = function (cb_stack, cb_args) { node += '<li><a href="javascript:;" ywl-user-id="0">全部</a></li>';
if (_tblf_st.filter_value == _tblf_st.filter_default) { node += '<li role="separator" class="divider"></li>';
cb_stack.exec(); $.each(user_list, function (i, g) {
return; node += '<li><a href="javascript:;" ywl-user-id="' + g.user_id + '">' + g.user_name + '</a></li>';
} });
cb_stack _tblf_st.filter_value = _tblf_st.filter_default;
.add(function (cb_stack) { $(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value);
_tblf_st.filter_value = _tblf_st.filter_default; $(_tblf_st.selector + ' ul').empty().append($(node));
$(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value);
cb_stack.exec(); // 点击事件绑定
}); $(_tblf_st.selector + ' ul [ywl-user-id]').click(_tblf_st._on_select);
};
if (_.isFunction(on_created)) {
_tblf_st.init = function (cb_stack) { on_created(_tblf_st);
var node = ''; }
var user_list = ywl.page_options.user_list;
node += '<li><a href="javascript:;" ywl-user-id="0">全部</a></li>'; cb_stack.exec();
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._on_select = function () {
}); var user_name = $(this).html();
_tblf_st.filter_value = _tblf_st.filter_default; var cb_stack = CALLBACK_STACK.create();
$(_tblf_st.selector + ' button span:first').html(_tblf_st.filter_value); cb_stack
$(_tblf_st.selector + ' ul').empty().append($(node)); .add(_tblf_st._table_ctrl.load_data)
.add(function (cb_stack) {
// 点击事件绑定 _tblf_st.filter_value = user_name;
$(_tblf_st.selector + ' ul [ywl-user-id]').click(_tblf_st._on_select); $(_tblf_st.selector + ' button span:first').html(user_name);
cb_stack.exec();
if (_.isFunction(on_created)) { });
on_created(_tblf_st); cb_stack.exec();
} };
cb_stack.exec(); return _tblf_st;
}; };
_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}, ywl.ajax_post_json('/auth/modify-pwd', {o_pwd: old_pwd, n_pwd: new_pwd_1, callback: 1},
function (ret) { function (ret) {
if (ret.code == 0) { if (ret.code === TPE_OK) {
ywl.notify_success('密码修改成功!'); ywl.notify_success('密码修改成功!');
ywl.clear_input(); ywl.clear_input();
} else if (ret.code == -2) { } else if (ret.code === -101) {
ywl.notify_error('密码错误!'); ywl.notify_error('密码错误!');
} else { } else {
ywl.notify_error('密码修改失败errcode:'+ret.code); ywl.notify_error('密码修改失败'+ret.message);
} }
}, },

View File

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

View File

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

View File

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