逐步调整const常量在各个模块中的统一。

pull/32/merge
apexliu 2017-03-21 01:19:08 +08:00
parent 738a5cf01e
commit 2cada368e6
10 changed files with 236 additions and 138 deletions

View File

@ -61,7 +61,7 @@
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_WINSOCK_DEPRECATED_NO_WARNINGS;MG_ENABLE_THREADS;MG_DISABLE_HTTP_DIGEST_AUTH;MG_DISABLE_MQTT;MG_DISABLE_SSI;MG_DISABLE_FILESYSTEM;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_WINSOCK_DEPRECATED_NO_WARNINGS;MG_ENABLE_THREADS;MG_DISABLE_HTTP_DIGEST_AUTH;MG_DISABLE_MQTT;MG_DISABLE_SSI;MG_DISABLE_FILESYSTEM;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\common\libex\include;..\..\external\jsoncpp\include;..\..\external\openssl\inc32</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\..\common\teleport;..\..\common\libex\include;..\..\external\jsoncpp\include;..\..\external\openssl\inc32</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -78,7 +78,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_WINSOCK_DEPRECATED_NO_WARNINGS;MG_ENABLE_THREADS;MG_DISABLE_HTTP_DIGEST_AUTH;MG_DISABLE_MQTT;MG_DISABLE_SSI;MG_DISABLE_FILESYSTEM;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_WINSOCK_DEPRECATED_NO_WARNINGS;MG_ENABLE_THREADS;MG_DISABLE_HTTP_DIGEST_AUTH;MG_DISABLE_MQTT;MG_DISABLE_SSI;MG_DISABLE_FILESYSTEM;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\..\common\libex\include;..\..\external\jsoncpp\include;..\..\external\openssl\inc32</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\..\common\teleport;..\..\common\libex\include;..\..\external\jsoncpp\include;..\..\external\openssl\inc32</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile> </ClCompile>
<Link> <Link>
@ -100,6 +100,7 @@
<ClInclude Include="..\..\common\libex\include\ex\ex_thread.h" /> <ClInclude Include="..\..\common\libex\include\ex\ex_thread.h" />
<ClInclude Include="..\..\common\libex\include\ex\ex_types.h" /> <ClInclude Include="..\..\common\libex\include\ex\ex_types.h" />
<ClInclude Include="..\..\common\libex\include\ex\ex_util.h" /> <ClInclude Include="..\..\common\libex\include\ex\ex_util.h" />
<ClInclude Include="..\..\common\teleport\teleport_const.h" />
<ClInclude Include="..\..\external\mongoose\mongoose.h" /> <ClInclude Include="..\..\external\mongoose\mongoose.h" />
<ClInclude Include="dlg_main.h" /> <ClInclude Include="dlg_main.h" />
<ClInclude Include="msocketx.h" /> <ClInclude Include="msocketx.h" />

View File

@ -126,6 +126,9 @@
<ClInclude Include="..\..\common\libex\include\ex\ex_thread.h"> <ClInclude Include="..\..\common\libex\include\ex\ex_thread.h">
<Filter>libex\header</Filter> <Filter>libex\header</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\common\teleport\teleport_const.h">
<Filter>teleport</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Image Include="res\tp.ico"> <Image Include="res\tp.ico">
@ -160,6 +163,9 @@
<Filter Include="libex\src"> <Filter Include="libex\src">
<UniqueIdentifier>{d7d49fa4-5192-42c5-bc70-5584d9d646c6}</UniqueIdentifier> <UniqueIdentifier>{d7d49fa4-5192-42c5-bc70-5584d9d646c6}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="teleport">
<UniqueIdentifier>{1291a5cf-cb08-4ad6-8a86-8a0486297c63}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="tp_assist.rc"> <ResourceCompile Include="tp_assist.rc">

View File

@ -4,6 +4,9 @@
#include <commdlg.h> #include <commdlg.h>
#include <ShlObj.h> #include <ShlObj.h>
#include <teleport_const.h>
#include "ts_http_rpc.h" #include "ts_http_rpc.h"
#include "dlg_main.h" #include "dlg_main.h"
#include "ts_ver.h" #include "ts_ver.h"
@ -335,7 +338,7 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
ex_astr method; ex_astr method;
ex_astr json_param; ex_astr json_param;
unsigned int rv = _this->_parse_request(hm, method, json_param); int rv = _this->_parse_request(hm, method, json_param);
if (0 != rv) if (0 != rv)
{ {
EXLOGE("[ERROR] http-rpc got invalid request.\n"); EXLOGE("[ERROR] http-rpc got invalid request.\n");
@ -355,10 +358,10 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
} }
} }
unsigned int TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_cmd, ex_astr& func_args) int TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_cmd, ex_astr& func_args)
{ {
if (NULL == req) if (NULL == req)
return TSR_INVALID_REQUEST; return TPE_FAILED;
bool is_get = true; bool is_get = true;
if (req->method.len == 3 && 0 == memcmp(req->method.p, "GET", req->method.len)) if (req->method.len == 3 && 0 == memcmp(req->method.p, "GET", req->method.len))
@ -366,7 +369,7 @@ unsigned int TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_c
else if (req->method.len == 4 && 0 == memcmp(req->method.p, "POST", req->method.len)) else if (req->method.len == 4 && 0 == memcmp(req->method.p, "POST", req->method.len))
is_get = false; is_get = false;
else else
return TSR_INVALID_REQUEST; return TPE_HTTP_METHOD;
ex_astrs strs; ex_astrs strs;
@ -394,7 +397,7 @@ unsigned int TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_c
} }
if (0 == strs.size()) if (0 == strs.size())
return TSR_INVALID_REQUEST; return TPE_PARAM;
if (is_get) if (is_get)
{ {
@ -409,7 +412,7 @@ unsigned int TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_c
} }
else else
{ {
return TSR_INVALID_REQUEST; return TPE_PARAM;
} }
} }
else else
@ -420,7 +423,7 @@ unsigned int TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_c
} }
else else
{ {
return TSR_INVALID_REQUEST; return TPE_PARAM;
} }
if (req->body.len > 0) if (req->body.len > 0)
@ -437,14 +440,14 @@ unsigned int TsHttpRpc::_parse_request(struct http_message* req, ex_astr& func_c
sztmp.resize(len); sztmp.resize(len);
memset(&sztmp[0], 0, len); memset(&sztmp[0], 0, len);
if (-1 == ts_url_decode(func_args.c_str(), func_args.length(), &sztmp[0], len, 0)) if (-1 == ts_url_decode(func_args.c_str(), func_args.length(), &sztmp[0], len, 0))
return TSR_INVALID_URL_ENCODE; return TPE_HTTP_URL_ENCODE;
func_args = &sztmp[0]; func_args = &sztmp[0];
} }
EXLOGV("[rpc] method=%s, json_param=%s\n", func_cmd.c_str(), func_args.c_str()); EXLOGV("[rpc] method=%s, json_param=%s\n", func_cmd.c_str(), func_args.c_str());
return TSR_OK; return TPE_OK;
} }
void TsHttpRpc::_process_js_request(const ex_astr& func_cmd, const ex_astr& func_args, ex_astr& buf) void TsHttpRpc::_process_js_request(const ex_astr& func_cmd, const ex_astr& func_args, ex_astr& buf)
@ -480,7 +483,7 @@ void TsHttpRpc::_process_js_request(const ex_astr& func_cmd, const ex_astr& func
else else
{ {
EXLOGE("[rpc] got unknown command: %s\n", func_cmd.c_str()); EXLOGE("[rpc] got unknown command: %s\n", func_cmd.c_str());
_create_json_ret(buf, TSR_NO_SUCH_METHOD); _create_json_ret(buf, TPE_UNKNOWN_CMD);
} }
} }
@ -514,12 +517,12 @@ void TsHttpRpc::_rpc_func_create_ts_client(const ex_astr& func_args, ex_astr& bu
if (!jreader.parse(func_args.c_str(), jsRoot)) if (!jreader.parse(func_args.c_str(), jsRoot))
{ {
_create_json_ret(buf, TSR_INVALID_JSON_FORMAT); _create_json_ret(buf, TPE_JSON_FORMAT);
return; return;
} }
if (jsRoot.isArray()) if (jsRoot.isArray())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
@ -529,7 +532,7 @@ void TsHttpRpc::_rpc_func_create_ts_client(const ex_astr& func_args, ex_astr& bu
|| !jsRoot["session_id"].isString() || !jsRoot["pro_type"].isNumeric() || !jsRoot["session_id"].isString() || !jsRoot["pro_type"].isNumeric()
) )
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
@ -862,12 +865,12 @@ void TsHttpRpc::_rpc_func_create_ts_client(const ex_astr& func_args, ex_astr& bu
if (!CreateProcess(NULL, (wchar_t *)w_exe_path.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) if (!CreateProcess(NULL, (wchar_t *)w_exe_path.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{ {
EXLOGE(_T("CreateProcess() failed. Error=0x%08X.\n %s\n"), GetLastError(), w_exe_path.c_str()); EXLOGE(_T("CreateProcess() failed. Error=0x%08X.\n %s\n"), GetLastError(), w_exe_path.c_str());
root_ret["code"] = TSR_CREATE_PROCESS_ERROR; root_ret["code"] = TPE_START_CLIENT;
_create_json_ret(buf, root_ret); _create_json_ret(buf, root_ret);
return; return;
} }
root_ret["code"] = TSR_OK; root_ret["code"] = TPE_OK;
_create_json_ret(buf, root_ret); _create_json_ret(buf, root_ret);
} }
@ -919,12 +922,12 @@ void TsHttpRpc::_rpc_func_ts_check(const ex_astr& func_args, ex_astr& buf)
if (!jreader.parse(func_args.c_str(), jsRoot)) if (!jreader.parse(func_args.c_str(), jsRoot))
{ {
_create_json_ret(buf, TSR_INVALID_JSON_FORMAT); _create_json_ret(buf, TPE_JSON_FORMAT);
return; return;
} }
if (jsRoot.isArray()) if (jsRoot.isArray())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
int windows_size = 2; int windows_size = 2;
@ -936,7 +939,7 @@ void TsHttpRpc::_rpc_func_ts_check(const ex_astr& func_args, ex_astr& buf)
|| !jsRoot["rdp_port"].isNumeric() || !jsRoot["rdp_port"].isNumeric()
) )
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
@ -959,7 +962,7 @@ void TsHttpRpc::_rpc_func_ts_check(const ex_astr& func_args, ex_astr& buf)
if ((hptr = gethostbyname(ptr)) == NULL) if ((hptr = gethostbyname(ptr)) == NULL)
{ {
//printf("gethostbyname error for host:%s/n", ptr); //printf("gethostbyname error for host:%s/n", ptr);
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; /* 如果调用gethostbyname发生错误返回1 */ return; /* 如果调用gethostbyname发生错误返回1 */
} }
/* 将主机的规范名打出来 */ /* 将主机的规范名打出来 */
@ -988,24 +991,24 @@ void TsHttpRpc::_rpc_func_ts_check(const ex_astr& func_args, ex_astr& buf)
} }
if (!isIPAddress(server_ip.c_str())) if (!isIPAddress(server_ip.c_str()))
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
if (TestTCPPort(server_ip, rdp_port) && TestTCPPort(server_ip, ssh_port)) if (TestTCPPort(server_ip, rdp_port) && TestTCPPort(server_ip, ssh_port))
{ {
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
ICMPheaderRet temp = { 0 }; ICMPheaderRet temp = { 0 };
int b_ok = ICMPSendTo(&temp, (char*)server_ip.c_str(), 16, 8); int b_ok = ICMPSendTo(&temp, (char*)server_ip.c_str(), 16, 8);
if (b_ok == 0) if (b_ok == 0)
{ {
_create_json_ret(buf, TSR_PING_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
else else
{ {
_create_json_ret(buf, TSR_PING_ERROR); _create_json_ret(buf, TPE_NETWORK);
} }
return; return;
@ -1018,24 +1021,24 @@ void TsHttpRpc::_rpc_func_ts_rdp_play(const ex_astr& func_args, ex_astr& buf)
if (!jreader.parse(func_args.c_str(), jsRoot)) if (!jreader.parse(func_args.c_str(), jsRoot))
{ {
_create_json_ret(buf, TSR_INVALID_JSON_FORMAT); _create_json_ret(buf, TPE_JSON_FORMAT);
return; return;
} }
// 判断参数是否正确 // 判断参数是否正确
if (!jsRoot["host"].isString()) if (!jsRoot["host"].isString())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
if (!jsRoot["port"].isInt()) if (!jsRoot["port"].isInt())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
if (!jsRoot["tail"].isString()) if (!jsRoot["tail"].isString())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
ex_astr a_host = jsRoot["host"].asCString(); ex_astr a_host = jsRoot["host"].asCString();
@ -1057,7 +1060,7 @@ void TsHttpRpc::_rpc_func_ts_rdp_play(const ex_astr& func_args, ex_astr& buf)
if ((hptr = gethostbyname(ptr)) == NULL) if ((hptr = gethostbyname(ptr)) == NULL)
{ {
//printf("gethostbyname error for host:%s/n", ptr); //printf("gethostbyname error for host:%s/n", ptr);
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
/* 将主机的规范名打出来 */ /* 将主机的规范名打出来 */
@ -1120,12 +1123,12 @@ void TsHttpRpc::_rpc_func_ts_rdp_play(const ex_astr& func_args, ex_astr& buf)
if (!CreateProcess(NULL, (wchar_t *)w_exe_path.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) if (!CreateProcess(NULL, (wchar_t *)w_exe_path.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{ {
EXLOGE(_T("CreateProcess() failed. Error=0x%08X.\n %s\n"), GetLastError(), w_exe_path.c_str()); EXLOGE(_T("CreateProcess() failed. Error=0x%08X.\n %s\n"), GetLastError(), w_exe_path.c_str());
root_ret["code"] = TSR_CREATE_PROCESS_ERROR; root_ret["code"] = TPE_START_CLIENT;
_create_json_ret(buf, root_ret); _create_json_ret(buf, root_ret);
return; return;
} }
root_ret["code"] = TSR_OK; root_ret["code"] = TPE_OK;
_create_json_ret(buf, root_ret); _create_json_ret(buf, root_ret);
return; return;
} }
@ -1137,13 +1140,13 @@ void TsHttpRpc::_rpc_func_get_config(const ex_astr& func_args, ex_astr& buf)
if (!jreader.parse(func_args.c_str(), jsRoot)) if (!jreader.parse(func_args.c_str(), jsRoot))
{ {
_create_json_ret(buf, TSR_INVALID_JSON_FORMAT); _create_json_ret(buf, TPE_JSON_FORMAT);
return; return;
} }
// 判断参数是否正确 // 判断参数是否正确
if (!jsRoot["type"].isNumeric()) if (!jsRoot["type"].isNumeric())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
int type = jsRoot["type"].asUInt(); int type = jsRoot["type"].asUInt();
@ -1278,7 +1281,7 @@ void TsHttpRpc::_rpc_func_get_config(const ex_astr& func_args, ex_astr& buf)
} }
else else
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
} }
@ -1290,12 +1293,12 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
if (!jreader.parse(func_args.c_str(), jsRoot)) if (!jreader.parse(func_args.c_str(), jsRoot))
{ {
_create_json_ret(buf, TSR_INVALID_JSON_FORMAT); _create_json_ret(buf, TPE_JSON_FORMAT);
return; return;
} }
if (jsRoot.isArray()) if (jsRoot.isArray())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
@ -1304,7 +1307,7 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
!jsRoot["commandline"].isString() || !jsRoot["commandline"].isString() ||
!jsRoot["type"].isNumeric()) !jsRoot["type"].isNumeric())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
int type = jsRoot["type"].asUInt(); int type = jsRoot["type"].asUInt();
@ -1325,7 +1328,7 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
clientsetmap::iterator it = g_cfgSSH.m_clientsetmap.find(w_name); clientsetmap::iterator it = g_cfgSSH.m_clientsetmap.find(w_name);
if (it == g_cfgSSH.m_clientsetmap.end()) { if (it == g_cfgSSH.m_clientsetmap.end()) {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
if (it->second.is_default) if (it->second.is_default)
@ -1333,7 +1336,7 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
g_cfgSSH.set(_T("common"), _T("current_client"), w_name); g_cfgSSH.set(_T("common"), _T("current_client"), w_name);
g_cfgSSH.save(); g_cfgSSH.save();
g_cfgSSH.init(); g_cfgSSH.init();
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
g_cfgSSH.set(w_name, _T("path"), w_path); g_cfgSSH.set(w_name, _T("path"), w_path);
@ -1342,7 +1345,7 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
g_cfgSSH.save(); g_cfgSSH.save();
g_cfgSSH.init(); g_cfgSSH.init();
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
@ -1350,7 +1353,7 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
{ {
clientsetmap::iterator it = g_cfgScp.m_clientsetmap.find(w_name); clientsetmap::iterator it = g_cfgScp.m_clientsetmap.find(w_name);
if (it == g_cfgScp.m_clientsetmap.end()) { if (it == g_cfgScp.m_clientsetmap.end()) {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
if (it->second.is_default) if (it->second.is_default)
@ -1358,7 +1361,7 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
g_cfgScp.set(_T("common"), _T("current_client"), w_name); g_cfgScp.set(_T("common"), _T("current_client"), w_name);
g_cfgScp.save(); g_cfgScp.save();
g_cfgScp.init(); g_cfgScp.init();
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
g_cfgScp.set(w_name, _T("path"), w_path); g_cfgScp.set(w_name, _T("path"), w_path);
@ -1367,14 +1370,14 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
g_cfgScp.save(); g_cfgScp.save();
g_cfgScp.init(); g_cfgScp.init();
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
else if (type == 3) else if (type == 3)
{ {
clientsetmap::iterator it = g_cfgTelnet.m_clientsetmap.find(w_name); clientsetmap::iterator it = g_cfgTelnet.m_clientsetmap.find(w_name);
if (it == g_cfgTelnet.m_clientsetmap.end()) { if (it == g_cfgTelnet.m_clientsetmap.end()) {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
if (it->second.is_default) if (it->second.is_default)
@ -1382,7 +1385,7 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
g_cfgTelnet.set(_T("common"), _T("current_client"), w_name); g_cfgTelnet.set(_T("common"), _T("current_client"), w_name);
g_cfgTelnet.save(); g_cfgTelnet.save();
g_cfgTelnet.init(); g_cfgTelnet.init();
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
g_cfgTelnet.set(w_name, _T("path"), w_path); g_cfgTelnet.set(w_name, _T("path"), w_path);
@ -1391,11 +1394,11 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
g_cfgTelnet.save(); g_cfgTelnet.save();
g_cfgTelnet.init(); g_cfgTelnet.init();
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
else { else {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
} }
@ -1407,13 +1410,13 @@ void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf) {
if (!jreader.parse(func_args.c_str(), jsRoot)) if (!jreader.parse(func_args.c_str(), jsRoot))
{ {
_create_json_ret(buf, TSR_INVALID_JSON_FORMAT); _create_json_ret(buf, TPE_JSON_FORMAT);
return; return;
} }
// 判断参数是否正确 // 判断参数是否正确
if (!jsRoot["action"].isNumeric()) if (!jsRoot["action"].isNumeric())
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
int action = jsRoot["action"].asUInt(); int action = jsRoot["action"].asUInt();
@ -1483,7 +1486,7 @@ void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf) {
if (wsDefaultPath.length() == 0) if (wsDefaultPath.length() == 0)
{ {
_create_json_ret(buf, TSR_INVALID_JSON_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
@ -1518,13 +1521,13 @@ void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf) {
} }
else else
{ {
_create_json_ret(buf, TSR_OK); _create_json_ret(buf, TPE_OK);
return; return;
} }
} }
else else
{ {
_create_json_ret(buf, TSR_INVALID_DATA); _create_json_ret(buf, TPE_DATA);
return; return;
} }
} }
@ -1536,7 +1539,7 @@ void TsHttpRpc::_rpc_func_get_version(const ex_astr& func_args, ex_astr& buf)
ex_astr version; ex_astr version;
ex_wstr2astr(w_version, version, EX_CODEPAGE_UTF8); ex_wstr2astr(w_version, version, EX_CODEPAGE_UTF8);
root_ret["version"] = version; root_ret["version"] = version;
root_ret["code"] = TSR_OK; root_ret["code"] = TPE_OK;
_create_json_ret(buf, root_ret); _create_json_ret(buf, root_ret);
return; return;
} }

View File

@ -13,25 +13,25 @@
#include "../../external/mongoose/mongoose.h" #include "../../external/mongoose/mongoose.h"
typedef ex_u32 ts_rv; // typedef ex_u32 ts_rv;
#define TSR_OK 0x0000 // #define TSR_OK 0x0000
#define TSR_INVALID_DATA 0x0001 // #define TSR_INVALID_DATA 0x0001
#define TSR_SEND_ERROR 0x0002 // #define TSR_SEND_ERROR 0x0002
#define TSR_NEED_MORE_DATA 0x0005 // #define TSR_NEED_MORE_DATA 0x0005
#define TSR_FAILED 0x0006 // #define TSR_FAILED 0x0006
#define TSR_PING_OK 0x0007 // #define TSR_PING_OK 0x0007
#define TSR_PING_ERROR 0x0008 // #define TSR_PING_ERROR 0x0008
//
#define TSR_INVALID_REQUEST 0x1000 // #define TSR_INVALID_REQUEST 0x1000
#define TSR_INVALID_URI 0x1001 // #define TSR_INVALID_URI 0x1001
#define TSR_INVALID_URL_ENCODE 0x1002 // #define TSR_INVALID_URL_ENCODE 0x1002
#define TSR_NO_SUCH_METHOD 0x1003 // #define TSR_NO_SUCH_METHOD 0x1003
#define TSR_INVALID_JSON_FORMAT 0x1004 // #define TSR_INVALID_JSON_FORMAT 0x1004
#define TSR_INVALID_JSON_PARAM 0x1005 // #define TSR_INVALID_JSON_PARAM 0x1005
#define TSR_CREATE_PROCESS_ERROR 0x1006 // #define TSR_CREATE_PROCESS_ERROR 0x1006
#define TSR_OPENFILE_ERROR 0x1007 // #define TSR_OPENFILE_ERROR 0x1007
#define TSR_GETTEMPPATH_ERROR 0x1007 // #define TSR_GETTEMPPATH_ERROR 0x1007
/* /*
//================================================================= //=================================================================
@ -97,7 +97,7 @@ public:
}; };
private: private:
unsigned int _parse_request(struct http_message* req, ex_astr& func_cmd, ex_astr& func_args); int _parse_request(struct http_message* req, ex_astr& func_cmd, ex_astr& func_args);
void _process_js_request(const ex_astr& func_cmd, const ex_astr& func_args, ex_astr& buf); void _process_js_request(const ex_astr& func_cmd, const ex_astr& func_args, ex_astr& buf);
void _create_json_ret(ex_astr& buf, int errcode); void _create_json_ret(ex_astr& buf, int errcode);
void _create_json_ret(ex_astr& buf, Json::Value& jr_root); void _create_json_ret(ex_astr& buf, Json::Value& jr_root);

View File

@ -0,0 +1,56 @@
#ifndef __TELEPORT_CONST_H__
#define __TELEPORT_CONST_H__
// 本文件设定teleport各个模块之间通讯时的错误值JSON数据包括
// - WEB界面与助手
// - WEB界面与WEB后台
// - WEB后台与CORE核心服务
// 成功
#define TPE_OK 0
//-------------------------------------------------------
// 通用错误值
//-------------------------------------------------------
#define TPE_NEED_MORE_DATA 1 // 需要更多数据(不一定是错误)
// 100~299是通用错误值
#define TPE_FAILED 100 // 内部错误
#define TPE_NETWORK 101 // 网络错误
// HTTP请求相关错误
#define TPE_HTTP_METHOD 120 // 无效的请求方法不是GET/POST等或者错误的请求方法例如需要POST却使用GET方式请求
#define TPE_HTTP_URL_ENCODE 121 // URL编码错误无法解码
//#define TPE_HTTP_URI 122 // 无效的URI
#define TPE_UNKNOWN_CMD 124 // 未知的命令
#define TPE_JSON_FORMAT 125 // 错误的JSON格式需要JSON格式数据但是却无法按JSON格式解码
#define TPE_PARAM 126 // 参数错误
#define TPE_DATA 127 // 数据错误
// #define TPE_OPENFILE_ERROR 0x1007 // 无法打开文件
// #define TPE_GETTEMPPATH_ERROR 0x1007
//-------------------------------------------------------
// 助手程序专用错误值
//-------------------------------------------------------
#define TPE_NO_ASSIST 100000 // 未能检测到助手程序
#define TPE_OLD_ASSIST 100001 // 助手程序版本太低
#define TPE_START_CLIENT 100002 // 无法启动客户端程序(无法创建进程)
//-------------------------------------------------------
// 核心服务专用错误值
//-------------------------------------------------------
#define TPE_NO_CORE_SERVER 200000 // 未能检测到核心服务
#endif // __TELEPORT_CONST_H__

View File

@ -1,4 +1,3 @@
/*! ywl v1.0.1, (c)2015 eomsoft.net */
"use strict"; "use strict";
var OS_TYPE_WINDOWS = 1; var OS_TYPE_WINDOWS = 1;
@ -73,10 +72,10 @@ ywl.on_init = function (cb_stack, cb_args) {
$("#tp-assist-current-version").text("当前助手版本:" + ret.version); $("#tp-assist-current-version").text("当前助手版本:" + ret.version);
}, },
function (ret, code, error) { function (ret, code, error) {
if (code == TP_ERR_NO_ASSIST) { if (code == TPE_NO_ASSIST) {
$("#tp-assist-current-version").text("未能检测到TP助手请您下载并启动TP助手"); $("#tp-assist-current-version").text("未能检测到TP助手请您下载并启动TP助手");
g_assist.alert_assist_not_found(); g_assist.alert_assist_not_found();
} else if (code == TP_ERR_VERSION_TOO_LOW) { } else if (code == TPE_OLD_ASSIST) {
ywl.notify_error(error); ywl.notify_error(error);
$('#tp-assist-current-version').html('当前助手版本太低v' + ret.version + '),请<a href="http://teleport.eomsoft.net/static/download/teleport-assist-last-win.zip">下载最新版本</a>!'); $('#tp-assist-current-version').html('当前助手版本太低v' + ret.version + '),请<a href="http://teleport.eomsoft.net/static/download/teleport-assist-last-win.zip">下载最新版本</a>!');
} else { } else {
@ -445,7 +444,7 @@ ywl.on_host_table_created = function (tbl) {
console.log('远程连接建立成功!') console.log('远程连接建立成功!')
}, },
function (code, error) { function (code, error) {
if (code == TP_ERR_NO_ASSIST) if (code == TPE_NO_ASSIST)
g_assist.alert_assist_not_found(); g_assist.alert_assist_not_found();
else { else {
ywl.notify_error(error); ywl.notify_error(error);
@ -1104,7 +1103,7 @@ ywl.create_sys_user = function (tbl) {
console.log('远程连接建立成功!') console.log('远程连接建立成功!')
}, },
function (code, error) { function (code, error) {
if (code == TP_ERR_NO_ASSIST) if (code == TPE_NO_ASSIST)
g_assist.alert_assist_not_found(); g_assist.alert_assist_not_found();
else { else {
ywl.notify_error(error); ywl.notify_error(error);

View File

@ -23,16 +23,16 @@ ywl.on_init = function (cb_stack, cb_args) {
$("#tp-assist-current-version").text("当前助手版本:" + ret.version); $("#tp-assist-current-version").text("当前助手版本:" + ret.version);
}, },
function (ret, code, error) { function (ret, code, error) {
if (code == TP_ERR_NO_ASSIST) { if (code == TPE_NO_ASSIST) {
$("#tp-assist-current-version").text("未能检测到TP助手请您下载并启动TP助手") $("#tp-assist-current-version").text("未能检测到TP助手请您下载并启动TP助手")
g_assist.alert_assist_not_found(); g_assist.alert_assist_not_found();
} }
else if (code == TP_ERR_VERSION_TOO_LOW) { else if (code == TPE_OLD_ASSIST) {
ywl.notify_error(error); ywl.notify_error(error);
$('#tp-assist-current-version').html('当前助手版本太低v' + ret.version + '),请<a href="http://teleport.eomsoft.net/static/download/teleport-assist-last-win.zip">下载最新版本</a>!'); $('#tp-assist-current-version').html('当前助手版本太低v' + ret.version + '),请<a href="http://teleport.eomsoft.net/static/download/teleport-assist-last-win.zip">下载最新版本</a>!');
} }
else { else {
$("#tp-assist-current-version").text(error) $("#tp-assist-current-version").text(error);
ywl.notify_error(error); ywl.notify_error(error);
console.log('error:', error) console.log('error:', error)
@ -146,7 +146,7 @@ ywl.on_host_table_created = function (tbl) {
console.log('远程连接建立成功!') console.log('远程连接建立成功!')
}, },
function (code, error) { function (code, error) {
if (code == TP_ERR_NO_ASSIST) if (code == TPE_NO_ASSIST)
g_assist.alert_assist_not_found(); g_assist.alert_assist_not_found();
else { else {
ywl.notify_error(error); ywl.notify_error(error);
@ -201,7 +201,7 @@ ywl.on_host_table_created = function (tbl) {
console.log('远程连接建立成功!') console.log('远程连接建立成功!')
}, },
function (code, error) { function (code, error) {
if (code == TP_ERR_NO_ASSIST) if (code == TPE_NO_ASSIST)
g_assist.alert_assist_not_found(); g_assist.alert_assist_not_found();
else { else {
ywl.notify_error(error); ywl.notify_error(error);

View File

@ -185,14 +185,13 @@ ywl.on_host_table_created = function (tbl) {
start_rdp_replay(args, start_rdp_replay(args,
function () { function () {
ywl.notify_success('RDP 录像播放器成功启动!'); ywl.notify_success('RDP 录像播放器成功启动!');
//console.log('RDP 录像播放器成功启动!')
}, },
function (code, error) { function (code, msg) {
if (code == TP_ERR_NO_ASSIST) if (code == TPE_NO_ASSIST)
g_assist.alert_assist_not_found(); g_assist.alert_assist_not_found();
else { else {
ywl.notify_error(error); ywl.notify_error(msg);
console.log('error:', error) console.log('error:', msg)
} }
}); });
}); });

View File

@ -1,16 +1,5 @@
/**
* Created by mi on 2016/6/28.
*/
"use strict"; "use strict";
var TP_ERR_NETWORK = 1;
var TP_ERR_START_CLIENT = 2;
var TP_ERR_NO_ASSIST = 3;
//var TP_ERR_ASSIST_DENIED = 4;
var TP_ERR_CORE_SRV = 5;
var TP_ERR_TRIAL_LIMITED = 6;
var TP_ERR_VERSION_TOO_LOW = 7;
var g_low_version = ""; var g_low_version = "";
var g_last_version = ""; var g_last_version = "";
var g_current_version = ""; var g_current_version = "";
@ -18,23 +7,23 @@ var g_current_version = "";
var g_host_name = window.location.hostname; var g_host_name = window.location.hostname;
var error_process = function (ret, func_success, func_error) { var error_process = function (ret, func_success, func_error) {
console.log("ret", ret); // console.log("ret", ret);
var code = ret.code; var code = ret.code;
if (code == 0) { if (code == TPE_OK) {
func_success(ret); func_success(ret);
return; return;
} }
if (code == 0x1006) { if (code == TPE_START_CLIENT) {
func_error(TP_ERR_START_CLIENT, '启动本地客户端进程失败,请检查命令行是否正确:' + ret.path); func_error(TPE_START_CLIENT, '启动本地客户端进程失败,请检查命令行是否正确:' + ret.path);
console.log('启动本地进程失败,命令行:', ret.path); console.log('启动本地进程失败,命令行:', ret.path);
} else if (code == 0x1004) { } else if (code == TPE_JSON_FORMAT || code == TPE_PARAM) {
func_error(TP_ERR_START_CLIENT, "启动本地客户端进程失败:启动参数错误!"); func_error(TPE_START_CLIENT, "启动本地客户端进程失败:启动参数错误!");
} else if (code == TP_ERR_VERSION_TOO_LOW) { } else if (code == TPE_OLD_ASSIST) {
func_error(TP_ERR_VERSION_TOO_LOW, '助手版本太低,请下载最新版本!'); func_error(TPE_OLD_ASSIST, '助手版本太低,请下载最新版本!');
} }
else { else {
func_error(TP_ERR_START_CLIENT, '启动本地客户端失败,错误代码:' + ret.code); func_error(TPE_START_CLIENT, '启动本地客户端失败,错误代码:' + ret.code);
} }
}; };
@ -56,11 +45,11 @@ var teleport_init = function (low_version, last_version, func_success, func_erro
if (version_compare()) { if (version_compare()) {
error_process(ret, func_success, func_error); error_process(ret, func_success, func_error);
} else { } else {
func_error(ret, TP_ERR_VERSION_TOO_LOW, '助手版本太低,请<a style="color:#aaaaff;" href="http://teleport.eomsoft.net/static/download/teleport-assist-last-win.zip">下载最新版本</a>'); func_error(ret, TPE_OLD_ASSIST, '助手版本太低,请<a style="color:#aaaaff;" href="http://teleport.eomsoft.net/static/download/teleport-assist-last-win.zip">下载最新版本</a>');
} }
}, },
error: function (jqXhr) { error: function (jqXhr) {
func_error({}, TP_ERR_NO_ASSIST, '无法连接到teleport助手可能尚未启动'); func_error({}, TPE_NO_ASSIST, '无法连接到teleport助手可能尚未启动');
} }
}); });
}; };
@ -109,15 +98,15 @@ var to_teleport = function (url, args, func_success, func_error) {
error_process(ret, func_success, func_error); error_process(ret, func_success, func_error);
}, },
error: function (jqXhr) { error: function (jqXhr) {
func_error(TP_ERR_NO_ASSIST, '无法连接到teleport助手可能尚未启动'); func_error(TPE_NO_ASSIST, '无法连接到teleport助手可能尚未启动');
} }
}); });
} else { } else {
func_error(TP_ERR_CORE_SRV, '远程连接请求失败可能teleport核心服务尚未启动'); func_error(TPE_NO_CORE_SERVER, '远程连接请求失败可能teleport核心服务尚未启动');
} }
}, },
error: function () { error: function () {
func_error(TP_ERR_NETWORK, '远程网络通讯失败!'); func_error(TPE_NETWORK, '远程网络通讯失败!');
} }
}); });
}; };
@ -158,15 +147,15 @@ var to_admin_teleport = function (url, args, func_success, func_error) {
error_process(ret, func_success, func_error); error_process(ret, func_success, func_error);
}, },
error: function () { error: function () {
func_error(TP_ERR_NO_ASSIST, '无法连接到teleport助手可能尚未启动'); func_error(TPE_NO_ASSIST, '无法连接到teleport助手可能尚未启动');
} }
}); });
} else { } else {
func_error(TP_ERR_CORE_SRV, '远程连接请求失败可能teleport核心服务尚未启动'); func_error(TPE_NO_CORE_SERVER, '远程连接请求失败可能teleport核心服务尚未启动');
} }
}, },
error: function () { error: function () {
func_error(TP_ERR_NETWORK, '远程网络通讯失败!'); func_error(TPE_NETWORK, '远程网络通讯失败!');
} }
}); });
}; };
@ -210,15 +199,15 @@ var to_admin_fast_teleport = function (url, args, func_success, func_error) {
console.log('e', _e); console.log('e', _e);
console.log('state:', jqXhr.state()); console.log('state:', jqXhr.state());
func_error(TP_ERR_NO_ASSIST, '无法连接到teleport助手可能尚未启动'); func_error(TPE_NO_ASSIST, '无法连接到teleport助手可能尚未启动');
} }
}); });
} else { } else {
func_error(TP_ERR_CORE_SRV, '远程连接请求失败可能teleport核心服务尚未启动'); func_error(TPE_NO_CORE_SERVER, '远程连接请求失败可能teleport核心服务尚未启动');
} }
}, },
error: function () { error: function () {
func_error(TP_ERR_NETWORK, '远程网络通讯失败!'); func_error(TPE_NETWORK, '远程网络通讯失败!');
} }
}); });
}; };
@ -233,15 +222,15 @@ var start_rdp_replay = function (args, func_success, func_error) {
jsonp: 'callback', jsonp: 'callback',
dataType: 'json', dataType: 'json',
success: function (ret) { success: function (ret) {
if (ret.code === 0) { if (ret.code === TPE_OK) {
error_process(ret, func_success, func_error); error_process(ret, func_success, func_error);
} else { } else {
func_error(1, '查看录像失败!'); func_error(ret.code, '查看录像失败!');
} }
console.log('ret', ret); console.log('ret', ret);
}, },
error: function () { error: function () {
func_error(TP_ERR_NETWORK, '远程网络通讯失败!'); func_error(TPE_NETWORK, '远程网络通讯失败!');
} }
}); });
}; };

View File

@ -1,4 +1,3 @@
/*! ywl v1.0.1, (c)2016 eomsoft.net */
"use strict"; "use strict";
var USER_TYPE_TEAM_MEMBER = 1; var USER_TYPE_TEAM_MEMBER = 1;
@ -35,27 +34,73 @@ var SECONDS_PER_MINUTE = 60;
var system_group = [ var system_group = [
{id: 0, name: '全部'}, {id: 0, name: '全部'},
{id: -1}, {id: -1},
{id: 1, name: 'Windows'}, {id: 1, name: 'Windows'},
{id: -1}, {id: -1},
{id: 2, name: 'Linux'} {id: 2, name: 'Linux'}
]; ];
var paging_normal = { var paging_normal = {
use_cookie: true, use_cookie: true,
default_select: '25', default_select: '25',
selections: [ selections: [
{name: '10', val: 10}, {name: '10', val: 10},
{name: "25", val: 25}, {name: "25", val: 25},
{name: "50", val: 50}, {name: "50", val: 50},
{name: "100", val: 100}] {name: "100", val: 100}]
}; };
var paging_big = { var paging_big = {
use_cookie: false, use_cookie: false,
default_select: '100', default_select: '100',
selections: [{name: "100", val: 100}] selections: [{name: "100", val: 100}]
}; };
//========================================================
// 错误值(请参考源代码/common/teleport/teleport_const.h
//========================================================
var TPE_OK = 0;
//-------------------------------------------------------
// 通用错误值
//-------------------------------------------------------
var TPE_NEED_MORE_DATA = 1; // 需要更多数据(不一定是错误)
// 100~299是通用错误值
var TPE_FAILED = 100; // 内部错误
var TPE_NETWORK = 101; // 网络错误
// HTTP请求相关错误
var TPE_HTTP_METHOD = 120; // 无效的请求方法不是GET/POST等或者错误的请求方法例如需要POST却使用GET方式请求
var TPE_HTTP_URL_ENCODE = 121; // URL编码错误无法解码
//#define TPE_HTTP_URI 122 // 无效的URI
var TPE_UNKNOWN_CMD = 124; // 未知的命令
var TPE_JSON_FORMAT = 125; // 错误的JSON格式需要JSON格式数据但是却无法按JSON格式解码
var TPE_PARAM = 126; // 参数错误
var TPE_DATA = 127; // 数据错误
// #define TPE_OPENFILE_ERROR 0x1007 // 无法打开文件
// #define TPE_GETTEMPPATH_ERROR 0x1007
//-------------------------------------------------------
// 助手程序专用错误值
//-------------------------------------------------------
var TPE_NO_ASSIST = 100000; // 未能检测到助手程序
var TPE_OLD_ASSIST = 100001; // 助手程序版本太低
var TPE_START_CLIENT = 100002; // 无法启动客户端程序(无法创建进程)
//-------------------------------------------------------
// 核心服务专用错误值
//-------------------------------------------------------
var TPE_NO_CORE_SERVER = 200000; // 未能检测到核心服务