pull/32/merge
Apex Liu 2017-03-16 18:45:31 +08:00
parent 61512f287c
commit f142793394
24 changed files with 839 additions and 750 deletions

View File

@ -90,8 +90,8 @@ def main():
def clean_all(): def clean_all():
cc.v('remove compiler out path...') cc.e('sorry, clean not implemented yet.')
utils.remove(os.path.join(ROOT_PATH, 'out')) # utils.remove(os.path.join(env.root_path, 'out'))
def do_opt(opt): def do_opt(opt):
@ -130,7 +130,7 @@ def do_opt(opt):
return return
# cmd = '"%s" -B "%s" %s' % (utils.cfg.py_exec, os.path.join(BUILDER_PATH, script), arg) # cmd = '"%s" -B "%s" %s' % (utils.cfg.py_exec, os.path.join(BUILDER_PATH, script), arg)
cmd = '%s -B %s %s' % (utils.cfg.py_exec, os.path.join(env.builder_path, script), arg) cmd = '%s -B %s %s' % (env.py_exec, os.path.join(env.builder_path, script), arg)
os.system(cmd) os.system(cmd)

View File

@ -105,7 +105,13 @@ class BuilderWin(BuilderBase):
self._prepare_python_header() self._prepare_python_header()
def _prepare_python_header(self): def _prepare_python_header(self):
cc.n('prepare python header files ...') cc.n('prepare python header files ...', end='')
if os.path.exists(os.path.join(PATH_EXTERNAL, 'python', 'include', 'pyctype.h')):
cc.w('already exists, skip.')
return
cc.v('')
_header_path = None _header_path = None
for p in sys.path: for p in sys.path:
if os.path.exists(os.path.join(p, 'include', 'pyctype.h')): if os.path.exists(os.path.join(p, 'include', 'pyctype.h')):
@ -203,16 +209,18 @@ class BuilderWin(BuilderBase):
cc.w('already exists, skip.') cc.w('already exists, skip.')
def _build_mongoose(self, file_name): def _build_mongoose(self, file_name):
cc.n('prepare mongoose source code...') cc.n('prepare mongoose source code... ', end='')
if not os.path.exists(self.MONGOOSE_PATH_SRC): if not os.path.exists(self.MONGOOSE_PATH_SRC):
cc.v('')
utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
os.rename(os.path.join(PATH_EXTERNAL, 'mongoose-{}'.format(env.ver_mongoose)), self.MONGOOSE_PATH_SRC) os.rename(os.path.join(PATH_EXTERNAL, 'mongoose-{}'.format(env.ver_mongoose)), self.MONGOOSE_PATH_SRC)
else: else:
cc.w('already exists, skip.') cc.w('already exists, skip.')
def _build_mbedtls(self, file_name): def _build_mbedtls(self, file_name):
cc.n('prepare mbedtls source code...') cc.n('prepare mbedtls source code... ', end='')
if not os.path.exists(self.MBEDTLS_PATH_SRC): if not os.path.exists(self.MBEDTLS_PATH_SRC):
cc.v('')
utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL) utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
os.rename(os.path.join(PATH_EXTERNAL, 'mbedtls-mbedtls-{}'.format(env.ver_mbedtls)), self.MBEDTLS_PATH_SRC) os.rename(os.path.join(PATH_EXTERNAL, 'mbedtls-mbedtls-{}'.format(env.ver_mbedtls)), self.MBEDTLS_PATH_SRC)
else: else:

View File

@ -5,16 +5,18 @@ import codecs
from core import colorconsole as cc from core import colorconsole as cc
from core import utils from core import utils
from core.env import env
from core.context import * from core.context import *
ctx = BuildContext() ctx = BuildContext()
ROOT_PATH = utils.cfg.ROOT_PATH
# ROOT_PATH = utils.cfg.ROOT_PATH
class Builder: class Builder:
def __init__(self): def __init__(self):
self.ver_in = os.path.join(ROOT_PATH, 'version.in') self.ver_in = os.path.join(env.root_path, 'version.in')
self.VER_TELEPORT_SERVER = '' self.VER_TELEPORT_SERVER = ''
self.VER_TELEPORT_ASSIST = '' self.VER_TELEPORT_ASSIST = ''
@ -57,7 +59,7 @@ class Builder:
self.make_web_ver() self.make_web_ver()
def make_build_ver(self): def make_build_ver(self):
ver_file = os.path.join(ROOT_PATH, 'build', 'builder', 'core', 'ver.py') ver_file = os.path.join(env.root_path, 'build', 'builder', 'core', 'ver.py')
# ver_content = '# -*- coding: utf8 -*-\nVER_TELEPORT_SERVER = "{}"\nVER_TELEPORT_ASSIST = "{}"\nVER_TELEPORT_MAKECERT = "{}"\n'.format(self.VER_TELEPORT_SERVER, self.VER_TELEPORT_ASSIST, self.VER_TELEPORT_MAKECERT) # ver_content = '# -*- coding: utf8 -*-\nVER_TELEPORT_SERVER = "{}"\nVER_TELEPORT_ASSIST = "{}"\nVER_TELEPORT_MAKECERT = "{}"\n'.format(self.VER_TELEPORT_SERVER, self.VER_TELEPORT_ASSIST, self.VER_TELEPORT_MAKECERT)
ver_content = '# -*- coding: utf8 -*-\nVER_TELEPORT_SERVER = "{}"\nVER_TELEPORT_ASSIST = "{}"\n'.format(self.VER_TELEPORT_SERVER, self.VER_TELEPORT_ASSIST) ver_content = '# -*- coding: utf8 -*-\nVER_TELEPORT_SERVER = "{}"\nVER_TELEPORT_ASSIST = "{}"\n'.format(self.VER_TELEPORT_SERVER, self.VER_TELEPORT_ASSIST)
@ -77,7 +79,7 @@ class Builder:
f.write(ver_content) f.write(ver_content)
def make_web_ver(self): def make_web_ver(self):
ver_file = os.path.join(ROOT_PATH, 'server', 'www', 'teleport', 'app', 'eom_ver.py') ver_file = os.path.join(env.root_path, 'server', 'www', 'teleport', 'app', 'eom_ver.py')
# ver_content = '# -*- coding: utf8 -*-\n\nTS_VER = "{}"\n'.format(self.VER_TELEPORT_SERVER) # ver_content = '# -*- coding: utf8 -*-\n\nTS_VER = "{}"\n'.format(self.VER_TELEPORT_SERVER)
ver_content = '# -*- coding: utf8 -*-\nTS_VER = "{}"\nTP_ASSIST_LAST_VER = "{}"\nTP_ASSIST_REQUIRE = "{}"\n'.format(self.VER_TELEPORT_SERVER, self.VER_TELEPORT_ASSIST, self.VER_TELEPORT_ASSIST_REQUIRE) ver_content = '# -*- coding: utf8 -*-\nTS_VER = "{}"\nTP_ASSIST_LAST_VER = "{}"\nTP_ASSIST_REQUIRE = "{}"\n'.format(self.VER_TELEPORT_SERVER, self.VER_TELEPORT_ASSIST, self.VER_TELEPORT_ASSIST_REQUIRE)
@ -97,7 +99,7 @@ class Builder:
f.write(ver_content) f.write(ver_content)
def make_assist_ver(self): def make_assist_ver(self):
ver_file = os.path.join(ROOT_PATH, 'client', 'tp_assist', 'ts_ver.h') ver_file = os.path.join(env.root_path, 'client', 'tp_assist', 'ts_ver.h')
ver_content = '#ifndef __TS_ASSIST_VER_H__\n#define __TS_ASSIST_VER_H__\n\n#define TP_ASSIST_VER\tL"{}"\n\n#endif // __TS_ASSIST_VER_H__\n'.format(self.VER_TELEPORT_ASSIST) ver_content = '#ifndef __TS_ASSIST_VER_H__\n#define __TS_ASSIST_VER_H__\n\n#define TP_ASSIST_VER\tL"{}"\n\n#endif // __TS_ASSIST_VER_H__\n'.format(self.VER_TELEPORT_ASSIST)
rewrite = False rewrite = False
@ -115,14 +117,14 @@ class Builder:
with open(ver_file, 'w') as f: with open(ver_file, 'w') as f:
f.write(ver_content) f.write(ver_content)
rc_file = os.path.join(ROOT_PATH, 'client', 'tp_assist', 'tp_assist.rc') rc_file = os.path.join(env.root_path, 'client', 'tp_assist', 'tp_assist.rc')
self._update_vs_rc(rc_file, self.VER_TELEPORT_ASSIST) self._update_vs_rc(rc_file, self.VER_TELEPORT_ASSIST)
nsi_file = os.path.join(ROOT_PATH, 'dist', 'windows', 'client', 'assist', 'installer.nsi') nsi_file = os.path.join(env.root_path, 'dist', 'windows', 'client', 'assist', 'installer.nsi')
self._update_nsi_rc(nsi_file, self.VER_TELEPORT_ASSIST) self._update_nsi_rc(nsi_file, self.VER_TELEPORT_ASSIST)
def make_tp_core_ver(self): def make_tp_core_ver(self):
ver_file = os.path.join(ROOT_PATH, 'server', 'tp_core', 'core', 'ts_ver.h') ver_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'ts_ver.h')
ver_content = '#ifndef __TS_SERVER_VER_H__\n#define __TS_SERVER_VER_H__\n\n#define TP_SERVER_VER\tL"{}"\n\n#endif // __TS_SERVER_VER_H__\n'.format(self.VER_TELEPORT_SERVER) ver_content = '#ifndef __TS_SERVER_VER_H__\n#define __TS_SERVER_VER_H__\n\n#define TP_SERVER_VER\tL"{}"\n\n#endif // __TS_SERVER_VER_H__\n'.format(self.VER_TELEPORT_SERVER)
rewrite = False rewrite = False
@ -140,11 +142,11 @@ class Builder:
with open(ver_file, 'w') as f: with open(ver_file, 'w') as f:
f.write(ver_content) f.write(ver_content)
rc_file = os.path.join(ROOT_PATH, 'server', 'tp_core', 'core', 'tp_core.rc') rc_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'tp_core.rc')
self._update_vs_rc(rc_file, self.VER_TELEPORT_SERVER) self._update_vs_rc(rc_file, self.VER_TELEPORT_SERVER)
def make_tp_web_ver(self): def make_tp_web_ver(self):
ver_file = os.path.join(ROOT_PATH, 'server', 'tp_web', 'src', 'ts_ver.h') ver_file = os.path.join(env.root_path, 'server', 'tp_web', 'src', 'ts_ver.h')
ver_content = '#ifndef __TS_SERVER_VER_H__\n#define __TS_SERVER_VER_H__\n\n#define TP_SERVER_VER\tL"{}"\n\n#endif // __TS_SERVER_VER_H__\n'.format(self.VER_TELEPORT_SERVER) ver_content = '#ifndef __TS_SERVER_VER_H__\n#define __TS_SERVER_VER_H__\n\n#define TP_SERVER_VER\tL"{}"\n\n#endif // __TS_SERVER_VER_H__\n'.format(self.VER_TELEPORT_SERVER)
rewrite = False rewrite = False
@ -162,7 +164,7 @@ class Builder:
with open(ver_file, 'w') as f: with open(ver_file, 'w') as f:
f.write(ver_content) f.write(ver_content)
rc_file = os.path.join(ROOT_PATH, 'server', 'tp_web', 'src', 'tp_web.rc') rc_file = os.path.join(env.root_path, 'server', 'tp_web', 'src', 'tp_web.rc')
self._update_vs_rc(rc_file, self.VER_TELEPORT_SERVER) self._update_vs_rc(rc_file, self.VER_TELEPORT_SERVER)
def _update_vs_rc(self, rcFilePath, ver): def _update_vs_rc(self, rcFilePath, ver):
@ -352,6 +354,9 @@ class Builder:
def main(): def main():
if not env.init():
return
builder = Builder() builder = Builder()
builder.build() builder.build()

View File

@ -1,97 +0,0 @@
# -*- coding: utf8 -*-
import os
import sys
import platform
import configparser
from . import colorconsole as cc
__all__ = ['cfg']
class AttrDict(dict):
"""
可以像属性一样访问字典的 Keyvar.key 等同于 var['key']
"""
def __getattr__(self, name):
try:
return self[name]
except KeyError:
# print(self.__class__.__name__)
raise
def __setattr__(self, name, val):
self[name] = val
class ConfigFile(AttrDict):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def init(self, cfg_file):
self['ROOT_PATH'] = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
self['py_exec'] = sys.executable
_py_ver = platform.python_version_tuple()
self['py_ver'] = _py_ver
self['py_ver_str'] = '%s%s' % (_py_ver[0], _py_ver[1])
self['is_py2'] = sys.version_info[0] == 2
self['is_py3'] = sys.version_info[0] == 3
_bits = platform.architecture()[0]
if _bits == '64bit':
self['is_x64'] = True
self['is_x86'] = False
else:
self['is_x64'] = False
self['is_x86'] = True
_os = platform.system().lower()
self['is_win'] = False
self['is_linux'] = False
self['is_macos'] = False
self['dist'] = ''
if _os == 'windows':
self['is_win'] = True
self['dist'] = 'windows'
elif _os == 'linux':
self['is_linux'] = True
self['dist'] = 'linux'
elif _os == 'darwin':
self['is_macos'] = True
self['dist'] = 'macos'
else:
cc.e('not support this OS: {}'.format(platform.system()))
return False
_cfg = configparser.ConfigParser()
_cfg.read(cfg_file)
if 'external_ver' not in _cfg.sections() or 'toolchain' not in _cfg.sections():
cc.e('invalid configuration file: need `external_ver` and `toolchain` section.')
return False
_tmp = _cfg['external_ver']
if 'libuv' not in _tmp or 'mbedtls' not in _tmp or 'sqlite' not in _tmp:
cc.e('invalid configuration file: external version not set.')
return False
self['ver'] = AttrDict()
for k in _tmp:
self['ver'][k] = _tmp[k]
_tmp = _cfg['toolchain']
self['toolchain'] = AttrDict()
if self.is_win:
self['toolchain']['nsis'] = _tmp.get('nsis', None)
self['toolchain']['msbuild'] = None # msbuild always read from register.
else:
self['toolchain']['cmake'] = _tmp.get('cmake', '/usr/bin/cmake')
return True
cfg = ConfigFile()
del ConfigFile

View File

@ -10,24 +10,24 @@ import time
from . import colorconsole as cc from . import colorconsole as cc
from .env import env from .env import env
from .configs import cfg # from .configs import cfg
#
# try:
# CONFIG_FILE = os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')), 'config.ini')
# if not cfg.init(CONFIG_FILE):
# sys.exit(1)
# except:
# cc.e('can not load configuration.\n\nplease copy `config.ini.in` into `config.ini` and modify it to fit your condition and try again.')
# sys.exit(1)
try: if env.is_py2:
CONFIG_FILE = os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')), 'config.ini')
if not cfg.init(CONFIG_FILE):
sys.exit(1)
except:
cc.e('can not load configuration.\n\nplease copy `config.ini.in` into `config.ini` and modify it to fit your condition and try again.')
sys.exit(1)
if cfg.is_py2:
import imp import imp
elif cfg.is_py3: elif env.is_py3:
import importlib import importlib
import importlib.machinery import importlib.machinery
if sys.platform == 'win32': # if sys.platform == 'win32':
import winreg # import winreg
THIS_PATH = os.path.abspath(os.path.dirname(__file__)) THIS_PATH = os.path.abspath(os.path.dirname(__file__))
ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..')) ROOT_PATH = os.path.abspath(os.path.join(THIS_PATH, '..'))
@ -80,7 +80,7 @@ def extension_suffixes():
# type为文件类型, 1代表PY_SOURCE, 2代表PY_COMPILED, 3代表C_EXTENSION # type为文件类型, 1代表PY_SOURCE, 2代表PY_COMPILED, 3代表C_EXTENSION
EXTENSION_SUFFIXES = list() EXTENSION_SUFFIXES = list()
if cfg.is_py2: if env.is_py2:
suf = imp.get_suffixes() suf = imp.get_suffixes()
for s in suf: for s in suf:
if s[2] == 3: if s[2] == 3:
@ -88,16 +88,16 @@ def extension_suffixes():
else: else:
EXTENSION_SUFFIXES = importlib.machinery.EXTENSION_SUFFIXES EXTENSION_SUFFIXES = importlib.machinery.EXTENSION_SUFFIXES
if cfg.dist == 'windows': if env.is_win:
if '.dll' not in EXTENSION_SUFFIXES: if '.dll' not in EXTENSION_SUFFIXES:
EXTENSION_SUFFIXES.append('.dll') EXTENSION_SUFFIXES.append('.dll')
elif cfg.dist == 'linux': elif env.is_linux:
if '.so' not in EXTENSION_SUFFIXES: if '.so' not in EXTENSION_SUFFIXES:
EXTENSION_SUFFIXES.append('.so') EXTENSION_SUFFIXES.append('.so')
elif cfg.dist == 'macos': else:
raise RuntimeError('not support MacOS now.') raise RuntimeError('not support this platform now.')
return EXTENSION_SUFFIXES return EXTENSION_SUFFIXES
@ -260,66 +260,66 @@ def python_exec():
return sys.executable return sys.executable
def msbuild_path(): # def msbuild_path():
if cfg.toolchain.msbuild is not None: # if cfg.toolchain.msbuild is not None:
return cfg.toolchain.msbuild # return cfg.toolchain.msbuild
#
# 14.0 = VS2015 # # 14.0 = VS2015
# 12.0 = VS2012 # # 12.0 = VS2012
# 4.0 = VS2008 # # 4.0 = VS2008
chk = ['14.0', '4.0', '12.0'] # chk = ['14.0', '4.0', '12.0']
#
msp = None # msp = None
for c in chk: # for c in chk:
msp = winreg_read("SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\{}".format(c), 'MSBuildToolsPath') # msp = winreg_read("SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\{}".format(c), 'MSBuildToolsPath')
if msp is not None: # if msp is not None:
break # break
#
if msp is None: # if msp is None:
raise RuntimeError('Can not locate MSBuild.') # raise RuntimeError('Can not locate MSBuild.')
#
msb = os.path.join(msp[0], 'MSBuild.exe') # msb = os.path.join(msp[0], 'MSBuild.exe')
if not os.path.exists(msb): # if not os.path.exists(msb):
raise RuntimeError('Can not locate MSBuild at {}'.format(msp)) # raise RuntimeError('Can not locate MSBuild at {}'.format(msp))
#
cfg.toolchain.msbuild = msb # cfg.toolchain.msbuild = msb
return msb # return msb
def nsis_path(): # def nsis_path():
if cfg.toolchain.nsis is not None: # if cfg.toolchain.nsis is not None:
return cfg.toolchain.nsis # return cfg.toolchain.nsis
#
p = winreg_read_wow64_32(r'SOFTWARE\NSIS\Unicode', '') # p = winreg_read_wow64_32(r'SOFTWARE\NSIS\Unicode', '')
if p is None: # if p is None:
raise RuntimeError('Can not locate unicode version of NSIS.') # raise RuntimeError('Can not locate unicode version of NSIS.')
#
p = os.path.join(p[0], 'makensis.exe') # p = os.path.join(p[0], 'makensis.exe')
if not os.path.exists(p): # if not os.path.exists(p):
raise RuntimeError('Can not locate NSIS at {}'.format(p)) # raise RuntimeError('Can not locate NSIS at {}'.format(p))
#
cfg.toolchain.nsis = p # cfg.toolchain.nsis = p
return p # return p
def winreg_read(path, key): # def winreg_read(path, key):
try: # try:
hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ) # hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ)
value = winreg.QueryValueEx(hkey, key) # value = winreg.QueryValueEx(hkey, key)
except OSError: # except OSError:
return None # return None
#
return value # return value
def winreg_read_wow64_32(path, key): # def winreg_read_wow64_32(path, key):
try: # try:
hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY) # hkey = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
value = winreg.QueryValueEx(hkey, key) # value = winreg.QueryValueEx(hkey, key)
except OSError: # except OSError:
return None # return None
#
return value # return value
def sys_exec(cmd, direct_output=False, output_codec=None): def sys_exec(cmd, direct_output=False, output_codec=None):

View File

@ -1,3 +1,3 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
VER_TELEPORT_SERVER = "2.0.0.1" VER_TELEPORT_SERVER = "2.1.0.1"
VER_TELEPORT_ASSIST = "2.0.0.1" VER_TELEPORT_ASSIST = "2.1.0.1"

Binary file not shown.

View File

@ -964,7 +964,7 @@ void TsHttpRpc::_rpc_func_ts_check(const ex_astr& func_args, ex_astr& buf)
} }
/* 将主机的规范名打出来 */ /* 将主机的规范名打出来 */
//printf("official hostname:%s/n", hptr->h_name); //printf("official hostname:%s/n", hptr->h_name);
///* 主机可能有多个别名,将所有别名分别打出来 */ // 主机可能有多个别名,将所有别名分别打出来
//for (pptr = hptr->h_aliases; *pptr != NULL; pptr++) //for (pptr = hptr->h_aliases; *pptr != NULL; pptr++)
// printf(" alias:%s/n", *pptr); // printf(" alias:%s/n", *pptr);
/* 根据地址类型,将地址打出来 */ /* 根据地址类型,将地址打出来 */

View File

@ -1,6 +1,6 @@
#ifndef __TS_ASSIST_VER_H__ #ifndef __TS_ASSIST_VER_H__
#define __TS_ASSIST_VER_H__ #define __TS_ASSIST_VER_H__
#define TP_ASSIST_VER L"2.0.0.1" #define TP_ASSIST_VER L"2.1.0.1"
#endif // __TS_ASSIST_VER_H__ #endif // __TS_ASSIST_VER_H__

Binary file not shown.

View File

@ -21,6 +21,11 @@ MemBuffer::~MemBuffer()
void MemBuffer::append(const ex_u8* data, size_t size) void MemBuffer::append(const ex_u8* data, size_t size)
{ {
reserve(m_data_size + size); reserve(m_data_size + size);
// TODO: should return boolean.
if(NULL == m_buffer)
return;
memcpy(m_buffer+m_data_size, data, size); memcpy(m_buffer+m_data_size, data, size);
m_data_size += size; m_data_size += size;
} }
@ -40,6 +45,13 @@ void MemBuffer::reserve(size_t size)
m_buffer_size = new_size; m_buffer_size = new_size;
// TODO: reserve() should return boolean.
if(NULL == m_buffer)
{
m_buffer_size = 0;
m_data_size = 0;
}
//TSLOGD("[mbuf] reserve(): #%d, buffer-size: %d, data-size: %d\n", m_index, m_buffer_size, m_data_size); //TSLOGD("[mbuf] reserve(): #%d, buffer-size: %d, data-size: %d\n", m_index, m_buffer_size, m_data_size);
} }

Binary file not shown.

View File

@ -1,6 +1,6 @@
#ifndef __TS_SERVER_VER_H__ #ifndef __TS_SERVER_VER_H__
#define __TS_SERVER_VER_H__ #define __TS_SERVER_VER_H__
#define TP_SERVER_VER L"2.0.0.1" #define TP_SERVER_VER L"2.1.0.1"
#endif // __TS_SERVER_VER_H__ #endif // __TS_SERVER_VER_H__

View File

@ -937,7 +937,7 @@ int SshSession::_on_server_channel_data(ssh_session session, ssh_channel channel
" - authroized by %s\r\n"\ " - authroized by %s\r\n"\
"=============================================\r\n"\ "=============================================\r\n"\
"\r\n"\ "\r\n"\
"\033]0;TP#telnet://%s\007", "\033]0;tpssh://%s\007",
_this->m_server_ip.c_str(), _this->m_server_ip.c_str(),
_this->m_server_port, auth_mode, _this->m_server_port, auth_mode,
_this->m_server_ip.c_str() _this->m_server_ip.c_str()
@ -954,10 +954,14 @@ int SshSession::_on_server_channel_data(ssh_session session, ssh_channel channel
if (is_stderr) if (is_stderr)
{ {
ret = ssh_channel_write_stderr(info->channel, data, len); ret = ssh_channel_write_stderr(info->channel, data, len);
}
else if(info->type != TS_SSH_CHANNEL_TYPE_SHELL)
{
ret = ssh_channel_write(info->channel, data, len);
} }
else else
{ {
if (len > 5) if (len > 5 && len < 256)
{ {
const ex_u8* _begin = ex_memmem((const ex_u8*)data, len, (const ex_u8*)"\033]0;", 4); const ex_u8* _begin = ex_memmem((const ex_u8*)data, len, (const ex_u8*)"\033]0;", 4);
if (NULL != _begin) if (NULL != _begin)
@ -975,13 +979,15 @@ int SshSession::_on_server_channel_data(ssh_session session, ssh_channel channel
if (len_before > 0) if (len_before > 0)
mbuf.append((ex_u8*)data, len_before); mbuf.append((ex_u8*)data, len_before);
mbuf.append((ex_u8*)"\033]0;TP#ssh://", 13); mbuf.append((ex_u8*)"\033]0;tpssh://", 13);
mbuf.append((ex_u8*)_this->m_server_ip.c_str(), _this->m_server_ip.length()); mbuf.append((ex_u8*)_this->m_server_ip.c_str(), _this->m_server_ip.length());
mbuf.append((ex_u8*)"\007", 1); mbuf.append((ex_u8*)"\007", 1);
if (len_end > 0) if (len_end > 0)
mbuf.append((ex_u8*)_end, len_end); mbuf.append((ex_u8*)_end, len_end);
if(mbuf.size() > 0)
{
ret = ssh_channel_write(info->channel, mbuf.data(), mbuf.size()); ret = ssh_channel_write(info->channel, mbuf.data(), mbuf.size());
if (ret <= 0) if (ret <= 0)
EXLOGE("[ssh] send to client failed (1).\n"); EXLOGE("[ssh] send to client failed (1).\n");
@ -1003,6 +1009,11 @@ int SshSession::_on_server_channel_data(ssh_session session, ssh_channel channel
ret = ssh_channel_write(info->channel, data, len); ret = ssh_channel_write(info->channel, data, len);
} }
} }
else
{
ret = ssh_channel_write(info->channel, data, len);
}
}
_this->m_recving_from_srv = false; _this->m_recving_from_srv = false;
if (ret <= 0) if (ret <= 0)
EXLOGE("[ssh] send to client failed (2).\n"); EXLOGE("[ssh] send to client failed (2).\n");

Binary file not shown.

View File

@ -1,6 +1,6 @@
#ifndef __TS_SERVER_VER_H__ #ifndef __TS_SERVER_VER_H__
#define __TS_SERVER_VER_H__ #define __TS_SERVER_VER_H__
#define TP_SERVER_VER L"2.0.0.1" #define TP_SERVER_VER L"2.1.0.1"
#endif // __TS_SERVER_VER_H__ #endif // __TS_SERVER_VER_H__

View File

@ -25,6 +25,7 @@ controllers = [
(r'/maintenance/install', maintenance.InstallHandler), (r'/maintenance/install', maintenance.InstallHandler),
(r'/maintenance/upgrade', maintenance.UpgradeHandler), (r'/maintenance/upgrade', maintenance.UpgradeHandler),
(r'/maintenance/rpc', maintenance.RpcHandler),
(r'/maintenance/', maintenance.IndexHandler), (r'/maintenance/', maintenance.IndexHandler),
(r'/maintenance', maintenance.IndexHandler), (r'/maintenance', maintenance.IndexHandler),

View File

@ -1,6 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from .base import TPBaseUserAuthHandler, TPBaseAdminAuthHandler import json
import time
import threading
from .base import TPBaseUserAuthHandler, TPBaseAdminAuthHandler, TPBaseAdminAuthJsonHandler
from eom_app.app.db import get_db from eom_app.app.db import get_db
@ -23,3 +26,107 @@ class UpgradeHandler(TPBaseAdminAuthHandler):
return self.redirect('/maintenance/install') return self.redirect('/maintenance/install')
self.render('maintenance/upgrade.mako') self.render('maintenance/upgrade.mako')
class RpcThreadManage:
def __init__(self):
self._lock = threading.RLock()
self._threads = dict()
self._id_base = 0
def create_db(self):
with self._lock:
self._id_base += 1
task_id = self._id_base
t = threading.Thread(target=self._create_db, args=[task_id])
self._threads[task_id] = {'cmd': 'create_db', 'running': True, 'stop': False, 'steps': list()}
t.start()
return task_id
def get_task(self, task_id):
with self._lock:
if task_id in self._threads:
# msg = list()
# for i in range(len(self._threads[task_id]['sub_tasks'])):
# msg.append({'ip': self._threads[task_id]['sub_tasks'][i]['ip'], 'msg': self._threads[task_id]['sub_tasks'][i]['msg']})
ret = {
'cmd': self._threads[task_id]['cmd'],
'running': self._threads[task_id]['running'],
# 'stop': self._threads[task_id]['stop'],
'steps': self._threads[task_id]['steps']
}
if not self._threads[task_id]['running']:
del self._threads[task_id]
return ret
else:
return None
def stop_task(self, task_id):
with self._lock:
if task_id in self._threads:
self._threads[task_id]['msg'] = '正在终止...'
self._threads[task_id]['stop'] = True
def _create_db(self, tid):
time.sleep(2)
self._add_step_result(tid, 0, '正在初始化 1...')
self._add_step_result(tid, 0, '正在初始化 2...')
self._add_step_result(tid, 0, '正在初始化 3...')
self._add_step_result(tid, 0, '正在初始化 4...')
# self._threads[tid]['steps'].append({'stat': 0, 'msg': '执行已结束'})
# if self._threads[tid]['stop']:
# self._add_step_result(tid, -1, '操作被终止')
self._thread_end(tid)
def _add_step_result(self, tid, code, msg):
if len(self._threads[tid]['steps']) > 0:
self._threads[tid]['steps'][-1]['stat'] = 0 # 0 表示此步骤已完成
self._threads[tid]['steps'].append({'stat': 1, 'code': code, 'msg': msg})
def _thread_end(self, tid):
with self._lock:
if tid in self._threads:
self._threads[tid]['running'] = False
if self._threads[tid]['stop']:
self._add_step_result(tid, -1, '操作被终止')
if len(self._threads[tid]['steps']) > 0:
self._threads[tid]['steps'][-1]['stat'] = 0
thread_mgr = RpcThreadManage()
class RpcHandler(TPBaseAdminAuthJsonHandler):
def post(self):
args = self.get_argument('args', None)
# print('args', args)
if args is not None:
args = json.loads(args)
else:
self.write_json(-1)
return
# print(args)
cmd = args['cmd']
if cmd == 'create_db':
if not get_db().need_create:
return self.write_json(-1)
task_id = thread_mgr.create_db()
return self.write_json(0, data={"task_id": task_id})
elif cmd == 'get_task_ret':
# return self.write_json(-1)
r = thread_mgr.get_task(args['tid'])
if r is None:
return self.write_json(0, data={'running': False, 'msg': []})
else:
# del r['stop']
return self.write_json(0, data=r)
else:
self.write_json(-1, '未知命令 `{}`'.format(cmd))

View File

@ -1,4 +1,4 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
TS_VER = "2.0.0.1" TS_VER = "2.1.0.1"
TP_ASSIST_LAST_VER = "2.0.0.1" TP_ASSIST_LAST_VER = "2.1.0.1"
TP_ASSIST_REQUIRE = "1.5.46.5" TP_ASSIST_REQUIRE = "2.0.0.1"

View File

@ -32,7 +32,7 @@ var YWL = {
cb_stack cb_stack
//.add(self.on_init) //.add(self.on_init)
.add(self.assist.init, self.page_options) // .add(self.assist.init, self.page_options)
.exec(); .exec();
}; };

File diff suppressed because it is too large Load Diff

View File

@ -13,13 +13,15 @@
<style type="text/css"> <style type="text/css">
.container { .container {
background-color: #fff; background-color: #fff;
padding-bottom:20px; padding-bottom: 20px;
} }
h1 { h1 {
font-size:200%; font-size: 200%;
} }
h2 { h2 {
font-size:160%; font-size: 160%;
} }
</style> </style>
</%block> </%block>
@ -38,7 +40,7 @@
<div id="step-create-db"> <div id="step-create-db">
<p>请选择要使用的数据库类型暂时仅支持sqlite其它类型开发中</p> <p>请选择要使用的数据库类型暂时仅支持sqlite其它类型开发中</p>
<input id="db-sqlite" type="radio" checked="checked" name="database" value="sqlite"/> <label for="db-sqlite">SQLite</label><br/> <input id="db-sqlite" type="radio" checked="checked" name="database" value="sqlite"/> <label for="db-sqlite">SQLite</label><br/>
<input id="db-mysql" type="radio" name="database" value="mysql" disabled="disabled"/> <label for="db-mysql">MySQL暂不支持</label> <input id="db-mysql" type="radio" name="database" value="mysql" disabled="disabled"/> <label for="db-mysql">MySQL开发中,暂不支持)</label>
<div> <div>
<button id="btn-create-db" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始创建</button> <button id="btn-create-db" type="button" class="btn btn-primary"><i class="fa fa-wrench fa-fw"></i> 开始创建</button>
</div> </div>
@ -58,5 +60,46 @@
<%block name="embed_js"> <%block name="embed_js">
<script type="text/javascript"> <script type="text/javascript">
"use strict"; "use strict";
ywl.on_init = function (cb_stack, cb_args) {
ywl.dom = {
btn_create_db: $('#btn-create-db'),
};
ywl.dom.btn_create_db.click(function () {
console.log('create-db-click');
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'create_db'},
function (ret) {
console.log('create-db:', ret);
if (ret.code == 0) {
ywl.get_task_ret(ret.data.task_id);
}
},
function () {
ywl.show_message('error', '无法连接到服务器!');
}
);
});
ywl.get_task_ret = function (task_id) {
ywl.ajax_post_json('/maintenance/rpc', {cmd: 'get_task_ret', 'tid': task_id},
function (ret) {
console.log('get_task_ret:', ret);
if (ret.code == 0) {
}
},
function () {
ywl.show_message('error', '无法连接到服务器!');
}
);
};
cb_stack.exec();
};
</script> </script>
</%block> </%block>

View File

@ -72,7 +72,7 @@
## <script type="text/javascript" src="${ static_url('js/json2.js') }"></script> ## <script type="text/javascript" src="${ static_url('js/json2.js') }"></script>
<script type="text/javascript" src="${ static_url('plugins/gritter/js/jquery.gritter.js') }"></script> <script type="text/javascript" src="${ static_url('plugins/gritter/js/jquery.gritter.js') }"></script>
<script type="text/javascript" src="${ static_url('plugins/jstree/jstree.js') }"></script> ## <script type="text/javascript" src="${ static_url('plugins/jstree/jstree.js') }"></script>
<script type="text/javascript" src="${ static_url('plugins/keypress/keypress.js') }"></script> <script type="text/javascript" src="${ static_url('plugins/keypress/keypress.js') }"></script>
@ -92,7 +92,7 @@
$(document).ready(function () { $(document).ready(function () {
// once page ready, init ywl object. // once page ready, init ywl object.
## ywl.init(); ywl.init();
}); });
</script> </script>

View File

@ -14,6 +14,6 @@ Build 构建号。构建号用于表明此版本发布之前进行了多少
TELEPORT_SERVER 2.0.0.1 TELEPORT_SERVER 2.1.0.1
TELEPORT_ASSIST 2.0.0.1 TELEPORT_ASSIST 2.1.0.1
TELEPORT_ASSIST_REQUIRE 1.5.46.5 TELEPORT_ASSIST_REQUIRE 2.0.0.1