From 90d67e9ef2af9d6fe22a3898f70024a9185a85ca Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Wed, 15 Jul 2020 03:11:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=EF=BC=9A=E5=BD=93TP=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E9=85=8D=E7=BD=AE=E4=B8=BA=20`https`?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=AE=BF=E9=97=AE=E6=97=B6=EF=BC=8CRDP?= =?UTF-8?q?=E5=BD=95=E5=83=8F=E6=92=AD=E6=94=BE=E5=99=A8=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96=E5=BD=95=E5=83=8F=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/builder/build-external.py | 75 +++++++++++++++++-- build/builder/core/env.py | 35 +++++++-- build/builder/core/utils.py | 9 ++- client/tp-player/downloader.cpp | 25 ++++++- client/tp-player/downloader.h | 4 + .../www/teleport/webroot/app/base/webapp.py | 2 +- 6 files changed, 129 insertions(+), 21 deletions(-) diff --git a/build/builder/build-external.py b/build/builder/build-external.py index 2a059cd..1ca3d57 100644 --- a/build/builder/build-external.py +++ b/build/builder/build-external.py @@ -172,6 +172,20 @@ class BuilderWin(BuilderBase): if x == 'q': return + _chk_output = [ + os.path.join(self.OPENSSL_PATH_SRC, 'include', 'openssl', 'aes.h'), + os.path.join(self.OPENSSL_PATH_SRC, 'include', 'openssl', 'opensslv.h'), + os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'libcrypto32MT.lib'), + os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'libeay32MT.lib'), + os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'ssleay32MT.lib'), + os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static', 'libcrypto32MT.lib'), + os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static', 'libeay32MT.lib'), + os.path.join(self.OPENSSL_PATH_SRC, 'lib', 'VC', 'static', 'ssleay32MT.lib'), + ] + + for f in _chk_output: + if not os.path.exists(f): + raise RuntimeError('build openssl static library from source code failed.') # cc.n('build openssl static library from source code... ') @@ -245,15 +259,57 @@ class BuilderWin(BuilderBase): return cc.v('') - cc.w('On Windows, when build libssh, need you use cmake-gui.exe to generate solution file') - cc.w('for Visual Studio 2017. Visit https://docs.tp4a.com for more details.') - cc.w('\nOnce the libssh.sln generated, press Enter to continue or Q to quit...', end='') + + + build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build') + if not os.path.exists(build_path): + utils.makedirs(build_path) + + openssl_path = os.path.join(PATH_EXTERNAL, 'OpenSSL') + + cmake_define = ' -DOPENSSL_INCLUDE_DIR={path_release}\include' \ + ' -DOPENSSL_LIBRARIES={path_release}\lib\VC\static' \ + ' -DWITH_SFTP=ON' \ + ' -DWITH_SERVER=ON' \ + ' -DWITH_GSSAPI=OFF' \ + ' -DWITH_ZLIB=OFF' \ + ' -DWITH_PCAP=OFF' \ + ' -DWITH_STATIC_LIB=ON' \ + ' -DUNIT_TESTING=OFF' \ + ' -DWITH_EXAMPLES=OFF' \ + ' -DWITH_BENCHMARKS=OFF' \ + ' -DWITH_NACL=OFF' \ + ''.format(path_release=openssl_path) + + # ' -DCMAKE_INSTALL_PREFIX={path_release}' + # ' -DWITH_STATIC_LIB=ON' + # ' -DBUILD_SHARED_LIBS=OFF' + + + old_p = os.getcwd() try: - x = env.input() - except EOFError: - x = 'q' - if x == 'q': - return + os.chdir(build_path) + utils.cmake(build_path, 'Release', False, cmake_define=cmake_define) + os.chdir(build_path) + # utils.sys_exec('make install') + except: + cc.e('can not make') + raise + os.chdir(old_p) + + + + + + # cc.w('On Windows, when build libssh, need you use cmake-gui.exe to generate solution file') + # cc.w('for Visual Studio 2017. Visit https://docs.tp4a.com for more details.') + # cc.w('\nOnce the libssh.sln generated, press Enter to continue or Q to quit...', end='') + # try: + # x = env.input() + # except EOFError: + # x = 'q' + # if x == 'q': + # return cc.i('build libssh...') sln_file = os.path.join(self.LIBSSH_PATH_SRC, 'build', 'libssh.sln') @@ -544,6 +600,7 @@ class BuilderLinux(BuilderBase): try: utils.cmake(build_path, 'Release', False, cmake_define=cmake_define, cmake_pre_define='CFLAGS="-fPIC"') os.chdir(build_path) + utils.sys_exec('make') utils.sys_exec('make install') except: pass @@ -579,6 +636,7 @@ class BuilderLinux(BuilderBase): try: utils.cmake(build_path, 'Release', False, cmake_define=cmake_define, cmake_pre_define='CFLAGS="-fPIC"') os.chdir(build_path) + utils.sys_exec('make') utils.sys_exec('make install') except: pass @@ -814,6 +872,7 @@ class BuilderMacOS(BuilderBase): try: utils.cmake(build_path, 'Release', False, cmake_define=cmake_define, cmake_pre_define='CFLAGS="-fPIC"') os.chdir(build_path) + utils.sys_exec('make') utils.sys_exec('make install') except: pass diff --git a/build/builder/core/env.py b/build/builder/core/env.py index 52aa8c1..e9680d8 100644 --- a/build/builder/core/env.py +++ b/build/builder/core/env.py @@ -3,6 +3,7 @@ import os import platform import sys +import json import configparser from . import colorconsole as cc @@ -74,14 +75,27 @@ class Env(object): return True def _load_config(self, warn_miss_tool): - _cfg_file = os.path.join(self.root_path, 'config.ini') + # _cfg_file = os.path.join(self.root_path, 'config.ini') + _cfg_file = os.path.join(self.root_path, 'config.json') 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.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.') return False - _cfg = configparser.ConfigParser() - _cfg.read(_cfg_file) - if 'toolchain' not in _cfg.sections(): + try: + with open(_cfg_file, 'r') as f: + _cfg = json.loads(f.read()) + except: + 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 @@ -148,14 +162,19 @@ class Env(object): if warn_miss_tool: cc.w(' - can not locate `nsis`, so I can not make installer.') - if 'qt' in _tmp: - self.qt = _tmp['qt'] + if 'cmake' in _tmp: + self.cmake = _tmp['cmake'] + else: + self.cmake = 'c:\\cmake\\bin\\cmake.exe' + + if 'qt_path' in _tmp: + self.qt = _tmp['qt_path'] else: self.qt = None if self.qt is None or not os.path.exists(self.qt): if warn_miss_tool: - cc.w(' - can not locate `qt`, so I can not build tp-player.') + cc.w(' - can not locate `qt_path`, so I can not build tp-player.') elif self.is_linux: if 'cmake' in _tmp: diff --git a/build/builder/core/utils.py b/build/builder/core/utils.py index 0043938..c0571f7 100644 --- a/build/builder/core/utils.py +++ b/build/builder/core/utils.py @@ -413,9 +413,16 @@ def cmake(work_path, target, force_rebuild, cmake_define='', cmake_pre_define='' target = 'Debug' else: target = 'Release' - cmd = '{} "{}" -DCMAKE_BUILD_TYPE={} {} ..;make'.format(cmake_pre_define, env.cmake, target, cmake_define) + cmd = '{} "{}" -DCMAKE_BUILD_TYPE={} {} ..'.format(cmake_pre_define, env.cmake, target, cmake_define) cc.o(cmd) ret, _ = sys_exec(cmd, direct_output=True) + # if ret != 0: + # raise RuntimeError('build with cmake failed, ret={}. [{}]'.format(ret, target)) + + # cmd = 'make' + # cc.o(cmd) + # ret, _ = sys_exec(cmd, direct_output=True) + os.chdir(old_p) if ret != 0: raise RuntimeError('build with cmake failed, ret={}. [{}]'.format(ret, target)) diff --git a/client/tp-player/downloader.cpp b/client/tp-player/downloader.cpp index 0f5a10a..da9e4ac 100644 --- a/client/tp-player/downloader.cpp +++ b/client/tp-player/downloader.cpp @@ -9,6 +9,8 @@ Downloader::Downloader() : QObject () { m_data = nullptr; m_reply = nullptr; m_result = false; + + connect(&m_nam, &QNetworkAccessManager::sslErrors, this, &Downloader::_on_ssl_errors); } Downloader::~Downloader() { @@ -44,9 +46,10 @@ bool Downloader::_request(const QString& url, const QString& sid, const QString& req.setUrl(QUrl(url)); req.setRawHeader("Cookie", cookie.toLatin1()); - QNetworkAccessManager* nam = new QNetworkAccessManager(); + //QNetworkAccessManager* nam = new QNetworkAccessManager(); QEventLoop eloop; - m_reply = nam->get(req); + //m_reply = nam->get(req); + m_reply = m_nam.get(req); connect(m_reply, &QNetworkReply::finished, &eloop, &QEventLoop::quit); connect(m_reply, &QNetworkReply::finished, this, &Downloader::_on_finished); @@ -62,7 +65,7 @@ bool Downloader::_request(const QString& url, const QString& sid, const QString& delete m_reply; m_reply = nullptr; - delete nam; + //delete nam; qDebug("Downloader::_request() end."); return m_result; @@ -118,3 +121,19 @@ void Downloader::_on_finished() { m_result = true; } + +void Downloader::_on_ssl_errors(QNetworkReply *reply, const QList &errors) { + QString errorString; + foreach (const QSslError &error, errors) { + if (!errorString.isEmpty()) + errorString += '\n'; + errorString += error.errorString(); + } + +// if (QMessageBox::warning(this, tr("SSL Errors"), +// tr("One or more SSL errors has occurred:\n%1").arg(errorString), +// QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) { +// reply->ignoreSslErrors(); +// } + reply->ignoreSslErrors(); +} diff --git a/client/tp-player/downloader.h b/client/tp-player/downloader.h index 5f5a123..ea2656e 100644 --- a/client/tp-player/downloader.h +++ b/client/tp-player/downloader.h @@ -2,6 +2,7 @@ #define DOWNLOADER_H #include +#include #include class Downloader : public QObject { @@ -19,6 +20,8 @@ public: private: bool _request(const QString& url, const QString& sid, const QString& filename, QByteArray* data); + void _on_ssl_errors(QNetworkReply *, const QList &errors); + private slots: void _on_data_ready(); // 有数据可读了,读取并写入文件 void _on_finished(); // 下载结束了 @@ -28,6 +31,7 @@ private: QByteArray* m_data; bool m_result; + QNetworkAccessManager m_nam; QNetworkReply* m_reply; }; diff --git a/server/www/teleport/webroot/app/base/webapp.py b/server/www/teleport/webroot/app/base/webapp.py index 5c14638..7c9e246 100644 --- a/server/www/teleport/webroot/app/base/webapp.py +++ b/server/www/teleport/webroot/app/base/webapp.py @@ -162,7 +162,7 @@ class WebApp: _app = tornado.web.Application(controllers, **settings) server = tornado.httpserver.HTTPServer(_app, xheaders=True) - # server = tornado.httpserver.HTTPServer(_app, ssl_options={ + # server = tornado.httpserver.HTTPServer(_app, xheaders=True, ssl_options={ # "certfile": os.path.join(cfg.data_path, 'cert', "server.pem"), # "keyfile": os.path.join(cfg.data_path, 'cert', "server.key"), # })