From da209cbea75b1f1fb2aacabcc6bf491ccdf1bd3e Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Thu, 6 Feb 2020 23:19:06 +0800 Subject: [PATCH] =?UTF-8?q?macOS=E7=89=88=E5=8A=A9=E6=89=8B=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E9=85=8D=E5=90=88FreeRDP=202.0.0-rc4=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=BD=BF=E7=94=A8=E4=BA=86=EF=BC=88=E4=B8=8ETP3.2.2?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E7=AB=AF=E9=85=8D=E5=90=88=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E6=B5=8B=E8=AF=95=E8=BF=9E=E6=8E=A5Win10=E9=80=9A?= =?UTF-8?q?=E8=BF=87=EF=BC=89=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/builder/build-assist.py | 3 + client/cfg/tp-assist.macos.json | 2 +- .../TP-Assist.xcodeproj/project.pbxproj | 5 +- client/tp_assist_macos/src/csrc/ts_cfg.cpp | 28 +++-- .../tp_assist_macos/src/csrc/ts_http_rpc.cpp | 107 ++++++++++-------- client/tp_assist_win/site/js/config.js | 3 +- dist/client/windows/assist/installer.nsi | Bin 3052 -> 2938 bytes 7 files changed, 92 insertions(+), 56 deletions(-) diff --git a/build/builder/build-assist.py b/build/builder/build-assist.py index 06cad85..05a7c64 100644 --- a/build/builder/build-assist.py +++ b/build/builder/build-assist.py @@ -152,6 +152,9 @@ class BuilderMacOS(BuilderBase): utils.xcode_build(proj_file, 'TP-Assist', configuration, False) utils.ensure_file_exists(os.path.join(out_file, 'Contents', 'Info.plist')) + def build_player(self): + cc.o('skip build tp_player now...') + def build_installer(self): cc.i('make tp_assist dmg file...') diff --git a/client/cfg/tp-assist.macos.json b/client/cfg/tp-assist.macos.json index 93ff8bc..189b78f 100644 --- a/client/cfg/tp-assist.macos.json +++ b/client/cfg/tp-assist.macos.json @@ -102,7 +102,7 @@ "name": "FreeRDP", "display": "FreeRDP", "app": "", - "cmdline": "", + "cmdline": "/u:{user_name} /v:{host_ip} /port:{host_port}", "desc": [ "建议使用homebrew安装freerdp,安装后freerdp默认路径在:/usr/local/Cellar/freerdp/x.y.z/bin/xfreerdp", "首次安装freerdp后需要重新启动计算机" diff --git a/client/tp_assist_macos/TP-Assist.xcodeproj/project.pbxproj b/client/tp_assist_macos/TP-Assist.xcodeproj/project.pbxproj index 2a18ea2..c86b523 100644 --- a/client/tp_assist_macos/TP-Assist.xcodeproj/project.pbxproj +++ b/client/tp_assist_macos/TP-Assist.xcodeproj/project.pbxproj @@ -631,7 +631,10 @@ COMBINE_HIDPI_IMAGES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "src/TP-Assist-Prefix.pch"; - GCC_PREPROCESSOR_DEFINITIONS = MG_ENABLE_SSL; + GCC_PREPROCESSOR_DEFINITIONS = ( + MG_ENABLE_SSL, + "MG_SSL_IF=MG_SSL_IF_MBEDTLS", + ); HEADER_SEARCH_PATHS = ( ../../common/teleport, ../../common/libex/include, diff --git a/client/tp_assist_macos/src/csrc/ts_cfg.cpp b/client/tp_assist_macos/src/csrc/ts_cfg.cpp index 7e3daf5..4896d37 100644 --- a/client/tp_assist_macos/src/csrc/ts_cfg.cpp +++ b/client/tp_assist_macos/src/csrc/ts_cfg.cpp @@ -41,9 +41,12 @@ bool TsCfg::save(const ex_astr& new_value) if(!_load(new_value)) return false; - Json::StyledWriter jwriter; - ex_astr val = jwriter.write(m_root); - + Json::StreamWriterBuilder jwb; + std::unique_ptr jwriter(jwb.newStreamWriter()); + ex_aoss os; + jwriter->write(m_root, &os); + ex_astr val = os.str(); + if(!ex_write_text_file(g_env.m_cfg_file, val)) { EXLOGE("can not save config file.\n"); return false; @@ -123,12 +126,21 @@ bool TsCfg::_parse_app(const Json::Value& m_root, const ex_astr& str_app, APP_CO bool TsCfg::_load(const ex_astr& str_json) { - Json::Reader jreader; +// Json::Reader jreader; +// +// if (!jreader.parse(str_json.c_str(), m_root)) { +// EXLOGE("can not parse new config data, not in json format?\n"); +// return false; +// } + Json::CharReaderBuilder jcrb; + std::unique_ptr const jreader(jcrb.newCharReader()); + const char *str_json_begin = str_json.c_str(); - if (!jreader.parse(str_json.c_str(), m_root)) { - EXLOGE("can not parse new config data, not in json format?\n"); - return false; - } + ex_astr 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()); + return false; + } //=================================== // check ssh config diff --git a/client/tp_assist_macos/src/csrc/ts_http_rpc.cpp b/client/tp_assist_macos/src/csrc/ts_http_rpc.cpp index eb63c99..3d04d21 100644 --- a/client/tp_assist_macos/src/csrc/ts_http_rpc.cpp +++ b/client/tp_assist_macos/src/csrc/ts_http_rpc.cpp @@ -264,7 +264,7 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat _this->_process_js_request(method, json_param, ret_buf); } - mg_printf(nc, "HTTP/1.0 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: %ld\r\nContent-Type: application/json\r\n\r\n%s", ret_buf.size() - 1, &ret_buf[0]); + mg_printf(nc, "HTTP/1.0 200 OK\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: %ld\r\nContent-Type: application/json\r\n\r\n%s", ret_buf.length(), ret_buf.c_str()); nc->flags |= MG_F_SEND_AND_CLOSE; return; } @@ -308,7 +308,7 @@ void TsHttpRpc::_mg_event_handler(struct mg_connection *nc, int ev, void *ev_dat ex_wstr page = L"404 Not Found

404 Not Found


Teleport Assistor configuration page not found.

"; ex_wstr2astr(page, ret_buf, EX_CODEPAGE_UTF8); - mg_printf(nc, "HTTP/1.0 404 File Not Found\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: %ld\r\nContent-Type: text/html\r\n\r\n%s", ret_buf.size() - 1, &ret_buf[0]); + mg_printf(nc, "HTTP/1.0 404 File Not Found\r\nAccess-Control-Allow-Origin: *\r\nContent-Length: %ld\r\nContent-Type: text/html\r\n\r\n%s", ret_buf.length(), ret_buf.c_str()); nc->flags |= MG_F_SEND_AND_CLOSE; return; } @@ -449,35 +449,41 @@ void TsHttpRpc::_create_json_ret(ex_astr& buf, int errcode) { // return {"code":123} - Json::FastWriter jr_writer; Json::Value jr_root; - jr_root["code"] = errcode; - buf = jr_writer.write(jr_root); + Json::StreamWriterBuilder jwb; + std::unique_ptr jwriter(jwb.newStreamWriter()); + ex_aoss os; + jwriter->write(jr_root, &os); + buf = os.str(); } void TsHttpRpc::_create_json_ret(ex_astr& buf, Json::Value& jr_root) { - Json::FastWriter jr_writer; - buf = jr_writer.write(jr_root); + Json::StreamWriterBuilder jwb; + std::unique_ptr jwriter(jwb.newStreamWriter()); + ex_aoss os; + jwriter->write(jr_root, &os); + buf = os.str(); } -void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) -{ +void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) { // param: {"ip":"192.168.5.11","port":22,"uname":"root","uauth":"abcdefg","authmode":1,"protocol":2} // authmode: 1=password, 2=private-key // protocol: 1=rdp, 2=ssh // SSH return {"code":0, "data":{"sid":"0123abcde"}} // RDP return {"code":0, "data":{"sid":"0123abcde0A"}} - Json::Reader jreader; - Json::Value jsRoot; + Json::CharReaderBuilder jcrb; + std::unique_ptr const jreader(jcrb.newCharReader()); + const char *str_json_begin = func_args.c_str(); - if (!jreader.parse(func_args.c_str(), jsRoot)) - { - _create_json_ret(buf, TPE_JSON_FORMAT); - return; - } + Json::Value jsRoot; + ex_astr err; + if (!jreader->parse(str_json_begin, str_json_begin + func_args.length(), &jsRoot, &err)) { + _create_json_ret(buf, TPE_JSON_FORMAT); + return; + } if (!jsRoot.isObject()) { _create_json_ret(buf, TPE_PARAM); @@ -513,8 +519,7 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) ex_astrs s_argv; - if (pro_type == TP_PROTOCOL_TYPE_RDP) - { + if (pro_type == TP_PROTOCOL_TYPE_RDP) { //============================================== // RDP //============================================== @@ -588,16 +593,27 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) //w_exe_path = _T("xfreerdp -u {user_name} {size} {console} "); //s_exec = "/usr/local/Cellar/freerdp/1.0.2_1/bin/xfreerdp"; s_exec = g_cfg.rdp.application; - s_argv.push_back(s_exec.c_str()); + s_arg = g_cfg.rdp.cmdline; + + sid = "02" + real_sid; + s_argv.push_back("/f"); + + ex_astr _tmp_pass = "/p:"; + _tmp_pass += szPwd; + s_argv.push_back(_tmp_pass); + +#if 0 + //s_argv.push_back(s_exec.c_str()); { ex_astr username = "02" + real_sid; - s_argv.push_back("-u"); - s_argv.push_back(username.c_str()); +// s_argv.push_back("/u:"); +// s_argv.push_back(username.c_str()); + if (rdp_w == 0 || rdp_h == 0) { - s_argv.push_back("-f"); + s_argv.push_back("/f"); } else { char sz_size[64] = {0}; @@ -625,10 +641,9 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) s_argv.push_back(sz_temp); } } - +#endif } - else if (pro_type == TP_PROTOCOL_TYPE_SSH) - { + else if (pro_type == TP_PROTOCOL_TYPE_SSH) { //============================================== // SSH //============================================== @@ -676,11 +691,9 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) s_argv.push_back(s_exec.c_str()); s_arg = g_cfg.sftp.cmdline; - } } - else if (pro_type == TP_PROTOCOL_TYPE_TELNET) - { + else if (pro_type == TP_PROTOCOL_TYPE_TELNET) { //============================================== // TELNET //============================================== @@ -811,31 +824,36 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) _create_json_ret(buf, root_ret); } - - -void TsHttpRpc::_rpc_func_rdp_play(const ex_astr& func_args, ex_astr& buf) -{ +void TsHttpRpc::_rpc_func_rdp_play(const ex_astr& func_args, ex_astr& buf) { _create_json_ret(buf, TPE_NOT_IMPLEMENT); } -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; jr_root["code"] = 0; jr_root["data"] = g_cfg.get_root(); _create_json_ret(buf, jr_root); } -void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf) -{ - Json::Reader jreader; - Json::Value jsRoot; - if (!jreader.parse(func_args.c_str(), jsRoot)) - { - _create_json_ret(buf, TPE_JSON_FORMAT); - return; - } +void TsHttpRpc::_rpc_func_set_config(const ex_astr& func_args, ex_astr& buf) { +// Json::Reader jreader; +// Json::Value jsRoot; +// if (!jreader.parse(func_args.c_str(), jsRoot)) +// { +// _create_json_ret(buf, TPE_JSON_FORMAT); +// return; +// } + Json::CharReaderBuilder jcrb; + std::unique_ptr const jreader(jcrb.newCharReader()); + const char *str_json_begin = func_args.c_str(); + Json::Value jsRoot; + ex_astr err; + if (!jreader->parse(str_json_begin, str_json_begin + func_args.length(), &jsRoot, &err)) { + _create_json_ret(buf, TPE_JSON_FORMAT); + return; + } + if(!g_cfg.save(func_args)) _create_json_ret(buf, TPE_FAILED); else @@ -883,8 +901,7 @@ void TsHttpRpc::_rpc_func_file_action(const ex_astr& func_args, ex_astr& buf) { #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; ex_wstr w_version = TP_ASSIST_VER; ex_astr version; diff --git a/client/tp_assist_win/site/js/config.js b/client/tp_assist_win/site/js/config.js index 541943a..583c3bb 100644 --- a/client/tp_assist_win/site/js/config.js +++ b/client/tp_assist_win/site/js/config.js @@ -1,6 +1,7 @@ "use strict"; -var g_url_base = 'http://localhost:50022'; +//var g_url_base = 'http://localhost:50022'; +var g_url_base = 'http://127.0.0.1:50022'; var g_cfg = null; diff --git a/dist/client/windows/assist/installer.nsi b/dist/client/windows/assist/installer.nsi index f6fc853c9e2169d09e3925df4329357da2e4b60b..db662a9150cbc3db13df8053ef144a46177a2bcc 100644 GIT binary patch delta 343 zcmaDO{!45^*~E%0W-bQn$&5_JLO_}UgcTTOMSJ>L#GRiwxrotk@*ze8cBm9k*~Ezo zEX+W4lOHk*PhP{M!3bf!VX~V1h*@c}7qcFip2Msr$ptlSx!=K%&gi2ZtikRKp$wi3 zEu|XN j1Bz>MHJ9e(Wn5Z7*{fU!C(qz^;DcE1%HYr72J|ohK^$Zi delta 480 zcmew*_C|a{89Ofn7lSne=j69c@)KvdG4f8lUoHU=gOCagv!XryEaJ{j|LVA5cP@qB@*L1GHbc2HIUvza_t7Hq8o!*aia zA)V1jJ6MC=8A2I68C;;IC@>35e#Be^*Do=-jztHFcZJ0aZVSkKfysKTLQwf2Ruw3# zgH;ZyYB{SuRO|&SOs71XDpV|t%?he+B3nF^^^r{+Dl5g_1{GV#ZV43Y=Tx7>AqHfK za;P%_L&b)}3LcCXIfW_i<>6LjqHgA(bJIA%!86Aq^U0KRJS-w#0E7fz7rD ylZKQ3af)%mLW*~?J(u`oJuZ+B?YXp}uF2*)2;^&XJBq;6Su?mY_%pbH%?1F#Xl0N9