pull/32/merge
Apex Liu 2017-03-08 19:12:37 +08:00
parent 86af784330
commit 83e9b9439e
10 changed files with 57 additions and 120 deletions

View File

@ -6,7 +6,6 @@
#define TS_TRAY_MSG L"Teleport助手正常工作中"
#define TS_HTTP_RPC_PORT 50022
//#define TS_HTTP_RPC_HOST "0.0.0.0"
#define TS_HTTP_RPC_HOST "127.0.0.1"
#endif // __TS_CONST_H__

View File

@ -198,8 +198,6 @@ bool TsHttpRpc::init(const char* ip, int port)
nc->user_data = this;
mg_set_protocol_http_websocket(nc);
mg_enable_multithreading(nc);
m_content_type_map[".js"] = "application/javascript";
m_content_type_map[".png"] = "image/png";

View File

@ -142,12 +142,6 @@ int _app_main(int argc, wchar_t** argv)
}
#endif
// if (!g_env.check_db_file())
// {
// EXLOGE("[tpcore] env init failed.\n");
// return 1;
// }
if (!g_is_debug)
{
if (!_run_daemon())

View File

@ -108,6 +108,7 @@
<AdditionalLibraryDirectories>
</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>libcmt.lib</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>Debug</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

View File

@ -105,20 +105,5 @@ bool TsEnv::init(void)
rpc_bind_port = TS_HTTP_RPC_PORT;
}
// m_db_file = base_path;
// ex_path_join(m_db_file, false, L"data", L"ts_db.db", NULL);
return true;
}
// bool TsEnv::check_db_file(void)
// {
// if (!ex_is_file_exists(m_db_file.c_str()))
// {
// EXLOGE("[core] can not found database file.\n");
// return false;
// }
//
// return true;
// }

View File

@ -10,7 +10,6 @@ public:
~TsEnv();
bool init(void);
// bool check_db_file(void);
ExIniFile& get_ini(void) { return m_ini; }
@ -20,8 +19,6 @@ public:
ex_wstr m_etc_path;
ex_wstr m_replay_path;
//ex_wstr m_db_file;
ex_astr rpc_bind_ip;
int rpc_bind_port;

View File

@ -58,10 +58,8 @@ void TsHttpRpc::_thread_loop(void)
{
EXLOGV("[core-rpc] TeleportServer-HTTP-RPC ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
for (;;)
while(!m_stop_flag)
{
if (m_stop_flag)
break;
mg_mgr_poll(&m_mg_mgr, 500);
}
@ -86,7 +84,6 @@ bool TsHttpRpc::init(void)
else
ex_strformat(addr, 128, "%s:%d", m_host_ip.c_str(), m_host_port);
mg_mgr_init(&m_mg_mgr, NULL);
nc = mg_bind(&m_mg_mgr, addr, _mg_event_handler);
if (NULL == nc)
{
@ -97,7 +94,12 @@ bool TsHttpRpc::init(void)
nc->user_data = this;
mg_set_protocol_http_websocket(nc);
mg_enable_multithreading(nc);
// 导致内存泄露的地方每次请求约消耗1KB内存
// DO NOT USE MULTITHREADING OF MG.
// cpq (one of the authors of MG) commented on 3 Feb: Multithreading support has been removed.
// https://github.com/cesanta/mongoose/commit/707b9ed2d6f177b3ad8787cb16a1bff90ddad992
//mg_enable_multithreading(nc);
return true;
}

View File

@ -3,53 +3,12 @@
#include "ts_http_rpc.h"
#include "ts_web_rpc.h"
#include "ts_env.h"
//#include "ts_http_client.h"
//#include "ts_ver.h"
//#include "ts_crypto.h"
//#include "../common/protocol_interface.h"
#include <mbedtls/platform.h>
#include <mbedtls/debug.h>
//#include <list>
bool g_exit_flag = false;
//static unsigned char ToHex(unsigned char x)
//{
// return x > 9 ? x + 55 : x + 48;
//}
//
//ex_astr UrlEncode(const ex_astr& str)
//{
// ex_astr strTemp = "";
// size_t length = str.length();
// for (size_t i = 0; i < length; i++)
// {
// if (isalnum((unsigned char)str[i]) ||
// (str[i] == '-') ||
// (str[i] == '_') ||
// (str[i] == '.') ||
// (str[i] == '~'))
// {
// strTemp += str[i];
// }
// else if (str[i] == ' ')
// {
// strTemp += "+";
// }
// else
// {
// strTemp += '%';
// strTemp += ToHex((unsigned char)str[i] >> 4);
// strTemp += ToHex((unsigned char)str[i] % 16);
// }
// }
//
// return strTemp;
//}
bool tpp_take_session(const ex_astr& sid, TS_SESSION_INFO& info)
{
return g_session_mgr.take_session(sid, info);
@ -257,13 +216,15 @@ int ts_main(void)
g_exit_flag = true;
}
ts_web_rpc_register_core();
EXLOGV("[core] ---- initialized, ready for service ----\n");
while (!g_exit_flag)
if (!g_exit_flag)
{
ex_sleep_ms(1000);
ts_web_rpc_register_core();
EXLOGV("[core] ---- initialized, ready for service ----\n");
while (!g_exit_flag)
{
ex_sleep_ms(1000);
}
}
g_tpp_mgr.stop_all();

View File

@ -1056,16 +1056,16 @@ ywl.create_table_render = function (tbl, on_created) {
return g.group_name;
};
_tbl_render.command_info = function (row_id, fields) {
var command = get_command_name_by_id(fields.cmd_id);
if (command === null)
return '命令 ' + fields.cmd_id;
else
//return '<a href="#" data-toggle="tooltip" title=\"' + command.cmd_name + '\">' + command.cmd_desc + '</a>';
return '<span data-toggle="tooltip" title=\"' + command.cmd_name + '\">' + command.cmd_desc + '</span>';
//var info = command.cmd_name + ' '+ command.cmd_desc;
//return info;
};
// _tbl_render.command_info = function (row_id, fields) {
// var command = get_command_name_by_id(fields.cmd_id);
// if (command === null)
// return '命令 ' + fields.cmd_id;
// else
// //return '<a href="#" data-toggle="tooltip" title=\"' + command.cmd_name + '\">' + command.cmd_desc + '</a>';
// return '<span data-toggle="tooltip" title=\"' + command.cmd_name + '\">' + command.cmd_desc + '</span>';
// //var info = command.cmd_name + ' '+ command.cmd_desc;
// //return info;
// };
_tbl_render.user_info = function (row_id, fields) {
var user_info = get_user_info_by_id(fields.u_id);
if (user_info === null)
@ -1075,36 +1075,36 @@ ywl.create_table_render = function (tbl, on_created) {
//var info = command.cmd_name + ' '+ command.cmd_desc;
//return info;
};
_tbl_render.event_type = function (row_id, fields) {
var _e_id = fields.id1 + '-' + fields.id2 + '-' + fields.id3 + '-' + fields.id4;
var content = '';
if (_e_id == '3-1-1-100') {
content = '系统性能监控';
return '<a href="#"> ' + content + '</a>';
} else if (_e_id == '3-1-1-107') {
content = 'TCP监听白名单监控';
return '<a href="#"> ' + content + '</a>';
} else if (_e_id == '3-1-1-108') {
content = 'UDP白名单监控';
return '<a href="#"> ' + content + '</a>';
} else if (_e_id == '3-1-1-109') {
content = 'TCP连接白名单监控';
return '<a href="#"> ' + content + '</a>';
} else if (_e_id == '3-1-1-110') {
content = '进程白名单监控';
return '<a href="#"> ' + content + '</a>';
} else if (_e_id == '3-1-1-7') {
content = '系统用户监控';
return '<a href="#"> ' + content + '</a>';
} else {
content = '未知';
return '<a href="#"> ' + content + '</a>';
}
//var info = command.cmd_name + ' '+ command.cmd_desc;
//return info;
};
// _tbl_render.event_type = function (row_id, fields) {
// var _e_id = fields.id1 + '-' + fields.id2 + '-' + fields.id3 + '-' + fields.id4;
// var content = '';
// if (_e_id == '3-1-1-100') {
// content = '系统性能监控';
// return '<a href="#"> ' + content + '</a>';
// } else if (_e_id == '3-1-1-107') {
// content = 'TCP监听白名单监控';
// return '<a href="#"> ' + content + '</a>';
// } else if (_e_id == '3-1-1-108') {
// content = 'UDP白名单监控';
// return '<a href="#"> ' + content + '</a>';
// } else if (_e_id == '3-1-1-109') {
// content = 'TCP连接白名单监控';
// return '<a href="#"> ' + content + '</a>';
// } else if (_e_id == '3-1-1-110') {
// content = '进程白名单监控';
// return '<a href="#"> ' + content + '</a>';
// } else if (_e_id == '3-1-1-7') {
// content = '系统用户监控';
// return '<a href="#"> ' + content + '</a>';
// } else {
// content = '未知';
// return '<a href="#"> ' + content + '</a>';
// }
//
//
// //var info = command.cmd_name + ' '+ command.cmd_desc;
// //return info;
// };
_tbl_render.event_code = function (row_id, fields) {
var _e_id = fields.id1 + '-' + fields.id2 + '-' + fields.id3 + '-' + fields.id4;
var _e_info = get_event_code_by_id(_e_id);

View File

@ -71,7 +71,7 @@
ywl.add_page_options(${page_param});
var danger_cmd = ['rm', 'su', 'sudo'];
var danger_cmd = ['rm', 'su', 'sudo', 'kill'];
var info_cmd = ['exit'];
ywl.on_init = function (cb_stack, cb_args) {