#10 问题仍然存在,暂时屏蔽可能导致此问题的代码,再进行测试。

pull/32/head
Apex Liu 2017-04-17 17:40:17 +08:00
parent 1db6a66ba1
commit e2e0097a4a
5 changed files with 355 additions and 288 deletions

View File

@ -61,6 +61,9 @@ def main():
if x == 'c': if x == 'c':
clean_all() clean_all()
continue continue
elif x == 'a':
clean_everything()
continue
try: try:
x = int(x) x = int(x)
@ -90,8 +93,20 @@ def main():
def clean_all(): def clean_all():
cc.e('sorry, clean not implemented yet.') # cc.e('sorry, clean not implemented yet.')
# utils.remove(os.path.join(env.root_path, 'out')) utils.remove(os.path.join(env.root_path, 'out'))
def clean_everything():
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'))
def do_opt(opt): def do_opt(opt):
@ -210,7 +225,7 @@ def get_input(msg, log_func=cc.w):
def show_logo(): def show_logo():
cc.v('[]=======================================================[]') cc.v('[]=======================================================[]')
cc.o((cc.CR_VERBOSE, ' | '), (cc.CR_INFO, 'Teleport Projects Builder'), (cc.CR_VERBOSE, ' |')) cc.o((cc.CR_VERBOSE, ' | '), (cc.CR_INFO, 'Teleport Projects Builder'), (cc.CR_VERBOSE, ' |'))
cc.v(' | auth: apexliu@eomsoft.net |') cc.v(' | auth: apex.liu@qq.com |')
cc.v('[]=======================================================[]') cc.v('[]=======================================================[]')
@ -224,7 +239,8 @@ def show_menu():
cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, '%2d' % options[o]['id']), (cc.CR_NORMAL, '] ', options[o]['disp'])) cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, '%2d' % options[o]['id']), (cc.CR_NORMAL, '] ', options[o]['disp']))
cc.v(' -------------------------------------------------------') cc.v(' -------------------------------------------------------')
cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' C'), (cc.CR_NORMAL, '] clean build and dist env.')) 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.v(' -------------------------------------------------------') cc.v(' -------------------------------------------------------')
cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' Q'), (cc.CR_NORMAL, '] exit')) cc.o((cc.CR_NORMAL, ' ['), (cc.CR_INFO, ' Q'), (cc.CR_NORMAL, '] exit'))

View File

@ -1,224 +1,244 @@
# -*- coding: utf8 -*- # -*- coding: utf8 -*-
import os import os
import platform import platform
import sys import sys
import configparser import configparser
from . import colorconsole as cc from . import colorconsole as cc
if platform.system().lower() == 'windows': if platform.system().lower() == 'windows':
try: try:
import winreg import winreg
except ImportError: except ImportError:
cc.e('Can not load module `winreg`, so I can not locate toolchain for you.') cc.e('Can not load module `winreg`, so I can not locate toolchain for you.')
class Env(object): class Env(object):
BITS_32 = 32 BITS_32 = 32
BITS_64 = 64 BITS_64 = 64
def __init__(self): def __init__(self):
_this_path = os.path.abspath(os.path.dirname(__file__)) _this_path = os.path.abspath(os.path.dirname(__file__))
self.root_path = os.path.abspath(os.path.join(_this_path, '..', '..', '..')) self.root_path = os.path.abspath(os.path.join(_this_path, '..', '..', '..'))
self.build_path = os.path.abspath(os.path.join(_this_path, '..', '..')) self.build_path = os.path.abspath(os.path.join(_this_path, '..', '..'))
self.builder_path = os.path.join(self.build_path, 'builder') self.builder_path = os.path.join(self.build_path, 'builder')
self.win32_tools_path = os.path.join(self.build_path, 'tools', 'win32') self.win32_tools_path = os.path.join(self.build_path, 'tools', 'win32')
self.is_py2 = sys.version_info[0] == 2 self.is_py2 = sys.version_info[0] == 2
self.is_py3 = sys.version_info[0] == 3 self.is_py3 = sys.version_info[0] == 3
self.py_ver = platform.python_version_tuple() self.py_ver = platform.python_version_tuple()
self.py_ver_str = '%s%s' % (self.py_ver[0], self.py_ver[1]) self.py_ver_str = '%s%s' % (self.py_ver[0], self.py_ver[1])
self.py_exec = sys.executable self.py_exec = sys.executable
self.bits = self.BITS_32 self.bits = self.BITS_32
self.bits_str = 'x86' self.bits_str = 'x86'
_bits = platform.architecture()[0] _bits = platform.architecture()[0]
if _bits == '64bit': if _bits == '64bit':
self.bits = self.BITS_64 self.bits = self.BITS_64
self.bits_str = 'x64' self.bits_str = 'x64'
self.is_win = False self.is_win = False
self.is_win_x64 = False self.is_win_x64 = False
self.is_linux = False self.is_linux = False
self.is_macos = False self.is_macos = False
_os = platform.system().lower() _os = platform.system().lower()
self.plat = '' self.plat = ''
if _os == 'windows': if _os == 'windows':
self.is_win = True self.is_win = True
self.plat = 'windows' self.plat = 'windows'
self.is_win_x64 = 'PROGRAMFILES(X86)' in os.environ self.is_win_x64 = 'PROGRAMFILES(X86)' in os.environ
elif _os == 'linux': elif _os == 'linux':
self.is_linux = True self.is_linux = True
self.plat = 'linux' self.plat = 'linux'
elif _os == 'darwin': elif _os == 'darwin':
self.is_macos = True self.is_macos = True
self.plat = 'macos' self.plat = 'macos'
def init(self, warn_miss_tool=False): def init(self, warn_miss_tool=False):
if not self._load_config(warn_miss_tool): if not self._load_config(warn_miss_tool):
return False return False
return True if not self._load_version():
return False
def _load_config(self, warn_miss_tool):
_cfg_file = os.path.join(self.root_path, 'config.ini') return True
if not os.path.exists(_cfg_file):
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.') def _load_config(self, warn_miss_tool):
return False _cfg_file = os.path.join(self.root_path, 'config.ini')
if not os.path.exists(_cfg_file):
_cfg = configparser.ConfigParser() 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.')
_cfg.read(_cfg_file) return False
if 'external_ver' not in _cfg.sections() or 'toolchain' not in _cfg.sections():
cc.e('invalid configuration file: need `external_ver` and `toolchain` section.') _cfg = configparser.ConfigParser()
return False _cfg.read(_cfg_file)
if 'toolchain' not in _cfg.sections():
_tmp = _cfg['external_ver'] cc.e('invalid configuration file: need `toolchain` section.')
try: return False
_v_openssl = _tmp['openssl'].split(',')
self.ver_openssl = _v_openssl[0].strip() _tmp = _cfg['toolchain']
self.ver_openssl_number = _v_openssl[1].strip() if self.is_win:
if 'wget' in _tmp:
self.ver_libuv = _tmp['libuv'] self.wget = _tmp['wget']
self.ver_mbedtls = _tmp['mbedtls'] else:
self.ver_sqlite = _tmp['sqlite'] self.wget = None
self.ver_libssh = _tmp['libssh']
self.ver_jsoncpp = _tmp['jsoncpp'] if self.wget is None or not os.path.exists(self.wget):
self.ver_mongoose = _tmp['mongoose'] if warn_miss_tool:
except KeyError: cc.w(' - can not find `wget.exe`, you can get it at https://eternallybored.org/misc/wget/')
cc.e('invalid configuration file: not all necessary external version are set.')
return False if '7z' in _tmp:
self.zip7 = _tmp['7z']
_tmp = _cfg['toolchain'] else:
if self.is_win: self.zip7 = None
if 'wget' in _tmp: if self.zip7 is None or not os.path.exists(self.zip7):
self.wget = _tmp['wget'] if warn_miss_tool:
else: cc.w(' - can not find `7z.exe`, you can get it at http://www.7-zip.org')
self.wget = None
if 'nasm' in _tmp:
if self.wget is None or not os.path.exists(self.wget): self.nasm = _tmp['nasm']
if warn_miss_tool: else:
cc.w(' - can not find `wget.exe`, you can get it at https://eternallybored.org/misc/wget/') self.nasm = self._get_nasm()
if '7z' in _tmp: if self.nasm is None or not os.path.exists(self.nasm):
self.zip7 = _tmp['7z'] if warn_miss_tool:
else: cc.w(' - can not locate `nasm`, so I can build openssl.')
self.zip7 = None else:
if self.zip7 is None or not os.path.exists(self.zip7): _nasm_path = os.path.abspath(os.path.join(self.nasm, '..'))
if warn_miss_tool: os.environ['path'] = os.environ['path'] + ';' + _nasm_path
cc.w(' - can not find `7z.exe`, you can get it at http://www.7-zip.org')
if 'perl' in _tmp:
if 'nasm' in _tmp: self.perl = _tmp['perl']
self.nasm = _tmp['nasm'] else:
else: self.perl = self._get_perl()
self.nasm = self._get_nasm()
if self.perl is None or not os.path.exists(self.perl):
if self.nasm is None or not os.path.exists(self.nasm): if warn_miss_tool:
if warn_miss_tool: cc.w(' - can not locate `perl`, so I can build openssl.')
cc.w(' - can not locate `nasm`, so I can build openssl.')
self.visual_studio_path = self._get_visual_studio_path()
if 'perl' in _tmp: if self.visual_studio_path is None or not os.path.exists(self.visual_studio_path):
self.perl = _tmp['perl'] if warn_miss_tool:
else: cc.w(' - can not locate Visual Studio installation, so I can build openssl.')
self.perl = self._get_perl()
if 'msbuild' in _tmp:
if self.perl is None or not os.path.exists(self.perl): self.msbuild = _tmp['msbuild']
if warn_miss_tool: else:
cc.w(' - can not locate `perl`, so I can build openssl.') self.msbuild = self._get_msbuild()
self.visual_studio_path = self._get_visual_studio_path() if self.msbuild is None or not os.path.exists(self.msbuild):
if self.visual_studio_path is None or not os.path.exists(self.visual_studio_path): if warn_miss_tool:
if warn_miss_tool: cc.w(' - can not locate `MSBuild`, so I can build nothing.')
cc.w(' - can not locate Visual Studio installation, so I can build openssl.')
if 'nsis' in _tmp:
if 'msbuild' in _tmp: self.nsis = _tmp['nsis']
self.msbuild = _tmp['msbuild'] else:
else: self.nsis = self._get_nsis()
self.msbuild = self._get_msbuild()
if self.nsis is None or not os.path.exists(self.nsis):
if self.msbuild is None or not os.path.exists(self.msbuild): if warn_miss_tool:
if warn_miss_tool: cc.w(' - can not locate `nsis`, so I can not make installer.')
cc.w(' - can not locate `MSBuild`, so I can build nothing.')
elif self.is_linux:
if 'nsis' in _tmp: if 'cmake' in _tmp:
self.nsis = _tmp['nsis'] self.cmake = _tmp['cmake']
else: else:
self.nsis = self._get_nsis() self.cmake = '/usr/bin/cmake'
if self.nsis is None or not os.path.exists(self.nsis): if not os.path.exists(self.cmake):
if warn_miss_tool: if warn_miss_tool:
cc.w(' - can not locate `nsis`, so I can not make installer.') cc.e(' - can not locate `cmake`, so I can not build binary from source.')
elif self.is_linux: return True
if 'cmake' in _tmp:
self.cmake = _tmp['cmake'] def _load_version(self):
else: _ver_file = os.path.join(self.root_path, 'external', 'version.ini')
self.cmake = '/usr/bin/cmake' if not os.path.exists(_ver_file):
cc.e('can not load version configuration for external.')
if not os.path.exists(self.cmake): return False
if warn_miss_tool:
cc.e(' - can not locate `cmake`, so I can not build binary from source.') _cfg = configparser.ConfigParser()
_cfg.read(_ver_file)
return True if 'external_ver' not in _cfg.sections():
cc.e('invalid configuration file: need `external_ver` section.')
def _get_msbuild(self): return False
# 14.0 = VS2015
# 12.0 = VS2012 _tmp = _cfg['external_ver']
# 4.0 = VS2008 try:
chk = ['14.0', '12.0', '4.0'] _v_openssl = _tmp['openssl'].split(',')
self.ver_openssl = _v_openssl[0].strip()
p = None self.ver_openssl_number = _v_openssl[1].strip()
for c in chk:
p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\MSBuild\ToolsVersions\{}'.format(c), r'MSBuildToolsPath') self.ver_libuv = _tmp['libuv']
if p is not None: self.ver_mbedtls = _tmp['mbedtls']
break self.ver_sqlite = _tmp['sqlite']
self.ver_libssh = _tmp['libssh']
return os.path.join(p[0], 'MSBuild.exe') if p is not None else None self.ver_jsoncpp = _tmp['jsoncpp']
self.ver_mongoose = _tmp['mongoose']
def _get_visual_studio_path(self): except KeyError:
chk = ['14.0', '12.0', '4.0'] cc.e('invalid configuration file: not all necessary external version are set.')
p = None return False
for c in chk:
p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\VisualStudio\{}'.format(c), r'ShellFolder') return True
if p is not None:
break def _get_msbuild(self):
# 14.0 = VS2015
return p[0] if p is not None else None # 12.0 = VS2012
# 4.0 = VS2008
def _get_perl(self): chk = ['14.0', '12.0', '4.0']
p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\perl', 'BinDir')
return p[0] if p is not None else None p = None
for c in chk:
def _get_nasm(self): p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\MSBuild\ToolsVersions\{}'.format(c), r'MSBuildToolsPath')
p = self._winreg_read(winreg.HKEY_CURRENT_USER, r'SOFTWARE\nasm', '') if p is not None:
return os.path.join(p[0], 'nasm.exe') if p is not None else None break
def _get_nsis(self): return os.path.join(p[0], 'MSBuild.exe') if p is not None else None
p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\NSIS\Unicode', '')
if p is None: def _get_visual_studio_path(self):
p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\NSIS', '') chk = ['14.0', '12.0', '4.0']
return os.path.join(p[0], 'makensis.exe') if p is not None else None p = None
for c in chk:
def _winreg_read(self, base, path, key): p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\VisualStudio\{}'.format(c), r'ShellFolder')
try: if p is not None:
if self.is_win_x64: break
hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
else: return p[0] if p is not None else None
hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ)
def _get_perl(self):
value = winreg.QueryValueEx(hkey, key) p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\perl', 'BinDir')
return value return p[0] if p is not None else None
except OSError: def _get_nasm(self):
return None p = self._winreg_read(winreg.HKEY_CURRENT_USER, r'SOFTWARE\nasm', '')
return os.path.join(p[0], 'nasm.exe') if p is not None else None
env = Env() def _get_nsis(self):
del Env p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\NSIS\Unicode', '')
if p is None:
if __name__ == '__main__': p = self._winreg_read(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\NSIS', '')
pass return os.path.join(p[0], 'makensis.exe') if p is not None else None
def _winreg_read(self, base, path, key):
try:
if self.is_win_x64:
hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
else:
hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ)
value = winreg.QueryValueEx(hkey, key)
return value
except OSError:
return None
env = Env()
del Env
if __name__ == '__main__':
pass

View File

@ -29,14 +29,3 @@ wget = C:\Program Files (x86)\wget\wget.exe
# if not set cmake path, default to '/usr/bin/cmake' # if not set cmake path, default to '/usr/bin/cmake'
cmake = /opt/cmake/bin/cmake cmake = /opt/cmake/bin/cmake
[external_ver]
openssl = 1.0.2h,1000208f
libuv = 1.11.0
mbedtls = 2.3.0
sqlite = 3170000
libssh = 0.7.4
jsoncpp = 0.10.6
mongoose = 6.6

42
external/version.ini vendored Normal file
View File

@ -0,0 +1,42 @@
[toolchain]
#============================================
# for windows
#============================================
# Need wget to download necessary dependency files.
wget = C:\Program Files (x86)\wget\wget.exe
# Need 7z to unzip downloaded files.
7z = C:\Program Files (x86)\7zip\7z.exe
# need perl to build openssl on Windows, if not set, default to get it from register.
# suggest install ActivePerl.
#perl = C:\Perl\bin\perl.exe
# need nasm to build openssl on Windows, if not set, default to locate it from register.
#nasm = C:\Users\username\AppData\Local\NASM\nasm.exe
# if not set nsis path, default to get it by register.
#nsis = C:\Program Files (x86)\NSIS\Unicode\makensis.exe
# if not set msbuild path, default to get it by register.
#msbuild = C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe
# ============================================
# for linux
# ============================================
# if not set cmake path, default to '/usr/bin/cmake'
cmake = /opt/cmake/bin/cmake
[external_ver]
openssl = 1.0.2h,1000208f
libuv = 1.11.0
mbedtls = 2.3.0
sqlite = 3170000
libssh = 0.7.4
jsoncpp = 0.10.6
mongoose = 6.6

View File

@ -965,55 +965,55 @@ int SshSession::_on_server_channel_data(ssh_session session, ssh_channel channel
} }
else else
{ {
if (len > 5 && len < 256) // 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)
{ // {
size_t len_before = _begin - (const ex_u8*)data; // size_t len_before = _begin - (const ex_u8*)data;
const ex_u8* _end = ex_memmem(_begin + 4, len - len_before, (const ex_u8*)"\007", 1); // const ex_u8* _end = ex_memmem(_begin + 4, len - len_before, (const ex_u8*)"\007", 1);
if (NULL != _end) // if (NULL != _end)
{ // {
_end++; // _end++;
//
// 这个包中含有改变标题的数据,将标题换为我们想要的 // // 这个包中含有改变标题的数据,将标题换为我们想要的
size_t len_end = len - (_end - (const ex_u8*)data); // size_t len_end = len - (_end - (const ex_u8*)data);
MemBuffer mbuf; // MemBuffer mbuf;
//
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;tpssh://", 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) // 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");
else // else
ret = len; // ret = len;
} // }
else // else
{ // {
ret = ssh_channel_write(info->channel, data, len); // ret = ssh_channel_write(info->channel, data, len);
} // }
} // }
else // else
{ // {
ret = ssh_channel_write(info->channel, data, len); // ret = ssh_channel_write(info->channel, data, len);
} // }
} // }
else // else
{ // {
ret = ssh_channel_write(info->channel, data, len); // ret = ssh_channel_write(info->channel, data, len);
} // }
} // }
else // else
{ {
ret = ssh_channel_write(info->channel, data, len); ret = ssh_channel_write(info->channel, data, len);
} }