From 59f14d3e73f109db0d0a7b81e195e5a069dc9b03 Mon Sep 17 00:00:00 2001 From: apexliu Date: Sun, 16 Apr 2017 06:15:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=A2=AB=E9=94=81=E5=AE=9A?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E6=88=B7=E4=BB=8D=E7=84=B6=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=99=BB=E5=BD=95=EF=BC=9B=E4=BF=AE=E6=AD=A3=E5=BD=95=E5=83=8F?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=AD=E8=AE=B0=E5=BD=95=E7=9A=84=E8=B5=B7?= =?UTF-8?q?=E5=A7=8B=E6=97=B6=E9=97=B4=E4=B8=8D=E6=AD=A3=E7=A1=AE=EF=BC=9B?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0ssh=E5=9B=9E=E6=94=BE=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=BC=9A=E8=AF=9D=E8=AF=A6=E7=BB=86=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/tp_assist/site/index.html | 20 +- client/tp_assist/ts_http_rpc.cpp | 43 +- common/teleport/teleport_const.h | 8 +- server/tp_core/common/base_record.cpp | 232 -- server/tp_core/protocol/ssh/ssh_recorder.cpp | 4 +- .../teleport/app/eom_app/controller/auth.py | 10 +- .../teleport/app/eom_app/controller/host.py | 15 +- .../www/teleport/app/eom_app/module/host.py | 2 +- .../www/teleport/app/eom_app/module/record.py | 85 +- .../www/teleport/app/eom_app/module/user.py | 14 +- server/www/teleport/static/css/auth.css | 2 +- .../www/teleport/static/js/ui/admin_host.js | 2477 ++++++++--------- server/www/teleport/static/js/ui/auth.js | 4 +- .../www/teleport/static/js/ui/auth/login.js | 43 +- server/www/teleport/static/js/ui/cert.js | 30 +- server/www/teleport/static/js/ui/common.js | 6 +- .../www/teleport/static/js/ui/common_host.js | 16 +- server/www/teleport/static/js/ui/controls.js | 28 +- server/www/teleport/static/js/ui/record.js | 8 +- server/www/teleport/static/js/ui/teleport.js | 23 +- server/www/teleport/static/js/ywl_const.js | 72 +- server/www/teleport/static/less/auth.less | 6 + server/www/teleport/view/auth/page_base.mako | 2 +- server/www/teleport/view/cert/index.mako | 2 +- .../view/common/_sidebar_nav_menu.mako | 40 +- server/www/teleport/view/group/index.mako | 2 +- .../www/teleport/view/host/admin_index.mako | 237 +- server/www/teleport/view/log/index.mako | 2 +- server/www/teleport/view/log/record.mako | 1 + server/www/teleport/view/pwd/index.mako | 2 +- server/www/teleport/view/set/index.mako | 2 +- server/www/teleport/view/user/index.mako | 2 +- version.in | 4 +- 33 files changed, 1494 insertions(+), 1950 deletions(-) diff --git a/client/tp_assist/site/index.html b/client/tp_assist/site/index.html index dda9547..2325531 100644 --- a/client/tp_assist/site/index.html +++ b/client/tp_assist/site/index.html @@ -16,9 +16,6 @@ - - - @@ -33,7 +30,7 @@ @@ -82,21 +79,6 @@ - - - - - - - - - - - - - - -
diff --git a/client/tp_assist/ts_http_rpc.cpp b/client/tp_assist/ts_http_rpc.cpp index 6a5a344..012ed45 100644 --- a/client/tp_assist/ts_http_rpc.cpp +++ b/client/tp_assist/ts_http_rpc.cpp @@ -44,12 +44,15 @@ End Sub ֹˣubuntuԣ֪Ƿܹ֧еLinuxSecureCRTԴ˱ʾԡ */ -//#define RDP_CLIENT_SYSTEM_BUILTIN +// #define RDP_CLIENT_SYSTEM_BUILTIN // #define RDP_CLIENT_SYSTEM_ACTIVE_CONTROL #define RDP_CLIENT_FREERDP #ifdef RDP_CLIENT_SYSTEM_BUILTIN +#include +#pragma comment(lib, "Crypt32.lib") + std::string rdp_content = "\ connect to console:i:%d\n\ screen mode id:i:%d\n\ @@ -87,6 +90,7 @@ redirectposdevices:i:0\n\ redirectdirectx:i:0\n\ autoreconnection enabled:i:0\n\ drivestoredirect:s:*\n\ +password 51:b:%s\n\ "; //password 51:b:01000000D08C9DDF0115D1118C7A00C04FC297EB0100000052A9E191EA75A948B359790578C9371A0000000008000000700073007700000003660000A8000000100000000A1DCCD2E50775CA25EC3857164B34DC0000000004800000A000000010000000FCE1A645B9B61AA450946BB6F955058108020000D83591CA47562D6DDAA689F050AE145039EBE22E00D1D3AEAA98373C7B63C3E8E7149072DF989EA43EFCE20513AD3D27B11BE7F17066A688E1DCE828AF85460AAC327B38E90776DB962888E4393D19637578984B19A187AAD95F6D2726ADE7DD315FF56C15FF5B3031014EDDCC3C24D1B81779AFDB006EE575F5BEFB8D2D2138D9D9D642BBB251CC5ED7226968764856EC660A646BACE748A13D6002A9A537AA70710615650B9387EED66DE28BD57B304BBDD7B581B943DA628EB0289E30A8BA784B76F7885BECCAB4FEF7820E97EE3C6E036EEAF6EAA669288DF2FCACC9BEC045C907EBBDE87AFB8CC6B07A600BD63AC891B61D95C2265DD9FD5E635D61BFBF5EDC28311375066611C610FB533D64515B643C82F57D9B183B05C156D91BC0974D38E546022B139E82452E6F1EDF76E52F732C3904E5E433F8F3D488DB0698427DBB0791A9F207F8CB6654CB8410BAF4A59C4F9E821E589ABC1E6E6E1D432181B690408F6884FE1007895A4D26D4A5A2C7458EE747DA35D44AC9FB08AB5477EA3E7CCDB3E37EE20FAFD0D0CF9584E420598B7003B347943AC28048F45E0FD21AD08148FFADCE0E7877219259A7BE722FFAE845A429BA2CF0A71F2D19EA7495530FABDB5106E8D404A38A7E6394C38457640EA7398C5D55F0C4D342CC6A39C77E10A2A5145AEA40B14F5C7C3760334D83C9BE748383FADE231248537353817D51F7B44F61B406ABC61400000071C354139F458B02D978015F785B97F7F6B307380\n\ @@ -155,6 +159,34 @@ int ts_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_f return i >= src_len ? j : -1; } +#ifdef RDP_CLIENT_SYSTEM_BUILTIN +bool calc_psw51b(const char* password, std::string& ret) +{ + DATA_BLOB DataIn; + DATA_BLOB DataOut; + + ex_wstr w_pswd; + ex_astr2wstr(password, w_pswd, EX_CODEPAGE_ACP); + + DataIn.cbData = w_pswd.length() * sizeof(wchar_t); + DataIn.pbData = (BYTE*)w_pswd.c_str(); + + + if (!CryptProtectData(&DataIn, L"psw", NULL, NULL, NULL, 0, &DataOut)) + return false; + + char szRet[5] = {0}; + for (int i = 0; i < DataOut.cbData; ++i) + { + sprintf_s(szRet, 5, "%02X", DataOut.pbData[i]); + ret += szRet; + } + + LocalFree(DataOut.pbData); + return true; +} +#endif + TsHttpRpc::TsHttpRpc() { m_stop = false; @@ -742,12 +774,21 @@ void TsHttpRpc::_rpc_func_create_ts_client(const ex_astr& func_args, ex_astr& bu int split_pos = sid.length() - 2; std::string real_sid = sid.substr(0, split_pos); + std::string psw51b; + if (!calc_psw51b("Abcd1234", psw51b)) + { + printf("calc password failed.\n"); + _create_json_ret(buf, TPE_FAILED); + return; + } + char sz_rdp_file_content[4096] = { 0 }; sprintf_s(sz_rdp_file_content, rdp_content.c_str(), console, display, width, higth , cx, cy, cx + width + 20, cy + higth + 40 , teleport_ip.c_str(), teleport_port , real_sid.c_str() + , psw51b.c_str() ); char sz_file_name[MAX_PATH] = { 0 }; diff --git a/common/teleport/teleport_const.h b/common/teleport/teleport_const.h index 4fdf8f8..dd29680 100644 --- a/common/teleport/teleport_const.h +++ b/common/teleport/teleport_const.h @@ -27,8 +27,8 @@ #define TPE_UNKNOWN_CMD 124 // δ֪ #define TPE_JSON_FORMAT 125 // JSONʽҪJSONʽݣȴ޷JSONʽ룩 -#define TPE_PARAM 126 // -#define TPE_DATA 127 // ݴ +#define TPE_PARAM 126 // +#define TPE_DATA 127 // ݴ @@ -40,9 +40,9 @@ //------------------------------------------------------- // ֳרôֵ //------------------------------------------------------- -#define TPE_NO_ASSIST 100000 // δܼ⵽ֳ +#define TPE_NO_ASSIST 100000 // δܼ⵽ֳ #define TPE_OLD_ASSIST 100001 // ֳ汾̫ -#define TPE_START_CLIENT 100002 // ޷ͻ˳޷̣ +#define TPE_START_CLIENT 100002 // ޷ͻ˳޷̣ diff --git a/server/tp_core/common/base_record.cpp b/server/tp_core/common/base_record.cpp index 965991f..7f974fe 100644 --- a/server/tp_core/common/base_record.cpp +++ b/server/tp_core/common/base_record.cpp @@ -5,238 +5,6 @@ #include "base_record.h" -#if 0 -base_record::base_record() -{ - //g_env.m_record_ssh_path - m_buf = new unsigned char[MAX_SIZE_PER_FILE]; - memset(m_buf, 0, MAX_SIZE_PER_FILE); - m_buf_offset = 0; - m_begin_time = 0; - m_last_time = 0; - m_file_current_index = 0; - m_current_file = 0; - m_totol_size = 0; -} - - -base_record::~base_record() -{ - if (NULL != m_buf) - { - delete[] m_buf; - m_buf = NULL; - } -} - -void base_record::begin(int record_id, int record_type) -{ - char szPath[1024] = { 0 }; - ex_astr ssh_path; - - m_begin_time = ex_get_tick_count(); - m_last_time = m_begin_time; - m_file_current_index = 0; - m_current_file = 0; - if (record_type == 2) - { - //ex_mkdirs() - -#ifdef EX_OS_WIN32 - ts_str2astr(g_env.m_record_ssh_path, ssh_path); - sprintf_s(szPath, "%s\\%d\\", ssh_path.c_str(), record_id); - int ret = _mkdir(szPath); -#else - ssh_path = g_env.m_record_ssh_path; - snprintf(szPath, 1024, "%s/%d", ssh_path.c_str(), record_id); - EXLOGV("try to create folder for record: [%s]\n", szPath); - int status = mkdir(szPath, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - EXLOGV("create folder for record return %d, errno=%d.\n", status, errno); -#endif - m_current_path = szPath; - open_next_file(); - } -} -void base_record::end() -{ - ex_u64 current_time = ex_get_tick_count(); - ex_u64 internal_time = m_last_time - m_begin_time; - - save_buffer_to_file(int(internal_time)); - - if (m_buf) - { - delete[] m_buf; - m_buf = NULL; - } - if (m_current_file) - { - fclose(m_current_file); - } - - ts_replay_header header = {0}; - ex_strcpy(header.ID, 16, "teleport"); - ex_strcpy(header.version, 16, "1.0.0.1"); - header.total_time = (ex_u32)internal_time; - header.total_file_count = (ex_u8)m_file_current_index; - header.total_size = (ex_u8)m_totol_size; - int ts_replay_header_len = sizeof(ts_replay_header); - char szPath[1024] = { 0 }; -#ifdef EX_OS_WIN32 - sprintf_s(szPath, "%s\\head.init", m_current_path.c_str()); -#else - snprintf(szPath, 1024, "%s/head.init", m_current_path.c_str()); -#endif - FILE* f = NULL; - if ((f = fopen(szPath, "wb")) == NULL) /* open file TEST.$$$ */ - { - return; - } - - int ret = fwrite(&header, sizeof(ts_replay_header), 1, f); - ret = fwrite(&m_timelist[0], m_timelist.size() * sizeof(int), 1, f); - fclose(f); - - char szTermPath[1024] = { 0 }; -#ifdef EX_OS_WIN32 - sprintf_s(szTermPath, "%s\\term.init", m_current_path.c_str()); -#else - snprintf(szTermPath, 1024, "%s/term.init", m_current_path.c_str()); -#endif - - if ((f = fopen(szTermPath, "wb")) == NULL) - { - return; - } - ssh_terms_data_header terms_header = { 0 }; - ex_strcpy(terms_header.ID, 16,"teleport"); - ex_strcpy(terms_header.version, 16,"1.0.0.1"); - terms_header.term_count = (ex_u32)m_windows_size_list.size(); - ret = fwrite(&terms_header,sizeof(ssh_terms_data_header), 1, f); - if (m_windows_size_list.size() > 0) - { - ret = fwrite(&m_windows_size_list[0], m_windows_size_list.size() * sizeof(ssh_terms_data), 1, f); - } - - fclose(f); -} - -void base_record::windows_size(ssh_terms_data size_info) -{ - ex_u64 internal_time = ex_get_tick_count() - m_begin_time; - size_info.time = (ex_u32)internal_time; - m_windows_size_list.push_back(size_info); -} - -void base_record::record(unsigned char* buf, int len, int cmd) -{ - ex_u64 current_time = ex_get_tick_count(); - ex_u64 internal_time = current_time - m_begin_time; - m_last_time = current_time; - - //bool bSwitchFile = false; - //bool bWriteFile = false; - - ts_replay_data_header replay_header = {0}; - replay_header.action = (ex_u8)cmd; - replay_header.time = (ex_u32)internal_time; - replay_header.size = (ex_u32)len; - //int header_len = sizeof(ts_replay_data_header); - - bool bRet = cached_buffer(&replay_header, buf, len); - if (!bRet) - { - //ѻļջ - save_buffer_to_file(int(internal_time)); - - //¸ļ - open_next_file(); - - bRet = cached_buffer(&replay_header, buf, len); - - if (!bRet) - { - //̫󣬲ܻ棬ֱӴļ - save_to_file(ex_u32(internal_time), &replay_header, buf, len); - open_next_file(); - } - } -} - -bool base_record::cached_buffer(ts_replay_data_header* header, unsigned char* buf, int len) -{ - size_t header_len = sizeof(ts_replay_data_header); - if ((m_buf_offset + len + header_len) > MAX_SIZE_PER_FILE) - { - return false; - } - - //ȹֱӴ滺 - memcpy(m_buf + m_buf_offset, header, header_len); - m_buf_offset += header_len; - - memcpy(m_buf + m_buf_offset, buf, len); - m_buf_offset += len; - - return true; -} - -bool base_record::open_next_file() -{ - char szPath[1024] = { 0 }; -#ifdef EX_OS_WIN32 - sprintf_s(szPath, "%s\\%d.ts", m_current_path.c_str(), m_file_current_index); -#else - snprintf(szPath, 1024, "%s/%d.ts", m_current_path.c_str(), m_file_current_index); -#endif - if (NULL != m_current_file) - { - fclose(m_current_file); - } - if ((m_current_file = fopen(szPath, "wb")) == NULL) /* open file TEST.$$$ */ - { - return false; - } - - m_file_current_index++; - - return true; -} - -bool base_record::save_buffer_to_file(int internal_time) -{ - if(NULL == m_current_file) - return false; - - int ret = fwrite(m_buf, m_buf_offset, 1, m_current_file); /* дstructļ*/ - m_totol_size += m_buf_offset; - - m_buf_offset = 0; - m_timelist.push_back(ex_u32(internal_time)); - return true; -} - -bool base_record::save_to_file(int internal_time,ts_replay_data_header* header, unsigned char* buf, int len) -{ - if(NULL == m_current_file) - return false; - - int ret = fwrite(header, sizeof(ts_replay_data_header), 1, m_current_file); - ret = fwrite(buf, len, 1, m_current_file); - - m_totol_size += sizeof(ts_replay_data_header); - m_totol_size += len; - m_timelist.push_back(ex_u32(internal_time)); - return true; -} -#endif - -//==================================================== -// NEW INTERFACE -//==================================================== - - - TppRecBase::TppRecBase() { m_cache.reserve(MAX_SIZE_PER_FILE); diff --git a/server/tp_core/protocol/ssh/ssh_recorder.cpp b/server/tp_core/protocol/ssh/ssh_recorder.cpp index 7d4fc07..b245a0c 100644 --- a/server/tp_core/protocol/ssh/ssh_recorder.cpp +++ b/server/tp_core/protocol/ssh/ssh_recorder.cpp @@ -21,7 +21,7 @@ void TppSshRec::_on_begin(const TPP_SESSION_INFO* info) { if (NULL == info) return; - + m_head.timestamp = time(NULL); m_head.port = info->host_port; // memcpy(m_head.account, info.account_name.c_str(), info.account_name.length() > 15 ? 15 : info.account_name.length()); // memcpy(m_head.username, info.user_name.c_str(), info.user_name.length() > 15 ? 15 : info.user_name.length()); @@ -41,7 +41,7 @@ void TppSshRec::_on_end(void) _save_to_cmd_file(); // ͷϢ - m_head.timestamp = m_start_time; + //m_head.timestamp = m_start_time; m_head.time_ms = (ex_u32)(m_last_time - m_start_time); ex_wstr fname = m_base_path; diff --git a/server/www/teleport/app/eom_app/controller/auth.py b/server/www/teleport/app/eom_app/controller/auth.py index cd4f6ab..f88c4a9 100644 --- a/server/www/teleport/app/eom_app/controller/auth.py +++ b/server/www/teleport/app/eom_app/controller/auth.py @@ -58,12 +58,14 @@ class VerifyUser(TPBaseJsonHandler): return try: - user_id, account_type, nickname = user.verify_user(username, userpwd) + user_id, account_type, nickname, locked = user.verify_user(username, userpwd) + if locked == 1: + return self.write_json(-1, '账号被锁定,请联系管理员!') if user_id == 0: if cfg.app_mode == APP_MODE_MAINTENANCE: - self.write_json(-2, '系统维护中,请稍候再试') + self.write_json(-2, '系统维护中,请稍候再试!') else: - self.write_json(-1, '用户名/密码错误') + self.write_json(-1, '用户名/密码错误!') return _user = self.get_session('user') @@ -92,7 +94,7 @@ class VerifyUser(TPBaseJsonHandler): except: log.e('can not set session.') - self.write_json(-1, '无法记录用户登录状态') + self.write_json(-1, '无法记录用户登录状态!') class LogoutHandler(TPBaseUserAuthHandler): diff --git a/server/www/teleport/app/eom_app/controller/host.py b/server/www/teleport/app/eom_app/controller/host.py index de39949..812f11b 100644 --- a/server/www/teleport/app/eom_app/controller/host.py +++ b/server/www/teleport/app/eom_app/controller/host.py @@ -513,22 +513,19 @@ class DeleteCert(TPBaseUserAuthJsonHandler): args = self.get_argument('args', None) if args is not None: args = json.loads(args) - # print('args', args) else: - # ret = {'code':-1} - self.write_json(-1) - return + return self.write_json(-1) + cert_id = args['cert_id'] + try: ret = host.delete_cert(cert_id) if ret: - self.write_json(0) + return self.write_json(0) else: - self.write_json(-1) - return + return self.write_json(-2) except: - self.write_json(-1) - return + return self.write_json(-3) class UpdateCert(TPBaseUserAuthJsonHandler): diff --git a/server/www/teleport/app/eom_app/module/host.py b/server/www/teleport/app/eom_app/module/host.py index a46ed05..8546662 100644 --- a/server/www/teleport/app/eom_app/module/host.py +++ b/server/www/teleport/app/eom_app/module/host.py @@ -414,7 +414,7 @@ def add_cert(cert_pub, cert_pri, cert_name): def delete_cert(cert_id): db = get_db() - sql = 'DELETE FROM `{}key` WHERE `cert_id`={};'.format(int(cert_id)) + sql = 'DELETE FROM `{}key` WHERE `cert_id`={};'.format(db.table_prefix, int(cert_id)) return db.exec(sql) diff --git a/server/www/teleport/app/eom_app/module/record.py b/server/www/teleport/app/eom_app/module/record.py index c249135..fd0c63c 100644 --- a/server/www/teleport/app/eom_app/module/record.py +++ b/server/www/teleport/app/eom_app/module/record.py @@ -19,8 +19,12 @@ def read_record_head(record_id): data = file.read() offset = 0 - magic, = struct.unpack_from('I', data, offset) # magic must be 1381126228, 'TPRR' + magic, = struct.unpack_from('I', data, offset) # magic must be 1381126228, 'TPPR' offset += 4 + ver, = struct.unpack_from('H', data, offset) + offset += 2 + protocol, = struct.unpack_from('H', data, offset) + offset += 2 time_start, = struct.unpack_from('Q', data, offset) offset += 8 pkg_count, = struct.unpack_from('I', data, offset) @@ -42,6 +46,11 @@ def read_record_head(record_id): user_name, = struct.unpack_from('16s', data, offset) user_name = user_name.decode() offset += 16 + ip, = struct.unpack_from('18s', data, offset) + ip = ip.decode() + offset += 18 + port, = struct.unpack_from('H', data, offset) + offset += 2 except Exception as e: return None @@ -50,81 +59,19 @@ def read_record_head(record_id): file.close() header = dict() + header['start'] = time_start header['file_count'] = file_count header['time_used'] = time_used header['width'] = width header['height'] = height + header['account'] = account + header['user_name'] = user_name + header['ip'] = ip + header['port'] = port + return header -# def read_record_term(record_id): -# record_path = os.path.join(cfg.core.replay_path, 'ssh', '{}'.format(record_id)) -# term_file_path = os.path.join(record_path, 'term.init') -# # term_file_path = r"E:\GitWork\teleport\share\data\replay\ssh\103\term.init" -# -# file = None -# try: -# file = open(term_file_path, 'rb') -# data = file.read() -# x = len(data) -# offset = 0 -# # data = data.decode() -# ID, = struct.unpack_from('16s', data, offset) -# ID = ID.decode() -# offset += 16 -# -# Version, = struct.unpack_from('16s', data, offset) -# Version = Version.decode() -# offset += 16 -# -# t_count, = struct.unpack_from('I', data, offset) -# offset += 4 -# term_list = list() -# for i in range(t_count): -# # _term, = struct.unpack_from('16s', data, offset) -# # _term = _term.decode() -# # offset += 16 -# _time, = struct.unpack_from('I', data, offset) -# offset += 4 -# -# x, = struct.unpack_from('I', data, offset) -# offset += 4 -# -# y, = struct.unpack_from('I', data, offset) -# offset += 4 -# -# # px, = struct.unpack_from('I', data, offset) -# # offset += 4 -# # -# # py, = struct.unpack_from('I', data, offset) -# # offset += 4 -# # -# # _time, = struct.unpack_from('I', data, offset) -# # offset += 4 -# temp = dict() -# # temp['term'] = _term -# temp['t'] = _time -# temp['w'] = x -# temp['h'] = y -# # temp['px'] = px -# # temp['py'] = py -# -# term_list.append(temp) -# -# except Exception as e: -# return None -# finally: -# if file is not None: -# file.close() -# -# header = dict() -# header['id'] = ID -# header['ver'] = Version -# header['count'] = t_count -# header['term_list'] = term_list -# return header - - def read_record_info(record_id, file_id): record_path = os.path.join(app_cfg().core.replay_path, 'ssh', '{:06d}'.format(int(record_id))) file_info = os.path.join(record_path, 'tp-ssh.{:03d}'.format(int(file_id))) diff --git a/server/www/teleport/app/eom_app/module/user.py b/server/www/teleport/app/eom_app/module/user.py index 3c6c27a..5c615c6 100644 --- a/server/www/teleport/app/eom_app/module/user.py +++ b/server/www/teleport/app/eom_app/module/user.py @@ -12,7 +12,7 @@ def verify_user(name, password): cfg = app_cfg() db = get_db() - sql = 'SELECT `account_id`, `account_type`, `account_name`, `account_pwd` 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) if db_ret is None: # 特别地,如果无法取得数据库连接,有可能是新安装的系统,尚未建立数据库,此时应该处于维护模式 @@ -20,25 +20,29 @@ def verify_user(name, password): if cfg.app_mode == APP_MODE_MAINTENANCE: if name == 'admin' and password == 'admin': return 1, 100, 'admin' - return 0, 0, '' + return 0, 0, '', 0 if len(db_ret) != 1: - return 0, 0, '' + return 0, 0, '', 0 user_id = db_ret[0][0] account_type = db_ret[0][1] name = db_ret[0][2] + locked = db_ret[0][4] + if locked == 1: + return 0, 0, '', locked + if not sec_verify_password(password, db_ret[0][3]): # 按新方法验证密码失败,可能是旧版本的密码散列格式,再尝试一下 if db_ret[0][3] != hashlib.sha256(password.encode()).hexdigest(): - return 0, 0, '' + return 0, 0, '', locked else: # 发现此用户的密码散列格式还是旧的,更新成新的吧! _new_sec_password = sec_generate_password(password) sql = 'UPDATE `{}account` SET `account_pwd`="{}" WHERE `account_id`={}'.format(db.table_prefix, _new_sec_password, int(user_id)) db.exec(sql) - return user_id, account_type, name + return user_id, account_type, name, locked def modify_pwd(old_pwd, new_pwd, user_id): diff --git a/server/www/teleport/static/css/auth.css b/server/www/teleport/static/css/auth.css index ab14080..882cdaa 100644 --- a/server/www/teleport/static/css/auth.css +++ b/server/www/teleport/static/css/auth.css @@ -1 +1 @@ -@charset "utf-8";body{padding-top:70px;padding-bottom:24px;background-color:#ececed}#head nav.navbar{height:70px;line-height:70px;background-color:#333;color:#fff}#head .logo .desc{display:block;float:right;color:#ccc;margin-top:10px;font-size:18px}#foot nav.navbar{min-height:24px;height:24px;line-height:24px;background-color:#ddd;color:#fff;font-size:12px;border-top:1px solid #ccc}#foot nav.navbar .container{height:24px}#foot nav.navbar p{margin:0 auto;text-align:center;color:#333}#content{margin:10px 0 50px 0}.auth-box{margin-top:30px;min-height:120px;border:1px solid #ccc;border-radius:8px;background-color:rgba(255,255,255,0.6)}.auth-box .header{min-height:50px;height:50px;border:none;box-shadow:none;border-bottom:1px solid #ccc}.auth-box .header .title{display:inline-block;float:left;margin-left:60px;height:24px;margin-top:25px;line-height:16px;font-size:20px;color:#999}.auth-box .header .selected{border-bottom:1px solid #69c;color:#555}.auth-box .header .title:hover{border-bottom:1px solid #999}.auth-box .inputarea{margin:30px}.auth-box .inputarea .input-group-addon{padding:0 5px 0 5px}.auth-box .inputarea p.input-addon-desc{text-align:right;padding:0 5px 0 5px;color:#999}#leftside{width:560px;height:560px;padding-top:60px;background:url(../img/login/side-001.jpg) 0 0 no-repeat}#leftside h1{font-size:24px;color:#888}#leftside p{font-size:18px;color:#888;padding-left:24px}.auth-box .inputbox{margin-bottom:10px}.auth-box-lg .inputbox{margin-bottom:20px}.auth-box .op_box{display:block;padding:5px;border-radius:3px;text-align:center;margin:5px 20px 10px 20px}.auth-box .op_error{background:#fbb}.auth-box .op_wait{background:#ccc}.auth-box .quick-area{padding:80px 0 80px 0}.auth-box .quick-area .quick-disc{text-align:center;margin-bottom:20px}.auth-box .quick-area .quick-no{padding-top:80px;padding-bottom:100px}.auth-box .quick-area .quick-yes{text-align:center}.auth-box .quick-area .quick-yes .quick-account{display:inline-block;margin:auto;margin-bottom:20px}.auth-box .quick-area .quick-yes .quick-account:hover .quick-image{box-shadow:0 0 8px #00c2f6}.auth-box .quick-area .quick-yes .quick-image{display:block;width:82px;height:82px;line-height:80px;font-size:64px;margin:auto;border:1px solid #a4cdf6;box-shadow:0 0 6px #a7d1fb}.auth-box .quick-area .quick-yes .quick-name{display:block;margin-top:5px} \ No newline at end of file +@charset "utf-8";body{padding-top:70px;padding-bottom:24px;background-color:#ececed}#head nav.navbar{height:70px;line-height:70px;background-color:#333;color:#fff}#head .logo .desc{display:block;float:right;color:#ccc;margin-top:10px;font-size:18px}#foot nav.navbar{min-height:24px;height:24px;line-height:24px;background-color:#ddd;color:#fff;font-size:12px;border-top:1px solid #ccc}#foot nav.navbar .container{height:24px}#foot nav.navbar p{margin:0 auto;text-align:center;color:#333}#content{margin:10px 0 50px 0}.auth-box{margin-top:30px;min-height:120px;border:1px solid #ccc;border-radius:8px;background-color:rgba(255,255,255,0.6)}.auth-box .header{min-height:50px;height:50px;border:none;box-shadow:none;border-bottom:1px solid #ccc}.auth-box .header .title{display:inline-block;float:left;margin-left:60px;height:24px;margin-top:25px;line-height:16px;font-size:20px;color:#999}.auth-box .header .selected{border-bottom:1px solid #69c;color:#555}.auth-box .header .title:hover{border-bottom:1px solid #999}.auth-box .inputarea{margin:30px}.auth-box .inputarea .input-group-addon{padding:0 5px 0 5px}.auth-box .inputarea p.input-addon-desc{text-align:right;padding:0 5px 0 5px;color:#999}#leftside{width:560px;height:560px;padding-top:60px;background:url(../img/login/side-001.jpg) 0 0 no-repeat}@media screen and (max-width:990px){#leftside{display:none}}#leftside h1{font-size:24px;color:#888}#leftside p{font-size:18px;color:#888;padding-left:24px}.auth-box .inputbox{margin-bottom:10px}.auth-box-lg .inputbox{margin-bottom:20px}.auth-box .op_box{display:block;padding:5px;border-radius:3px;text-align:center;margin:5px 20px 10px 20px}.auth-box .op_error{background:#fbb}.auth-box .op_wait{background:#ccc}.auth-box .quick-area{padding:80px 0 80px 0}.auth-box .quick-area .quick-disc{text-align:center;margin-bottom:20px}.auth-box .quick-area .quick-no{padding-top:80px;padding-bottom:100px}.auth-box .quick-area .quick-yes{text-align:center}.auth-box .quick-area .quick-yes .quick-account{display:inline-block;margin:auto;margin-bottom:20px}.auth-box .quick-area .quick-yes .quick-account:hover .quick-image{box-shadow:0 0 8px #00c2f6}.auth-box .quick-area .quick-yes .quick-image{display:block;width:82px;height:82px;line-height:80px;font-size:64px;margin:auto;border:1px solid #a4cdf6;box-shadow:0 0 6px #a7d1fb}.auth-box .quick-area .quick-yes .quick-name{display:block;margin-top:5px} \ No newline at end of file diff --git a/server/www/teleport/static/js/ui/admin_host.js b/server/www/teleport/static/js/ui/admin_host.js index 19eb10d..9d44f66 100644 --- a/server/www/teleport/static/js/ui/admin_host.js +++ b/server/www/teleport/static/js/ui/admin_host.js @@ -1,13 +1,13 @@ "use strict"; -var OS_TYPE_WINDOWS = 1; -var OS_TYPE_LINUX = 2; -var PROTOCOL_TYPE_RDP = 1; -var PROTOCOL_TYPE_SSH = 2; -var PROTOCOL_TYPE_TELNET = 3; -var AUTH_TYPE_PASSWORD = 1; -var AUTH_TYPE_SSHKEY = 2; -var AUTH_NONE = 0; +//var OS_TYPE_WINDOWS = 1; +//var OS_TYPE_LINUX = 2; +//var PROTOCOL_TYPE_RDP = 1; +//var PROTOCOL_TYPE_SSH = 2; +//var PROTOCOL_TYPE_TELNET = 3; +//var AUTH_TYPE_PASSWORD = 1; +//var AUTH_TYPE_SSHKEY = 2; +//var AUTH_NONE = 0; var g_assist = null; var g_host_table = null; @@ -19,231 +19,231 @@ var g_dlg_sys_user = null; var g_join_group_dlg = null; ywl.do_upload_file = function () { - var param = {}; - $.ajaxFileUpload({ - url: "/host/upload-import",// 需要链接到服务器地址 - secureuri: false, - fileElementId: "upload-file", // 文件选择框的id属性 - dataType: 'text', // 服务器返回的格式,可以是json - data: param, - success: function (data) { - $('#upload-file').remove(); - var obj = JSON.parse(data); - if (obj.code == 0) { - g_host_table.reload(); - ywl.notify_success('批量导入主机成功!'); - console.log('msg', obj); - if (obj.msg.length > 0) { - console.log(obj.msg); - var html = []; - html.push('
    '); - for (var i = 0, cnt = obj.msg.length; i < cnt; ++i) { - html.push('
  • '); - html.push('' + obj.msg[i].reason + '
    '); - html.push(obj.msg[i].line); - html.push('
  • '); - } - html.push('
'); + var param = {}; + $.ajaxFileUpload({ + url: "/host/upload-import",// 需要链接到服务器地址 + secureuri: false, + fileElementId: "upload-file", // 文件选择框的id属性 + dataType: 'text', // 服务器返回的格式,可以是json + data: param, + success: function (data) { + $('#upload-file').remove(); + var obj = JSON.parse(data); + if (obj.code === TPE_OK) { + g_host_table.reload(); + ywl.notify_success('批量导入主机成功!'); + console.log('msg', obj); + if (obj.msg.length > 0) { + console.log(obj.msg); + var html = []; + html.push('
    '); + for (var i = 0, cnt = obj.msg.length; i < cnt; ++i) { + html.push('
  • '); + html.push('' + obj.msg[i].reason + '
    '); + html.push(obj.msg[i].line); + html.push('
  • '); + } + html.push('
'); - $('#batch_add_host_result').html(html.join('')); - $('#dialog_batch_add_host').modal({backdrop: 'static'}); - } - } else { - ywl.notify_error('批量导入主机失败! 错误号:' + obj.code); - } - }, - error: function (data, status, e) { // 相当于java中catch语句块的用法 - $('#upload-file').remove(); - ywl.notify_error('网络故障,批量导入主机失败!'); - } - }); + $('#batch_add_host_result').html(html.join('')); + $('#dialog_batch_add_host').modal({backdrop: 'static'}); + } + } else { + ywl.notify_error('批量导入主机失败! 错误号:' + obj.code); + } + }, + error: function (data, status, e) { // 相当于java中catch语句块的用法 + $('#upload-file').remove(); + ywl.notify_error('网络故障,批量导入主机失败!'); + } + }); }; ywl.on_init = function (cb_stack, cb_args) { - g_assist = ywl.create_assist(); + g_assist = ywl.create_assist(); - var _ver_obj = $("#tp-assist-version"); - var last_version = _ver_obj.text(); - var req_version = _ver_obj.attr("req-version"); + var _ver_obj = $("#tp-assist-version"); + var last_version = _ver_obj.text(); + var req_version = _ver_obj.attr("req-version"); - teleport_init(last_version, req_version, - function (ret) { - $("#tp-assist-current-version").text("当前助手版本:" + ret.version); - }, - function (ret, code, error) { - if (code == TPE_NO_ASSIST) { - $("#tp-assist-current-version").text("未能检测到TP助手,请您下载并启动TP助手!"); - g_assist.alert_assist_not_found(); - } else if (code == TPE_OLD_ASSIST) { - ywl.notify_error(error); - $('#tp-assist-current-version').html('当前助手版本太低(v' + ret.version + '),请下载最新版本!'); - } else { - $("#tp-assist-current-version").text('检测TP助手版本时发生错误!'); - ywl.notify_error(error); - } - }); + teleport_init(last_version, req_version, + function (ret) { + $("#tp-assist-current-version").text("当前助手版本:" + ret.version); + }, + function (ret, code, error) { + if (code === TPE_NO_ASSIST) { + $("#tp-assist-current-version").text("未能检测到TP助手,请您下载并启动TP助手!"); + g_assist.alert_assist_not_found(); + } else if (code === TPE_OLD_ASSIST) { + ywl.notify_error(error); + $('#tp-assist-current-version').html('当前助手版本太低(v' + ret.version + '),请下载最新版本!'); + } else { + $("#tp-assist-current-version").text('检测TP助手版本时发生错误!'); + ywl.notify_error(error); + } + }); - //=================================== - // 创建页面控件对象 - //=================================== - var tbl_dom_id = '#ywl_host_list'; - // 表格数据 - var host_table_options = { - selector: tbl_dom_id + " [ywl-table='host-list']", - data_source: { - type: 'ajax-post', - url: '/host/list' - }, - //render: ywl.create_table_render(ywl.on_host_table_render_created),//ywl_TableRender.create(); - column_default: {sort: false, header_align: 'center', cell_align: 'center'}, - columns: [ - { - title: '', - key: 'select_all', - sort: false, - width: 24, - render: 'make_check_box', - fields: {id: 'host_id'} - }, - {title: "主机", key: "host_id", width: 200, render: 'host_id', fields: {id: 'host_ip', host_port: 'host_port', host_desc: 'host_desc'}}, - {title: "分组", key: "group_name"}, - {title: "系统", key: "host_sys_type", width: 36, render: 'sys_type', fields: {sys_type: 'host_sys_type'}}, - // {title: "协议", key: "protocol", width: 40, render: 'protocol', fields: {protocol: 'protocol', host_port: 'host_port'}}, - {title: "状态", key: "host_lock", render: 'host_lock', fields: {host_lock: 'host_lock'}}, - {title: "远程连接", key: "auth_list", width: 390, header_align: 'left', cell_align: 'left', render: 'auth_list', fields: {id: 'host_id', protocol: 'protocol', auth_list: 'auth_list'}}, - { - title: "系统用户", - sort: false, - key: "action", - //width: 60, - render: 'make_user_btn', - fields: {id: 'host_id'} - }, - { - title: "操作", - sort: false, - key: "action", - width: 150, - render: 'make_action_btn', - fields: {id: 'host_id', host_lock: 'host_lock'} - } - ], - paging: {selector: tbl_dom_id + " [ywl-paging='host-list']", per_page: paging_normal}, + //=================================== + // 创建页面控件对象 + //=================================== + var tbl_dom_id = '#ywl_host_list'; + // 表格数据 + var host_table_options = { + selector: tbl_dom_id + " [ywl-table='host-list']", + data_source: { + type: 'ajax-post', + url: '/host/list' + }, + //render: ywl.create_table_render(ywl.on_host_table_render_created),//ywl_TableRender.create(); + column_default: {sort: false, header_align: 'center', cell_align: 'center'}, + columns: [ + { + title: '', + key: 'select_all', + sort: false, + width: 24, + render: 'make_check_box', + fields: {id: 'host_id'} + }, + {title: "主机", key: "host_id", width: 200, render: 'host_id', fields: {id: 'host_ip', host_port: 'host_port', host_desc: 'host_desc'}}, + {title: "分组", key: "group_name"}, + {title: "系统", key: "host_sys_type", width: 36, render: 'sys_type', fields: {sys_type: 'host_sys_type'}}, + // {title: "协议", key: "protocol", width: 40, render: 'protocol', fields: {protocol: 'protocol', host_port: 'host_port'}}, + {title: "状态", key: "host_lock", render: 'host_lock', fields: {host_lock: 'host_lock'}}, + {title: "远程连接", key: "auth_list", width: 390, header_align: 'left', cell_align: 'left', render: 'auth_list', fields: {id: 'host_id', protocol: 'protocol', auth_list: 'auth_list'}}, + { + title: "系统用户", + sort: false, + key: "action", + //width: 60, + render: 'make_user_btn', + fields: {id: 'host_id'} + }, + { + title: "操作", + sort: false, + key: "action", + width: 150, + render: 'make_action_btn', + fields: {id: 'host_id', host_lock: 'host_lock'} + } + ], + paging: {selector: tbl_dom_id + " [ywl-paging='host-list']", per_page: paging_normal}, - // 可用的属性设置 - //have_header: true or false + // 可用的属性设置 + //have_header: true or false - // 可用的回调函数 - on_created: ywl.on_host_table_created, - on_header_created: ywl.on_host_table_header_created + // 可用的回调函数 + on_created: ywl.on_host_table_created, + on_header_created: ywl.on_host_table_header_created - // 可重载的函数(在on_created回调函数中重载) - // on_render_created - // on_header_created - // on_paging_created - // on_data_loaded - // on_row_rendered - // on_table_rendered - // on_cell_created - // on_begin_load - // on_after_load + // 可重载的函数(在on_created回调函数中重载) + // on_render_created + // on_header_created + // on_paging_created + // on_data_loaded + // on_row_rendered + // on_table_rendered + // on_cell_created + // on_begin_load + // on_after_load - // 可用的函数 - // load_data - // cancel_load - // set_data - // add_row - // remove_row - // get_row - // update_row - // clear - // reset_filter - }; + // 可用的函数 + // load_data + // cancel_load + // set_data + // add_row + // remove_row + // get_row + // update_row + // clear + // reset_filter + }; - var host_table = ywl.create_table(host_table_options); - g_host_table = host_table; - // 主机分组过滤器 - g_cert_list = ywl.page_options.cert_list; - g_group_list = ywl.page_options.group_list; - ywl.create_table_filter_host_group(host_table, tbl_dom_id + " [ywl-filter='host-group']", g_group_list); + var host_table = ywl.create_table(host_table_options); + g_host_table = host_table; + // 主机分组过滤器 + g_cert_list = ywl.page_options.cert_list; + g_group_list = ywl.page_options.group_list; + ywl.create_table_filter_host_group(host_table, tbl_dom_id + " [ywl-filter='host-group']", g_group_list); - ywl.create_table_filter_system_type(host_table, tbl_dom_id + " [ywl-filter='system-type']"); - // 搜索框 - ywl.create_table_filter_search_box(host_table, tbl_dom_id + " [ywl-filter='search']"); + ywl.create_table_filter_system_type(host_table, tbl_dom_id + " [ywl-filter='system-type']"); + // 搜索框 + ywl.create_table_filter_search_box(host_table, tbl_dom_id + " [ywl-filter='search']"); - g_dlg_edit_host = ywl.create_host_edit_dlg(host_table); - g_dlg_edit_host.init(); + g_dlg_edit_host = ywl.create_host_edit_dlg(host_table); + g_dlg_edit_host.init(); - g_dlg_edit_host_user = ywl.create_host_user_edit_dlg(host_table); - g_dlg_edit_host_user.init(); + g_dlg_edit_host_user = ywl.create_host_user_edit_dlg(host_table); + g_dlg_edit_host_user.init(); - g_dlg_sys_user = ywl.create_sys_user(host_table); - g_dlg_sys_user.init(); + g_dlg_sys_user = ywl.create_sys_user(host_table); + g_dlg_sys_user.init(); - g_join_group_dlg = ywl.create_batch_join_group_dlg(host_table); - g_join_group_dlg.init(); + g_join_group_dlg = ywl.create_batch_join_group_dlg(host_table); + g_join_group_dlg.init(); - //====================================================== - // 事件绑定 - //====================================================== - $("#btn-add-host").click(function () { - g_dlg_edit_host.create_show(); - }); + //====================================================== + // 事件绑定 + //====================================================== + $("#btn-add-host").click(function () { + g_dlg_edit_host.create_show(); + }); - $("#btn-delete-host").click(function () { - var host_list = []; - var _objs = $(host_table.selector + " tbody tr td [data-check-box]"); - $.each(_objs, function (i, _obj) { - if ($(_obj).is(':checked')) { - var _row_data = host_table.get_row(_obj); - host_list.push(_row_data.host_id); - } - }); + $("#btn-delete-host").click(function () { + var host_list = []; + var _objs = $(host_table.selector + " tbody tr td [data-check-box]"); + $.each(_objs, function (i, _obj) { + if ($(_obj).is(':checked')) { + var _row_data = host_table.get_row(_obj); + host_list.push(_row_data.host_id); + } + }); - if (host_list.length === 0) { - ywl.notify_error('请选择要批量删除的主机!'); - return; - } + if (host_list.length === 0) { + ywl.notify_error('请选择要批量删除的主机!'); + return; + } - var _fn_sure = function (cb_stack, cb_args) { - ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, - function (ret) { - g_host_table.reload(); - ywl.notify_success('删除主机操作成功!'); - }, - function () { - ywl.notify_error('网络故障,删除主机操作失败!'); - } - ); - }; + var _fn_sure = function (cb_stack, cb_args) { + ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, + function (ret) { + g_host_table.reload(); + ywl.notify_success('删除主机操作成功!'); + }, + function () { + ywl.notify_error('网络故障,删除主机操作失败!'); + } + ); + }; - var cb_stack = CALLBACK_STACK.create(); - ywl.dlg_confirm(cb_stack, { - msg: '

注意:移除操作不可恢复!!

如果您只是希望临时禁用某个远程主机,可对其进行“锁定”操作!

您确定要移除所有选定的远程主机吗?

', - fn_yes: _fn_sure - }); - }); + var cb_stack = CALLBACK_STACK.create(); + ywl.dlg_confirm(cb_stack, { + msg: '

注意:移除操作不可恢复!!

如果您只是希望临时禁用某个远程主机,可对其进行“锁定”操作!

您确定要移除所有选定的远程主机吗?

', + fn_yes: _fn_sure + }); + }); - $('#btn-batch-add-host').click(function (e) { - var html = ''; - $(this).after($(html)); - var update_file = $("#upload-file"); + $('#btn-batch-add-host').click(function (e) { + var html = ''; + $(this).after($(html)); + var update_file = $("#upload-file"); - update_file.change(function () { - var file_path = $(this).val(); - if (file_path === null || file_path === undefined || file_path === '') { - return; - } - ywl.do_upload_file(); - }); + update_file.change(function () { + var file_path = $(this).val(); + if (file_path === null || file_path === undefined || file_path === '') { + return; + } + ywl.do_upload_file(); + }); - update_file.trigger('click'); - }); + update_file.trigger('click'); + }); - $('#btn-batch-export-host').click(function (e) { + $('#btn-batch-export-host').click(function (e) { window.location.href = '/host/export-host'; // ywl.ajax_post_json('/host/export-host', {}, // function (ret) { @@ -260,352 +260,352 @@ ywl.on_init = function (cb_stack, cb_args) { // ywl.notify_error('操作失败'); // } // ); - }); + }); - $("#btn-apply-group").click(function () { - var _data_list = []; - var _objs = $(host_table.selector + " tbody tr td [data-check-box]"); - $.each(_objs, function (i, _obj) { - if ($(_obj).is(':checked')) { - var _row_data = host_table.get_row(_obj); - var data = {host_id: _row_data.host_id, row_id: _row_data.ywl_row_id}; - _data_list.push(data); - } - }); - if (_data_list.length === 0) { - ywl.notify_error('请选择要批量设置分组的主机!'); - return; - } - g_join_group_dlg.show(_data_list); - }); + $("#btn-apply-group").click(function () { + var _data_list = []; + var _objs = $(host_table.selector + " tbody tr td [data-check-box]"); + $.each(_objs, function (i, _obj) { + if ($(_obj).is(':checked')) { + var _row_data = host_table.get_row(_obj); + var data = {host_id: _row_data.host_id, row_id: _row_data.ywl_row_id}; + _data_list.push(data); + } + }); + if (_data_list.length === 0) { + ywl.notify_error('请选择要批量设置分组的主机!'); + return; + } + g_join_group_dlg.show(_data_list); + }); - // 将刷新按钮点击事件绑定到表格的重新加载函数上,这样,点击刷新就导致表格数据重新加载。 - $(tbl_dom_id + " [ywl-filter='reload']").click(host_table.reload); + // 将刷新按钮点击事件绑定到表格的重新加载函数上,这样,点击刷新就导致表格数据重新加载。 + $(tbl_dom_id + " [ywl-filter='reload']").click(host_table.reload); - cb_stack - .add(host_table.load_data) - .add(host_table.init) - .exec(); + cb_stack + .add(host_table.load_data) + .add(host_table.init) + .exec(); }; // 扩展/重载表格的功能 ywl.on_host_table_created = function (tbl) { - tbl.on_cell_created = function (row_id, col_key, cell_obj) { - var row_data; + tbl.on_cell_created = function (row_id, col_key, cell_obj) { + var row_data; - if (col_key == 'select_all') { - // 选择 - $('#host-select-' + row_id).click(function () { - var _all_checked = true; - var _objs = $(tbl.selector + ' tbody').find('[data-check-box]'); - $.each(_objs, function (i, _obj) { - if (!$(_obj).is(':checked')) { - _all_checked = false; - return false; - } - }); + if (col_key == 'select_all') { + // 选择 + $('#host-select-' + row_id).click(function () { + var _all_checked = true; + var _objs = $(tbl.selector + ' tbody').find('[data-check-box]'); + $.each(_objs, function (i, _obj) { + if (!$(_obj).is(':checked')) { + _all_checked = false; + return false; + } + }); - var select_all_dom = $('#host-select-all'); - if (_all_checked) { - select_all_dom.prop('checked', true); - } else { - select_all_dom.prop('checked', false); - } - }); + var select_all_dom = $('#host-select-all'); + if (_all_checked) { + select_all_dom.prop('checked', true); + } else { + select_all_dom.prop('checked', false); + } + }); - } else if (col_key == 'host_id') { - // 为主机描述绑定点击事件 - var _link = $(cell_obj).find(" [ywl-host-desc]"); - _link.click(function () { - var row_data = tbl.get_row(row_id); - ywl.create_dlg_modify_host_desc(tbl, row_data.ywl_row_id, row_data.host_id, row_data.host_ip, row_data.host_desc).show(_link); - }); - } else if (col_key == 'action') { - row_data = tbl.get_row(row_id); - //console.log('row_data', row_data); - $(cell_obj).find('[ywl-btn-edit]').click(function () { - g_dlg_edit_host.update_show(row_id, row_data); - }); - $(cell_obj).find('[ywl-btn-user-edit]').click(function () { - g_dlg_edit_host_user.update_show(row_id, row_data); - }); + } else if (col_key == 'host_id') { + // 为主机描述绑定点击事件 + var _link = $(cell_obj).find(" [ywl-host-desc]"); + _link.click(function () { + var row_data = tbl.get_row(row_id); + ywl.create_dlg_modify_host_desc(tbl, row_data.ywl_row_id, row_data.host_id, row_data.host_ip, row_data.host_desc).show(_link); + }); + } else if (col_key == 'action') { + row_data = tbl.get_row(row_id); + //console.log('row_data', row_data); + $(cell_obj).find('[ywl-btn-edit]').click(function () { + g_dlg_edit_host.update_show(row_id, row_data); + }); + $(cell_obj).find('[ywl-btn-user-edit]').click(function () { + g_dlg_edit_host_user.update_show(row_id, row_data); + }); - $(cell_obj).find('[ywl-btn-lock]').click(function () { - var host_id = row_data.host_id; - var host_lock = row_data.host_lock; - var message = ''; - if (host_lock === 0) { - host_lock = 1; - message = '确认要锁定该主机吗?'; - } else { - host_lock = 0; - message = '确认要解锁该主机吗?'; - } - var _fn_sure = function (cb_stack, cb_args) { - ywl.ajax_post_json('/host/lock-host', {host_id: host_id, lock: host_lock}, - function (ret) { - var update_args = {host_lock: host_lock}; - tbl.update_row(row_id, update_args); - ywl.notify_success('操作成功'); - }, - function () { - ywl.notify_error('操作失败'); - } - ); - }; - var cb_stack = CALLBACK_STACK.create(); + $(cell_obj).find('[ywl-btn-lock]').click(function () { + var host_id = row_data.host_id; + var host_lock = row_data.host_lock; + var message = ''; + if (host_lock === 0) { + host_lock = 1; + message = '确认要锁定该主机吗?'; + } else { + host_lock = 0; + message = '确认要解锁该主机吗?'; + } + var _fn_sure = function (cb_stack, cb_args) { + ywl.ajax_post_json('/host/lock-host', {host_id: host_id, lock: host_lock}, + function (ret) { + var update_args = {host_lock: host_lock}; + tbl.update_row(row_id, update_args); + ywl.notify_success('操作成功'); + }, + function () { + ywl.notify_error('操作失败'); + } + ); + }; + var cb_stack = CALLBACK_STACK.create(); - ywl.dlg_confirm(cb_stack, - { - msg: '

' + message + '

', - fn_yes: _fn_sure - }); + ywl.dlg_confirm(cb_stack, + { + msg: '

' + message + '

', + fn_yes: _fn_sure + }); - }); + }); - $(cell_obj).find('[ywl-btn-delete]').click(function () { - var host_id = row_data.host_id; - var _fn_sure = function (cb_stack, cb_args) { - var host_list = []; - host_list.push(host_id); - ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, - function (ret) { - tbl.remove_row(row_id); - ywl.notify_success('操作成功'); - }, - function () { - ywl.notify_error('操作失败'); - } - ); - }; - var cb_stack = CALLBACK_STACK.create(); + $(cell_obj).find('[ywl-btn-delete]').click(function () { + var host_id = row_data.host_id; + var _fn_sure = function (cb_stack, cb_args) { + var host_list = []; + host_list.push(host_id); + ywl.ajax_post_json('/host/delete-host', {host_list: host_list}, + function (ret) { + tbl.remove_row(row_id); + ywl.notify_success('操作成功'); + }, + function () { + ywl.notify_error('操作失败'); + } + ); + }; + var cb_stack = CALLBACK_STACK.create(); - ywl.dlg_confirm(cb_stack, - { - msg: '

注意:移除操作不可恢复!!

如果您只是希望临时禁用此主机,可以执行“锁定”操作!

您确定要移除此远程主机吗?

', - fn_yes: _fn_sure - }); + ywl.dlg_confirm(cb_stack, + { + msg: '

注意:移除操作不可恢复!!

如果您只是希望临时禁用此主机,可以执行“锁定”操作!

您确定要移除此远程主机吗?

', + fn_yes: _fn_sure + }); - }); + }); - } else if (col_key == 'auth_list') { - row_data = tbl.get_row(row_id); - $(cell_obj).find('[data-action="remote"]').click(function () { - var ts_rdp_port = ywl.page_options.core.rdp_port; - var ts_ssh_port = ywl.page_options.core.ssh_port; - var ts_telnet_port = ywl.page_options.core.telnet_port; - var host_ip = row_data.host_ip; - var host_port = 0; - var pro_type = parseInt($(this).attr('data-protocol')); - var pro_sub = parseInt($(this).attr('data-sub-protocol')); - var host_auth_id = parseInt($(this).attr('host-auth-id')); - var size = 0; - var rdp_console = 0; - var pro_port; - if (typeof row_data.pro_port === 'string') { - pro_port = $.parseJSON(row_data.pro_port); - } else { - pro_port = row_data.pro_port; - } + } else if (col_key === 'auth_list') { + row_data = tbl.get_row(row_id); + $(cell_obj).find('[data-action="remote"]').click(function () { + var ts_rdp_port = ywl.page_options.core.rdp_port; + var ts_ssh_port = ywl.page_options.core.ssh_port; + var ts_telnet_port = ywl.page_options.core.telnet_port; + var host_ip = row_data.host_ip; + var host_port = 0; + var pro_type = parseInt($(this).attr('data-protocol')); + var pro_sub = parseInt($(this).attr('data-sub-protocol')); + var host_auth_id = parseInt($(this).attr('host-auth-id')); + var size = 0; + var rdp_console = 0; + var pro_port; + if (typeof row_data.pro_port === 'string') { + pro_port = $.parseJSON(row_data.pro_port); + } else { + pro_port = row_data.pro_port; + } - if (pro_type == 1) { - host_port = ts_rdp_port; - size = parseInt($(this).parent().parent().find('#dlg-rdp-size select').val()) - if ($(this).parent().parent().find('#dlg-action-rdp-console').is(':checked')) { - rdp_console = 1; - } else { - rdp_console = 0; - } - } else if (pro_type == 2) { - host_port = ts_ssh_port; - } else if (pro_type == 3) { - host_port = ts_telnet_port; - } else { - ywl.notify_error("未知的服务器端口号" + pro_port); - return; - } - var args = {}; - args.host_auth_id = host_auth_id; - args.server_ip = ywl.server_ip; - args.server_port = host_port; - args.pro_type = pro_type; - args.pro_sub = pro_sub; - args.host_ip = host_ip; - args.console = rdp_console; - args.size = size; - to_admin_teleport( - '/host/admin-get-session-id', - args, - function () { - console.log('远程连接建立成功!') - }, - function (code, error) { - if (code == TPE_NO_ASSIST) - g_assist.alert_assist_not_found(); - else { - ywl.notify_error(error); - console.log('error:', error) - } - } - ); - }); + if (pro_type === PROTOCOL_TYPE_RDP) { + host_port = ts_rdp_port; + size = parseInt($(this).parent().parent().find('#dlg-rdp-size select').val()) + if ($(this).parent().parent().find('#dlg-action-rdp-console').is(':checked')) { + rdp_console = 1; + } else { + rdp_console = 0; + } + } else if (pro_type === PROTOCOL_TYPE_SSH) { + host_port = ts_ssh_port; + } else if (pro_type === PROTOCOL_TYPE_TELNET) { + host_port = ts_telnet_port; + } else { + ywl.notify_error("未知的服务器端口号" + pro_port); + return; + } + var args = {}; + args.host_auth_id = host_auth_id; + args.server_ip = ywl.server_ip; + args.server_port = host_port; + args.pro_type = pro_type; + args.pro_sub = pro_sub; + args.host_ip = host_ip; + args.console = rdp_console; + args.size = size; + to_admin_teleport( + '/host/admin-get-session-id', + args, + function () { + console.log('远程连接建立成功!') + }, + function (code, error) { + if (code === TPE_NO_ASSIST) + g_assist.alert_assist_not_found(); + else { + ywl.notify_error(error); + console.log('error:', error) + } + } + ); + }); - $(cell_obj).find('[data-action="remote-rdp-advance"]').click(function () { - ywl.create_dlg_show_rdp_advance(row_data).show($(this)); - }); - } - }; + $(cell_obj).find('[data-action="remote-rdp-advance"]').click(function () { + ywl.create_dlg_show_rdp_advance(row_data).show($(this)); + }); + } + }; - // 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作 - tbl.on_render_created = function (render) { + // 重载表格渲染器的部分渲染方式,加入本页面相关特殊操作 + tbl.on_render_created = function (render) { - render.host_id = function (row_id, fields) { - var ret = []; + render.host_id = function (row_id, fields) { + var ret = []; // ret.push('' + fields.id + '' + fields.host_port + ''); - ret.push('' + fields.id + ':' + fields.host_port + ''); - ret.push('' + fields.host_desc + ''); - return ret.join(''); - }; + ret.push('' + fields.id + ':' + fields.host_port + ''); + ret.push('' + fields.host_desc + ''); + return ret.join(''); + }; - render.protocol = function (row_id, fields) { - var ret = []; - switch (fields.protocol) { - case 1: - return 'RDP:' + fields.host_port + ''; - case 2: - return 'SSH:' + fields.host_port + ''; - case 3: - return 'TELNET:' + fields.host_port + ''; - default: - return '未知'; - } - }; - render.auth_list = function (row_id, fields) { + render.protocol = function (row_id, fields) { + var ret = []; + switch (fields.protocol) { + case 1: + return 'RDP:' + fields.host_port + ''; + case 2: + return 'SSH:' + fields.host_port + ''; + case 3: + return 'TELNET:' + fields.host_port + ''; + default: + return '未知'; + } + }; + render.auth_list = function (row_id, fields) { - var auth_list = fields.auth_list; - var ret = []; - if (auth_list.length == 0) { - ret.push('尚未添加系统用户'); - return ret.join(''); - } - var protocol = fields.protocol; - for (var i = 0; i < auth_list.length; i++) { - var auth = auth_list[i]; + var auth_list = fields.auth_list; + var ret = []; + if (auth_list.length === 0) { + ret.push('尚未添加系统用户'); + return ret.join(''); + } + var protocol = fields.protocol; + for (var i = 0; i < auth_list.length; i++) { + var auth = auth_list[i]; - ret.push('
'); - ret.push('
    '); + ret.push('
    '); + ret.push('
      '); - if (auth.user_name.length > 0) - ret.push('
    • ' + auth.user_name + '
    • '); - else - ret.push('
    • - 未指定 -
    • '); + if (auth.user_name.length > 0) + ret.push('
    • ' + auth.user_name + '
    • '); + else + ret.push('
    • - 未指定 -
    • '); - if (auth.auth_mode == AUTH_TYPE_PASSWORD) { - ret.push('
    • 密码
    • '); - } else if (auth.auth_mode == AUTH_TYPE_SSHKEY) { - ret.push('
    • 私钥
    • '); - } else if (auth.auth_mode == AUTH_NONE) { - ret.push('
    • '); - } else { - ret.push('
    • 未知
    • '); - } + if (auth.auth_mode === AUTH_TYPE_PASSWORD) { + ret.push('
    • 密码
    • '); + } else if (auth.auth_mode === AUTH_TYPE_SSHKEY) { + ret.push('
    • 私钥
    • '); + } else if (auth.auth_mode === AUTH_NONE) { + ret.push('
    • '); + } else { + ret.push('
    • 未知
    • '); + } - switch (protocol) { - case PROTOCOL_TYPE_RDP: - ret.push('
    • RDP
    • '); - ret.push('
    • '); - ret.push('
    • '); - break; - case PROTOCOL_TYPE_SSH: - ret.push('
    • SSH
    • '); - ret.push('
    • SFTP
    • '); - break; - case PROTOCOL_TYPE_TELNET: - ret.push('
    • TELNET
    • '); - break; - default: - ret.push('
    • 未知协议类型
    • '); - } + switch (protocol) { + case PROTOCOL_TYPE_RDP: + ret.push('
    • RDP
    • '); + ret.push('
    • '); + ret.push('
    • '); + break; + case PROTOCOL_TYPE_SSH: + ret.push('
    • SSH
    • '); + ret.push('
    • SFTP
    • '); + break; + case PROTOCOL_TYPE_TELNET: + ret.push('
    • TELNET
    • '); + break; + default: + ret.push('
    • 未知协议类型
    • '); + } - ret.push('
    '); - ret.push('
    '); - } + ret.push('
'); + ret.push('
'); + } - return ret.join(''); - }; - render.host_lock = function (row_id, fields) { - switch (fields.host_lock) { - case 0: - return '正常'; - case 1: - return '禁止连接'; - default: - return '未知'; - } - }; - render.make_check_box = function (row_id, fields) { - return ''; - }; - render.make_action_btn = function (row_id, fields) { - var ret = []; - ret.push('
'); - ret.push(' 编辑'); + return ret.join(''); + }; + render.host_lock = function (row_id, fields) { + switch (fields.host_lock) { + case 0: + return '正常'; + case 1: + return '禁止连接'; + default: + return '未知'; + } + }; + render.make_check_box = function (row_id, fields) { + return ''; + }; + render.make_action_btn = function (row_id, fields) { + var ret = []; + ret.push('
'); + ret.push(' 编辑'); // if (fields.host_lock === 0) // ret.push(' 锁定'); // else // ret.push(' 解锁'); - ret.push(' 移除'); + ret.push(' 移除'); // ret.push(' 远程'); - ret.push('
'); - return ret.join(''); - }; - render.make_user_btn = function (row_id, fields) { - var ret = []; - ret.push('
'); - ret.push('用户管理'); - ret.push('
'); - return ret.join(''); - } - }; + ret.push('
'); + return ret.join(''); + }; + render.make_user_btn = function (row_id, fields) { + var ret = []; + ret.push('
'); + ret.push('用户管理'); + ret.push('
'); + return ret.join(''); + } + }; }; ywl.on_host_table_header_created = function (tbl) { - $('#host-select-all').click(function () { - var _is_selected = $(this).is(':checked'); - $(tbl.selector + ' tbody').find('[data-check-box]').prop('checked', _is_selected); - }); + $('#host-select-all').click(function () { + var _is_selected = $(this).is(':checked'); + $(tbl.selector + ' tbody').find('[data-check-box]').prop('checked', _is_selected); + }); }; ywl.create_host_edit_dlg = function (tbl) { - var dlg_edit_host = {}; - dlg_edit_host.dom_id = "#dialog-host-edit"; - dlg_edit_host.update = 0; - dlg_edit_host.tbl = tbl; - dlg_edit_host.host_id = 0; - dlg_edit_host.row_id = ""; - dlg_edit_host.sys_type = 1; - dlg_edit_host.group_id = 0; - dlg_edit_host.group_name = '默认分组'; - dlg_edit_host.host_desc = ''; - dlg_edit_host.ip = ''; - dlg_edit_host.protocol = 0; - dlg_edit_host.host_port = 0; + var dlg_edit_host = {}; + dlg_edit_host.dom_id = "#dialog-host-edit"; + dlg_edit_host.update = 0; + dlg_edit_host.tbl = tbl; + dlg_edit_host.host_id = 0; + dlg_edit_host.row_id = ""; + dlg_edit_host.sys_type = 1; + dlg_edit_host.group_id = 0; + dlg_edit_host.group_name = '默认分组'; + dlg_edit_host.host_desc = ''; + dlg_edit_host.ip = ''; + dlg_edit_host.protocol = 0; + dlg_edit_host.host_port = 0; // dlg_edit_host.pro_port = {}; - dlg_edit_host.init = function () { - $('#auth-sys-type').change(dlg_edit_host.on_sys_type_change); - $('#host-protocol-type').change(dlg_edit_host.on_protocol_change); + dlg_edit_host.init = function () { + $('#auth-sys-type').change(dlg_edit_host.on_sys_type_change); + $('#host-protocol-type').change(dlg_edit_host.on_protocol_change); // $('#auth-protocol-type').change(dlg_edit_host.on_protocol_change); // $('#auth-auth-type').change(dlg_edit_host.on_auth_type_change); @@ -616,30 +616,30 @@ ywl.create_host_edit_dlg = function (tbl) { // $("#dlg-edit-host-rdp-port").change(dlg_edit_host.on_rdp_port); - var obj_group = $('#dlg-edit-host-group'); - $('#dlg-edit-host-group').change(dlg_edit_host.on_group_change); + var obj_group = $('#dlg-edit-host-group'); + obj_group.change(dlg_edit_host.on_group_change); - var i, cnt; - // 分组选择 - var html_group = []; - html_group.push(''); - for (i = 0, cnt = g_group_list.length; i < cnt; ++i) { - html_group.push(''); - } - obj_group.append($(html_group.join(''))); - // 对话框按钮事件绑定 + var i, cnt; + // 分组选择 + var html_group = []; + html_group.push(''); + for (i = 0, cnt = g_group_list.length; i < cnt; ++i) { + html_group.push(''); + } + obj_group.append($(html_group.join(''))); + // 对话框按钮事件绑定 - $("#host-btn-save").click(function () { - if (!dlg_edit_host.check_args()) - return; - //console.log("dlg_edit_host"); - if (dlg_edit_host.update == 1) { - dlg_edit_host.update_post(); - } else { - dlg_edit_host.create_post(); - } + $("#host-btn-save").click(function () { + if (!dlg_edit_host.check_args()) + return; + //console.log("dlg_edit_host"); + if (dlg_edit_host.update === 1) { + dlg_edit_host.update_post(); + } else { + dlg_edit_host.create_post(); + } // - }); + }); // // SSH密钥选择 // var html_sshkey = []; @@ -666,837 +666,828 @@ ywl.create_host_edit_dlg = function (tbl) { // $('#dialog_test').modal({backdrop: 'static'}); // }); - }; - dlg_edit_host.on_sys_type_change = function () { - dlg_edit_host.sys_type = $('#auth-sys-type').val(); - if (dlg_edit_host.sys_type == OS_TYPE_WINDOWS && dlg_edit_host.protocol == 0) - dlg_edit_host.protocol = PROTOCOL_TYPE_RDP; - else if (dlg_edit_host.sys_type == OS_TYPE_LINUX && dlg_edit_host.protocol == 0) - dlg_edit_host.protocol = PROTOCOL_TYPE_SSH; + }; + dlg_edit_host.on_sys_type_change = function () { + dlg_edit_host.sys_type = parseInt($('#auth-sys-type').val()); + console.log('sys-type', dlg_edit_host.sys_type, 'protocol:', dlg_edit_host.protocol); + if (dlg_edit_host.sys_type === OS_TYPE_WINDOWS) {// && dlg_edit_host.protocol === 0) { + dlg_edit_host.protocol = PROTOCOL_TYPE_RDP; + console.log('--1', dlg_edit_host.protocol); + } + else if (dlg_edit_host.sys_type === OS_TYPE_LINUX) {// && dlg_edit_host.protocol === 0) { + dlg_edit_host.protocol = PROTOCOL_TYPE_SSH; + console.log('--2', dlg_edit_host.protocol); + } - $('#host-protocol-type').val(dlg_edit_host.protocol); + $('#host-protocol-type').val(dlg_edit_host.protocol); - dlg_edit_host.on_protocol_change(); - }; + dlg_edit_host.on_protocol_change(); + }; - dlg_edit_host.on_protocol_change = function () { - dlg_edit_host.protocol = $('#host-protocol-type').val(); - if (dlg_edit_host.protocol == PROTOCOL_TYPE_RDP) - $('#dlg-edit-host-protocol-port').val('3389'); - else if (dlg_edit_host.protocol == PROTOCOL_TYPE_SSH) - $('#dlg-edit-host-protocol-port').val('22'); - else if (dlg_edit_host.protocol == PROTOCOL_TYPE_TELNET) - $('#dlg-edit-host-protocol-port').val('23'); - else - $('#dlg-edit-host-protocol-port').val(0); - }; + dlg_edit_host.on_protocol_change = function () { + dlg_edit_host.protocol = parseInt($('#host-protocol-type').val()); + console.log('xx', dlg_edit_host.protocol); + if (dlg_edit_host.protocol === PROTOCOL_TYPE_RDP) + $('#dlg-edit-host-protocol-port').val('3389'); + else if (dlg_edit_host.protocol === PROTOCOL_TYPE_SSH) + $('#dlg-edit-host-protocol-port').val('22'); + else if (dlg_edit_host.protocol === PROTOCOL_TYPE_TELNET) + $('#dlg-edit-host-protocol-port').val('23'); + else + $('#dlg-edit-host-protocol-port').val(0); + }; - dlg_edit_host.on_group_change = function () { - //console.log('group-change.'); - var obj = $('#group-host-group'); - dlg_edit_host.group_id = parseInt(obj.val()); - dlg_edit_host.group_name = obj.find('option:selected').text(); - }; + dlg_edit_host.on_group_change = function () { + //console.log('group-change.'); + var obj = $('#group-host-group'); + dlg_edit_host.group_id = parseInt(obj.val()); + dlg_edit_host.group_name = obj.find('option:selected').text(); + }; - dlg_edit_host.init_dlg = function (row_id, args) { - if (dlg_edit_host.update === 1) { - dlg_edit_host.sys_type = args.host_sys_type; - dlg_edit_host.ip = args.host_ip; - dlg_edit_host.host_id = args.host_id; - dlg_edit_host.group_id = args.group_id; - dlg_edit_host.host_desc = args.host_desc; - dlg_edit_host.protocol = args.protocol; - dlg_edit_host.host_port = args.host_port; - dlg_edit_host.init_fields(); - dlg_edit_host.row_id = row_id; - } else { - // 新建主机默认设置 - dlg_edit_host.host_id = 0; - dlg_edit_host.row_id = ""; - dlg_edit_host.sys_type = OS_TYPE_LINUX; - dlg_edit_host.ip = ''; - dlg_edit_host.group_id = 0; - dlg_edit_host.group_name = '默认分组'; - dlg_edit_host.host_desc = ''; - dlg_edit_host.protocol = 0; - dlg_edit_host.host_port = 0; - dlg_edit_host.init_fields(); - } - }; + dlg_edit_host.init_dlg = function (row_id, args) { + if (dlg_edit_host.update === 1) { + dlg_edit_host.sys_type = args.host_sys_type; + dlg_edit_host.ip = args.host_ip; + dlg_edit_host.host_id = args.host_id; + dlg_edit_host.group_id = args.group_id; + dlg_edit_host.host_desc = args.host_desc; + dlg_edit_host.protocol = args.protocol; + dlg_edit_host.host_port = args.host_port; + dlg_edit_host.init_fields(); + dlg_edit_host.row_id = row_id; + } else { + // 新建主机默认设置 + dlg_edit_host.host_id = 0; + dlg_edit_host.row_id = ""; + dlg_edit_host.sys_type = OS_TYPE_LINUX; + dlg_edit_host.ip = ''; + dlg_edit_host.group_id = 0; + dlg_edit_host.group_name = '默认分组'; + dlg_edit_host.host_desc = ''; + dlg_edit_host.protocol = 0; + dlg_edit_host.host_port = 0; + dlg_edit_host.init_fields(); + } + }; - dlg_edit_host.clear_fields = function () { - $("#auth-host-ip").val(''); - $("#auth-host-desc").val(''); - $('#auth-sys-type').val(OS_TYPE_LINUX); - }; + dlg_edit_host.clear_fields = function () { + $("#auth-host-ip").val(''); + $("#auth-host-desc").val(''); + $('#auth-sys-type').val(OS_TYPE_LINUX); + }; - dlg_edit_host.init_fields = function () { - dlg_edit_host.clear_fields(); + dlg_edit_host.init_fields = function () { + dlg_edit_host.clear_fields(); - $('#auth-sys-type').val(dlg_edit_host.sys_type); - dlg_edit_host.on_sys_type_change(); + $('#auth-sys-type').val(dlg_edit_host.sys_type); + dlg_edit_host.on_sys_type_change(); - $("#auth-host-ip").val(dlg_edit_host.ip); - $("#auth-host-desc").val(dlg_edit_host.host_desc); + $("#auth-host-ip").val(dlg_edit_host.ip); + $("#auth-host-desc").val(dlg_edit_host.host_desc); - var obj_group = $('#dlg-edit-host-group'); - obj_group.val(dlg_edit_host.group_id); + var obj_group = $('#dlg-edit-host-group'); + obj_group.val(dlg_edit_host.group_id); - if (dlg_edit_host.host_port != 0) { - $("#dlg-edit-host-protocol-port").val(dlg_edit_host.host_port); - } - }; + if (dlg_edit_host.host_port !== 0) { + $("#dlg-edit-host-protocol-port").val(dlg_edit_host.host_port); + } + }; - dlg_edit_host.check_args = function () { - dlg_edit_host.sys_type = parseInt($('#auth-sys-type').val()); - var obj_group = $('#dlg-edit-host-group'); - dlg_edit_host.group_id = parseInt(obj_group.val()); - dlg_edit_host.group_name = obj_group.find('option:selected').text(); - dlg_edit_host.ip = $("#auth-host-ip").val(); + dlg_edit_host.check_args = function () { + dlg_edit_host.sys_type = parseInt($('#auth-sys-type').val()); + var obj_group = $('#dlg-edit-host-group'); + dlg_edit_host.group_id = parseInt(obj_group.val()); + dlg_edit_host.group_name = obj_group.find('option:selected').text(); + dlg_edit_host.ip = $("#auth-host-ip").val(); - dlg_edit_host.host_desc = $("#auth-host-desc").val(); + dlg_edit_host.host_desc = $("#auth-host-desc").val(); - dlg_edit_host.host_port = $("#dlg-edit-host-protocol-port").val(); - if (dlg_edit_host.ip.length == 0) { - ywl.notify_error('请设定远程主机的地址!'); - return false; - } + dlg_edit_host.host_port = $("#dlg-edit-host-protocol-port").val(); + if (dlg_edit_host.ip.length === 0) { + ywl.notify_error('请设定远程主机的地址!'); + return false; + } - if (dlg_edit_host.host_port.length == 0) { - ywl.notify_error('请设定协议端口号!'); - return false; - } - return true; - }; + if (dlg_edit_host.host_port.length === 0) { + ywl.notify_error('请设定协议端口号!'); + return false; + } + return true; + }; - dlg_edit_host.update_show = function (row_id, args) { - dlg_edit_host.update = 1; - dlg_edit_host.init_dlg(row_id, args); - $(dlg_edit_host.dom_id).modal({backdrop: 'static'}); - }; + dlg_edit_host.update_show = function (row_id, args) { + dlg_edit_host.update = 1; + dlg_edit_host.init_dlg(row_id, args); + $(dlg_edit_host.dom_id).modal({backdrop: 'static'}); + }; - dlg_edit_host.create_show = function () { - dlg_edit_host.update = 0; - dlg_edit_host.init_dlg(); - $(dlg_edit_host.dom_id).modal({backdrop: 'static'}); - }; + dlg_edit_host.create_show = function () { + dlg_edit_host.update = 0; + dlg_edit_host.init_dlg(); + $(dlg_edit_host.dom_id).modal({backdrop: 'static'}); + }; - dlg_edit_host.hide = function () { - $(dlg_edit_host.dom_id).modal('hide'); - }; + dlg_edit_host.hide = function () { + $(dlg_edit_host.dom_id).modal('hide'); + }; - dlg_edit_host.update_post = function () { - var host_sys_type = parseInt(dlg_edit_host.sys_type); - var protocol = parseInt(dlg_edit_host.protocol); - var host_port = parseInt(dlg_edit_host.host_port); - var host_ip = dlg_edit_host.ip; - var host_id = dlg_edit_host.host_id; - var args = { - group_id: dlg_edit_host.group_id, - host_sys_type: host_sys_type, - host_ip: host_ip, - protocol: protocol, - host_port: host_port, - host_desc: dlg_edit_host.desc - }; - ywl.ajax_post_json('/host/update', {host_id: host_id, kv: args}, - function (ret) { - var update_args = { - host_ip: dlg_edit_host.ip, - group_name: dlg_edit_host.group_name, - group_id: dlg_edit_host.group_id, - host_desc: dlg_edit_host.host_desc, - host_sys_type: dlg_edit_host.sys_type, - protocol: protocol, - host_port: host_port - }; + dlg_edit_host.update_post = function () { + var host_sys_type = parseInt(dlg_edit_host.sys_type); + var protocol = parseInt(dlg_edit_host.protocol); + var host_port = parseInt(dlg_edit_host.host_port); + var host_ip = dlg_edit_host.ip; + var host_id = dlg_edit_host.host_id; + var args = { + group_id: dlg_edit_host.group_id, + host_sys_type: host_sys_type, + host_ip: host_ip, + protocol: protocol, + host_port: host_port, + host_desc: dlg_edit_host.desc + }; + ywl.ajax_post_json('/host/update', {host_id: host_id, kv: args}, + function (ret) { + var update_args = { + host_ip: dlg_edit_host.ip, + group_name: dlg_edit_host.group_name, + group_id: dlg_edit_host.group_id, + host_desc: dlg_edit_host.host_desc, + host_sys_type: dlg_edit_host.sys_type, + protocol: protocol, + host_port: host_port + }; - dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args); - ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 的认证信息已保存!'); - dlg_edit_host.hide(); - }, - function () { - ywl.notify_error('主机 ' + self.host_ip + ' 更新失败!', ''); - } - ); - }; + dlg_edit_host.tbl.update_row(dlg_edit_host.row_id, update_args); + ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 的认证信息已保存!'); + dlg_edit_host.hide(); + }, + function () { + ywl.notify_error('主机 ' + self.host_ip + ' 更新失败!', ''); + } + ); + }; - dlg_edit_host.create_post = function () { - var protocol = parseInt(dlg_edit_host.protocol); - var host_port = parseInt(dlg_edit_host.host_port); + dlg_edit_host.create_post = function () { + var protocol = parseInt(dlg_edit_host.protocol); + var host_port = parseInt(dlg_edit_host.host_port); - var args = { - host_ip: dlg_edit_host.ip, - host_port: host_port, - protocol: protocol, - host_sys_type: dlg_edit_host.sys_type, - group_id: dlg_edit_host.group_id, - host_desc: dlg_edit_host.host_desc - }; + var args = { + host_ip: dlg_edit_host.ip, + host_port: host_port, + protocol: protocol, + host_sys_type: dlg_edit_host.sys_type, + group_id: dlg_edit_host.group_id, + host_desc: dlg_edit_host.host_desc + }; - ywl.ajax_post_json('/host/add-host', args, - function (ret) { - if (ret.code == 0) { - dlg_edit_host.tbl.reload(); - ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已添加!'); - dlg_edit_host.hide(); - } - else { - if (ret.code == -100) { - ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已经添加,请不要重复添加主机!', ''); - } else { - ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.code, ''); - } + ywl.ajax_post_json('/host/add-host', args, + function (ret) { + if (ret.code === 0) { + dlg_edit_host.tbl.reload(); + ywl.notify_success('主机 ' + dlg_edit_host.ip + ' 信息已添加!'); + dlg_edit_host.hide(); + } + else { + if (ret.code === -100) { + ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 已经添加,请不要重复添加主机!', ''); + } else { + ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!' + ret.code, ''); + } - } - }, - function () { - ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!', ''); - } - ); - }; + } + }, + function () { + ywl.notify_error('主机 ' + dlg_edit_host.ip + ' 信息保存失败!', ''); + } + ); + }; - return dlg_edit_host; + return dlg_edit_host; }; ywl.create_host_user_edit_dlg = function (tbl) { - var dlg_user_edit_host = {}; - dlg_user_edit_host.dom_id = "#dialog-host-user-edit"; - dlg_user_edit_host.update = 0; - dlg_user_edit_host.tbl = tbl; - dlg_user_edit_host.host_id = 0; - dlg_user_edit_host.row_id = ""; - dlg_user_edit_host.host_ip = ''; - dlg_user_edit_host.pro_port = {}; + var dlg_user_edit_host = {}; + dlg_user_edit_host.dom_id = "#dialog-host-user-edit"; + dlg_user_edit_host.update = 0; + dlg_user_edit_host.tbl = tbl; + dlg_user_edit_host.host_id = 0; + dlg_user_edit_host.row_id = ""; + dlg_user_edit_host.host_ip = ''; + dlg_user_edit_host.pro_port = {}; - dlg_user_edit_host.auth_list = []; + dlg_user_edit_host.auth_list = []; - dlg_user_edit_host.init = function () { + dlg_user_edit_host.init = function () { - $("#host-user-btn-save").click(function () { - dlg_user_edit_host.hide(); - }); + $("#host-user-btn-save").click(function () { + dlg_user_edit_host.hide(); + }); - }; + }; - dlg_user_edit_host.create_user_html = function (host_auth_id, index, user_name, pro_name, auth_name) { - if(user_name.length == 0) - user_name = '- 未指定 -'; - var html = ""; - html += '
'; - html += '
    '; - html += '
  • ' + user_name + '
  • '; - html += '
  • ' + pro_name + '
  • '; - html += '
  • ' + auth_name + '
  • '; - html += '
  • '; - html += ' '; - html += '
  • '; - html += '
  • '; - html += ' '; - html += '
  • '; - html += '
'; - html += '
'; - return html; - }; - dlg_user_edit_host.sync_user_info = function (host_id) { - ywl.ajax_post_json('/host/sys-user/list', {host_id: host_id}, - function (ret) { + dlg_user_edit_host.create_user_html = function (host_auth_id, index, user_name, pro_name, auth_name) { + if (user_name.length === 0) + user_name = '- 未指定 -'; + var html = []; + html.push('
    '); + html.push('
  • ' + user_name + '
  • '); + html.push('
  • ' + pro_name + '
  • '); + html.push('
  • ' + auth_name + '
  • '); + html.push('
  • '); + html.push(''); + html.push('
  • '); + html.push(''); + html.push('
'); + return html.join(''); + }; + dlg_user_edit_host.sync_user_info = function (host_id) { + ywl.ajax_post_json('/host/sys-user/list', {host_id: host_id}, + function (ret) { var data = ret.data; - dlg_user_edit_host.auth_list = data; - var update_args = { - auth_list: dlg_user_edit_host.auth_list - }; + dlg_user_edit_host.auth_list = data; + var update_args = { + auth_list: dlg_user_edit_host.auth_list + }; - dlg_user_edit_host.tbl.update_row(dlg_user_edit_host.row_id, update_args); - var row_data = tbl.get_row(dlg_user_edit_host.row_id); - var protocol = row_data.protocol; - var arr = dlg_user_edit_host.auth_list; - var html = ""; + dlg_user_edit_host.tbl.update_row(dlg_user_edit_host.row_id, update_args); + var row_data = tbl.get_row(dlg_user_edit_host.row_id); + var protocol = row_data.protocol; + var arr = dlg_user_edit_host.auth_list; + var html = ""; - for (var i = 0; i < arr.length; i++) { + for (var i = 0; i < arr.length; i++) { - var user_name = arr[i].user_name; - var host_auth_id = arr[i].host_auth_id; - var pro_name = '未知'; - if (protocol == PROTOCOL_TYPE_RDP) { - pro_name = 'RDP'; - } else if (protocol == PROTOCOL_TYPE_SSH) { - pro_name = 'SSH'; - } else if (protocol == PROTOCOL_TYPE_TELNET) { - pro_name = 'TELNET'; - } - var auth_name = "未知"; - if (arr[i].auth_mode == AUTH_NONE) { - auth_name = '无'; - } else if (arr[i].auth_mode == AUTH_TYPE_PASSWORD) { - auth_name = '密码'; - } else if (arr[i].auth_mode == AUTH_TYPE_SSHKEY) { - auth_name = '私钥'; - } - html += dlg_user_edit_host.create_user_html(host_auth_id, i, user_name, pro_name, auth_name); - } - html += ''; - $("#sys-user-list").html(html); + var user_name = arr[i].user_name; + var host_auth_id = arr[i].host_auth_id; + var pro_name = '未知'; + if (protocol === PROTOCOL_TYPE_RDP) { + pro_name = 'RDP'; + } else if (protocol === PROTOCOL_TYPE_SSH) { + pro_name = 'SSH'; + } else if (protocol === PROTOCOL_TYPE_TELNET) { + pro_name = 'TELNET'; + } + var auth_name = "未知"; + if (arr[i].auth_mode === AUTH_NONE) { + auth_name = '无'; + } else if (arr[i].auth_mode === AUTH_TYPE_PASSWORD) { + auth_name = '密码'; + } else if (arr[i].auth_mode === AUTH_TYPE_SSHKEY) { + auth_name = '私钥'; + } + html += dlg_user_edit_host.create_user_html(host_auth_id, i, user_name, pro_name, auth_name); + } + html += ''; + $("#sys-user-list").html(html); - $("#btn-add-sys-user").click(function () { - var row_data = tbl.get_row(dlg_user_edit_host.row_id); - g_dlg_sys_user.create_show(row_data); - }); + $("#btn-add-sys-user").click(function () { + var row_data = tbl.get_row(dlg_user_edit_host.row_id); + g_dlg_sys_user.create_show(row_data); + }); - $('[user-data-action="modify"]').click(function () { - var index = parseInt($(this).attr("index")); - var data = dlg_user_edit_host.auth_list[index]; - var row_data = tbl.get_row(dlg_user_edit_host.row_id); - g_dlg_sys_user.update_show(row_data, data); - }); - $('[user-data-action="delete"]').click(function () { - var host_auth_id = parseInt($(this).attr("auth-id")); - ywl.ajax_post_json('/host/sys-user/delete', {host_auth_id: host_auth_id}, - function (ret) { - //console.log("ret,", ret); - if (ret.code == 0) { - ywl.notify_success('系统用户删除成功'); - // var host_id = parseInt(dlg_user_edit_host.host_id); - g_dlg_edit_host_user.sync_user_info(host_id); + $('[user-data-action="modify"]').click(function () { + var index = parseInt($(this).attr("index")); + var data = dlg_user_edit_host.auth_list[index]; + var row_data = tbl.get_row(dlg_user_edit_host.row_id); + g_dlg_sys_user.update_show(row_data, data); + }); + $('[user-data-action="delete"]').click(function () { + var host_auth_id = parseInt($(this).attr("auth-id")); + ywl.ajax_post_json('/host/sys-user/delete', {host_auth_id: host_auth_id}, + function (ret) { + //console.log("ret,", ret); + if (ret.code === TPE_OK) { + ywl.notify_success('系统用户删除成功'); + // var host_id = parseInt(dlg_user_edit_host.host_id); + g_dlg_edit_host_user.sync_user_info(host_id); - } else { - ywl.notify_error('系统用户删除失败!' + ret.code); - } - }, - function () { - ywl.notify_error('系统用户删除失败!'); - } - ); - }); - }, - function () { - ywl.notify_error('网络故障,无法获取远程主机认证信息!'); - } - ); - }; - dlg_user_edit_host.init_dlg = function (row_id, args) { - dlg_user_edit_host.row_id = row_id; - if (dlg_user_edit_host.update === 1) { - var host_id = args.host_id; - dlg_user_edit_host.host_ip = args.host_ip; - dlg_user_edit_host.pro_port = args.pro_port; + } else { + ywl.notify_error('系统用户删除失败!' + ret.code); + } + }, + function () { + ywl.notify_error('系统用户删除失败!'); + } + ); + }); + }, + function () { + ywl.notify_error('网络故障,无法获取远程主机认证信息!'); + } + ); + }; + dlg_user_edit_host.init_dlg = function (row_id, args) { + dlg_user_edit_host.row_id = row_id; + if (dlg_user_edit_host.update === 1) { + var host_id = args.host_id; + dlg_user_edit_host.host_ip = args.host_ip; + dlg_user_edit_host.pro_port = args.pro_port; - dlg_user_edit_host.sync_user_info(host_id); - } - }; + dlg_user_edit_host.sync_user_info(host_id); + } + }; - dlg_user_edit_host.clear_fields = function () { + dlg_user_edit_host.clear_fields = function () { - }; + }; - dlg_user_edit_host.init_fields = function () { + dlg_user_edit_host.init_fields = function () { - }; + }; - dlg_user_edit_host.check_args = function () { - return true; - }; + dlg_user_edit_host.check_args = function () { + return true; + }; - dlg_user_edit_host.update_show = function (row_id, args) { - dlg_user_edit_host.update = 1; - dlg_user_edit_host.init_dlg(row_id, args); - $(dlg_user_edit_host.dom_id).modal({backdrop: 'static'}); - }; + dlg_user_edit_host.update_show = function (row_id, args) { + dlg_user_edit_host.update = 1; + dlg_user_edit_host.init_dlg(row_id, args); + $(dlg_user_edit_host.dom_id).modal({backdrop: 'static'}); + }; - dlg_user_edit_host.create_show = function () { - dlg_user_edit_host.update = 0; - dlg_user_edit_host.init_dlg(); - $(dlg_user_edit_host.dom_id).modal({backdrop: 'static'}); - }; + dlg_user_edit_host.create_show = function () { + dlg_user_edit_host.update = 0; + dlg_user_edit_host.init_dlg(); + $(dlg_user_edit_host.dom_id).modal({backdrop: 'static'}); + }; - dlg_user_edit_host.hide = function () { - $(dlg_user_edit_host.dom_id).modal('hide'); - }; + dlg_user_edit_host.hide = function () { + $(dlg_user_edit_host.dom_id).modal('hide'); + }; - return dlg_user_edit_host; + return dlg_user_edit_host; }; ywl.create_sys_user = function (tbl) { - var dlg_sys_user = {}; - dlg_sys_user.dom_id = "#dialog_user"; - dlg_sys_user.update = 0; - dlg_sys_user.tbl = tbl; - dlg_sys_user.row_id = ''; - dlg_sys_user.sys_type = 0; - dlg_sys_user.host_id = 0; - dlg_sys_user.host_ip = ''; - dlg_sys_user.auth_mode = 0; - dlg_sys_user.protocol = 0; - dlg_sys_user.host_auth_id = 0; - dlg_sys_user.user_name = ''; - dlg_sys_user.user_pswd = ''; - dlg_sys_user.cert_id = 0; - dlg_sys_user.user_param = ''; + var dlg_sys_user = {}; + dlg_sys_user.dom_id = "#dialog_user"; + dlg_sys_user.update = 0; + dlg_sys_user.tbl = tbl; + dlg_sys_user.row_id = ''; + dlg_sys_user.sys_type = 0; + dlg_sys_user.host_id = 0; + dlg_sys_user.host_ip = ''; + dlg_sys_user.auth_mode = 0; + dlg_sys_user.protocol = 0; + dlg_sys_user.host_auth_id = 0; + dlg_sys_user.user_name = ''; + dlg_sys_user.user_pswd = ''; + dlg_sys_user.cert_id = 0; + dlg_sys_user.user_param = ''; - dlg_sys_user.init = function () { - dlg_sys_user.update = 0; - dlg_sys_user.host_id = 0; - dlg_sys_user.host_ip = ''; - dlg_sys_user.sys_type = 0; - dlg_sys_user.auth_mode = 1; - dlg_sys_user.host_auth_id = 0; - dlg_sys_user.user_name = ''; - dlg_sys_user.user_pswd = ''; - dlg_sys_user.cert_id = 0; - dlg_sys_user.protocol = 0; - dlg_sys_user.host_port = 0; + dlg_sys_user.init = function () { + dlg_sys_user.update = 0; + dlg_sys_user.host_id = 0; + dlg_sys_user.host_ip = ''; + dlg_sys_user.sys_type = 0; + dlg_sys_user.auth_mode = 1; + dlg_sys_user.host_auth_id = 0; + dlg_sys_user.user_name = ''; + dlg_sys_user.user_pswd = ''; + dlg_sys_user.cert_id = 0; + dlg_sys_user.protocol = 0; + dlg_sys_user.host_port = 0; - $("#sys-user-btn-save").click(function () { - if (!dlg_sys_user.check_args()) - return; + $("#sys-user-btn-save").click(function () { + if (!dlg_sys_user.check_args()) + return; - if (dlg_sys_user.update === 1) { - dlg_sys_user.update_post(); - } else { - dlg_sys_user.create_post(); - } - }); - $("#test-btn-connect").click(function () { - if (!dlg_sys_user.check_args()) - return; + if (dlg_sys_user.update === 1) { + dlg_sys_user.update_post(); + } else { + dlg_sys_user.create_post(); + } + }); + $("#test-btn-connect").click(function () { + if (!dlg_sys_user.check_args()) + return; - var ts_rdp_port = ywl.page_options.core.rdp_port; - var ts_ssh_port = ywl.page_options.core.ssh_port; - var ts_telnet_port = ywl.page_options.core.telnet_port; - var server_port = 0; - var host_port = dlg_sys_user.host_port; - var protocol = dlg_sys_user.protocol; - if (protocol === 1) { - server_port = ts_rdp_port; - } else if (protocol === 2) { - server_port = ts_ssh_port; - } else if (protocol === 3) { - server_port = ts_telnet_port; - } else { - ywl.notify_error('未知协议!'); - return; - } + var ts_rdp_port = ywl.page_options.core.rdp_port; + var ts_ssh_port = ywl.page_options.core.ssh_port; + var ts_telnet_port = ywl.page_options.core.telnet_port; + var server_port = 0; + var host_port = dlg_sys_user.host_port; + var protocol = dlg_sys_user.protocol; + if (protocol === PROTOCOL_TYPE_RDP) { + server_port = ts_rdp_port; + } else if (protocol === PROTOCOL_TYPE_SSH) { + server_port = ts_ssh_port; + } else if (protocol === PROTOCOL_TYPE_TELNET) { + server_port = ts_telnet_port; + } else { + ywl.notify_error('未知协议!'); + return; + } - var args = {}; - args.server_ip = ywl.server_ip; - args.server_port = parseInt(server_port); - args.host_port = parseInt(host_port); - args.protocol = parseInt(protocol); - args.protocol_sub = 1; - args.sys_type = parseInt(dlg_sys_user.sys_type); - args.host_ip = dlg_sys_user.host_ip; - args.auth_mode = parseInt(dlg_sys_user.auth_mode); - args.user_name = dlg_sys_user.user_name; - args.user_pswd = dlg_sys_user.user_pswd; - args.cert_id = dlg_sys_user.cert_id; - args.host_auth_id = dlg_sys_user.host_auth_id; - args.user_param = dlg_sys_user.user_param; - args.size = 2; - to_admin_fast_teleport( - '/host/admin-fast-get-session-id', - args, - function () { - console.log('远程连接建立成功!') - }, - function (code, error) { - if (code == TPE_NO_ASSIST) - g_assist.alert_assist_not_found(); - else { - ywl.notify_error(error); - console.log('error:', error) - } - } - ); + var args = {}; + args.server_ip = ywl.server_ip; + args.server_port = parseInt(server_port); + args.host_port = parseInt(host_port); + args.protocol = parseInt(protocol); + args.protocol_sub = 1; + args.sys_type = parseInt(dlg_sys_user.sys_type); + args.host_ip = dlg_sys_user.host_ip; + args.auth_mode = parseInt(dlg_sys_user.auth_mode); + args.user_name = dlg_sys_user.user_name; + args.user_pswd = dlg_sys_user.user_pswd; + args.cert_id = dlg_sys_user.cert_id; + args.host_auth_id = dlg_sys_user.host_auth_id; + args.user_param = dlg_sys_user.user_param; + args.size = 2; + to_admin_fast_teleport( + '/host/admin-fast-get-session-id', + args, + function () { + console.log('远程连接建立成功!') + }, + function (code, error) { + if (code === TPE_NO_ASSIST) + g_assist.alert_assist_not_found(); + else { + ywl.notify_error(error); + console.log('error:', error) + } + } + ); - }); + }); // // SSH密钥选择 - var html_sshkey = []; - var i = 0; - var cnt = 0; - for (i = 0, cnt = g_cert_list.length; i < cnt; ++i) { - html_sshkey.push(''); - } - $('#auth-user-sshkey-list').append($(html_sshkey.join(''))); - }; + var html_sshkey = []; + var i, cnt = 0; + for (i = 0, cnt = g_cert_list.length; i < cnt; ++i) { + html_sshkey.push(''); + } + $('#auth-user-sshkey-list').append($(html_sshkey.join(''))); + }; - dlg_sys_user.init_dlg = function (row_data, args) { - dlg_sys_user.row_id = row_data.row_id; - dlg_sys_user.host_id = row_data.host_id; - dlg_sys_user.host_ip = row_data.host_ip; - dlg_sys_user.sys_type = row_data.host_sys_type; - dlg_sys_user.protocol = row_data.protocol; - dlg_sys_user.host_port = row_data.host_port; - if (dlg_sys_user.update == 1) { - dlg_sys_user.auth_mode = args.auth_mode; - dlg_sys_user.host_auth_id = args.host_auth_id; - dlg_sys_user.user_name = args.user_name; - dlg_sys_user.user_pswd = args.user_pswd; - dlg_sys_user.cert_id = args.cert_id; - dlg_sys_user.user_param = args.user_param; - if(dlg_sys_user.user_param.length == 0) - dlg_sys_user.user_param = 'ogin:\nassword:'; + dlg_sys_user.init_dlg = function (row_data, args) { + dlg_sys_user.row_id = row_data.row_id; + dlg_sys_user.host_id = row_data.host_id; + dlg_sys_user.host_ip = row_data.host_ip; + dlg_sys_user.sys_type = row_data.host_sys_type; + dlg_sys_user.protocol = row_data.protocol; + dlg_sys_user.host_port = row_data.host_port; + if (dlg_sys_user.update === 1) { + dlg_sys_user.auth_mode = args.auth_mode; + dlg_sys_user.host_auth_id = args.host_auth_id; + dlg_sys_user.user_name = args.user_name; + dlg_sys_user.user_pswd = args.user_pswd; + dlg_sys_user.cert_id = args.cert_id; + dlg_sys_user.user_param = args.user_param; + if (dlg_sys_user.user_param.length === 0) + dlg_sys_user.user_param = 'ogin:\nassword:'; - $('#auth-user-host-pswd').attr('placeholder', '不填写则使用已存储的密码'); - } else { - if (dlg_sys_user.sys_type == OS_TYPE_WINDOWS) { - dlg_sys_user.user_name = 'administrator'; - } else if (dlg_sys_user.sys_type == OS_TYPE_LINUX) { - dlg_sys_user.user_name = 'root'; - } else { - dlg_sys_user.user_name = ''; - } - dlg_sys_user.auth_mode = 1; - dlg_sys_user.host_auth_id = 0; - dlg_sys_user.user_pswd = ''; - dlg_sys_user.cert_id = 0; - dlg_sys_user.user_param = 'ogin:\nassword:'; - $('#auth-user-host-pswd').attr('placeholder', '请输入登录远程主机的密码'); - } - dlg_sys_user.init_fields(); - }; + $('#auth-user-host-pswd').attr('placeholder', '不填写则使用已存储的密码'); + } else { + if (dlg_sys_user.sys_type === OS_TYPE_WINDOWS) { + dlg_sys_user.user_name = 'administrator'; + } else if (dlg_sys_user.sys_type === OS_TYPE_LINUX) { + dlg_sys_user.user_name = 'root'; + } else { + dlg_sys_user.user_name = ''; + } + dlg_sys_user.auth_mode = 1; + dlg_sys_user.host_auth_id = 0; + dlg_sys_user.user_pswd = ''; + dlg_sys_user.cert_id = 0; + dlg_sys_user.user_param = 'ogin:\nassword:'; + $('#auth-user-host-pswd').attr('placeholder', '请输入登录远程主机的密码'); + } + dlg_sys_user.init_fields(); + }; - dlg_sys_user.clear_fields = function () { + dlg_sys_user.clear_fields = function () { - }; + }; - dlg_sys_user.init_fields = function () { + dlg_sys_user.init_fields = function () { - var info; - var combox_html = []; - if (dlg_sys_user.protocol == PROTOCOL_TYPE_RDP) { - info = "RDP协议"; - $('#auth-user-block-telnet').hide(); - combox_html.push(''); - } else if (dlg_sys_user.protocol == PROTOCOL_TYPE_SSH) { - info = "SSH协议"; - $('#auth-user-block-telnet').hide(); - combox_html.push(''); - } else if (dlg_sys_user.protocol == PROTOCOL_TYPE_TELNET) { - info = "TELNET协议"; - $('#auth-user-block-telnet').show(); - combox_html.push(''); + var info; + var combox_html = []; + if (dlg_sys_user.protocol === PROTOCOL_TYPE_RDP) { + info = "RDP协议"; + $('#auth-user-block-telnet').hide(); + combox_html.push(''); + } else if (dlg_sys_user.protocol === PROTOCOL_TYPE_SSH) { + info = "SSH协议"; + $('#auth-user-block-telnet').hide(); + combox_html.push(''); + } else if (dlg_sys_user.protocol === PROTOCOL_TYPE_TELNET) { + info = "TELNET协议"; + $('#auth-user-block-telnet').show(); + combox_html.push(''); - var user_param = dlg_sys_user.user_param.split("\n"); - var param1 = ''; - var param2 = ''; - if (user_param.length == 1) { - param1 = user_param[0]; - } else if (user_param.length == 2) { - param1 = user_param[0]; - param2 = user_param[1]; - } + var user_param = dlg_sys_user.user_param.split("\n"); + var param1 = ''; + var param2 = ''; + if (user_param.length === 1) { + param1 = user_param[0]; + } else if (user_param.length === 2) { + param1 = user_param[0]; + param2 = user_param[1]; + } - $('#auth-user-telnet-username-prompt').val(param1); - $('#auth-user-telnet-pswd-prompt').val(param2); - } else { - info = "未知协议"; - } + $('#auth-user-telnet-username-prompt').val(param1); + $('#auth-user-telnet-pswd-prompt').val(param2); + } else { + info = "未知协议"; + } - $('#auth-sys-user-type-combox').html(combox_html.join('')); - $('#auth-user-type').change(dlg_sys_user.on_user_auth_mode_change); - $('#auth-user-protocol-type').text(info); + $('#auth-sys-user-type-combox').html(combox_html.join('')); + $('#auth-user-type').change(dlg_sys_user.on_user_auth_mode_change); + $('#auth-user-protocol-type').text(info); - info = dlg_sys_user.host_ip + ':' + dlg_sys_user.host_port; - $('#add-user-host-ip').text(info); - $('#auth-user-type').val(dlg_sys_user.auth_mode); - $('#auth-user-host-username').val(dlg_sys_user.user_name); + info = dlg_sys_user.host_ip + ':' + dlg_sys_user.host_port; + $('#add-user-host-ip').text(info); + $('#auth-user-type').val(dlg_sys_user.auth_mode); + $('#auth-user-host-username').val(dlg_sys_user.user_name); - if (dlg_sys_user.auth_mode == AUTH_TYPE_PASSWORD) { - $('#auth-user-block-name').show(); - $('#auth-user-block-pswd').show(); - $('#auth-user-block-sshkey').hide(); - $('#auth-user-host-pswd').val(""); - $('#auth-user-host-pswd-confirm').val(""); - } else if (dlg_sys_user.auth_mode == AUTH_TYPE_SSHKEY) { - $('#auth-user-block-name').show(); - $('#auth-user-block-pswd').hide(); - $('#auth-user-block-sshkey').show(); - var cert_id = parseInt(dlg_sys_user.cert_id); - $('#auth-user-sshkey-list').val(cert_id); - } else if (dlg_sys_user.auth_mode == AUTH_NONE) { - $('#auth-user-block-telnet').hide(); - $('#auth-user-block-pswd').hide(); - $('#auth-user-block-name').hide(); - $('#auth-user-block-sshkey').hide(); - } + if (dlg_sys_user.auth_mode === AUTH_TYPE_PASSWORD) { + $('#auth-user-block-name').show(); + $('#auth-user-block-pswd').show(); + $('#auth-user-block-sshkey').hide(); + $('#auth-user-host-pswd').val(""); + $('#auth-user-host-pswd-confirm').val(""); + } else if (dlg_sys_user.auth_mode === AUTH_TYPE_SSHKEY) { + $('#auth-user-block-name').show(); + $('#auth-user-block-pswd').hide(); + $('#auth-user-block-sshkey').show(); + var cert_id = parseInt(dlg_sys_user.cert_id); + $('#auth-user-sshkey-list').val(cert_id); + } else if (dlg_sys_user.auth_mode === AUTH_NONE) { + $('#auth-user-block-telnet').hide(); + $('#auth-user-block-pswd').hide(); + $('#auth-user-block-name').hide(); + $('#auth-user-block-sshkey').hide(); + } + }; + dlg_sys_user.on_user_auth_mode_change = function () { + dlg_sys_user.auth_mode = parseInt($('#auth-user-type').val()); + if (dlg_sys_user.auth_mode === AUTH_TYPE_PASSWORD) { + if (dlg_sys_user.protocol === PROTOCOL_TYPE_RDP) { - }; + } else if (dlg_sys_user.protocol === PROTOCOL_TYPE_SSH) { + } else if (dlg_sys_user.protocol === PROTOCOL_TYPE_TELNET) { + $('#auth-user-block-telnet').show(); + } + $('#auth-user-block-pswd').show(); + $('#auth-user-block-name').show(); + $('#auth-user-block-sshkey').hide(); + } else if (dlg_sys_user.auth_mode === AUTH_TYPE_SSHKEY) { + $('#auth-user-block-telnet').hide(); + $('#auth-user-block-pswd').hide(); + $('#auth-user-block-sshkey').show(); + $('#auth-user-block-name').show(); + } else if (dlg_sys_user.auth_mode === AUTH_NONE) { + $('#auth-user-block-telnet').hide(); + $('#auth-user-block-pswd').hide(); + $('#auth-user-block-name').hide(); + $('#auth-user-block-sshkey').hide(); + } + }; - dlg_sys_user.on_user_auth_mode_change = function () { - dlg_sys_user.auth_mode = $('#auth-user-type').val(); - if (dlg_sys_user.auth_mode == AUTH_TYPE_PASSWORD) { - if (dlg_sys_user.protocol == 1) { + dlg_sys_user.check_args = function () { - } else if (dlg_sys_user.protocol == 2) { + dlg_sys_user.auth_mode = parseInt($('#auth-user-type').val()); + dlg_sys_user.user_name = parseInt($('#auth-user-host-username').val()); + if (dlg_sys_user.auth_mode !== AUTH_NONE && + dlg_sys_user.user_name.length === 0) { + ywl.notify_error('请输入系统用户名!'); + return false; + } - } else if (dlg_sys_user.protocol == 3) { - $('#auth-user-block-telnet').show(); - } - $('#auth-user-block-pswd').show(); - $('#auth-user-block-name').show(); - $('#auth-user-block-sshkey').hide(); - } else if (dlg_sys_user.auth_mode == AUTH_TYPE_SSHKEY) { - $('#auth-user-block-telnet').hide(); - $('#auth-user-block-pswd').hide(); - $('#auth-user-block-sshkey').show(); - $('#auth-user-block-name').show(); - } else if (dlg_sys_user.auth_mode == AUTH_NONE) { - $('#auth-user-block-telnet').hide(); - $('#auth-user-block-pswd').hide(); - $('#auth-user-block-name').hide(); - $('#auth-user-block-sshkey').hide(); - } - }; + if (dlg_sys_user.auth_mode === AUTH_TYPE_PASSWORD) { + if (dlg_sys_user.update !== 1) { + var temp1 = $('#auth-user-host-pswd').val(); + var temp2 = $('#auth-user-host-pswd-confirm').val(); + if (temp1.length === 0) { + ywl.notify_error('请输入密码!'); + return false; + } + if (temp2.length === 0) { + ywl.notify_error('请输入确认密码!'); + return false; + } + if (temp1 !== temp2) { + ywl.notify_error('两次密码输入不一致!'); + return false; + } + dlg_sys_user.user_pswd = temp1; + } else { + var temp1 = $('#auth-user-host-pswd').val(); + var temp2 = $('#auth-user-host-pswd-confirm').val(); + if (temp1 !== temp2) { + ywl.notify_error('两次密码输入不一致!'); + return false; + } + dlg_sys_user.user_pswd = temp1; + } + if (dlg_sys_user.protocol === PROTOCOL_TYPE_TELNET) { + var param1 = $('#auth-user-telnet-username-prompt').val(); + var param2 = $('#auth-user-telnet-pswd-prompt').val(); + dlg_sys_user.user_param = param1 + "\n" + param2; + } - dlg_sys_user.check_args = function () { + } else if (dlg_sys_user.auth_mode === AUTH_TYPE_SSHKEY) { + dlg_sys_user.cert_id = $('#auth-user-sshkey-list').val(); + } else if (dlg_sys_user.auth_mode === AUTH_NONE) { + dlg_sys_user.user_name = ''; + dlg_sys_user.user_pswd = ''; + dlg_sys_user.cert_id = 0; + } else { + ywl.notify_error('未知认证模式!'); + return false; + } + return true; + }; - dlg_sys_user.auth_mode = $('#auth-user-type').val(); - dlg_sys_user.user_name = $('#auth-user-host-username').val(); - if (dlg_sys_user.auth_mode != AUTH_NONE && - dlg_sys_user.user_name.length == 0) { - ywl.notify_error('请输入系统用户名!'); - return false; - } + dlg_sys_user.update_show = function (row_id, args) { + dlg_sys_user.update = 1; + dlg_sys_user.init_dlg(row_id, args); + $(dlg_sys_user.dom_id).modal({backdrop: 'static'}); + }; - if (dlg_sys_user.auth_mode == AUTH_TYPE_PASSWORD) { - if (dlg_sys_user.update != 1) { - var temp1 = $('#auth-user-host-pswd').val(); - var temp2 = $('#auth-user-host-pswd-confirm').val(); - if (temp1.length == 0) { - ywl.notify_error('请输入密码!'); - return false; - } - if (temp2.length == 0) { - ywl.notify_error('请输入确认密码!'); - return false; - } - if (temp1 != temp2) { - ywl.notify_error('两次密码输入不一致!'); - return false; - } - dlg_sys_user.user_pswd = temp1; - } else { - var temp1 = $('#auth-user-host-pswd').val(); - var temp2 = $('#auth-user-host-pswd-confirm').val(); - if (temp1 != temp2) { - ywl.notify_error('两次密码输入不一致!'); - return false; - } - dlg_sys_user.user_pswd = temp1; - } - if (dlg_sys_user.protocol == PROTOCOL_TYPE_TELNET) { - var param1 = $('#auth-user-telnet-username-prompt').val(); - var param2 = $('#auth-user-telnet-pswd-prompt').val(); - dlg_sys_user.user_param = param1 + "\n" + param2; - } + dlg_sys_user.create_show = function (row_data) { + dlg_sys_user.update = 0; + dlg_sys_user.init_dlg(row_data); + $(dlg_sys_user.dom_id).modal({backdrop: 'static'}); + }; - } else if (dlg_sys_user.auth_mode == AUTH_TYPE_SSHKEY) { - dlg_sys_user.cert_id = $('#auth-user-sshkey-list').val(); - } else if (dlg_sys_user.auth_mode == AUTH_NONE) { - dlg_sys_user.user_name = ''; - dlg_sys_user.user_pswd = ''; - dlg_sys_user.cert_id = 0; - } else { - ywl.notify_error('未知认证模式!'); - return false; - } - return true; - }; + dlg_sys_user.hide = function () { + $(dlg_sys_user.dom_id).modal('hide'); + }; - dlg_sys_user.update_show = function (row_id, args) { - dlg_sys_user.update = 1; - dlg_sys_user.init_dlg(row_id, args); - $(dlg_sys_user.dom_id).modal({backdrop: 'static'}); - }; + dlg_sys_user.update_post = function () { + var auth_mode = parseInt(dlg_sys_user.auth_mode); + var user_pswd = ''; + var cert_id = 0; + if (auth_mode === AUTH_TYPE_PASSWORD) { + user_pswd = dlg_sys_user.user_pswd; + } else if (auth_mode === AUTH_TYPE_SSHKEY) { + cert_id = parseInt(dlg_sys_user.cert_id); + } else { - dlg_sys_user.create_show = function (row_data) { - dlg_sys_user.update = 0; - dlg_sys_user.init_dlg(row_data); - $(dlg_sys_user.dom_id).modal({backdrop: 'static'}); - }; + } + var host_id = parseInt(dlg_sys_user.host_id); + var host_auth_id = parseInt(dlg_sys_user.host_auth_id); + var args = { + auth_mode: auth_mode, + host_id: host_id, + user_name: dlg_sys_user.user_name, + user_pswd: user_pswd, + cert_id: cert_id, + user_param: dlg_sys_user.user_param + }; + //console.log("args:", args); + ywl.ajax_post_json('/host/sys-user/update', {host_auth_id: host_auth_id, kv: args}, + function (ret) { + //console.log("ret,", ret); + if (ret.code === 0) { + ywl.notify_success('系统用户信息更新成功'); + g_dlg_edit_host_user.sync_user_info(host_id); + dlg_sys_user.hide(); - dlg_sys_user.hide = function () { - $(dlg_sys_user.dom_id).modal('hide'); - }; + } else { + ywl.notify_error('系统用户信息更新失败' + ret.code); + } + }, + function () { + ywl.notify_error('系统用户信息更新失败'); + } + ); + }; - dlg_sys_user.update_post = function () { - var auth_mode = parseInt(dlg_sys_user.auth_mode); - var user_pswd = ''; - var cert_id = 0; - if (auth_mode == AUTH_TYPE_PASSWORD) { - user_pswd = dlg_sys_user.user_pswd; - } else if (auth_mode == AUTH_TYPE_SSHKEY) { - cert_id = parseInt(dlg_sys_user.cert_id); - } else { + dlg_sys_user.create_post = function () { + if (!dlg_sys_user.check_args()) { + ywl.notify_error("参数输入有错误"); + return; + } + var auth_mode = parseInt(dlg_sys_user.auth_mode); + var user_pswd = ''; + var cert_id = 0; + if (auth_mode === AUTH_TYPE_PASSWORD) { + user_pswd = dlg_sys_user.user_pswd; + } else { + cert_id = parseInt(dlg_sys_user.cert_id); + } + var host_id = parseInt(dlg_sys_user.host_id); + var args = { + host_id: host_id, + auth_mode: auth_mode, + user_name: dlg_sys_user.user_name, + user_pswd: user_pswd, + cert_id: cert_id, + user_param: dlg_sys_user.user_param + }; - } - var host_id = parseInt(dlg_sys_user.host_id); - var host_auth_id = parseInt(dlg_sys_user.host_auth_id); - var args = { - auth_mode: auth_mode, - host_id: host_id, - user_name: dlg_sys_user.user_name, - user_pswd: user_pswd, - cert_id: cert_id, - user_param: dlg_sys_user.user_param - }; - //console.log("args:", args); - ywl.ajax_post_json('/host/sys-user/update', {host_auth_id: host_auth_id, kv: args}, - function (ret) { - //console.log("ret,", ret); - if (ret.code == 0) { - ywl.notify_success('系统用户信息更新成功'); - g_dlg_edit_host_user.sync_user_info(host_id); - dlg_sys_user.hide(); + ywl.ajax_post_json('/host/sys-user/add', args, + function (ret) { + if (ret.code === TPE_OK) { + ywl.notify_success('系统用户添加成功'); + g_dlg_edit_host_user.sync_user_info(host_id); + dlg_sys_user.hide(); + } else { + ywl.notify_error('系统用户添加失败' + ret.code); + } + }, + function () { + ywl.notify_error('系统用户信息更新失败'); + } + ); + }; - } else { - ywl.notify_error('系统用户信息更新失败' + ret.code); - } - }, - function () { - ywl.notify_error('系统用户信息更新失败'); - } - ); - }; - - dlg_sys_user.create_post = function () { - if (!dlg_sys_user.check_args()) { - ywl.notify_error("参数输入有错误"); - return; - } - var auth_mode = parseInt(dlg_sys_user.auth_mode); - var user_pswd = ''; - var cert_id = 0; - if (auth_mode == 1) { - user_pswd = dlg_sys_user.user_pswd; - } else { - cert_id = parseInt(dlg_sys_user.cert_id); - } - var host_id = parseInt(dlg_sys_user.host_id); - var args = { - host_id: host_id, - auth_mode: auth_mode, - user_name: dlg_sys_user.user_name, - user_pswd: user_pswd, - cert_id: cert_id, - user_param: dlg_sys_user.user_param - }; - - ywl.ajax_post_json('/host/sys-user/add', args, - function (ret) { - if (ret.code == 0) { - //console.log("ret,", ret); - if (ret.code == 0) { - ywl.notify_success('系统用户添加成功'); - g_dlg_edit_host_user.sync_user_info(host_id); - dlg_sys_user.hide(); - - } else { - ywl.notify_error('系统用户添加失败' + ret.code); - } - } - else { - ywl.notify_error('系统用户添加失败'); - } - }, - function () { - ywl.notify_error('系统用户信息更新失败'); - } - ); - }; - - return dlg_sys_user; + return dlg_sys_user; }; ywl.create_batch_join_group_dlg = function (tbl) { - var batch_join_dlg = {}; + var batch_join_dlg = {}; - batch_join_dlg.tbl = tbl; - batch_join_dlg.dom_id = "#dialog_batch_join_group"; - batch_join_dlg.host_list = []; + batch_join_dlg.tbl = tbl; + batch_join_dlg.dom_id = "#dialog_batch_join_group"; + batch_join_dlg.host_list = []; - batch_join_dlg.init = function () { - // 分组选择 - var html_group = []; - html_group.push(''); - for (var i = 0, cnt = g_group_list.length; i < cnt; ++i) { - html_group.push(''); - } - $('#group-host-group').append($(html_group.join(''))); + batch_join_dlg.init = function () { + // 分组选择 + var html_group = []; + html_group.push(''); + for (var i = 0, cnt = g_group_list.length; i < cnt; ++i) { + html_group.push(''); + } + $('#group-host-group').append($(html_group.join(''))); - batch_join_dlg.init_dlg(); - }; + batch_join_dlg.init_dlg(); + }; - batch_join_dlg.init_dlg = function () { - }; + batch_join_dlg.init_dlg = function () { + }; - batch_join_dlg.check_args = function () { - return true; - }; + batch_join_dlg.check_args = function () { + return true; + }; - batch_join_dlg.show = function (data_list) { - batch_join_dlg.host_list = data_list; - $(batch_join_dlg.dom_id).modal({backdrop: 'static'}); - }; + batch_join_dlg.show = function (data_list) { + batch_join_dlg.host_list = data_list; + $(batch_join_dlg.dom_id).modal({backdrop: 'static'}); + }; - batch_join_dlg.hide = function () { - $(batch_join_dlg.dom_id).modal('hide'); - }; + batch_join_dlg.hide = function () { + $(batch_join_dlg.dom_id).modal('hide'); + }; - batch_join_dlg.post = function () { + batch_join_dlg.post = function () { - var data_list = []; - for (var i = 0; i < batch_join_dlg.host_list.length; i++) { - var host_id = batch_join_dlg.host_list[i].host_id; - data_list.push(host_id); - } + var data_list = []; + for (var i = 0; i < batch_join_dlg.host_list.length; i++) { + var host_id = batch_join_dlg.host_list[i].host_id; + data_list.push(host_id); + } - var obj = $('#group-host-group'); - var group_id = parseInt(obj.val()); - var group_name = obj.find('option:selected').text(); + var obj = $('#group-host-group'); + var group_id = parseInt(obj.val()); + var group_name = obj.find('option:selected').text(); - ywl.ajax_post_json('/host/add-host-to-group', {host_list: data_list, group_id: group_id}, - function (ret) { - var update_args = {group_name: group_name}; - for (var i = 0; i < batch_join_dlg.host_list.length; i++) { - var row_id = batch_join_dlg.host_list[i].row_id; - batch_join_dlg.tbl.update_row(row_id, update_args); - } + ywl.ajax_post_json('/host/add-host-to-group', {host_list: data_list, group_id: group_id}, + function (ret) { + var update_args = {group_name: group_name}; + for (var i = 0; i < batch_join_dlg.host_list.length; i++) { + var row_id = batch_join_dlg.host_list[i].row_id; + batch_join_dlg.tbl.update_row(row_id, update_args); + } - ywl.notify_success("成功设定分组信息!"); - batch_join_dlg.hide(); - }, - function () { - ywl.notify_error("设定分组信息失败!"); - } - ); - }; + ywl.notify_success("成功设定分组信息!"); + batch_join_dlg.hide(); + }, + function () { + ywl.notify_error("设定分组信息失败!"); + } + ); + }; - $("#group-btn-save").click(function () { - if (!batch_join_dlg.check_args()) { - return; - } - batch_join_dlg.post(); - }); + $("#group-btn-save").click(function () { + if (!batch_join_dlg.check_args()) { + return; + } + batch_join_dlg.post(); + }); - return batch_join_dlg; + return batch_join_dlg; }; diff --git a/server/www/teleport/static/js/ui/auth.js b/server/www/teleport/static/js/ui/auth.js index 76c1806..c75601a 100644 --- a/server/www/teleport/static/js/ui/auth.js +++ b/server/www/teleport/static/js/ui/auth.js @@ -522,10 +522,10 @@ ywl.on_user_host_table_created = function (tbl) { ywl.ajax_post_json('/user/delete-host', {host_list: host_list, user_name: ywl.page_options.user_name}, function (ret) { tbl.remove_row(row_id); - ywl.notify_success('删除用户拥有主机成功'); + ywl.notify_success('回收授权成功!'); }, function () { - ywl.notify_error('删除用户拥有主机失败'); + ywl.notify_error('回收授权失败!'); } ); }; diff --git a/server/www/teleport/static/js/ui/auth/login.js b/server/www/teleport/static/js/ui/auth/login.js index 09ea6c9..c423a7d 100644 --- a/server/www/teleport/static/js/ui/auth/login.js +++ b/server/www/teleport/static/js/ui/auth/login.js @@ -25,23 +25,23 @@ ywl.create_app = function () { $('#captcha_image').click(function () { $(this).attr('src', '/auth/get-captcha?' + Math.random()); - $('#captcha').focus(); + $('#captcha').focus().val(''); }); $('#username_account').keydown(function (event) { $('[data-toggle="popover"]').popover('hide'); - if (event.which == 13) { + if (event.which === 13) { $('#password_account').focus(); } }); $('#password_account').keydown(function (event) { $('[data-toggle="popover"]').popover('hide'); - if (event.which == 13) { + if (event.which === 13) { $('#captcha').focus(); } }); $('#captcha').keydown(function (event) { $('[data-toggle="popover"]').popover('hide'); - if (event.which == 13) { + if (event.which === 13) { _app.login_account(); } }); @@ -64,7 +64,6 @@ ywl.create_app = function () { str_password = dom_password.val(); str_captcha = dom_captcha.val(); is_remember = dom_remember.is(':checked'); - console.log('xxxx', is_remember); if (str_username.length === 0) { show_op_box('error', '缺少账号!'); @@ -92,7 +91,7 @@ ywl.create_app = function () { // 先判断一下captcha是否正确,如果不正确,拒绝登录 ywl.ajax_post_json('/auth/verify-captcha', {captcha: str_captcha}, function (ret) { - if (ret.code === 0) { + if (ret.code === TPE_OK) { // 验证成功 hide_op_box(); show_op_box('wait', ' 正在登录TELEPORT,请稍候...'); @@ -116,14 +115,11 @@ ywl.create_app = function () { }; _app.do_account_login = function (username, userpwd, captcha, is_remember) { - console.log('remember', is_remember); ywl.ajax_post_json('/auth/verify-user', {username: username, userpwd: userpwd, captcha: captcha, remember: is_remember}, function (ret) { - if (ret.code == 0) { - // 验证成功 + if (ret.code === TPE_OK) { window.location.href = ywl.page_options.ref; - } - else { + } else { hide_op_box(); show_op_box('error', '无法登录TELEPORT:' + ret.message); console.log(ret); @@ -137,31 +133,6 @@ ywl.create_app = function () { $('#btn_login').removeAttr('disabled'); } ); - -// $.ajax({ -// type: 'GET', -// url: '/auth/verify-user', -// jsonp: "callback", -// data: {username: username, userpwd: userpwd, captcha: captcha}, -// dataType: 'jsonp', -// success: function (data) { -// if (data.code == 0) { -// // 验证成功 -// window.location.href = ywl.page_options.ref; -// } -// else { -// hide_op_box(); -// show_op_box('error', '无法登录TELEPORT!'); -// } -// -// $('#btn_login').removeAttr('disabled'); -// }, -// error: function () { -// hide_op_box(); -// show_op_box('error', '很抱歉,无法连接服务器!请稍后再试一次!'); -// $('#btn_login').removeAttr('disabled'); -// } -// }); }; return _app; diff --git a/server/www/teleport/static/js/ui/cert.js b/server/www/teleport/static/js/ui/cert.js index ce1c353..f095f84 100644 --- a/server/www/teleport/static/js/ui/cert.js +++ b/server/www/teleport/static/js/ui/cert.js @@ -1,7 +1,7 @@ -/** - * Created by mi on 2016/7/4. - */ +"use strict"; + var g_cert_dlg_info = null; + ywl.on_init = function (cb_stack, cb_args) { var dom_id = '#ywl_cert_list'; @@ -71,7 +71,7 @@ ywl.on_init = function (cb_stack, cb_args) { ywl.on_host_table_created = function (tbl) { 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); //console.log('row_data', row_data); $(cell_obj).find('[ywl-btn-edit]').click(function () { @@ -82,18 +82,18 @@ ywl.on_host_table_created = function (tbl) { var _fn_sure = function (cb_stack, cb_args) { ywl.ajax_post_json('/host/delete-cert', {cert_id: cert_id}, function (ret) { - if (ret.code == 0) { + if (ret.code === TPE_OK) { tbl.remove_row(row_id); ywl.notify_success('删除成功!'); - } else if (ret.code == -2) { + } else if (ret.code === -2) { ywl.notify_error('不能删除,有主机使用了此密钥!'); } else { - ywl.notify_error('删除失败!'); + ywl.notify_error('删除失败!错误代码:'+ret.code); } }, - function (ret) { - ywl.notify_error('删除失败'); + function () { + ywl.notify_error('网络通讯失败!'); } ); }; @@ -189,7 +189,7 @@ ywl.create_cert_info_dlg = function (tbl) { ywl.notify_error('必须填写公钥内容!'); 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('添加密钥时,必须填写私钥内容!'); return false; } @@ -197,7 +197,7 @@ ywl.create_cert_info_dlg = function (tbl) { }; 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}, function (ret) { var update_args = {cert_id: cert_info_dlg.cert_id, cert_name: cert_info_dlg.cert_name}; @@ -205,19 +205,19 @@ ywl.create_cert_info_dlg = function (tbl) { ywl.notify_success('密钥更新成功!'); cert_info_dlg.hide(); }, - function (ret) { + function () { ywl.notify_error('密钥更新失败!'); } ); } else { ywl.ajax_post_json('/host/add-cert', {cert_name: cert_info_dlg.cert_name, cert_pub: cert_info_dlg.cert_pub, cert_pri: cert_info_dlg.cert_pri}, function (ret) { - if(ret.code == 0){ + if(ret.code === TPE_OK){ cert_info_dlg.tbl.reload(); ywl.notify_success('密钥添加成功!'); cert_info_dlg.hide(); - }else if(ret.code == -2){ - ywl.notify_error('错误,没有启动核心服务!'); + }else if(ret.code === TPE_NO_CORE_SERVER){ + ywl.notify_error('错误,没有启动核心服务!'); }else{ ywl.notify_error('密钥添加失败!code:' + ret.code); } diff --git a/server/www/teleport/static/js/ui/common.js b/server/www/teleport/static/js/ui/common.js index 9175698..d433627 100644 --- a/server/www/teleport/static/js/ui/common.js +++ b/server/www/teleport/static/js/ui/common.js @@ -68,9 +68,9 @@ function get_system_group_by_id(gid) { } -function get_command_name_by_id(cmd_id) { - return ywl.assist.get_cache_by_id(CACHE_TYPE_COMMAND, cmd_id); -} +//function get_command_name_by_id(cmd_id) { +// return ywl.assist.get_cache_by_id(CACHE_TYPE_COMMAND, cmd_id); +//} //function notify_error(message_, title_) { // var _title = title_ || ''; diff --git a/server/www/teleport/static/js/ui/common_host.js b/server/www/teleport/static/js/ui/common_host.js index ae52447..bb67cdf 100644 --- a/server/www/teleport/static/js/ui/common_host.js +++ b/server/www/teleport/static/js/ui/common_host.js @@ -1,13 +1,13 @@ "use strict"; -var OS_TYPE_WINDOWS = 1; -var OS_TYPE_LINUX = 2; -var PROTOCOL_TYPE_RDP = 1; -var PROTOCOL_TYPE_SSH = 2; -var PROTOCOL_TYPE_TELNET = 3; -var AUTH_TYPE_PASSWORD = 1; -var AUTH_TYPE_SSHKEY = 2; -var AUTH_NONE = 0; +//var OS_TYPE_WINDOWS = 1; +//var OS_TYPE_LINUX = 2; +//var PROTOCOL_TYPE_RDP = 1; +//var PROTOCOL_TYPE_SSH = 2; +//var PROTOCOL_TYPE_TELNET = 3; +//var AUTH_TYPE_PASSWORD = 1; +//var AUTH_TYPE_SSHKEY = 2; +//var AUTH_NONE = 0; var g_assist = null; diff --git a/server/www/teleport/static/js/ui/controls.js b/server/www/teleport/static/js/ui/controls.js index fbe5382..268703d 100644 --- a/server/www/teleport/static/js/ui/controls.js +++ b/server/www/teleport/static/js/ui/controls.js @@ -1003,20 +1003,20 @@ ywl.create_table_render = function (tbl, on_created) { return ret; }; - _tbl_render.host_status = function (row_id, fields) { - if (fields.status == HOST_STAT_ACTIVE) { - switch (fields.online) { - case AGENT_STAT_ONLINE: - return '在线'; - case AGENT_STAT_OFFLINE: - return '离线'; - default: - return '未知'; - } - } else { - return '- 未使用 -'; - } - }; +// _tbl_render.host_status = function (row_id, fields) { +// if (fields.status == HOST_STAT_ACTIVE) { +// switch (fields.online) { +// case AGENT_STAT_ONLINE: +// return '在线'; +// case AGENT_STAT_OFFLINE: +// return '离线'; +// default: +// return '未知'; +// } +// } else { +// return '- 未使用 -'; +// } +// }; _tbl_render.sys_type = function (row_id, fields) { switch (fields.sys_type) { diff --git a/server/www/teleport/static/js/ui/record.js b/server/www/teleport/static/js/ui/record.js index aa3c910..a8d7b70 100644 --- a/server/www/teleport/static/js/ui/record.js +++ b/server/www/teleport/static/js/ui/record.js @@ -41,7 +41,7 @@ var speed_offset = 0; ywl.req_record_info = function (record_id, file_id, repeat) { ywl.ajax_post_json_time_out('/log/get-record-file-info', {id: record_id, file_id: file_id}, 30 * 1000, function (ret) { - if (ret.code == 0) { + if (ret.code === TPE_OK) { g_data[file_id] = ret.data; if ((g_down_play_file_id + 1) <= g_total_file_count) { @@ -49,9 +49,7 @@ ywl.req_record_info = function (record_id, file_id, repeat) { ywl.req_record_info(record_id, g_down_play_file_id, true); g_down_play_file_id++; } - } - //console.log('req_record_info successful'); } else { console.log('req_record_info error ', ret.code); } @@ -77,11 +75,13 @@ ywl.on_init = function (cb_stack, cb_args) { ywl.ajax_post_json('/log/get-record-header', {id: record_id}, function (ret) { - if (ret.code == 0) { + if (ret.code === TPE_OK) { g_header = ret.data.header; g_total_file_count = g_header.file_count; g_total_time = g_header.time_used; + $('#recorder-info').html(g_header.account + ' 于 ' + format_datetime(g_header.start) + ' 访问 ' + g_header.user_name + '@' + g_header.ip + ':' + g_header.port); + // 请求第一个录像数据块 g_down_play_file_id = 0; ywl.req_record_info(record_id, g_down_play_file_id, true); diff --git a/server/www/teleport/static/js/ui/teleport.js b/server/www/teleport/static/js/ui/teleport.js index 6be3e51..ba6db61 100644 --- a/server/www/teleport/static/js/ui/teleport.js +++ b/server/www/teleport/static/js/ui/teleport.js @@ -7,19 +7,18 @@ var g_current_version = ""; var g_host_name = window.location.hostname; var error_process = function (ret, func_success, func_error) { -// console.log("ret", ret); var code = ret.code; - if (code == TPE_OK) { + if (code === TPE_OK) { func_success(ret); return; } - if (code == TPE_START_CLIENT) { + if (code === TPE_START_CLIENT) { func_error(TPE_START_CLIENT, '启动本地客户端进程失败,请检查命令行是否正确:' + ret.path); console.log('启动本地进程失败,命令行:', ret.path); - } else if (code == TPE_JSON_FORMAT || code == TPE_PARAM) { + } else if (code === TPE_JSON_FORMAT || code === TPE_PARAM) { func_error(TPE_START_CLIENT, "启动本地客户端进程失败:启动参数错误!"); - } else if (code == TPE_OLD_ASSIST) { + } else if (code === TPE_OLD_ASSIST) { func_error(TPE_OLD_ASSIST, '助手版本太低,请下载最新版本!'); } else { @@ -47,7 +46,7 @@ var teleport_init = function (last_version, req_version, func_success, func_erro func_error(ret, TPE_OLD_ASSIST, '助手版本太低,请下载最新版本!'); } }, - error: function (jqXhr) { + error: function () { func_error({}, TPE_NO_ASSIST, '无法连接到teleport助手,可能尚未启动!'); } }); @@ -60,7 +59,6 @@ var version_compare = function () { }; var to_teleport = function (url, args, func_success, func_error) { - var auth_id = args['auth_id']; // 开始Ajax调用 var args_ = JSON.stringify({auth_id: auth_id}); @@ -94,7 +92,7 @@ var to_teleport = function (url, args, func_success, func_error) { success: function (ret) { error_process(ret, func_success, func_error); }, - error: function (jqXhr) { + error: function () { func_error(TPE_NO_ASSIST, '无法连接到teleport助手,可能尚未启动!'); } }); @@ -109,7 +107,6 @@ var to_teleport = function (url, args, func_success, func_error) { }; var to_admin_teleport = function (url, args, func_success, func_error) { - var host_auth_id = args['host_auth_id']; // 开始Ajax调用 var args_ = JSON.stringify({host_auth_id: host_auth_id}); @@ -124,7 +121,7 @@ var to_admin_teleport = function (url, args, func_success, func_error) { if (ret.code === 0) { var session_id = ret.data.session_id; var data = { - server_ip: g_host_name, // args.server_ip, + server_ip: g_host_name, server_port: parseInt(args.server_port), host_ip: args.host_ip, size: parseInt(args.size), @@ -158,7 +155,6 @@ var to_admin_teleport = function (url, args, func_success, func_error) { }; var to_admin_fast_teleport = function (url, args, func_success, func_error) { - // 开始Ajax调用 var args_ = JSON.stringify(args); $.ajax({ @@ -172,7 +168,7 @@ var to_admin_fast_teleport = function (url, args, func_success, func_error) { if (ret.code === 0) { var session_id = ret.data.session_id; var data = { - server_ip: g_host_name, //args.server_ip, + server_ip: g_host_name, server_port: parseInt(args.server_port), host_ip: args.host_ip, size: parseInt(args.size), @@ -210,7 +206,6 @@ var to_admin_fast_teleport = function (url, args, func_success, func_error) { }; var start_rdp_replay = function (args, func_success, func_error) { - var args_ = encodeURIComponent(JSON.stringify(args)); $.ajax({ type: 'GET', @@ -227,7 +222,7 @@ var start_rdp_replay = function (args, func_success, func_error) { console.log('ret', ret); }, error: function () { - func_error(TPE_NETWORK, '远程网络通讯失败!'); + func_error(TPE_NETWORK, '与助手的络通讯失败!'); } }); }; diff --git a/server/www/teleport/static/js/ywl_const.js b/server/www/teleport/static/js/ywl_const.js index aeab26d..9b793c1 100644 --- a/server/www/teleport/static/js/ywl_const.js +++ b/server/www/teleport/static/js/ywl_const.js @@ -1,12 +1,23 @@ "use strict"; -var USER_TYPE_TEAM_MEMBER = 1; -var USER_TYPE_TEAM_LEADER = 9; -var USER_TYPE_SYS_ADMIN = 99; +var PROTOCOL_TYPE_RDP = 1; +var PROTOCOL_TYPE_SSH = 2; +var PROTOCOL_TYPE_TELNET = 3; -var AGENT_STAT_ONLINE = 1; -var AGENT_STAT_OFFLINE = 0; -// var AGENT_STAT_NOT_ACTIVE = 2; +var OS_TYPE_WINDOWS = 1; +var OS_TYPE_LINUX = 2; +var AUTH_TYPE_PASSWORD = 1; +var AUTH_TYPE_SSHKEY = 2; +var AUTH_NONE = 0; + + +//var USER_TYPE_TEAM_MEMBER = 1; +//var USER_TYPE_TEAM_LEADER = 9; +//var USER_TYPE_SYS_ADMIN = 99; + +//var AGENT_STAT_ONLINE = 1; +//var AGENT_STAT_OFFLINE = 0; +//var AGENT_STAT_NOT_ACTIVE = 2; var HOST_STAT_NOT_ACTIVE = 0; var HOST_STAT_ACTIVE = 2; @@ -87,6 +98,7 @@ var TPE_DATA = 127; // 数据错误 // #define TPE_OPENFILE_ERROR 0x1007 // 无法打开文件 // #define TPE_GETTEMPPATH_ERROR 0x1007 +var TPE_OPENFILE = 300; // 无法打开文件 //------------------------------------------------------- @@ -103,4 +115,52 @@ var TPE_START_CLIENT = 100002; // 无法启动客户端程序(无法创建进 var TPE_NO_CORE_SERVER = 200000; // 未能检测到核心服务 +function tp_error_msg(error_code) { + switch (error_code) { + case TPE_FAILED: + return '内部错误'; + case TPE_NETWORK: + return '网络错误'; + +//------------------------------------------------------- +// HTTP请求相关错误 +//------------------------------------------------------- + case TPE_HTTP_METHOD: + return '无效/错误的请求方法'; + case TPE_HTTP_URL_ENCODE: + return 'URL编码错误(无法解码)'; + + case TPE_UNKNOWN_CMD: + return '未知命令'; + case TPE_JSON_FORMAT: + return '错误的JSON格式数据'; + case TPE_PARAM: + return '参数错误'; + case TPE_DATA: + return '数据错误'; + + + case TPE_OPENFILE: + return '无法打开文件'; + +//------------------------------------------------------- +// 助手程序专用错误值 +//------------------------------------------------------- + case TPE_NO_ASSIST: + return '未能检测到助手程序'; + case TPE_OLD_ASSIST: + return '助手程序版本太低'; + case TPE_START_CLIENT: + return '无法启动客户端程序(无法创建进程)'; + +//------------------------------------------------------- +// 核心服务专用错误值 +//------------------------------------------------------- + case TPE_NO_CORE_SERVER: + return '未能检测到核心服务'; + + default: + return '未知错误'; + } +} diff --git a/server/www/teleport/static/less/auth.less b/server/www/teleport/static/less/auth.less index 8b0305a..2fb559f 100644 --- a/server/www/teleport/static/less/auth.less +++ b/server/www/teleport/static/less/auth.less @@ -128,6 +128,12 @@ body { background: url(../img/login/side-001.jpg) 0 0 no-repeat; } +@media screen and (max-width: 990px) { + #leftside { + display: none; + } +} + #leftside h1 { font-size: 24px; color: #888; diff --git a/server/www/teleport/view/auth/page_base.mako b/server/www/teleport/view/auth/page_base.mako index 6baed43..82e7a0d 100644 --- a/server/www/teleport/view/auth/page_base.mako +++ b/server/www/teleport/view/auth/page_base.mako @@ -55,7 +55,7 @@ diff --git a/server/www/teleport/view/cert/index.mako b/server/www/teleport/view/cert/index.mako index 82aa25d..984f630 100644 --- a/server/www/teleport/view/cert/index.mako +++ b/server/www/teleport/view/cert/index.mako @@ -12,7 +12,7 @@ <%block name="breadcrumb"> diff --git a/server/www/teleport/view/common/_sidebar_nav_menu.mako b/server/www/teleport/view/common/_sidebar_nav_menu.mako index 868b13f..a0b0cd6 100644 --- a/server/www/teleport/view/common/_sidebar_nav_menu.mako +++ b/server/www/teleport/view/common/_sidebar_nav_menu.mako @@ -52,27 +52,28 @@ 'name': '日志查询', 'icon': 'fa-database', }, +## { +## 'require_type': 1, +## 'id': 'pwd', +## 'link': '/pwd', +## 'name': '密码修改', +## 'icon': 'fa-pencil-square-o', +## }, +## { +## 'require_type': 1, +## 'id': 'exit', +## 'link': '/exit', +## 'name': '安全退出', +## 'icon': 'fa-sign-out', +## }, { + 'separator': true, 'require_type': 1, 'id': 'assist-config', 'link': 'http://127.0.0.1:50022/config', 'target': '_blank', 'name': '助手配置', - 'icon': 'fa-pencil-square-o', - }, - { - 'require_type': 1, - 'id': 'pwd', - 'link': '/pwd', - 'name': '密码修改', - 'icon': 'fa-pencil-square-o', - }, - { - 'require_type': 1, - 'id': 'exit', - 'link': '/exit', - 'name': '安全退出', - 'icon': 'fa-sign-out', + 'icon': 'fa-cog', }, ] %> @@ -103,7 +104,8 @@
@@ -119,6 +121,10 @@ %for menu in _sidebar: %if menu['require_type'] <= current_user['type']: + %if 'separator' in menu: +
+ %endif + %if 'sub' in menu and len(menu['sub']) > 0:
\ No newline at end of file diff --git a/server/www/teleport/view/group/index.mako b/server/www/teleport/view/group/index.mako index 1406c89..a2613b3 100644 --- a/server/www/teleport/view/group/index.mako +++ b/server/www/teleport/view/group/index.mako @@ -12,7 +12,7 @@ <%block name="breadcrumb"> diff --git a/server/www/teleport/view/host/admin_index.mako b/server/www/teleport/view/host/admin_index.mako index bab22d0..0dce2f3 100644 --- a/server/www/teleport/view/host/admin_index.mako +++ b/server/www/teleport/view/host/admin_index.mako @@ -155,8 +155,8 @@
@@ -173,7 +173,6 @@ -
@@ -200,110 +199,18 @@
-##
-## -##
-## -##
-##
    -##
  • -##
  • 端口号
  • -##
  • -##
-##
-## -##
-##
    -##
  • -##
  • 端口号
  • -##
  • -##
-##
-## -##
-##
    -##
  • -##
  • 端口号
  • -##
  • -##
-##
-##
-##
-
- - ##
- ## - ##
- ## - ##
- ##
- ## - ##
- ## - ##
- ## - ##
- ##
- ## - ##
- ## - ##
- ## - ##
- ##
- ## - ##
- ## - ##
- ## - ##
- ##
- ## - ##
- ##
- ## - ##
- ## - ##
- ##
- ##
- ## - ##
- ## - ##
- ##
- ##
- ## - ## - ## - - + + -