diff --git a/client/tp_assist_macos/site/index.html b/client/tp_assist_macos/site/index.html index 953c7cb..ff3f54f 100644 --- a/client/tp_assist_macos/site/index.html +++ b/client/tp_assist_macos/site/index.html @@ -17,11 +17,11 @@ -
-
- Teleport助手本地配置 - 此处配置保存到本地计算机上,如果更换计算机,需要重新配置! -
+
+
+ Teleport助手本地配置 + + 此处配置保存到本地计算机上,如果更换计算机,需要重新配置!
@@ -34,11 +34,20 @@
-
- -
-

本地终端配置(用于SSH)

+
+
+

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

+ 注意:命令行参数设置中,可以用以下变量替换(注意大小写!): +
    +
  • {host_ip} 替换主机IP地址
  • +
  • {host_port} 替换主机端口号
  • +
  • {user_name} 替换用户名
  • +
  • {real_ip} 替换为远程主机真实IP(仅用于显示,例如客户端的窗口标题或标签页标题等)
  • +
+
+
+

本地 SSH 客户端配置

@@ -55,9 +64,69 @@
+
+

本地 SFTP 客户端配置

-
-

本地RDP配置

+ +
+
+ +
+ +
+
+ +
+ +
+
+ + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+

本地 TELNET 客户端配置

+ +
+
+ +
+ +
+
+ +
+ +
+
+ + +
+
+
+ +
+ +
+ +
+
+ +
+ +
+

本地RDP配置

diff --git a/client/tp_assist_macos/src/AppDelegate.mm b/client/tp_assist_macos/src/AppDelegate.mm index 8a1365c..1791214 100644 --- a/client/tp_assist_macos/src/AppDelegate.mm +++ b/client/tp_assist_macos/src/AppDelegate.mm @@ -77,7 +77,6 @@ int AppDelegate_start_ssh_client (void *_self, const char* cmd_line, const char* int ret = cpp_main((__bridge void*)self, cpp_cfg_file.c_str(), cpp_res_path.c_str()); if(ret != 0) { - // TODO: show error message and exit. NSString *msg = Nil; if(ret == -1) msg = @"初始化运行环境失败!"; @@ -85,6 +84,8 @@ int AppDelegate_start_ssh_client (void *_self, const char* cmd_line, const char* msg = @"加载配置文件失败!"; else if(ret == -3) msg = @"启动本地通讯端口失败!请检查本地50022端口是否被占用!"; + else + msg = @"发生未知错误!"; NSAlert *alert = [NSAlert alertWithMessageText:@"无法启动Teleport助手" defaultButton:@"确定" diff --git a/client/tp_assist_macos/src/csrc/ts_cfg.cpp b/client/tp_assist_macos/src/csrc/ts_cfg.cpp index c90ed0d..501d7b6 100644 --- a/client/tp_assist_macos/src/csrc/ts_cfg.cpp +++ b/client/tp_assist_macos/src/csrc/ts_cfg.cpp @@ -46,6 +46,220 @@ bool TsCfg::_load(const ex_astr& str_json) { return false; } + ex_astr sel_name; + size_t i = 0; + ex_astr tmp; + + //=================================== + // check ssh config + //=================================== + + if (!m_root["ssh"].isObject()) { + EXLOGE("invalid config, error 1.\n"); + return false; + } + + if (!m_root["ssh"]["selected"].isString()) { + EXLOGE("invalid config, error 2.\n"); + return false; + } + + sel_name = m_root["ssh"]["selected"].asCString(); + + if (!m_root["ssh"]["available"].isArray() || m_root["ssh"]["available"].size() == 0) { + EXLOGE("invalid config, error 3.\n"); + return false; + } + + for (i = 0; i < m_root["ssh"]["available"].size(); ++i) { + + if ( + !m_root["ssh"]["available"][i]["name"].isString() + || !m_root["ssh"]["available"][i]["app"].isString() + || !m_root["ssh"]["available"][i]["cmdline"].isString() + ) { + EXLOGE("invalid config, error 4.\n"); + return false; + } + + if (m_root["ssh"]["available"][i]["display"].isNull()) { + m_root["ssh"]["available"][i]["display"] = m_root["ssh"]["available"][i]["name"]; + } + + if (m_root["ssh"]["available"][i]["name"].asCString() != sel_name) + continue; + + ssh_app = m_root["ssh"]["available"][i]["app"].asCString(); + ssh_cmdline = m_root["ssh"]["available"][i]["cmdline"].asCString(); + + break; + } + + if (ssh_app.length() == 0 || ssh_cmdline.length() == 0) { + EXLOGE("invalid config, error 6.\n"); + return false; + } + + + //=================================== + // check sftp config + //=================================== + + if (!m_root["scp"].isObject()) { + EXLOGE("invalid config, error 1.\n"); + return false; + } + + if (!m_root["scp"]["selected"].isString()) { + EXLOGE("invalid config, error 2.\n"); + return false; + } + + sel_name = m_root["scp"]["selected"].asCString(); + + if (!m_root["scp"]["available"].isArray() || m_root["scp"]["available"].size() == 0) { + EXLOGE("invalid config, error 3.\n"); + return false; + } + + for (i = 0; i < m_root["sftp"]["available"].size(); ++i) { + + if ( + !m_root["sftp"]["available"][i]["name"].isString() + || !m_root["sftp"]["available"][i]["app"].isString() + || !m_root["sftp"]["available"][i]["cmdline"].isString() + ) { + EXLOGE("invalid config, error 4.\n"); + return false; + } + + if (m_root["scp"]["available"][i]["display"].isNull()) { + m_root["scp"]["available"][i]["display"] = m_root["scp"]["available"][i]["name"]; + } + + if (m_root["scp"]["available"][i]["name"].asCString() != sel_name) + continue; + + tmp = m_root["scp"]["available"][i]["app"].asCString(); + ex_astr2wstr(tmp, scp_app, EX_CODEPAGE_UTF8); + tmp = m_root["scp"]["available"][i]["cmdline"].asCString(); + ex_astr2wstr(tmp, scp_cmdline, EX_CODEPAGE_UTF8); + + break; + } + + if (scp_app.length() == 0 || scp_cmdline.length() == 0) { + EXLOGE("invalid config, error 6.\n"); + return false; + } + + //=================================== + // check telnet config + //=================================== + + if (!m_root["telnet"].isObject()) { + EXLOGE("invalid config, error 1.\n"); + return false; + } + + if (!m_root["telnet"]["selected"].isString()) { + EXLOGE("invalid config, error 2.\n"); + return false; + } + + sel_name = m_root["telnet"]["selected"].asCString(); + + if (!m_root["telnet"]["available"].isArray() || m_root["telnet"]["available"].size() == 0) { + EXLOGE("invalid config, error 3.\n"); + return false; + } + + for (i = 0; i < m_root["telnet"]["available"].size(); ++i) { + + if ( + !m_root["telnet"]["available"][i]["name"].isString() + || !m_root["telnet"]["available"][i]["app"].isString() + || !m_root["telnet"]["available"][i]["cmdline"].isString() + ) { + EXLOGE("invalid config, error 4.\n"); + return false; + } + + if (m_root["telnet"]["available"][i]["display"].isNull()) { + m_root["telnet"]["available"][i]["display"] = m_root["telnet"]["available"][i]["name"]; + } + + if (m_root["telnet"]["available"][i]["name"].asCString() != sel_name) + continue; + + tmp = m_root["telnet"]["available"][i]["app"].asCString(); + ex_astr2wstr(tmp, telnet_app, EX_CODEPAGE_UTF8); + tmp = m_root["telnet"]["available"][i]["cmdline"].asCString(); + ex_astr2wstr(tmp, telnet_cmdline, EX_CODEPAGE_UTF8); + + break; + } + + if (telnet_app.length() == 0 || telnet_cmdline.length() == 0) { + EXLOGE("invalid config, error 6.\n"); + return false; + } + + //=================================== + // check rdp config + //=================================== + + if (!m_root["rdp"].isObject()) { + EXLOGE("invalid config, error 1.\n"); + return false; + } + + if (!m_root["rdp"]["selected"].isString()) { + EXLOGE("invalid config, error 2.\n"); + return false; + } + + sel_name = m_root["rdp"]["selected"].asCString(); + + if (!m_root["rdp"]["available"].isArray() || m_root["rdp"]["available"].size() == 0) { + EXLOGE("invalid config, error 3.\n"); + return false; + } + + for (i = 0; i < m_root["rdp"]["available"].size(); ++i) { + + if ( + !m_root["rdp"]["available"][i]["name"].isString() + || !m_root["rdp"]["available"][i]["app"].isString() + || !m_root["rdp"]["available"][i]["cmdline"].isString() + ) { + EXLOGE("invalid config, error 4.\n"); + return false; + } + + if (m_root["rdp"]["available"][i]["display"].isNull()) { + m_root["rdp"]["available"][i]["display"] = m_root["rdp"]["available"][i]["name"]; + } + + if (m_root["rdp"]["available"][i]["name"].asCString() != sel_name) + continue; + + tmp = m_root["rdp"]["available"][i]["app"].asCString(); + ex_astr2wstr(tmp, rdp_app, EX_CODEPAGE_UTF8); + tmp = m_root["rdp"]["available"][i]["cmdline"].asCString(); + ex_astr2wstr(tmp, rdp_cmdline, EX_CODEPAGE_UTF8); + tmp = m_root["rdp"]["available"][i]["name"].asCString(); + ex_astr2wstr(tmp, rdp_name, EX_CODEPAGE_UTF8); + + break; + } + + if (rdp_app.length() == 0 || rdp_cmdline.length() == 0 || rdp_name.length() == 0) { + EXLOGE("invalid config, error 6.\n"); + return false; + } + +#if 0 // ------------ term --------------------- if (!m_root["term"].isObject()) { @@ -154,6 +368,7 @@ bool TsCfg::_load(const ex_astr& str_json) { EXLOGE("invalid config, error 6.\n"); return false; } +#endif return true; } diff --git a/client/tp_assist_macos/src/csrc/ts_cfg.h b/client/tp_assist_macos/src/csrc/ts_cfg.h index f37003d..1e7b6ec 100644 --- a/client/tp_assist_macos/src/csrc/ts_cfg.h +++ b/client/tp_assist_macos/src/csrc/ts_cfg.h @@ -17,14 +17,25 @@ public: Json::Value& get_root() {return m_root;} - ex_astr term_name; - ex_astr term_display; - ex_astr term_app; - ex_astr term_profile; +// ex_astr term_name; +// ex_astr term_display; +// ex_astr term_app; +// ex_astr term_profile; + ex_astr ssh_app; + ex_astr ssh_cmdline; + ex_astr scp_app; + ex_astr scp_cmdline; + ex_astr telnet_app; + ex_astr telnet_cmdline; ex_astr rdp_name; - ex_astr rdp_display; ex_astr rdp_app; + ex_astr rdp_cmdline; + + +// ex_astr rdp_name; +// ex_astr rdp_display; +// ex_astr rdp_app; //ex_astr rdp_cmdline; protected: diff --git a/client/tp_assist_win/ts_cfg.cpp b/client/tp_assist_win/ts_cfg.cpp index acbee67..722a7b5 100644 --- a/client/tp_assist_win/ts_cfg.cpp +++ b/client/tp_assist_win/ts_cfg.cpp @@ -1,7 +1,7 @@ -#include "stdafx.h" -#include "ts_cfg.h" -#include "ts_env.h" - +#include "stdafx.h" +#include "ts_cfg.h" +#include "ts_env.h" + TsCfg g_cfg; @@ -105,7 +105,7 @@ bool TsCfg::_load(const ex_astr& str_json) { } //=================================== - // check scp config + // check sftp config //=================================== if (!m_root["scp"].isObject()) { diff --git a/common/libex/src/ex_path.cpp b/common/libex/src/ex_path.cpp index 97a57af..930723e 100644 --- a/common/libex/src/ex_path.cpp +++ b/common/libex/src/ex_path.cpp @@ -182,9 +182,9 @@ EX_BOOL ex_copy_file(const wchar_t* from_file, const wchar_t* to_file) { return EX_FALSE; } else if (S_ISREG(src_stat.st_mode)) { - int src, dst; - int rsize; - char buf[1024]; + int src = -1, dst = -1; + int rsize = 0; + char buf[1024] = {0}; if ((src = open(source.c_str(), O_RDONLY)) == -1) { close(dst); return EX_FALSE;