mirror of https://github.com/tp4a/teleport
1. 去掉在rdp的sid前填写的两个字节;2. 格式化部分代码。
parent
e82eecfd04
commit
e9de6513eb
|
@ -692,8 +692,8 @@ class BuilderMacOS(BuilderBase):
|
||||||
cc.w('already exists, skip.')
|
cc.w('already exists, skip.')
|
||||||
|
|
||||||
def _build_openssl(self, file_name):
|
def _build_openssl(self, file_name):
|
||||||
cc.w('skip build openssl again.')
|
# cc.w('skip build openssl again.')
|
||||||
return
|
# return
|
||||||
|
|
||||||
if not self._download_openssl(file_name):
|
if not self._download_openssl(file_name):
|
||||||
return
|
return
|
||||||
|
@ -943,6 +943,7 @@ def main():
|
||||||
builder.build_jsoncpp()
|
builder.build_jsoncpp()
|
||||||
builder.build_mongoose()
|
builder.build_mongoose()
|
||||||
builder.build_zlib()
|
builder.build_zlib()
|
||||||
|
builder.build_mbedtls()
|
||||||
builder.build_openssl()
|
builder.build_openssl()
|
||||||
elif command == 'ext-server':
|
elif command == 'ext-server':
|
||||||
builder.prepare_python()
|
builder.prepare_python()
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
|
|
||||||
TsCfg g_cfg;
|
TsCfg g_cfg;
|
||||||
|
|
||||||
TsCfg::TsCfg()
|
TsCfg::TsCfg() {}
|
||||||
{}
|
|
||||||
|
|
||||||
TsCfg::~TsCfg()
|
TsCfg::~TsCfg() {}
|
||||||
{}
|
|
||||||
|
|
||||||
bool TsCfg::init(void) {
|
bool TsCfg::init(void)
|
||||||
|
{
|
||||||
ex_astr file_content;
|
ex_astr file_content;
|
||||||
if(!ex_read_text_file(g_env.m_cfg_file, file_content)) {
|
if (!ex_read_text_file(g_env.m_cfg_file, file_content))
|
||||||
|
{
|
||||||
EXLOGE("can not load config file.\n");
|
EXLOGE("can not load config file.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,20 @@ bool TsCfg::init(void) {
|
||||||
if (!_load(file_content))
|
if (!_load(file_content))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!m_root.isObject()) {
|
if (!m_root.isObject())
|
||||||
|
{
|
||||||
EXLOGE("invalid config file, not in json format?\n");
|
EXLOGE("invalid config file, not in json format?\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_root["file_version"].isNull()) {
|
if (m_root["file_version"].isNull())
|
||||||
|
{
|
||||||
EXLOGE("invalid config file, maybe need create new one?\n");
|
EXLOGE("invalid config file, maybe need create new one?\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!m_root["file_version"].isInt()) {
|
if (!m_root["file_version"].isInt())
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +52,8 @@ bool TsCfg::save(const ex_astr& new_value)
|
||||||
jwriter->write(m_root, &os);
|
jwriter->write(m_root, &os);
|
||||||
ex_astr val = os.str();
|
ex_astr val = os.str();
|
||||||
|
|
||||||
if(!ex_write_text_file(g_env.m_cfg_file, val)) {
|
if (!ex_write_text_file(g_env.m_cfg_file, val))
|
||||||
|
{
|
||||||
EXLOGE("can not save config file.\n");
|
EXLOGE("can not save config file.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -57,43 +61,51 @@ bool TsCfg::save(const ex_astr& new_value)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TsCfg::_parse_app(const Json::Value& m_root, const ex_astr& str_app, APP_CONFIG& cfg) {
|
bool TsCfg::_parse_app(const Json::Value& m_root, const ex_astr& str_app, APP_CONFIG& cfg)
|
||||||
|
{
|
||||||
const Json::Value& jApp = m_root[str_app.c_str()];
|
const Json::Value& jApp = m_root[str_app.c_str()];
|
||||||
if (!jApp.isObject())
|
if (!jApp.isObject())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!jApp["selected"].isString()) {
|
if (!jApp["selected"].isString())
|
||||||
|
{
|
||||||
EXLOGE("invalid config, error 2.\n");
|
EXLOGE("invalid config, error 2.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ex_astr _selected = jApp["selected"].asCString();;
|
ex_astr _selected = jApp["selected"].asCString();;
|
||||||
|
|
||||||
if (!jApp["available"].isArray() || jApp["available"].size() == 0) {
|
if (!jApp["available"].isArray() || jApp["available"].size() == 0)
|
||||||
|
{
|
||||||
EXLOGE("invalid config, error 3.\n");
|
EXLOGE("invalid config, error 3.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const Json::Value& jAppList = jApp["available"];
|
const Json::Value& jAppList = jApp["available"];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < jAppList.size(); ++i) {
|
for (i = 0; i < jAppList.size(); ++i)
|
||||||
|
{
|
||||||
if (
|
if (
|
||||||
!jAppList[i]["name"].isString()
|
!jAppList[i]["name"].isString()
|
||||||
|| !jAppList[i]["app"].isString()
|
|| !jAppList[i]["app"].isString()
|
||||||
|| !jAppList[i]["cmdline"].isString()
|
|| !jAppList[i]["cmdline"].isString()
|
||||||
|| !jAppList[i]["desc"].isArray()
|
|| !jAppList[i]["desc"].isArray()
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
EXLOGE("invalid config, error 4.\n");
|
EXLOGE("invalid config, error 4.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(jAppList[i]["name"].asString().empty()) {
|
if (jAppList[i]["name"].asString().empty())
|
||||||
|
{
|
||||||
EXLOGE("invalid config, need name.\n");
|
EXLOGE("invalid config, need name.\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jAppList[i]["display"].isNull() || jAppList[i]["display"].asString().empty()) {
|
if (jAppList[i]["display"].isNull() || jAppList[i]["display"].asString().empty())
|
||||||
|
{
|
||||||
cfg.display = jAppList[i]["name"].asCString();
|
cfg.display = jAppList[i]["name"].asCString();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
cfg.display = jAppList[i]["display"].asCString();
|
cfg.display = jAppList[i]["display"].asCString();
|
||||||
|
|
||||||
if (jAppList[i]["name"].asCString() != _selected)
|
if (jAppList[i]["name"].asCString() != _selected)
|
||||||
|
@ -104,11 +116,13 @@ bool TsCfg::_parse_app(const Json::Value& m_root, const ex_astr& str_app, APP_CO
|
||||||
cfg.application = jAppList[i]["app"].asCString();
|
cfg.application = jAppList[i]["app"].asCString();
|
||||||
cfg.cmdline = jAppList[i]["cmdline"].asCString();
|
cfg.cmdline = jAppList[i]["cmdline"].asCString();
|
||||||
|
|
||||||
if(jAppList[i]["desc"].size() > 0) {
|
if (jAppList[i]["desc"].size() > 0)
|
||||||
|
{
|
||||||
const Json::Value& jAppDescList = jAppList[i]["desc"];
|
const Json::Value& jAppDescList = jAppList[i]["desc"];
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(j = 0; j < jAppDescList.size(); ++j) {
|
for (j = 0; j < jAppDescList.size(); ++j)
|
||||||
|
{
|
||||||
if (!jAppDescList[j].isString())
|
if (!jAppDescList[j].isString())
|
||||||
return false;
|
return false;
|
||||||
cfg.description.push_back(jAppDescList[j].asCString());
|
cfg.description.push_back(jAppDescList[j].asCString());
|
||||||
|
@ -122,13 +136,15 @@ bool TsCfg::_parse_app(const Json::Value& m_root, const ex_astr& str_app, APP_CO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TsCfg::_load(const ex_astr& str_json) {
|
bool TsCfg::_load(const ex_astr& str_json)
|
||||||
|
{
|
||||||
Json::CharReaderBuilder jcrb;
|
Json::CharReaderBuilder jcrb;
|
||||||
std::unique_ptr<Json::CharReader> const jreader(jcrb.newCharReader());
|
std::unique_ptr<Json::CharReader> const jreader(jcrb.newCharReader());
|
||||||
const char* str_json_begin = str_json.c_str();
|
const char* str_json_begin = str_json.c_str();
|
||||||
|
|
||||||
ex_astr err;
|
ex_astr err;
|
||||||
if (!jreader->parse(str_json_begin, str_json_begin + str_json.length(), &m_root, &err)) {
|
if (!jreader->parse(str_json_begin, str_json_begin + str_json.length(), &m_root, &err))
|
||||||
|
{
|
||||||
EXLOGE("can not parse new config data, not in json format? %s\n", err.c_str());
|
EXLOGE("can not parse new config data, not in json format? %s\n", err.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
|
|
||||||
typedef struct APP_CONFIG {
|
typedef struct APP_CONFIG
|
||||||
|
{
|
||||||
ex_astr name;
|
ex_astr name;
|
||||||
ex_astr display;
|
ex_astr display;
|
||||||
ex_astr application;
|
ex_astr application;
|
||||||
|
@ -18,9 +19,11 @@ class TsCfg
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TsCfg();
|
TsCfg();
|
||||||
|
|
||||||
virtual ~TsCfg();
|
virtual ~TsCfg();
|
||||||
|
|
||||||
bool init(void);
|
bool init(void);
|
||||||
|
|
||||||
bool save(const ex_astr& new_value);
|
bool save(const ex_astr& new_value);
|
||||||
|
|
||||||
Json::Value& get_root() { return m_root; }
|
Json::Value& get_root() { return m_root; }
|
||||||
|
@ -32,6 +35,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _load(const ex_astr& str_json);
|
bool _load(const ex_astr& str_json);
|
||||||
|
|
||||||
bool _parse_app(const Json::Value& m_root, const ex_astr& str_app, APP_CONFIG& cfg);
|
bool _parse_app(const Json::Value& m_root, const ex_astr& str_app, APP_CONFIG& cfg);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "ts_env.h"
|
#include "ts_env.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef EX_OS_WIN32
|
#ifdef EX_OS_WIN32
|
||||||
# include <direct.h>
|
# include <direct.h>
|
||||||
//# include <ShlObj.h>
|
//# include <ShlObj.h>
|
||||||
|
@ -12,11 +13,9 @@ TsEnv g_env;
|
||||||
//
|
//
|
||||||
//=======================================================
|
//=======================================================
|
||||||
|
|
||||||
TsEnv::TsEnv()
|
TsEnv::TsEnv() {}
|
||||||
{}
|
|
||||||
|
|
||||||
TsEnv::~TsEnv()
|
TsEnv::~TsEnv() {}
|
||||||
{}
|
|
||||||
|
|
||||||
bool TsEnv::init(const char* bundle_path, const char* cfg_file, const char* res_path, const char* log_path)
|
bool TsEnv::init(const char* bundle_path, const char* cfg_file, const char* res_path, const char* log_path)
|
||||||
{
|
{
|
||||||
|
@ -37,9 +36,10 @@ bool TsEnv::init(const char* bundle_path, const char* cfg_file, const char* res_
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
int mg_ssl_if_mbed_random(void *ctx, unsigned char *buf, size_t len) {
|
int mg_ssl_if_mbed_random(void* ctx, unsigned char* buf, size_t len)
|
||||||
|
{
|
||||||
(void)ctx;
|
(void)ctx;
|
||||||
while (len--) *buf++ = (arc4random() % 255);
|
while (len--) { *buf++ = (arc4random() % 255); }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ class TsEnv
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TsEnv();
|
TsEnv();
|
||||||
|
|
||||||
~TsEnv();
|
~TsEnv();
|
||||||
|
|
||||||
bool init(const char* bundle_path, const char* cfg_file, const char* res_path, const char* log_path);
|
bool init(const char* bundle_path, const char* cfg_file, const char* res_path, const char* log_path);
|
||||||
|
|
|
@ -25,15 +25,18 @@ TsHttpRpc::~TsHttpRpc()
|
||||||
mg_mgr_free(&m_mg_mgr);
|
mg_mgr_free(&m_mg_mgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TsHttpRpc::init() {
|
bool TsHttpRpc::init()
|
||||||
|
{
|
||||||
struct mg_connection* nc = NULL;
|
struct mg_connection* nc = NULL;
|
||||||
|
|
||||||
for(int port = TS_HTTP_RPC_PORT_MIN; port < TS_HTTP_RPC_PORT_MAX; ++port) {
|
for (int port = TS_HTTP_RPC_PORT_MIN; port < TS_HTTP_RPC_PORT_MAX; ++port)
|
||||||
|
{
|
||||||
char addr[128] = {0};
|
char addr[128] = {0};
|
||||||
ex_strformat(addr, 128, "tcp://127.0.0.1:%d", port);
|
ex_strformat(addr, 128, "tcp://127.0.0.1:%d", port);
|
||||||
|
|
||||||
nc = mg_bind(&m_mg_mgr, addr, _mg_event_handler);
|
nc = mg_bind(&m_mg_mgr, addr, _mg_event_handler);
|
||||||
if (!nc) {
|
if (!nc)
|
||||||
|
{
|
||||||
EXLOGW("[WRN] can not start HTTP-RPC listener, maybe port %d is already in use.\n", port);
|
EXLOGW("[WRN] can not start HTTP-RPC listener, maybe port %d is already in use.\n", port);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +45,8 @@ bool TsHttpRpc::init() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_port == 0) {
|
if (m_port == 0)
|
||||||
|
{
|
||||||
EXLOGE("[rpc] can not listen on port %d~%d\n", TS_HTTP_RPC_PORT_MIN, TS_HTTP_RPC_PORT_MAX);
|
EXLOGE("[rpc] can not listen on port %d~%d\n", TS_HTTP_RPC_PORT_MIN, TS_HTTP_RPC_PORT_MAX);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +58,8 @@ bool TsHttpRpc::init() {
|
||||||
return _on_init();
|
return _on_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TsHttpRpc::_on_init() {
|
bool TsHttpRpc::_on_init()
|
||||||
|
{
|
||||||
m_content_type_map[".js"] = "application/javascript";
|
m_content_type_map[".js"] = "application/javascript";
|
||||||
m_content_type_map[".png"] = "image/png";
|
m_content_type_map[".png"] = "image/png";
|
||||||
m_content_type_map[".jpeg"] = "image/jpeg";
|
m_content_type_map[".jpeg"] = "image/jpeg";
|
||||||
|
@ -117,11 +122,13 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
|
||||||
ex_astr ret_buf;
|
ex_astr ret_buf;
|
||||||
bool b_is_html = false;
|
bool b_is_html = false;
|
||||||
|
|
||||||
if (uri == "/") {
|
if (uri == "/")
|
||||||
|
{
|
||||||
uri = "/status.html";
|
uri = "/status.html";
|
||||||
b_is_html = true;
|
b_is_html = true;
|
||||||
}
|
}
|
||||||
else if (uri == "/config") {
|
else if (uri == "/config")
|
||||||
|
{
|
||||||
uri = "/index.html";
|
uri = "/index.html";
|
||||||
b_is_html = true;
|
b_is_html = true;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +139,8 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
|
||||||
{
|
{
|
||||||
temp = uri.substr(1, offset - 1);
|
temp = uri.substr(1, offset - 1);
|
||||||
|
|
||||||
if(temp == "api") {
|
if (temp == "api")
|
||||||
|
{
|
||||||
ex_astr method;
|
ex_astr method;
|
||||||
ex_astr json_param;
|
ex_astr json_param;
|
||||||
int rv = _this->_parse_request(hm, method, json_param);
|
int rv = _this->_parse_request(hm, method, json_param);
|
||||||
|
@ -186,7 +194,9 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
|
||||||
delete[]buf;
|
delete[]buf;
|
||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
return;
|
return;
|
||||||
} else if (b_is_html) {
|
}
|
||||||
|
else if (b_is_html)
|
||||||
|
{
|
||||||
ex_wstr page = L"<html lang=\"zh_CN\"><html><head><title>404 Not Found</title></head><body bgcolor=\"white\"><center><h1>404 Not Found</h1></center><hr><center><p>Teleport Assistor configuration page not found.</p></center></body></html>";
|
ex_wstr page = L"<html lang=\"zh_CN\"><html><head><title>404 Not Found</title></head><body bgcolor=\"white\"><center><h1>404 Not Found</h1></center><hr><center><p>Teleport Assistor configuration page not found.</p></center></body></html>";
|
||||||
ex_wstr2astr(page, ret_buf, EX_CODEPAGE_UTF8);
|
ex_wstr2astr(page, ret_buf, EX_CODEPAGE_UTF8);
|
||||||
|
|
||||||
|
@ -197,8 +207,7 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default: break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,20 +350,23 @@ void TsHttpRpc::_create_json_ret(ex_astr& buf, Json::Value& jr_root)
|
||||||
buf = os.str();
|
buf = os.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TsHttpRpc::_rpc_func_get_config(const ex_astr& func_args, ex_astr& buf) {
|
void TsHttpRpc::_rpc_func_get_config(const ex_astr& func_args, ex_astr& buf)
|
||||||
|
{
|
||||||
Json::Value jr_root;
|
Json::Value jr_root;
|
||||||
jr_root["code"] = 0;
|
jr_root["code"] = 0;
|
||||||
jr_root["data"] = g_cfg.get_root();
|
jr_root["data"] = g_cfg.get_root();
|
||||||
_create_json_ret(buf, jr_root);
|
_create_json_ret(buf, jr_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf) {
|
void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf)
|
||||||
|
{
|
||||||
Json::CharReaderBuilder jcrb;
|
Json::CharReaderBuilder jcrb;
|
||||||
std::unique_ptr<Json::CharReader> const jreader(jcrb.newCharReader());
|
std::unique_ptr<Json::CharReader> const jreader(jcrb.newCharReader());
|
||||||
const char* str_json_begin = func_args.c_str();
|
const char* str_json_begin = func_args.c_str();
|
||||||
Json::Value jsRoot;
|
Json::Value jsRoot;
|
||||||
ex_astr err;
|
ex_astr err;
|
||||||
if (!jreader->parse(str_json_begin, str_json_begin + func_args.length(), &jsRoot, &err)) {
|
if (!jreader->parse(str_json_begin, str_json_begin + func_args.length(), &jsRoot, &err))
|
||||||
|
{
|
||||||
_create_json_ret(buf, TPE_JSON_FORMAT);
|
_create_json_ret(buf, TPE_JSON_FORMAT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -365,7 +377,8 @@ void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf) {
|
||||||
_create_json_ret(buf, TPE_OK);
|
_create_json_ret(buf, TPE_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf) {
|
void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf)
|
||||||
|
{
|
||||||
_create_json_ret(buf, TPE_FAILED);
|
_create_json_ret(buf, TPE_FAILED);
|
||||||
#if 0
|
#if 0
|
||||||
Json::Reader jreader;
|
Json::Reader jreader;
|
||||||
|
@ -406,7 +419,8 @@ void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TsHttpRpc::_rpc_func_get_version(const ex_astr& func_args, ex_astr& buf) {
|
void TsHttpRpc::_rpc_func_get_version(const ex_astr& func_args, ex_astr& buf)
|
||||||
|
{
|
||||||
Json::Value root_ret;
|
Json::Value root_ret;
|
||||||
ex_wstr w_version = TP_ASSIST_VER;
|
ex_wstr w_version = TP_ASSIST_VER;
|
||||||
ex_astr version;
|
ex_astr version;
|
||||||
|
|
|
@ -55,6 +55,7 @@ class TsHttpRpc : public ExThreadBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TsHttpRpc();
|
TsHttpRpc();
|
||||||
|
|
||||||
~TsHttpRpc();
|
~TsHttpRpc();
|
||||||
|
|
||||||
bool init();
|
bool init();
|
||||||
|
@ -81,13 +82,19 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
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);
|
||||||
|
|
||||||
void _rpc_func_get_config(const ex_astr& func_args, ex_astr& buf);
|
void _rpc_func_get_config(const ex_astr& func_args, ex_astr& buf);
|
||||||
|
|
||||||
void _rpc_func_set_config(const ex_astr& func_args, ex_astr& buf);
|
void _rpc_func_set_config(const ex_astr& func_args, ex_astr& buf);
|
||||||
|
|
||||||
void _rpc_func_file_action(const ex_astr& func_args, ex_astr& buf);
|
void _rpc_func_file_action(const ex_astr& func_args, ex_astr& buf);
|
||||||
|
|
||||||
void _rpc_func_get_version(const ex_astr& func_args, ex_astr& buf);
|
void _rpc_func_get_version(const ex_astr& func_args, ex_astr& buf);
|
||||||
|
|
||||||
static void _mg_event_handler(struct mg_connection* nc, int ev, void* ev_data);
|
static void _mg_event_handler(struct mg_connection* nc, int ev, void* ev_data);
|
||||||
|
|
|
@ -530,7 +530,8 @@ void TsWsClient::_rpc_func_replay_rdp(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
// for macOS, Create Process should be fork()/exec()...
|
// for macOS, Create Process should be fork()/exec()...
|
||||||
int ret_code = TPE_OK;
|
int ret_code = TPE_OK;
|
||||||
pid_t processId;
|
pid_t processId;
|
||||||
if ((processId = fork()) == 0) {
|
if ((processId = fork()) == 0)
|
||||||
|
{
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char** _argv = (char**)calloc(s_argv.size() + 1, sizeof(char*));
|
char** _argv = (char**)calloc(s_argv.size() + 1, sizeof(char*));
|
||||||
|
@ -545,16 +546,22 @@ void TsWsClient::_rpc_func_replay_rdp(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
|
|
||||||
execv(exec_file.c_str(), _argv);
|
execv(exec_file.c_str(), _argv);
|
||||||
|
|
||||||
for(i = 0; i < s_argv.size(); ++i) {
|
for (i = 0; i < s_argv.size(); ++i)
|
||||||
if(_argv[i] != NULL) {
|
{
|
||||||
|
if (_argv[i] != NULL)
|
||||||
|
{
|
||||||
free(_argv[i]);
|
free(_argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(_argv);
|
free(_argv);
|
||||||
|
|
||||||
} else if (processId < 0) {
|
}
|
||||||
|
else if (processId < 0)
|
||||||
|
{
|
||||||
ret_code = TPE_FAILED;
|
ret_code = TPE_FAILED;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ret_code = TPE_OK;
|
ret_code = TPE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -594,12 +601,15 @@ void TsWsClient::_rpc_func_run_client(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
|
|
||||||
const char* interactive_mode = "no";
|
const char* interactive_mode = "no";
|
||||||
bool is_interactive_mode = false;
|
bool is_interactive_mode = false;
|
||||||
if(!js_param["is_interactive"].isNull()) {
|
if (!js_param["is_interactive"].isNull())
|
||||||
if(!js_param["is_interactive"].isBool()) {
|
{
|
||||||
|
if (!js_param["is_interactive"].isBool())
|
||||||
|
{
|
||||||
_create_response(buf, msg_req, TPE_PARAM);
|
_create_response(buf, msg_req, TPE_PARAM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(js_param["is_interactive"].asBool()) {
|
if (js_param["is_interactive"].asBool())
|
||||||
|
{
|
||||||
interactive_mode = "yes";
|
interactive_mode = "yes";
|
||||||
is_interactive_mode = true;
|
is_interactive_mode = true;
|
||||||
}
|
}
|
||||||
|
@ -694,17 +704,19 @@ void TsWsClient::_rpc_func_run_client(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
rdp_console = false;
|
rdp_console = false;
|
||||||
|
|
||||||
|
|
||||||
size_t split_pos = sid.length() - 2;
|
// size_t split_pos = sid.length() - 2;
|
||||||
ex_astr real_sid = sid.substr(0, split_pos);
|
// ex_astr real_sid = sid.substr(0, split_pos);
|
||||||
ex_astr str_pwd_len = sid.substr(split_pos, sid.length());
|
// ex_astr str_pwd_len = sid.substr(split_pos, sid.length());
|
||||||
size_t n_pwd_len = strtol(str_pwd_len.c_str(), NULL, 16);
|
// size_t n_pwd_len = strtol(str_pwd_len.c_str(), NULL, 16);
|
||||||
n_pwd_len -= real_sid.length();
|
// n_pwd_len -= real_sid.length();
|
||||||
n_pwd_len -= 2;
|
// n_pwd_len -= 2;
|
||||||
char szPwd[256] = {0};
|
// char szPwd[256] = {0};
|
||||||
for (int i = 0; i < n_pwd_len; i++)
|
// for (int i = 0; i < n_pwd_len; i++)
|
||||||
{
|
// {
|
||||||
szPwd[i] = '*';
|
// szPwd[i] = '*';
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// ex_astr real_sid(sid);
|
||||||
|
|
||||||
//ex_astr2wstr(real_sid, w_sid);
|
//ex_astr2wstr(real_sid, w_sid);
|
||||||
|
|
||||||
|
@ -718,7 +730,7 @@ void TsWsClient::_rpc_func_run_client(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
s_exec = g_cfg.rdp.application;
|
s_exec = g_cfg.rdp.application;
|
||||||
s_arg = g_cfg.rdp.cmdline;
|
s_arg = g_cfg.rdp.cmdline;
|
||||||
|
|
||||||
sid = "02" + real_sid;
|
// sid = "02" + real_sid;
|
||||||
// s_argv.push_back("/f");
|
// s_argv.push_back("/f");
|
||||||
|
|
||||||
s_argv.push_back("/sec:tls");
|
s_argv.push_back("/sec:tls");
|
||||||
|
@ -729,7 +741,8 @@ void TsWsClient::_rpc_func_run_client(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
// Automatically accept certificate on first connect
|
// Automatically accept certificate on first connect
|
||||||
s_argv.push_back("/cert-tofu");
|
s_argv.push_back("/cert-tofu");
|
||||||
|
|
||||||
ex_astr _tmp_pass = "/p:PLACEHOLDER";
|
// ex_astr _tmp_pass = "/p:PLACEHOLDER";
|
||||||
|
ex_astr _tmp_pass = "/p:******";
|
||||||
//_tmp_pass += szPwd;
|
//_tmp_pass += szPwd;
|
||||||
s_argv.push_back(_tmp_pass);
|
s_argv.push_back(_tmp_pass);
|
||||||
|
|
||||||
|
@ -881,20 +894,25 @@ void TsWsClient::_rpc_func_run_client(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
ex_astr::size_type p2 = 0;
|
ex_astr::size_type p2 = 0;
|
||||||
ex_astr tmp;
|
ex_astr tmp;
|
||||||
|
|
||||||
for(;;){
|
for (;;)
|
||||||
|
{
|
||||||
p1 = s_arg.find("{password:");
|
p1 = s_arg.find("{password:");
|
||||||
if(p1 != ex_astr::npos) {
|
if (p1 != ex_astr::npos)
|
||||||
|
{
|
||||||
p2 = s_arg.find('}', p1 + 10);
|
p2 = s_arg.find('}', p1 + 10);
|
||||||
if(p2 == ex_astr::npos) {
|
if (p2 == ex_astr::npos)
|
||||||
|
{
|
||||||
_create_response(buf, msg_req, TPE_PARAM);
|
_create_response(buf, msg_req, TPE_PARAM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_interactive_mode) {
|
if (is_interactive_mode)
|
||||||
|
{
|
||||||
// 如果需要用户自己输入密码,则客户端命令行就不能带密码字段,需要抹去这个参数
|
// 如果需要用户自己输入密码,则客户端命令行就不能带密码字段,需要抹去这个参数
|
||||||
s_arg.erase(p1, p2 - p1 + 1);
|
s_arg.erase(p1, p2 - p1 + 1);
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
s_arg.erase(p2, 1);
|
s_arg.erase(p2, 1);
|
||||||
s_arg.erase(p1, 10);
|
s_arg.erase(p1, 10);
|
||||||
}
|
}
|
||||||
|
@ -905,20 +923,25 @@ void TsWsClient::_rpc_func_run_client(ex_astr& buf, AssistMessage& msg_req, Json
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(;;){
|
for (;;)
|
||||||
|
{
|
||||||
p1 = s_arg.find("{interactive:");
|
p1 = s_arg.find("{interactive:");
|
||||||
if(p1 != ex_astr::npos) {
|
if (p1 != ex_astr::npos)
|
||||||
|
{
|
||||||
p2 = s_arg.find('}', p1 + 13);
|
p2 = s_arg.find('}', p1 + 13);
|
||||||
if(p2 == ex_astr::npos) {
|
if (p2 == ex_astr::npos)
|
||||||
|
{
|
||||||
_create_response(buf, msg_req, TPE_PARAM);
|
_create_response(buf, msg_req, TPE_PARAM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!is_interactive_mode) {
|
if (!is_interactive_mode)
|
||||||
|
{
|
||||||
// 如果无需用户自己输入密码,则需要抹去这个参数
|
// 如果无需用户自己输入密码,则需要抹去这个参数
|
||||||
s_arg.erase(p1, p2 - p1 + 1);
|
s_arg.erase(p1, p2 - p1 + 1);
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
s_arg.erase(p2, 1);
|
s_arg.erase(p2, 1);
|
||||||
s_arg.erase(p1, 13);
|
s_arg.erase(p1, 13);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ public:
|
||||||
~TsWsClient();
|
~TsWsClient();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void stop_all_client();
|
void stop_all_client();
|
||||||
|
|
||||||
void url_scheme_handler(const std::string& url);
|
void url_scheme_handler(const std::string& url);
|
||||||
|
@ -71,6 +72,7 @@ private:
|
||||||
void _process_register(const std::string& param, Json::Value& js_root);
|
void _process_register(const std::string& param, Json::Value& js_root);
|
||||||
|
|
||||||
void _process_run(const std::string& param, Json::Value& js_root);
|
void _process_run(const std::string& param, Json::Value& js_root);
|
||||||
|
|
||||||
void _process_replay_rdp(const std::string& param, Json::Value& js_root);
|
void _process_replay_rdp(const std::string& param, Json::Value& js_root);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -161,9 +161,9 @@ bool TsSessionManager::request_session(ex_astr& sid, TS_CONNECT_INFO* info)
|
||||||
if (info->protocol_type == TP_PROTOCOL_TYPE_RDP)
|
if (info->protocol_type == TP_PROTOCOL_TYPE_RDP)
|
||||||
{
|
{
|
||||||
info->ref_count = 1; // 因为RDP连接之前可能会有很长时间用于确认是否连接、是否信任证书,所以很容易超时,我们认为将引用计数+1,防止因超时被清除。
|
info->ref_count = 1; // 因为RDP连接之前可能会有很长时间用于确认是否连接、是否信任证书,所以很容易超时,我们认为将引用计数+1,防止因超时被清除。
|
||||||
char szTmp[8] = {0};
|
// char szTmp[8] = {0};
|
||||||
snprintf(szTmp, 8, "%02X", (unsigned char)(info->acc_username.length() + info->acc_secret.length()));
|
// snprintf(szTmp, 8, "%02X", (unsigned char)(info->acc_username.length() + info->acc_secret.length()));
|
||||||
sid += szTmp;
|
// sid += szTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -518,11 +518,9 @@ $app.connect_remote = function (uni_id, acc_id, host_id, protocol_type, protocol
|
||||||
is_interactive: false,
|
is_interactive: false,
|
||||||
};
|
};
|
||||||
if (protocol_type === TP_PROTOCOL_TYPE_RDP) {
|
if (protocol_type === TP_PROTOCOL_TYPE_RDP) {
|
||||||
args.extends({
|
args.rdp_width = $app.dlg_rdp_options.rdp_w;
|
||||||
rdp_width: $app.dlg_rdp_options.rdp_w,
|
args.rdp_height = $app.dlg_rdp_options.rdp_h;
|
||||||
rdp_height: $app.dlg_rdp_options.rdp_h,
|
args.rdp_console = $app.dlg_rdp_options.rdp_console;
|
||||||
rdp_console: $app.dlg_rdp_options.rdp_console
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uni_id === 'none')
|
if (uni_id === 'none')
|
||||||
|
|
Loading…
Reference in New Issue