diff --git a/client/tp_assist_win/site/index.html b/client/tp_assist_win/site/index.html index cb6db67..55af950 100644 --- a/client/tp_assist_win/site/index.html +++ b/client/tp_assist_win/site/index.html @@ -23,7 +23,7 @@
Teleport助手本地配置 - 此处配置保存到本地计算机上,如果更换计算机,需要重新配置! +
@@ -40,6 +40,7 @@
+

此处配置保存到本地计算机上,如果更换计算机,需要重新配置!

注意:命令参数设置中,如需传递主机信息和登录信息,可以用以下变量替换(注意大小写!):
- - - - - - - @@ -117,12 +111,6 @@ - - - - - - diff --git a/client/tp_assist_win/site/js/config.js b/client/tp_assist_win/site/js/config.js index a4ac0aa..29a7cac 100644 --- a/client/tp_assist_win/site/js/config.js +++ b/client/tp_assist_win/site/js/config.js @@ -5,6 +5,8 @@ var g_url_base = 'http://127.0.0.1:50022'; var g_cfg = null; var dom = { + version: $('#version'), + ssh_type: $('#ssh-type'), ssh_app: $('#ssh-app'), ssh_cmdline: $('#ssh-cmdline'), @@ -23,6 +25,27 @@ var dom = { btn_save: $('#btn-save') }; +function get_version() { + $.ajax({ + type: 'GET', + timeout: 5000, + url: g_url_base + '/api/get_version', + jsonp: 'callback', + dataType: 'json', + success: function (ret) { + if (ret.code == 0) { + dom.version.text('v' + ret.version); + } else { + alert("获取助手版本信息失败!"); + } + }, + error: function (jqXhr, _error, _e) { + console.log('state:', jqXhr.state()); + alert("获取助手版本信息失败!"); + } + }); +} + function get_config() { $.ajax({ type: 'GET', @@ -32,7 +55,6 @@ function get_config() { dataType: 'json', success: function (ret) { if (ret.code == 0) { - console.log(ret.data); g_cfg = ret.data; update_dom(); } else { @@ -82,8 +104,6 @@ function update_dom() { } } - - dom.scp_type.html(''); if (!_.isUndefined(g_cfg.scp)) { if (_.isUndefined(g_cfg.scp.selected)) { @@ -215,7 +235,8 @@ var select_local_file = function (callback) { jsonp: 'callback', dataType: 'json', success: function (ret) { - callback(0, ret.path); + if(ret.code === 0) + callback(0, ret.path); }, error: function (jqXhr, _error, _e) { console.log('state:', jqXhr.state()); @@ -249,6 +270,8 @@ function notify_success(message_, title_) { }; $(document).ready(function () { + get_version(); + get_config(); dom.ssh_type.change(function () { @@ -322,81 +345,5 @@ $(document).ready(function () { dom.btn_save.click(function () { on_save(); - // var name = $("#ssh-client-type").val(); - // var path = $("#ssh-exec-path").val(); - // if (path == "") { - // alert("请选择路径"); - // return; - // } - // var command_line = $("#ssh-exec-args").val(); - // if (command_line == "") { - // alert("请输入命令行"); - // return; - // } - // set_current_client_config(1, name, path, command_line); }); - - - // $("#sftp-client-type").change(function () { - // var i = 0; - // var name = $("#sftp-client-type").val(); - // var item = g_sftp_config_dict[name]; - // init_config_param(2, item.build_in, item.path, item.commandline); - // g_current_sftp = item.name; - // }); - // $("#sftp-select-path").click(function () { - // open_exist_file(function (code, path) { - // if (code == 0) { - // $("#sftp-exec-path").val(path); - // } else { - // console.log("can not select file."); - // } - // }); - // }); - // $("#sftp-btn-save").click(function () { - // var name = $("#sftp-client-type").val(); - // var path = $("#sftp-exec-path").val(); - // if (path == "") { - // alert("请选择路径"); - // return; - // } - // var command_line = $("#sftp-exec-args").val(); - // if (command_line == "") { - // alert("请输入命令行"); - // return; - // } - // set_current_client_config(2, name, path, command_line); - // }); - // - // - // $("#telnet-client-type").change(function () { - // var i = 0; - // var name = $("#telnet-client-type").val(); - // var item = g_telnet_config_dict[name]; - // init_config_param(3, item.build_in, item.path, item.commandline); - // g_current_telnet = item.name; - // }); - // $("#telnet-select-path").click(function () { - // open_exist_file(function (code, path) { - // if (code == 0) { - // $("#telnet-exec-path").val(path); - // } else { - // console.log("can not select file."); - // } - // }); - // }); - // $("#telnet-btn-save").click(function () { - // var name = $("#telnet-client-type").val(); - // var path = $("#telnet-exec-path").val(); - // if (path == "") { - // alert("请选择路径"); - // return; - // } - // var command_line = $("#telnet-exec-args").val(); - // if (command_line == "") { - // alert("请输入命令行"); - // return; - // } - // set_current_client_config(3, name, path, command_line); - // }); }); \ No newline at end of file diff --git a/client/tp_assist_win/ts_http_rpc.cpp b/client/tp_assist_win/ts_http_rpc.cpp index 12af0ba..8f8614c 100644 --- a/client/tp_assist_win/ts_http_rpc.cpp +++ b/client/tp_assist_win/ts_http_rpc.cpp @@ -1331,6 +1331,7 @@ void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf) { ex_astr utf8_path; ex_wstr2astr(wszReturnPath, utf8_path, EX_CODEPAGE_UTF8); Json::Value root; + root["code"] = TPE_OK; root["path"] = utf8_path; _create_json_ret(buf, root); diff --git a/server/tp_core/common/base_record.h b/server/tp_core/common/base_record.h index d6d1b7c..b7c60bd 100644 --- a/server/tp_core/common/base_record.h +++ b/server/tp_core/common/base_record.h @@ -30,8 +30,8 @@ typedef struct TS_RECORD_HEADER_BASIC ex_u64 timestamp; // ¼ʼʱ䣨UTCʱ ex_u16 width; // ʼĻߴ磺 ex_u16 height; // ʼĻߴ磺 - char user_username[32]; // teleport˺ - char acc_username[32]; // Զû + char user_username[64]; // teleport˺ + char acc_username[64]; // Զû char host_ip[40]; // ԶIP char conn_ip[40]; // ԶIP @@ -42,7 +42,7 @@ typedef struct TS_RECORD_HEADER_BASIC // RDPר ex_u8 rdp_security; // 0 = RDP, 1 = TLS - ex_u8 reserve[256 - 4 - 2 - 2 - 2 - 8 - 2 - 2 - 32 - 32 - 40 - 2 - 40 - 40 - 1 - 12]; // У12BΪheader-infoĿռ + ex_u8 reserve[512 - 4 - 2 - 2 - 2 - 8 - 2 - 2 - 64 - 64 - 40 - 2 - 40 - 40 - 1 - 12]; // У12BΪheader-infoĿռ }TS_RECORD_HEADER_BASIC; #define ts_record_header_basic_size sizeof(TS_RECORD_HEADER_BASIC) @@ -52,7 +52,7 @@ typedef struct TS_RECORD_HEADER TS_RECORD_HEADER_BASIC basic; }TS_RECORD_HEADER; -// header֣header-info + header-basic = 256B +// header֣header-info + header-basic = 512B #define ts_record_header_size sizeof(TS_RECORD_HEADER) diff --git a/server/tp_core/common/protocol_interface.h b/server/tp_core/common/protocol_interface.h index 49966ce..1a28562 100644 --- a/server/tp_core/common/protocol_interface.h +++ b/server/tp_core/common/protocol_interface.h @@ -71,6 +71,7 @@ extern "C" TPP_API ex_rv tpp_init(TPP_INIT_ARGS* init_args); TPP_API ex_rv tpp_start(void); TPP_API ex_rv tpp_stop(void); + TPP_API void tpp_timer(void); #ifdef __cplusplus } @@ -78,6 +79,7 @@ extern "C" typedef ex_rv (*TPP_INIT_FUNC)(TPP_INIT_ARGS* init_args); typedef ex_rv (*TPP_START_FUNC)(void); -typedef ex_rv (*TPP_STOP_FUNC)(void); +typedef ex_rv(*TPP_STOP_FUNC)(void); +typedef void(*TPP_TIMER_FUNC)(void); #endif // __TP_PROTOCOL_INTERFACE_H__ diff --git a/server/tp_core/core/main.cpp b/server/tp_core/core/main.cpp index a212c64..5e89d56 100644 --- a/server/tp_core/core/main.cpp +++ b/server/tp_core/core/main.cpp @@ -1,6 +1,7 @@ #include "ts_env.h" #include "ts_ver.h" #include "ts_main.h" +#include "ts_http_client.h" #include @@ -11,15 +12,18 @@ // -u жطȻ˳Winƽ̨ // --version ӡ汾Ȼ˳ // start Էʽ +// stop ֹͣеij // ExLogger g_ex_logger; bool g_is_debug = false; +extern bool g_exit_flag; #define RUN_UNKNOWN 0 #define RUN_CORE 1 #define RUN_INSTALL_SRV 2 #define RUN_UNINST_SRV 3 +#define RUN_STOP 4 static ex_u8 g_run_type = RUN_UNKNOWN; #define EOM_CORE_SERVICE_NAME L"Teleport Core Service" @@ -83,6 +87,10 @@ static bool _process_cmd_line(int argc, wchar_t** argv) g_run_type = RUN_CORE; continue; } + else if (0 == wcscmp(argv[i], L"stop")) { + g_run_type = RUN_STOP; + continue; + } if (0 == wcscmp(argv[i], L"-d")) { @@ -153,6 +161,15 @@ int _app_main(int argc, wchar_t** argv) return 1; } + if (g_run_type == RUN_STOP) { + char url[1024] = {0}; + ex_strformat(url, 1023, "http://%s:%d/rpc?{\"method\":\"exit\"}", g_env.rpc_bind_ip.c_str(), g_env.rpc_bind_port); + ex_astr body; + ts_http_get(url, body); + ex_printf("%s\n", body.c_str()); + return 0; + } + if (!g_is_debug) { if (!_run_daemon()) @@ -244,14 +261,21 @@ static void WINAPI service_handler(DWORD fdwControl) { if (g_hWorkerThread) { - TerminateThread(g_hWorkerThread, 1); - g_hWorkerThread = NULL; - } + // TerminateThread(g_hWorkerThread, 1); + // g_hWorkerThread = NULL; + g_exit_flag = true; - g_ServiceStatus.dwWin32ExitCode = 0; - g_ServiceStatus.dwCurrentState = SERVICE_STOPPED; - g_ServiceStatus.dwCheckPoint = 0; - g_ServiceStatus.dwWaitHint = 0; + g_ServiceStatus.dwWin32ExitCode = 0; + g_ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING; + g_ServiceStatus.dwCheckPoint = 0; + g_ServiceStatus.dwWaitHint = 0; + } + else { + g_ServiceStatus.dwWin32ExitCode = 0; + g_ServiceStatus.dwCurrentState = SERVICE_STOPPED; + g_ServiceStatus.dwCheckPoint = 0; + g_ServiceStatus.dwWaitHint = 0; + } }break; @@ -286,7 +310,7 @@ VOID WINAPI service_main(DWORD argc, wchar_t** argv) g_hWorkerThread = CreateThread(NULL, 0, service_thread_func, NULL, 0, &tid); if (NULL == g_hWorkerThread) { - EXLOGE_WIN("CreateThread(python)"); + EXLOGE_WIN("CreateThread()"); g_ServiceStatus.dwWin32ExitCode = 0; g_ServiceStatus.dwCurrentState = SERVICE_STOPPED; @@ -336,7 +360,8 @@ void _sig_handler(int signum, siginfo_t* info, void* ptr) if (signum == SIGINT || signum == SIGTERM) { EXLOGW("[core] received signal SIGINT, exit now.\n"); - exit(1); + g_exit_flag = true; + // exit(1); } } diff --git a/server/tp_core/core/ts_http_rpc.cpp b/server/tp_core/core/ts_http_rpc.cpp index d9b0e4a..3167d14 100644 --- a/server/tp_core/core/ts_http_rpc.cpp +++ b/server/tp_core/core/ts_http_rpc.cpp @@ -327,7 +327,6 @@ void TsHttpRpc::_rpc_func_get_config(const Json::Value& json_param, ex_astr& buf _create_json_ret(buf, TPE_OK, jr_data); } - void TsHttpRpc::_rpc_func_request_session(const Json::Value& json_param, ex_astr& buf) { // https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#request_session diff --git a/server/tp_core/core/ts_main.cpp b/server/tp_core/core/ts_main.cpp index 15d844a..1592de6 100644 --- a/server/tp_core/core/ts_main.cpp +++ b/server/tp_core/core/ts_main.cpp @@ -114,6 +114,7 @@ typedef struct TPP_LIB TPP_INIT_FUNC init; TPP_START_FUNC start; TPP_STOP_FUNC stop; + TPP_TIMER_FUNC timer; }TPP_LIB; typedef std::list tpp_libs; @@ -136,6 +137,7 @@ public: bool load_tpp(const ex_wstr& libfile); void stop_all(void); + void timer(void); // Լ1һ int count(void) { return m_libs.size(); } private: @@ -178,13 +180,15 @@ bool TppManager::load_tpp(const ex_wstr& libname) lib->init = (TPP_INIT_FUNC)GetProcAddress(lib->dylib, "tpp_init"); lib->start = (TPP_START_FUNC)GetProcAddress(lib->dylib, "tpp_start"); lib->stop = (TPP_STOP_FUNC)GetProcAddress(lib->dylib, "tpp_stop"); + lib->timer = (TPP_TIMER_FUNC)GetProcAddress(lib->dylib, "tpp_timer"); #else lib->init = (TPP_INIT_FUNC)dlsym(lib->dylib, "tpp_init"); lib->start = (TPP_START_FUNC)dlsym(lib->dylib, "tpp_start"); - lib->stop = (TPP_STOP_FUNC)dlsym(lib->dylib, "tpp_stop"); + lib->stop = (TPP_STOP_FUNC)dlsym(lib->dylib, "tpp_stop"); + lib->timer = (TPP_TIMER_FUNC)dlsym(lib->dylib, "tpp_timer"); #endif - if (lib->init == NULL || lib->start == NULL || lib->stop == NULL) + if (lib->init == NULL || lib->start == NULL || lib->stop == NULL || lib->timer == NULL) { EXLOGE(L"[core] load dylib `%ls` failed, can not locate all functions.\n", libfile.c_str()); delete lib; @@ -219,8 +223,7 @@ bool TppManager::load_tpp(const ex_wstr& libname) return true; } -void TppManager::stop_all(void) -{ +void TppManager::stop_all(void) { tpp_libs::iterator it = m_libs.begin(); for (; it != m_libs.end(); ++it) { @@ -228,6 +231,14 @@ void TppManager::stop_all(void) } } +void TppManager::timer(void) { + tpp_libs::iterator it = m_libs.begin(); + for (; it != m_libs.end(); ++it) + { + (*it)->timer(); + } +} + int ts_main(void) { ExIniFile& ini = g_env.get_ini(); @@ -302,6 +313,7 @@ int ts_main(void) while (!g_exit_flag) { ex_sleep_ms(1000); + g_tpp_mgr.timer(); } } diff --git a/server/tp_core/protocol/ssh/ssh_proxy.cpp b/server/tp_core/protocol/ssh/ssh_proxy.cpp index 39b0792..beb9ca7 100644 --- a/server/tp_core/protocol/ssh/ssh_proxy.cpp +++ b/server/tp_core/protocol/ssh/ssh_proxy.cpp @@ -68,6 +68,10 @@ bool SshProxy::init(void) return true; } +void SshProxy::timer(void) { + EXLOGV("[ssh] on-timer.\n"); +} + void SshProxy::_thread_loop(void) { EXLOGV("[ssh] TeleportServer-SSH ready on %s:%d\n", m_host_ip.c_str(), m_host_port); diff --git a/server/tp_core/protocol/ssh/ssh_proxy.h b/server/tp_core/protocol/ssh/ssh_proxy.h index 7efd2f6..331aa95 100644 --- a/server/tp_core/protocol/ssh/ssh_proxy.h +++ b/server/tp_core/protocol/ssh/ssh_proxy.h @@ -1,69 +1,70 @@ -#ifndef __SSH_PROXY_H__ -#define __SSH_PROXY_H__ - -#include "ssh_session.h" - -#include - -typedef std::map ts_ssh_sessions; - -typedef struct TS_SFTP_SESSION_INFO -{ - ex_astr host_ip; - int host_port; - ex_astr user_name; - ex_astr user_auth; - int auth_mode; - int ref_count; // üñ¼Ϣssh-sftpͨرգ֮ -}TS_SFTP_SESSION_INFO; - -typedef std::map ts_sftp_sessions; - -class SshProxy : public ExThreadBase -{ -public: - SshProxy(); - ~SshProxy(); - - bool init(void); - - void add_sftp_session_info( - const ex_astr& sid, - const ex_astr& host_ip, - int host_port, - const ex_astr& user_name, - const ex_astr& user_auth, - int auth_mode - ); - bool get_sftp_session_info(const ex_astr& sid, TS_SFTP_SESSION_INFO& info); - void remove_sftp_sid(const ex_astr& sid); - - void session_finished(SshSession* sess); - -protected: - void _thread_loop(void); - void _set_stop_flag(void); - - void _run(void); - -private: - void _dump_sftp_sessions(void); - -private: - ssh_bind m_bind; - bool m_stop_flag; - - ExThreadLock m_lock; - - ex_astr m_host_ip; - int m_host_port; - - ts_ssh_sessions m_sessions; - ts_sftp_sessions m_sftp_sessions; - - ExThreadManager m_thread_mgr; -}; - -extern SshProxy g_ssh_proxy; - -#endif // __SSH_PROXY_H__ +#ifndef __SSH_PROXY_H__ +#define __SSH_PROXY_H__ + +#include "ssh_session.h" + +#include + +typedef std::map ts_ssh_sessions; + +typedef struct TS_SFTP_SESSION_INFO +{ + ex_astr host_ip; + int host_port; + ex_astr user_name; + ex_astr user_auth; + int auth_mode; + int ref_count; // üñ¼Ϣssh-sftpͨرգ֮ +}TS_SFTP_SESSION_INFO; + +typedef std::map ts_sftp_sessions; + +class SshProxy : public ExThreadBase +{ +public: + SshProxy(); + ~SshProxy(); + + bool init(void); + void timer(void); + + void add_sftp_session_info( + const ex_astr& sid, + const ex_astr& host_ip, + int host_port, + const ex_astr& user_name, + const ex_astr& user_auth, + int auth_mode + ); + bool get_sftp_session_info(const ex_astr& sid, TS_SFTP_SESSION_INFO& info); + void remove_sftp_sid(const ex_astr& sid); + + void session_finished(SshSession* sess); + +protected: + void _thread_loop(void); + void _set_stop_flag(void); + + void _run(void); + +private: + void _dump_sftp_sessions(void); + +private: + ssh_bind m_bind; + bool m_stop_flag; + + ExThreadLock m_lock; + + ex_astr m_host_ip; + int m_host_port; + + ts_ssh_sessions m_sessions; + ts_sftp_sessions m_sftp_sessions; + + ExThreadManager m_thread_mgr; +}; + +extern SshProxy g_ssh_proxy; + +#endif // __SSH_PROXY_H__ diff --git a/server/tp_core/protocol/ssh/ssh_recorder.cpp b/server/tp_core/protocol/ssh/ssh_recorder.cpp index ea3bf79..d05586a 100644 --- a/server/tp_core/protocol/ssh/ssh_recorder.cpp +++ b/server/tp_core/protocol/ssh/ssh_recorder.cpp @@ -29,8 +29,8 @@ void TppSshRec::_on_begin(const TPP_CONNECT_INFO* info) // memcpy(m_head.username, info.user_username.c_str(), info.user_username.length() > 15 ? 15 : info.user_username.length()); // memcpy(m_head.ip, info.host_ip.c_str(), info.host_ip.length() > 17 ? 17 : info.host_ip.length()); - memcpy(m_head.basic.acc_username, info->acc_username, strlen(info->acc_username) >= 31 ? 31 : strlen(info->acc_username)); - memcpy(m_head.basic.user_username, info->user_username, strlen(info->user_username) >= 31 ? 31 : strlen(info->user_username)); + memcpy(m_head.basic.acc_username, info->acc_username, strlen(info->acc_username) >= 63 ? 63 : strlen(info->acc_username)); + memcpy(m_head.basic.user_username, info->user_username, strlen(info->user_username) >= 63 ? 63 : strlen(info->user_username)); memcpy(m_head.basic.host_ip, info->host_ip, strlen(info->host_ip) >= 39 ? 39 : strlen(info->host_ip)); memcpy(m_head.basic.conn_ip, info->conn_ip, strlen(info->conn_ip) >= 39 ? 39 : strlen(info->conn_ip)); } diff --git a/server/tp_core/protocol/ssh/tpssh.cpp b/server/tp_core/protocol/ssh/tpssh.cpp index 4831493..5923a8f 100644 --- a/server/tp_core/protocol/ssh/tpssh.cpp +++ b/server/tp_core/protocol/ssh/tpssh.cpp @@ -33,3 +33,7 @@ TPP_API ex_rv tpp_stop(void) g_ssh_proxy.stop(); return 0; } + +TPP_API void tpp_timer(void) { + g_ssh_proxy.timer(); +}