diff --git a/CMakeCfg.txt b/CMakeCfg.txt index 58cf131..0bc9a03 100644 --- a/CMakeCfg.txt +++ b/CMakeCfg.txt @@ -4,9 +4,6 @@ MESSAGE(STATUS "operation system is ${CMAKE_SYSTEM}") MESSAGE(STATUS "root source directory is ${PROJECT_SOURCE_DIR}") MESSAGE(STATUS "current source directory is ${CMAKE_CURRENT_SOURCE_DIR}") -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/server/x64/bin") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/server/x64/bin") - set(CMAKE_CONFIGURATION_TYPES Debug Release) # Determine the platform. @@ -16,12 +13,16 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") set(OS_POSIX 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(TP_EXTERNAL_RELEASE_DIR "${PROJECT_SOURCE_DIR}/external/macos/release") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/server/macos/bin") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/server/macos/bin") elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") MESSAGE(STATUS "build on Linux...") set(OS_LINUX 1) set(OS_POSIX 1) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(TP_EXTERNAL_RELEASE_DIR "${PROJECT_SOURCE_DIR}/external/linux/release") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/server/linux/bin") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out/server/linux/bin") elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") MESSAGE(FATAL_ERROR "unsupported platform: Windows") else () diff --git a/build/build.py b/build/build.py index ddbaf7f..2792f9e 100644 --- a/build/build.py +++ b/build/build.py @@ -11,11 +11,6 @@ import builder.core.colorconsole as cc import builder.core.utils as utils from builder.core.context import * -if env.is_py2: - _input = raw_input -else: - _input = input - options = list() options_idx = 0 ctx = BuildContext() @@ -27,9 +22,6 @@ def main(): if not env.init(warn_miss_tool=True): return - # wget = os.environ.get('TP_TOOLCHAIN_WGET') - # cc.w(wget) - action = None argv = sys.argv[1:] if len(argv) >= 1: @@ -46,7 +38,21 @@ def main(): make_options() if action is not None: - cc.v(action) + if action == '-h' or action == '--help': + max_name_len = 0 + for x in options: + if x['id'] != '--SPLIT-LINE--': + max_name_len = max(len(x['name']), max_name_len) + max_name_len += 4 + + for x in options: + if x['id'] != '--SPLIT-LINE--': + name_pad = max_name_len - len(x['name']) + cc.o((cc.CR_INFO, x['name']), (cc.CR_VERBOSE, ' ' * name_pad), (cc.CR_VERBOSE, x['disp'])) + + return + + # cc.v(action) opt = select_option_by_name(action) if opt is None: cc.e('unknown config: ', action) @@ -61,16 +67,6 @@ def main(): if x == 'q': break - # if x == 'c': - # clean_all() - # continue - # elif x == 'a': - # clean_everything() - # continue - # elif x == 'e': - # clean_external() - # continue - try: x = int(x) except: @@ -91,7 +87,7 @@ def main(): cc.w('\ntask finished, press Enter to continue or Q to quit...', end='') try: - x = _input() + x = input() except EOFError: x = 'q' if x == 'q': @@ -124,16 +120,16 @@ def clean_everything(): def clean_external(): - #utils.remove(os.path.join(env.root_path, 'out')) + # utils.remove(os.path.join(env.root_path, 'out')) utils.remove(os.path.join(env.root_path, 'external', 'jsoncpp')) utils.remove(os.path.join(env.root_path, 'external', 'libuv')) utils.remove(os.path.join(env.root_path, 'external', 'mbedtls')) utils.remove(os.path.join(env.root_path, 'external', 'mongoose')) - #utils.remove(os.path.join(env.root_path, 'external', 'openssl')) - #utils.remove(os.path.join(env.root_path, 'external', 'python')) - #utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'lib')) - #utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'src')) - #utils.remove(os.path.join(env.root_path, 'external', 'linux', 'tmp')) + # utils.remove(os.path.join(env.root_path, 'external', 'openssl')) + # utils.remove(os.path.join(env.root_path, 'external', 'python')) + # utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'lib')) + # utils.remove(os.path.join(env.root_path, 'external', 'libssh-win-static', 'src')) + # utils.remove(os.path.join(env.root_path, 'external', 'linux', 'tmp')) utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedcrypto.a')) utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedtls.a')) utils.remove(os.path.join(env.root_path, 'external', 'linux', 'release', 'lib', 'libmbedx509.a')) @@ -153,9 +149,6 @@ def do_opt(opt): elif 'pysrt' == opt['name']: script = 'build-pysrt.py' - # elif 'external' == opt['name']: - # script = 'build-external.py' - # arg = '%s %s' % (ctx.target_path, opt['bits']) elif opt['name'] in ['ext-client', 'ext-server', 'clear-ext-client', 'clear-ext-server']: script = 'build-external.py' arg = '%s %s %s' % (opt['name'], ctx.target_path, opt['bits']) @@ -166,15 +159,12 @@ def do_opt(opt): elif 'server-installer' == opt['name']: script = 'build-installer.py' - # arg = 'installer' arg = '%s %s server-installer' % (ctx.dist, opt['bits']) elif 'client' == opt['name']: script = 'build-assist.py' arg = '%s %s exe' % (ctx.target_path, opt['bits']) - # elif 'assist-rdp' == opt['name']: - # script = 'build-assist.py' - # arg = '%s rdp' % (opt['bits']) + elif 'client-installer' == opt['name']: script = 'build-assist.py' arg = '%s %s installer' % (ctx.dist, opt['bits']) @@ -183,47 +173,35 @@ def do_opt(opt): cc.e('unknown option: ', opt['name']) return - # cmd = '"%s" -B "%s" %s' % (utils.cfg.py_exec, os.path.join(BUILDER_PATH, script), arg) cmd = '%s -B %s %s' % (env.py_exec, os.path.join(env.builder_path, script), arg) - print(cmd) os.system(cmd) def select_option_by_name(name): - global options - - for o in range(len(options)): - if options[o] is None: - continue - - if name == options[o]['name']: - return options[o] + for x in options: + if x['id'] != '--SPLIT-LINE--': + if name == x['name']: + return x return None def select_option_by_id(_id): - global options + for x in options: + if x['id'] == _id: + return x - for o in range(len(options)): - if options[o] is None: - continue - if options[o]['id'] == _id: - return options[o] return None def add_option(bits, name, disp): global options, options_idx options_idx += 1 - # if bits is not None: - # disp = '[%s] %s' % (bits, disp) options.append({'id': options_idx, 'name': name, 'disp': disp, 'bits': bits}) def add_split(title=None): global options - # options.append(None) options.append({'id': '--SPLIT-LINE--', 'title': title}) @@ -258,8 +236,8 @@ def make_options(): add_option('x64', 'client', 'build client applications [%s]' % ctx.target_path) add_option('x64', 'client-installer', 'make client installer') add_split('server side') - add_option('x64', 'ext-server', 'build external libraries for server') - add_option('x64', 'server', '(DEV-ONLY) build server applications [%s]' % ctx.target_path) + add_option('x64', 'ext-server', '(DEV-ONLY) build external libraries for server') + add_option('x64', 'server', '(DEV-ONLY) build server applications for MacOS [%s]' % ctx.target_path) add_split('clear') add_option('x64', 'clear-ext-client', 'clear external libraries for client') add_option('x64', 'clear-ext-server', 'clear external libraries for server') @@ -282,47 +260,36 @@ def make_options(): def get_input(msg, log_func=cc.w): log_func(msg, end=' ') try: - return _input() + return input() except EOFError: return '' def show_logo(): cc.v('[]==========================================================[]') - cc.o((cc.CR_VERBOSE, ' | '), (cc.CR_INFO, 'Teleport Projects Builder'), (cc.CR_VERBOSE, ' |')) + cc.v(' | Teleport Projects Builder v2.0 |') cc.v(' | auth: apex.liu@qq.com |') cc.v('[]==========================================================[]') def show_menu(): cc.v('\n=====================[ MENU ]===============================') - for o in range(len(options)): - if options[o]['id'] == '--SPLIT-LINE--': - if options[o]['title'] is not None: - # title = ' {}: '.format(options[o]['title']) - # pad = '-' * (60 - len(title)) - # cc.v('\n{}{}'.format(title, pad)) - cc.w('\n {}:'.format(options[o]['title'])) + for o in options: + if o['id'] == '--SPLIT-LINE--': + if o['title'] is not None: + cc.w('\n {}:'.format(o['title'])) else: cc.v('\n ----------------------------------------------------------') continue - # if options[o] is None: - # cc.v(' -------------------------------------------------------') - # continue - cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, '%2d' % options[o]['id']), (cc.CR_NORMAL, '] ', options[o]['disp'])) - - # cc.v(' -------------------------------------------------------') - # cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' E'), (cc.CR_NORMAL, '] clean external temp. files.')) - # cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' C'), (cc.CR_NORMAL, '] clean build and dist.')) - # cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' A'), (cc.CR_NORMAL, '] clean everything.')) + cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, '%2d' % o['id']), (cc.CR_NORMAL, '] ', o['disp'])) cc.v('\n ----------------------------------------------------------') cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' Q'), (cc.CR_NORMAL, '] exit')) cc.w('\nselect action: ', end='') try: - x = _input() + x = input() except EOFError: x = 'q' @@ -338,4 +305,4 @@ if __name__ == '__main__': except RuntimeError as e: cc.e(e.__str__()) except: - cc.f('got exception.') + cc.f('got an exception.') diff --git a/build/builder/build-external.py b/build/builder/build-external.py index 0f974ae..759e3ac 100644 --- a/build/builder/build-external.py +++ b/build/builder/build-external.py @@ -166,7 +166,7 @@ class BuilderWin(BuilderBase): cc.w('please install OpenSSL into "{}".'.format(self.OPENSSL_PATH_SRC)) cc.w('\nOnce the OpenSSL installed, press Enter to continue or Q to quit...', end='') try: - x = env.input() + x = input() except EOFError: x = 'q' if x == 'q': @@ -349,7 +349,7 @@ class BuilderWin(BuilderBase): cc.w('for Visual Studio 2017. Visit https://docs.tp4a.com for more details.') cc.w('\nOnce the zlib.sln generated, press Enter to continue or Q to quit...', end='') try: - x = env.input() + x = input() except EOFError: x = 'q' if x == 'q': diff --git a/build/builder/build-installer.py b/build/builder/build-installer.py index e8a1051..5ad77e3 100644 --- a/build/builder/build-installer.py +++ b/build/builder/build-installer.py @@ -129,7 +129,7 @@ class BuilderLinux(BuilderBase): utils.fix_new_line_flag(os.path.join(self.path_tmp_data, 'tmp', 'etc', 'web.ini')) utils.fix_new_line_flag(os.path.join(self.path_tmp_data, 'tmp', 'etc', 'core.ini')) - out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, 'bin') + out_path = os.path.join(env.root_path, 'out', 'server', 'linux', 'bin') bin_path = os.path.join(self.path_tmp_data, 'bin') utils.copy_ex(out_path, bin_path, 'tp_web') utils.copy_ex(out_path, bin_path, 'tp_core') diff --git a/build/builder/core/colorconsole.py b/build/builder/core/colorconsole.py index 9f3839e..38db25f 100644 --- a/build/builder/core/colorconsole.py +++ b/build/builder/core/colorconsole.py @@ -206,85 +206,12 @@ class ColorConsole: s = traceback.extract_stack() c = len(s) self._console_set_color(CR_RED) - for i in range(2, c): + for i in range(1, c): self._console_output(' ', os.path.abspath(s[c - i - 1][0]), '(', s[c - i - 1][1], '): ', s[c - i - 1][3], sep='') self._console_restore_color() sys.stdout.flush() - # def _do_log(self, msg, color=None): - # self._log_console(msg, color) - # - # def _console_default(self, msg, color=None): - # if msg is None: - # return - # - # sys.stdout.writelines(msg) - # sys.stdout.flush() - # - # def _console_win(self, msg, color=None): - # if msg is None: - # return - # - # # 这里的问题很复杂,日常使用没有问题,但是当在工作机上使用时,部分内容是捕获另一个脚本执行的结果再输出 - # # 如果结果中有中文,这里就会显示乱码。如果尝试编码转换,会抛出异常。目前暂时采用显示乱码的方式了。 - # - # # if CONSOLE_WIN_CMD == self.console_type: - # # try: - # # _msg = unicode(msg, 'utf-8') - # # except: - # # _msg = msg - # # else: - # # _msg = msg - # # _msg = None - # # if isinstance(msg, unicode): - # # _msg = msg - # # else: - # # # _msg = unicode(msg, 'utf-8') - # # try: - # # _msg = unicode(msg, 'utf-8') - # # except: - # # _msg = unicode(msg, 'gb2312') - # # # _msg = msg - # # - # # # if CONSOLE_WIN_CMD == self.console_type: - # # # sys.stdout.writelines(msg.encode('gb2312')) - # # # else: - # # # sys.stdout.writelines(msg.encode('utf-8')) - # # - # # - # # # try: - # # # _msg = unicode(msg, 'utf-8') - # # # except: - # # _msg = msg - # - # if color is None: - # sys.stdout.writelines(msg) - # else: - # self._win_color.set_color(COLORS[color][1]) - # sys.stdout.writelines(msg) - # sys.stdout.flush() - # self._win_color.set_color(COLORS[CR_RESTORE][1]) - # - # sys.stdout.flush() - # - # def _console_linux(self, msg, cr=None): - # if msg is None: - # return - # - # if cr is None: - # sys.stdout.writelines(msg) - # else: - # sys.stdout.writelines('\x1B') - # sys.stdout.writelines(COLORS[cr][0]) - # sys.stdout.writelines(msg) - # sys.stdout.writelines('\x1B[0m') - # - # sys.stdout.flush() - - # def _console_set_color_default(self, cr=None): - # pass - def _console_set_color_win(self, cr=None): if cr is None: return @@ -325,55 +252,33 @@ class ColorConsole: sys.stdout.writelines(end) sys.stdout.flush() - # def _test(self): - # self.log('###################', CR_RESTORE) - # self.log(' CR_RESTORE\n') - # self.log('###################', CR_BLACK) - # self.log(' CR_BLACK\n') - # self.log('###################', CR_LIGHT_GRAY) - # self.log(' CR_LIGHT_GRAY\n') - # self.log('###################', CR_GRAY) - # self.log(' CR_GRAY\n') - # self.log('###################', CR_WHITE) - # self.log(' CR_WHITE\n') - # self.log('###################', CR_RED) - # self.log(' CR_RED\n') - # self.log('###################', CR_GREEN) - # self.log(' CR_GREEN\n') - # self.log('###################', CR_YELLOW) - # self.log(' CR_YELLOW\n') - # self.log('###################', CR_BLUE) - # self.log(' CR_BLUE\n') - # self.log('###################', CR_MAGENTA) - # self.log(' CR_MAGENTA\n') - # self.log('###################', CR_CYAN) - # self.log(' CR_CYAN\n') - # self.log('###################', CR_LIGHT_RED) - # self.log(' CR_LIGHT_RED\n') - # self.log('###################', CR_LIGHT_GREEN) - # self.log(' CR_LIGHT_GREEN\n') - # self.log('###################', CR_LIGHT_YELLOW) - # self.log(' CR_LIGHT_YELLOW\n') - # self.log('###################', CR_LIGHT_BLUE) - # self.log(' CR_LIGHT_BLUE\n') - # self.log('###################', CR_LIGHT_MAGENTA) - # self.log(' CR_LIGHT_MAGENTA\n') - # self.log('###################', CR_LIGHT_CYAN) - # self.log(' CR_LIGHT_CYAN\n') - # # data = b'This is a test string and you can see binary format data here.' - # # self.bin('Binary Data:\n', data) - # # data = b'' - # # self.bin('Empty binary\n', data) - # # self.bin('This is string\n\n', 'data') - # - # # self.d('This is DEBUG message.\n') - # self.v('This is VERBOSE message.\n') - # self.i('This is INFORMATION message.\n') - # self.w('This is WARNING message.\n') - # self.e('This is ERROR message.\n') - # self.f('This is FAIL message.\n') - # - # self.v('test auto\nsplit lines.\nYou should see\nmulti-lines.\n') + def test(self): + self.o((CR_RESTORE, '################### CR_RESTORE')) + self.o((CR_BLACK, '################### CR_BLACK')) + self.o((CR_LIGHT_GRAY, '################### CR_LIGHT_GRAY')) + self.o((CR_GRAY, '################### CR_GRAY')) + self.o((CR_WHITE, '################### CR_WHITE')) + self.o((CR_RED, '################### CR_RED')) + self.o((CR_GREEN, '################### CR_GREEN')) + self.o((CR_YELLOW, '################### CR_YELLOW')) + self.o((CR_BLUE, '################### CR_BLUE')) + self.o((CR_MAGENTA, '################### CR_MAGENTA')) + self.o((CR_CYAN, '################### CR_CYAN')) + self.o((CR_LIGHT_RED, '################### CR_LIGHT_RED')) + self.o((CR_LIGHT_GREEN, '################### CR_LIGHT_GREEN')) + self.o((CR_LIGHT_YELLOW, '################### CR_LIGHT_YELLOW')) + self.o((CR_LIGHT_BLUE, '################### CR_LIGHT_BLUE')) + self.o((CR_LIGHT_MAGENTA, '################### CR_LIGHT_MAGENTA')) + self.o((CR_LIGHT_CYAN, '################### CR_LIGHT_CYAN')) + + self.v('This is VERBOSE message.') + self.n('This is NORMAL message.') + self.i('This is INFORMATION message.') + self.w('This is WARNING message.') + self.e('This is ERROR message.') + self.f('This is FAIL message, show backtrace also.') + + self.v('test auto\nsplit lines.\nYou should see\nmulti-lines.\n') class Win32ColorConsole: @@ -474,3 +379,7 @@ def e(*args, **kwargs): def f(*args, **kwargs): _cc.f(*args, **kwargs) + + +if __name__ == '__main__': + _cc.test() diff --git a/build/builder/core/env.py b/build/builder/core/env.py index 7f8a6b9..1bcc88a 100644 --- a/build/builder/core/env.py +++ b/build/builder/core/env.py @@ -26,14 +26,6 @@ class Env(object): self.build_path = os.path.abspath(os.path.join(_this_path, '..', '..')) self.builder_path = os.path.join(self.build_path, 'builder') - self.is_py2 = sys.version_info[0] == 2 - self.is_py3 = sys.version_info[0] == 3 - - if self.is_py2: - self.input = raw_input - else: - self.input = input - self.py_ver = platform.python_version_tuple() self.py_ver_str = '%s%s' % (self.py_ver[0], self.py_ver[1]) self.py_ver_dot = '%s.%s' % (self.py_ver[0], self.py_ver[1]) @@ -76,10 +68,8 @@ class Env(object): def _load_config(self, warn_miss_tool): _cfg_file = 'config.{}.json'.format(self.plat) - # _cfg_file = os.path.join(self.root_path, 'config.ini') _cfg_file = os.path.join(self.root_path, _cfg_file) if not os.path.exists(_cfg_file): - # cc.e('can not load configuration.\n\nplease copy `config.ini.in` to `config.ini` and modify it to fit your condition and try again.') cc.e('can not load configuration.\n\nplease copy `config.json.in` to `config.{}.json` and modify it to fit your condition and try again.'.format(self.plat)) return False @@ -90,12 +80,6 @@ class Env(object): cc.e('can ot load configuration file, not in JSON format.') return False - # _cfg = configparser.ConfigParser() - # _cfg.read(_cfg_file) - # if 'toolchain' not in _cfg.sections(): - # cc.e('invalid configuration file: need `toolchain` section.') - # return False - if 'toolchain' not in _cfg: cc.e('invalid configuration file: need `toolchain` section.') return False diff --git a/build/builder/core/utils.py b/build/builder/core/utils.py index 10d32c3..114c09f 100644 --- a/build/builder/core/utils.py +++ b/build/builder/core/utils.py @@ -9,11 +9,8 @@ import time from . import colorconsole as cc from .env import env -if env.is_py2: - import imp -elif env.is_py3: - import importlib - import importlib.machinery +import importlib +import importlib.machinery def _check_download_file(file_name): @@ -96,13 +93,7 @@ def extension_suffixes(): # type为文件类型, 1代表PY_SOURCE, 2代表PY_COMPILED, 3代表C_EXTENSION EXTENSION_SUFFIXES = list() - if env.is_py2: - suf = imp.get_suffixes() - for s in suf: - if s[2] == 3: - EXTENSION_SUFFIXES.append(s[0]) - else: - EXTENSION_SUFFIXES = importlib.machinery.EXTENSION_SUFFIXES + EXTENSION_SUFFIXES = importlib.machinery.EXTENSION_SUFFIXES if env.is_win: if '.dll' not in EXTENSION_SUFFIXES: 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 2b62c82..79e6344 100644 --- a/client/tp_assist_macos/src/csrc/ts_http_rpc.cpp +++ b/client/tp_assist_macos/src/csrc/ts_http_rpc.cpp @@ -713,33 +713,35 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf) { //============================================== // sorry, TELNET not supported yet for macOS. - _create_json_ret(buf, TPE_NOT_IMPLEMENT); - return; +// _create_json_ret(buf, TPE_NOT_IMPLEMENT); +// return; -// if(g_cfg.telnet.name == "terminal" || g_cfg.telnet.name == "iterm2") { -// char szCmd[1024] = {0}; -// ex_strformat(szCmd, 1023, "telnet -l %s %s %d", sid.c_str(), teleport_ip.c_str(), teleport_port); -// -// char szTitle[128] = {0}; -// ex_strformat(szTitle, 127, "TP#%s", real_host_ip.c_str()); -// -// int ret = AppDelegate_start_ssh_client(g_app, szCmd, g_cfg.telnet.name.c_str(), g_cfg.telnet.cmdline.c_str(), szTitle); -// if(ret == 0) -// _create_json_ret(buf, TPE_OK); -// else -// _create_json_ret(buf, TPE_FAILED); -// return; -// } -// -// if(g_cfg.telnet.application.length() == 0) { -// _create_json_ret(buf, TPE_NOT_EXISTS); -// return; -// } -// -// s_exec = g_cfg.telnet.application; -// s_argv.push_back(s_exec.c_str()); -// -// s_arg = g_cfg.telnet.cmdline; + g_cfg.telnet.name = "iterm2"; + + if(g_cfg.telnet.name == "terminal" || g_cfg.telnet.name == "iterm2") { + char szCmd[1024] = {0}; + ex_strformat(szCmd, 1023, "telnet -l %s %s %d", sid.c_str(), teleport_ip.c_str(), teleport_port); + + char szTitle[128] = {0}; + ex_strformat(szTitle, 127, "TP#%s", real_host_ip.c_str()); + + int ret = AppDelegate_start_ssh_client(g_app, szCmd, g_cfg.telnet.name.c_str(), g_cfg.telnet.cmdline.c_str(), szTitle); + if(ret == 0) + _create_json_ret(buf, TPE_OK); + else + _create_json_ret(buf, TPE_FAILED); + return; + } + + if(g_cfg.telnet.application.length() == 0) { + _create_json_ret(buf, TPE_NOT_EXISTS); + return; + } + + s_exec = g_cfg.telnet.application; + s_argv.push_back(s_exec.c_str()); + + s_arg = g_cfg.telnet.cmdline; } diff --git a/make.sh b/make.sh index 8b3b2b4..706c94c 100755 --- a/make.sh +++ b/make.sh @@ -94,7 +94,7 @@ function build_macos { check_cfg_file - python3 -B "${PATH_ROOT}/build/build.py" $@ + python3 -B "${PATH_ROOT}/build/build.py" $@ } function on_error() diff --git a/server/tp_core/core/ts_web_rpc.cpp b/server/tp_core/core/ts_web_rpc.cpp index 096d722..ce330cd 100644 --- a/server/tp_core/core/ts_web_rpc.cpp +++ b/server/tp_core/core/ts_web_rpc.cpp @@ -194,7 +194,7 @@ int ts_web_rpc_get_conn_info(int conn_id, TS_CONNECT_INFO& info) || user_username.length() == 0 || host_ip.length() == 0 || conn_ip.length() == 0 || client_ip.length() == 0 || conn_port <= 0 || conn_port >= 65535 - || acc_username.length() == 0 || acc_secret.length() == 0 + || acc_username.length() == 0 || !(protocol_type == TP_PROTOCOL_TYPE_RDP || protocol_type == TP_PROTOCOL_TYPE_SSH || protocol_type == TP_PROTOCOL_TYPE_TELNET) || !(auth_type == TP_AUTH_TYPE_NONE || auth_type == TP_AUTH_TYPE_PASSWORD || auth_type == TP_AUTH_TYPE_PRIVATE_KEY) ) @@ -202,7 +202,11 @@ int ts_web_rpc_get_conn_info(int conn_id, TS_CONNECT_INFO& info) return TPE_PARAM; } - if (_enc) { + if(auth_type != TP_AUTH_TYPE_NONE && acc_secret.length() == 0) { + return TPE_PARAM; + } + + if (_enc && !acc_secret.empty()) { ex_astr _auth; if (!ts_db_field_decrypt(acc_secret, _auth)) return TPE_FAILED; diff --git a/server/www/teleport/webroot/app/model/record.py b/server/www/teleport/webroot/app/model/record.py index a3b797d..599943d 100644 --- a/server/www/teleport/webroot/app/model/record.py +++ b/server/www/teleport/webroot/app/model/record.py @@ -493,10 +493,18 @@ def session_fix(): def session_begin(sid, user_id, host_id, acc_id, user_username, acc_username, host_ip, conn_ip, conn_port, client_ip, auth_type, protocol_type, protocol_sub_type): db = get_db() - sql = 'INSERT INTO `{}record` (sid,user_id,host_id,acc_id,state,user_username,host_ip,conn_ip,conn_port,client_ip,acc_username,auth_type,protocol_type,protocol_sub_type,time_begin,time_end) ' \ - 'VALUES ("{sid}",{user_id},{host_id},{acc_id},0,"{user_username}","{host_ip}","{conn_ip}",{conn_port},"{client_ip}","{acc_username}",{auth_type},{protocol_type},{protocol_sub_type},{time_begin},0)' \ + + sql = 'SELECT surname FROM `{tp}user` WHERE id={ph};'.format(tp=db.table_prefix, ph=db.place_holder) + db_ret = db.query(sql, (user_id, )) + if db_ret is None or len(db_ret) == 0: + user_surname = user_username + else: + user_surname = db_ret[0][0] + + sql = 'INSERT INTO `{}record` (sid,user_id,host_id,acc_id,state,user_username,user_surname,host_ip,conn_ip,conn_port,client_ip,acc_username,auth_type,protocol_type,protocol_sub_type,time_begin,time_end) ' \ + 'VALUES ("{sid}",{user_id},{host_id},{acc_id},0,"{user_username}","{user_surname}","{host_ip}","{conn_ip}",{conn_port},"{client_ip}","{acc_username}",{auth_type},{protocol_type},{protocol_sub_type},{time_begin},0)' \ ';'.format(db.table_prefix, - sid=sid, user_id=user_id, host_id=host_id, acc_id=acc_id, user_username=user_username, host_ip=host_ip, conn_ip=conn_ip, conn_port=conn_port, + sid=sid, user_id=user_id, host_id=host_id, acc_id=acc_id, user_username=user_username, user_surname=user_surname, host_ip=host_ip, conn_ip=conn_ip, conn_port=conn_port, client_ip=client_ip, acc_username=acc_username, auth_type=auth_type, protocol_type=protocol_type, protocol_sub_type=protocol_sub_type, time_begin=tp_timestamp_sec())