Example #1
0
    def _build_mbedtls(self, file_name):
        cc.n('prepare mbedtls source code... ', end='')
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            cc.v('')
            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)
        else:
            cc.w('already exists, skip.')
            return
        cc.v('')

        # fix source file
        utils.ensure_file_exists(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include',
                         'mbedtls', 'config.h'))
        utils.copy_file(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include',
                         'mbedtls'),
            os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'),
            'config.h')
        utils.ensure_file_exists(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library',
                         'rsa.c'))
        utils.copy_file(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'),
            os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c')
Example #2
0
    def _build_mbedtls(self, file_name):
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP))
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))

        cc.n('build mbedtls...', end='')
        if os.path.exists(
                os.path.join(self.PATH_RELEASE, 'lib', 'libmbedtls.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        # fix the Makefile
        mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'Makefile')
        f = open(mkfile)
        fl = f.readlines()
        f.close()

        fixed = False
        for i in range(len(fl)):
            x = fl[i].split('=')
            if x[0] == 'DESTDIR':
                fl[i] = 'DESTDIR={}\n'.format(self.PATH_RELEASE)
                fixed = True
                break

        if not fixed:
            cc.e('can not fix Makefile of mbedtls.')
            return

        f = open(mkfile, 'w')
        f.writelines(fl)
        f.close()

        # fix source file
        utils.ensure_file_exists(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include',
                         'mbedtls', 'config.h'))
        utils.copy_file(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include',
                         'mbedtls'),
            os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'),
            'config.h')
        utils.ensure_file_exists(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library',
                         'rsa.c'))
        utils.copy_file(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'),
            os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c')

        old_p = os.getcwd()
        os.chdir(self.MBEDTLS_PATH_SRC)
        os.system('make CFLAGS="-fPIC" lib')
        os.system('make install')
        os.chdir(old_p)
Example #3
0
    def _build_libssh(self, file_name):
        # cc.n('skip build libssh on macOS.')
        # return

        if not self._download_libssh(file_name):
            return
        if not os.path.exists(self.LIBSSH_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))

        cc.n('build libssh...', end='')
        # if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) and os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh_threads.a')):
        if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include' \
                       ' -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib' \
                       ' -DWITH_GCRYPT=OFF' \
                       ' -DWITH_GEX=OFF' \
                       ' -DWITH_SFTP=ON' \
                       ' -DWITH_SERVER=ON' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=ON' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DBUILD_SHARED_LIBS=OFF' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ''.format(path_release=self.PATH_RELEASE)

        # ' -DWITH_STATIC_LIB=ON'

        try:
            utils.cmake(build_path, 'Release', False, cmake_define)
        except:
            pass

        # because make install will fail because we can not disable ssh_shared target,
        # so we copy necessary files ourselves.
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a'))
        # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a'))
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'),
                        os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a')
        utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'),
                      os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
Example #4
0
    def _build_mbedtls(self, file_name):
        cc.n('prepare mbedtls source code... ', end='')
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            cc.v('')
            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)
        else:
            cc.w('already exists, skip.')
            return
        cc.v('')

        # fix source file
        utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls', 'config.h'))
        utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls'), os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'), 'config.h')
Example #5
0
    def _build_libssh(self, file_name):
        cc.n('build libssh static library from source code... ', end='')

        if not os.path.exists(self.LIBSSH_PATH_SRC):
            cc.v('')
            utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
            os.rename(os.path.join(PATH_EXTERNAL, 'libssh-{}'.format(env.ver_libssh)), self.LIBSSH_PATH_SRC)

            # cc.n('fix libssh source code... ', end='')
            # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src', 'sftp.c'))
            # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'sftp.c')
            cc.n('fix libssh source code... ', end='')
            s_name = 'libssh-{}'.format(env.ver_libssh)
            utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'session.c'))
            utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c'))
            utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c'))
            utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c')
            utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c')
            utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto-compat.c')

        out_file_lib = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.lib')
        out_file_dll = os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path, 'ssh.dll')

        if os.path.exists(out_file_lib) and os.path.exists(out_file_dll):
            cc.w('already exists, skip.')
            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='')
        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')
        utils.msvc_build(sln_file, 'ssh_shared', ctx.target_path, 'win32', False)
        utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.lib'))
        utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path, 'ssh.dll'))
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.lib')
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path), os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path), 'ssh.dll')
        utils.ensure_file_exists(out_file_lib)
        utils.ensure_file_exists(out_file_dll)
Example #6
0
    def build_server(self):
        cc.n('build web server ...')
        # notice: now we can not build debug version of tp_web.exe
        if ctx.target_path == 'debug':
            cc.w('cannot build debug version of tp_web, skip.')
        else:
            sln_file = os.path.join(env.root_path, 'server', 'tp_web', 'src', 'tp_web.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_web.exe')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tp_web', ctx.target_path, ctx.bits_path, False)
            utils.ensure_file_exists(out_file)

        cc.n('build core server ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'core', 'tp_core.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tp_core.exe')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tp_core', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)

        cc.n('build SSH protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'ssh', 'tpssh.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tpssh.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tpssh', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)
        utils.copy_file(os.path.join(env.root_path, 'external', 'libssh', 'lib', ctx.target_path), os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path), 'ssh.dll')

        cc.n('build TELNET protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'telnet', 'tptelnet.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tptelnet.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tptelnet', ctx.target_path, ctx.bits_path, False)
        utils.ensure_file_exists(out_file)

        if with_rdp:
            cc.n('build RDP protocol ...')
            sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol', 'rdp', 'tprdp.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path, 'tprdp.dll')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tprdp', ctx.target_path, ctx.bits_path, False)
            utils.ensure_file_exists(out_file)
Example #7
0
    def _build_mbedtls(self, file_name):
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))

        cc.n('build mbedtls...', end='')
        if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libmbedtls.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        # fix the Makefile
        mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'Makefile')
        f = open(mkfile)
        fl = f.readlines()
        f.close()

        fixed = False
        for i in range(len(fl)):
            x = fl[i].split('=')
            if x[0] == 'DESTDIR':
                fl[i] = 'DESTDIR={}\n'.format(self.PATH_RELEASE)
                fixed = True
                break

        if not fixed:
            cc.e('can not fix Makefile of mbedtls.')
            return

        f = open(mkfile, 'w')
        f.writelines(fl)
        f.close()

        # fix source file
        utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls', 'config.h'))
        utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include', 'mbedtls'), os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'), 'config.h')
        # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library', 'rsa.c'))
        # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'), os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c')

        old_p = os.getcwd()
        os.chdir(self.MBEDTLS_PATH_SRC)
        os.system('make CFLAGS="-fPIC" lib')
        os.system('make install')
        os.chdir(old_p)
Example #8
0
    def _build_libssh(self, file_name):
        if not os.path.exists(self.LIBSSH_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))

        cc.n('build libssh...', end='')
        # if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')) and os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh_threads.a')):
        if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' -DOPENSSL_INCLUDE_DIR={path_release}/include' \
                       ' -DOPENSSL_LIBRARIES={path_release}/lib' \
                       ' -DWITH_SFTP=ON' \
                       ' -DWITH_SERVER=ON' \
                       ' -DWITH_STATIC_LIB=ON' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ''.format(path_release=self.PATH_RELEASE)

        try:
            utils.cmake(build_path, 'Release', False, cmake_define)
        except:
            pass

        # because make install will fail because we can not disable ssh_shared target,
        # so we copy necessary files ourselves.
        utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a'))
        # utils.ensure_file_exists(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads', 'libssh_threads.a'))
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a')
        utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
Example #9
0
    def build_installer(self):
        cc.n('make teleport installer package...')

        if os.path.exists(self.base_tmp):
            utils.remove(self.base_tmp)

        self._build_web(self.base_path, 'windows', self.path_tmp_data)
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), 'tp_ssh_server.key')

        out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path)
        bin_path = os.path.join(self.path_tmp_data, 'bin')
        utils.copy_ex(out_path, bin_path, 'tp_web.exe')
        utils.copy_ex(out_path, bin_path, 'tp_core.exe')
        utils.copy_ex(out_path, bin_path, 'tpssh.dll')
        utils.copy_ex(out_path, bin_path, 'tptelnet.dll')
        if with_rdp:
            utils.copy_ex(out_path, bin_path, 'tprdp.dll')

        utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))

        # copy scripts
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.bat')
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')

        if os.path.exists(self._final_file):
            utils.remove(self._final_file)

        utils.make_zip(self.path_tmp, self._final_file)
Example #10
0
    def build_installer(self):
        cc.n('make teleport installer package...')

        if os.path.exists(self.base_tmp):
            utils.remove(self.base_tmp)

        self._build_web(self.base_path, 'windows', self.path_tmp_data)
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), 'tp_ssh_server.key')

        out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path, ctx.target_path)
        bin_path = os.path.join(self.path_tmp_data, 'bin')
        utils.copy_ex(out_path, bin_path, 'tp_web.exe')
        utils.copy_ex(out_path, bin_path, 'tp_core.exe')
        utils.copy_ex(out_path, bin_path, 'tpssh.dll')
        utils.copy_ex(out_path, bin_path, 'tptelnet.dll')
        if with_rdp:
            utils.copy_ex(out_path, bin_path, 'tprdp.dll')

        utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))

        # 复制安装所需的脚本
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.bat')
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')

        if os.path.exists(self._final_file):
            utils.remove(self._final_file)

        utils.make_zip(self.path_tmp, self._final_file)
Example #11
0
    def handle(self, **options):
        to_dir = os.path.abspath(options['to_dir'])

        if not os.path.exists(to_dir):
            os.makedirs(to_dir, exist_ok=True)
        if not os.path.exists(to_dir):
            raise CommandError('"%s" not exists' % to_dir)

        for file_hash_obj in models.FileHash.objects.all():
            try:
                file = file_hash_obj.files.all()[0]
            except IndexError:
                continue

            to_file_dir = os.path.join(to_dir, *file.file_dir.split('/')[1:])

            if not os.path.exists(to_file_dir):
                os.makedirs(to_file_dir, exist_ok=True)

            to_file = os.path.join(to_file_dir, file.file_name)

            if os.path.exists(to_file):
                if get_file_size(to_file) == file.file_size:
                    if get_file_hash(to_file) == file.file_hash_obj.file_hash:
                        print('** skip', file.full_path)
                        continue

            print('--', file.full_path, '->', to_file)

            copy_file(file.full_path, to_file)

            if options['new_copy']:
                models.FileCopy(
                    file_hash_obj=file_hash_obj,
                    from_file=file.full_path,
                    to_file=to_file,
                ).save()
Example #12
0
    def _build_libssh(self, file_name):
        if not os.path.exists(self.LIBSSH_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name, self.PATH_TMP))

        cc.n('build libssh...', end='')
        if os.path.exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.n('fix libssh source code... ', end='')
        s_name = 'libssh-{}'.format(env.ver_libssh)
        utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'session.c'))
        utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c'))
        utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c'))
        utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c')
        utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c')
        utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto-compat.c')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' -DOPENSSL_INCLUDE_DIR={path_release}/include' \
                       ' -DOPENSSL_LIBRARIES={path_release}/lib' \
                       ' -DWITH_SFTP=ON' \
                       ' -DWITH_SERVER=ON' \
                       ' -DWITH_STATIC_LIB=ON' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ' ..'.format(path_release=self.PATH_RELEASE)

        old_p = os.getcwd()
        try:
            utils.cmake(build_path, 'Release', False, cmake_define=cmake_define, cmake_pre_define='CFLAGS="-fPIC"')
            os.chdir(build_path)
            utils.sys_exec('make install')
        except:
            pass
        os.chdir(old_p)

        utils.ensure_file_exists(os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a'))
        files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib'))
        for i in files:
            if i.startswith('libssh.so'):
                # use os.unlink() because some file should be a link.
                os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
Example #13
0
    def build_installer(self):
        cc.n('make teleport installer package...')

        if os.path.exists(self.base_tmp):
            utils.remove(self.base_tmp)

        self._build_web(self.base_path, 'linux', self.path_tmp_data)

        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'),
                        os.path.join(self.path_tmp_data, 'tmp', 'etc'),
                        ('web.ini.in', 'web.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'),
                        os.path.join(self.path_tmp_data, 'tmp', 'etc'),
                        ('core.ini.in', 'core.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'),
                        os.path.join(self.path_tmp_data, 'tmp', 'etc'),
                        'tp_ssh_server.key')

        # fix new line flag
        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', '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')
        utils.copy_ex(out_path, bin_path, 'libtpssh.so')
        utils.copy_ex(out_path, bin_path, 'libtptelnet.so')
        if with_rdp:
            utils.copy_ex(out_path, bin_path, 'libtprdp.so')

        utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path,
                      (ctx.dist_path, 'pysrt'))

        # copy scripts
        utils.copy_ex(self.dist_path, self.path_tmp, 'setup.sh')
        utils.copy_ex(self.dist_path, self.path_tmp, 'script')
        utils.copy_ex(self.dist_path, self.path_tmp, 'daemon')

        if os.path.exists(self._final_file):
            utils.remove(self._final_file)

        utils.sys_exec('chmod +x {}'.format(
            os.path.join(self.path_tmp, 'setup.sh')))
        utils.make_targz(self.base_tmp, self.name, self._final_file)
Example #14
0
    def build_installer(self):
        cc.n('make teleport installer package...')

        if os.path.exists(self.base_tmp):
            utils.remove(self.base_tmp)

        self._build_web(self.base_path, 'linux', self.path_tmp_data)

        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('web.ini.in', 'web.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), ('core.ini.in', 'core.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'), os.path.join(self.path_tmp_data, 'tmp', 'etc'), 'tp_ssh_server.key')

        # fix new line flag
        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')
        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')
        utils.copy_ex(out_path, bin_path, 'libtpssh.so')
        utils.copy_ex(out_path, bin_path, 'libtptelnet.so')
        if with_rdp:
            utils.copy_ex(out_path, bin_path, 'libtprdp.so')

        utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path, (ctx.dist_path, 'pysrt'))

        # 复制安装所需的脚本
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.sh')
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'daemon')

        if os.path.exists(self._final_file):
            utils.remove(self._final_file)

        utils.make_targz(self.base_tmp, self.name, self._final_file)
Example #15
0
    def _build_installer():
        tmp_path = os.path.join(env.root_path, 'dist', 'client', 'windows',
                                'assist')
        tmp_app_path = os.path.join(tmp_path, 'apps')
        tmp_cfg_path = os.path.join(tmp_app_path, 'cfg')

        if os.path.exists(tmp_app_path):
            utils.remove(tmp_app_path)

        utils.makedirs(tmp_app_path)
        utils.makedirs(tmp_cfg_path)

        utils.copy_file(
            os.path.join(env.root_path, 'out', 'client', ctx.bits_path,
                         ctx.target_path), tmp_app_path, 'tp_assist.exe')
        utils.copy_file(
            os.path.join(env.root_path, 'client', 'tp_assist_win', 'runtime'),
            tmp_app_path, 'vcruntime140.dll')

        utils.copy_file(os.path.join(env.root_path, 'client',
                                     'cfg'), tmp_cfg_path,
                        ('tp-assist.windows.json', 'tp-assist.json'))
        utils.copy_file(os.path.join(env.root_path, 'client', 'cfg'),
                        tmp_cfg_path, 'cacert.cer')
        utils.copy_file(os.path.join(env.root_path, 'client', 'cfg'),
                        tmp_cfg_path, 'localhost.key')
        utils.copy_file(os.path.join(env.root_path, 'client', 'cfg'),
                        tmp_cfg_path, 'localhost.pem')

        # assist configuration web page
        utils.copy_ex(os.path.join(env.root_path, 'client', 'tp_assist_win'),
                      tmp_app_path, 'site')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'putty'))
        utils.copy_file(
            os.path.join(env.root_path, 'client', 'tools', 'putty'),
            os.path.join(tmp_app_path, 'tools', 'putty'), 'putty.exe')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'winscp'))
        utils.copy_file(
            os.path.join(env.root_path, 'client', 'tools', 'winscp'),
            os.path.join(tmp_app_path, 'tools', 'winscp'), 'WinSCP.exe')
        utils.copy_file(
            os.path.join(env.root_path, 'client', 'tools', 'winscp'),
            os.path.join(tmp_app_path, 'tools', 'winscp'), 'license.txt')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'tprdp'))
        # utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'tprdp-client.exe')
        # utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'tprdp-replay.exe')
        # utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'libeay32.dll')
        # utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'ssleay32.dll')
        # utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'msvcr120.dll')
        utils.copy_file(
            os.path.join(env.root_path, 'client', 'tools', 'tprdp'),
            os.path.join(tmp_app_path, 'tools', 'tprdp'), 'wfreerdp.exe')

        utils.copy_file(os.path.join(env.root_path, 'client', 'tools'),
                        os.path.join(tmp_app_path, 'tools'),
                        'securecrt-telnet.vbs')

        # tp-player
        utils.copy_file(
            os.path.join(env.root_path, 'out', 'client', ctx.bits_path,
                         ctx.target_path), tmp_app_path, 'tp-player.exe')

        # qt-redist
        qt_redist_path = os.path.join(env.root_path, 'client', 'tools',
                                      'qt-redist')
        utils.copy_file(qt_redist_path, tmp_app_path, 'Qt5Core.dll')
        utils.copy_file(qt_redist_path, tmp_app_path, 'Qt5Gui.dll')
        utils.copy_file(qt_redist_path, tmp_app_path, 'Qt5Network.dll')
        utils.copy_file(qt_redist_path, tmp_app_path, 'Qt5Widgets.dll')
        utils.copy_ex(os.path.join(qt_redist_path, 'platforms'),
                      os.path.join(tmp_app_path, 'platforms'))
        utils.copy_ex(os.path.join(qt_redist_path, 'styles'),
                      os.path.join(tmp_app_path, 'styles'))
        utils.copy_ex(os.path.join(qt_redist_path, 'translations'),
                      os.path.join(tmp_app_path, 'translations'))

        # zlib
        suffix = 'd' if ctx.target_path == 'debug' else ''
        utils.copy_file(
            os.path.join(env.root_path, 'external', 'zlib', 'build',
                         ctx.target_path), tmp_app_path,
            'zlib{}.dll'.format(suffix))

        # openssl
        utils.copy_file(
            os.path.join(env.root_path, 'external', 'openssl', 'bin'),
            tmp_app_path, 'libcrypto-1_1.dll')
        utils.copy_file(
            os.path.join(env.root_path, 'external', 'openssl', 'bin'),
            tmp_app_path, 'libssl-1_1.dll')

        # final build
        utils.nsis_build(
            os.path.join(env.root_path, 'dist', 'client', 'windows', 'assist',
                         'installer.nsi'))
Example #16
0
    def _build_libssh(self, file_name):
        if not self._download_libssh(file_name):
            return
        if not os.path.exists(self.LIBSSH_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))

        cc.n('build libssh...', end='')
        out_file = os.path.join(self.PATH_RELEASE, 'lib', 'libssh.a')
        if os.path.exists(out_file):
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.n('fix libssh source code... ', end='')
        s_name = 'libssh-{}'.format(env.ver_libssh)
        utils.ensure_file_exists(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name,
                         'src', 'session.c'))
        # ## utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c'))
        # # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c'))
        utils.copy_file(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh',
                         s_name, 'src'),
            os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c')
        # ## utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c')
        # # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto-compat.c')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' -DOPENSSL_INCLUDE_DIR={path_release}/include' \
                       ' -DOPENSSL_LIBRARIES={path_release}/lib' \
                       ' -DWITH_SFTP=ON' \
                       ' -DWITH_SERVER=ON' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=ON' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DWITH_STATIC_LIB=ON' \
                       ' -DUNIT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ''.format(path_release=self.PATH_RELEASE)

        # ' -DWITH_STATIC_LIB=ON'
        # ' -DBUILD_SHARED_LIBS=OFF'

        old_p = os.getcwd()
        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
        os.chdir(old_p)

        utils.ensure_file_exists(out_file)
        files = os.listdir(os.path.join(self.PATH_RELEASE, 'lib'))
        for i in files:
            if i.startswith('libssh.so'):
                # use os.unlink() because some file should be a link.
                os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
Example #17
0
    def _build_libssh(self, file_name):
        if not self._download_libssh(file_name):
            return
        cc.n('build libssh library from source code... ', end='')

        if not os.path.exists(self.LIBSSH_PATH_SRC):
            cc.v('')
            utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
            os.rename(
                os.path.join(PATH_EXTERNAL,
                             'libssh-{}'.format(env.ver_libssh)),
                self.LIBSSH_PATH_SRC)

            cc.n('fix libssh source code... ', end='')
            s_name = 'libssh-{}'.format(env.ver_libssh)
            utils.ensure_file_exists(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name,
                             'src', 'session.c'))
            # # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto.c'))
            # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src', 'libcrypto-compat.c'))
            utils.copy_file(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh',
                             s_name, 'src'),
                os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c')
            # ## utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c')
            # # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name, 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto-compat.c')

        out_file_lib = os.path.join(self.LIBSSH_PATH_SRC, 'lib',
                                    ctx.target_path, 'ssh.lib')
        out_file_dll = os.path.join(self.LIBSSH_PATH_SRC, 'lib',
                                    ctx.target_path, 'ssh.dll')

        if os.path.exists(out_file_lib) and os.path.exists(out_file_dll):
            cc.w('already exists, skip.')
            return
        cc.v('')

        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:
            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')
        utils.msvc_build(sln_file, 'ssh_shared', ctx.target_path, 'win32',
                         False)
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path,
                         'ssh.lib'))
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path,
                         'ssh.dll'))
        utils.copy_file(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src',
                         ctx.target_path),
            os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path),
            'ssh.lib')
        utils.copy_file(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src',
                         ctx.target_path),
            os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path),
            'ssh.dll')
        utils.ensure_file_exists(out_file_lib)
        utils.ensure_file_exists(out_file_dll)
Example #18
0
    def build_server(self):
        cc.n('build web server ...')
        # notice: now we can not build debug version of tp_web.exe
        if ctx.target_path == 'debug':
            cc.w('cannot build debug version of tp_web, skip.')
        else:
            sln_file = os.path.join(env.root_path, 'server', 'tp_web', 'src',
                                    'tp_web.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server',
                                    ctx.bits_path, ctx.target_path,
                                    'tp_web.exe')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tp_web', ctx.target_path,
                             ctx.bits_path, False)
            utils.ensure_file_exists(out_file)

        cc.n('build core server ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'core',
                                'tp_core.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                ctx.target_path, 'tp_core.exe')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tp_core', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)

        cc.n('build SSH protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol',
                                'ssh', 'tpssh.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                ctx.target_path, 'tpssh.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tpssh', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)
        utils.copy_file(
            os.path.join(env.root_path, 'external', 'libssh', 'lib',
                         ctx.target_path),
            os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                         ctx.target_path), 'ssh.dll')

        cc.n('build TELNET protocol ...')
        sln_file = os.path.join(env.root_path, 'server', 'tp_core', 'protocol',
                                'telnet', 'tptelnet.vs2017.sln')
        out_file = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                ctx.target_path, 'tptelnet.dll')
        if os.path.exists(out_file):
            utils.remove(out_file)
        utils.msvc_build(sln_file, 'tptelnet', ctx.target_path, ctx.bits_path,
                         False)
        utils.ensure_file_exists(out_file)

        if with_rdp:
            cc.n('build RDP protocol ...')
            sln_file = os.path.join(env.root_path, 'server', 'tp_core',
                                    'protocol', 'rdp', 'tprdp.vs2017.sln')
            out_file = os.path.join(env.root_path, 'out', 'server',
                                    ctx.bits_path, ctx.target_path,
                                    'tprdp.dll')
            if os.path.exists(out_file):
                utils.remove(out_file)
            utils.msvc_build(sln_file, 'tprdp', ctx.target_path, ctx.bits_path,
                             False)
            utils.ensure_file_exists(out_file)
Example #19
0
    def _build_installer():
        tmp_path = os.path.join(env.root_path, 'dist', 'client', 'windows', 'assist')
        tmp_app_path = os.path.join(tmp_path, 'apps')
        tmp_cfg_path = os.path.join(tmp_app_path, 'cfg')

        if os.path.exists(tmp_app_path):
            utils.remove(tmp_app_path)

        utils.makedirs(tmp_app_path)
        utils.makedirs(tmp_cfg_path)

        utils.copy_file(os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path), tmp_app_path, 'tp_assist.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'cfg'), tmp_cfg_path, ('tp-assist.windows.json', 'tp-assist.json'))

        utils.copy_file(os.path.join(env.root_path, 'client', 'cfg'), tmp_cfg_path, 'cacert.cer')
        utils.copy_file(os.path.join(env.root_path, 'client', 'cfg'), tmp_cfg_path, 'localhost.key')
        utils.copy_file(os.path.join(env.root_path, 'client', 'cfg'), tmp_cfg_path, 'localhost.pem')

        utils.copy_ex(os.path.join(env.root_path, 'client', 'tp_assist_win'), tmp_app_path, 'site')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'putty'))
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'putty'), os.path.join(tmp_app_path, 'tools', 'putty'), 'putty.exe')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'winscp'))
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'winscp'), os.path.join(tmp_app_path, 'tools', 'winscp'), 'WinSCP.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'winscp'), os.path.join(tmp_app_path, 'tools', 'winscp'), 'license.txt')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'tprdp'))
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'tprdp-client.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'tprdp-replay.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'libeay32.dll')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'ssleay32.dll')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'msvcr120.dll')

        utils.copy_file(os.path.join(env.root_path, 'client', 'tools'), os.path.join(tmp_app_path, 'tools'), 'securecrt-telnet.vbs')

        utils.nsis_build(os.path.join(env.root_path, 'dist', 'client', 'windows', 'assist', 'installer.nsi'))
Example #20
0
    def _build_libssh(self, file_name):
        cc.n('build libssh static library from source code... ', end='')

        if not os.path.exists(self.LIBSSH_PATH_SRC):
            cc.v('')
            utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
            os.rename(
                os.path.join(PATH_EXTERNAL,
                             'libssh-{}'.format(env.ver_libssh)),
                self.LIBSSH_PATH_SRC)

            # cc.n('fix libssh source code... ', end='')
            # utils.ensure_file_exists(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src', 'sftp.c'))
            # utils.copy_file(os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', 'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'sftp.c')
            cc.n('fix libssh source code... ', end='')
            s_name = 'libssh-{}'.format(env.ver_libssh)
            utils.ensure_file_exists(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name,
                             'src', 'session.c'))
            utils.ensure_file_exists(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name,
                             'src', 'libcrypto.c'))
            utils.ensure_file_exists(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name,
                             'src', 'libcrypto-compat.c'))
            utils.copy_file(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh',
                             s_name, 'src'),
                os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'session.c')
            utils.copy_file(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh',
                             s_name, 'src'),
                os.path.join(self.LIBSSH_PATH_SRC, 'src'), 'libcrypto.c')
            utils.copy_file(
                os.path.join(PATH_EXTERNAL, 'fix-external', 'libssh', s_name,
                             'src'), os.path.join(self.LIBSSH_PATH_SRC, 'src'),
                'libcrypto-compat.c')

        out_file_lib = os.path.join(self.LIBSSH_PATH_SRC, 'lib',
                                    ctx.target_path, 'ssh.lib')
        out_file_dll = os.path.join(self.LIBSSH_PATH_SRC, 'lib',
                                    ctx.target_path, 'ssh.dll')

        if os.path.exists(out_file_lib) and os.path.exists(out_file_dll):
            cc.w('already exists, skip.')
            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='')
        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')
        utils.msvc_build(sln_file, 'ssh_shared', ctx.target_path, 'win32',
                         False)
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path,
                         'ssh.lib'))
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', ctx.target_path,
                         'ssh.dll'))
        utils.copy_file(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src',
                         ctx.target_path),
            os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path),
            'ssh.lib')
        utils.copy_file(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src',
                         ctx.target_path),
            os.path.join(self.LIBSSH_PATH_SRC, 'lib', ctx.target_path),
            'ssh.dll')
        utils.ensure_file_exists(out_file_lib)
        utils.ensure_file_exists(out_file_dll)
Example #21
0
    def _build_installer():
        tmp_path = os.path.join(env.root_path, 'dist', 'client', 'windows', 'assist')
        tmp_app_path = os.path.join(tmp_path, 'apps')
        tmp_cfg_path = os.path.join(tmp_app_path, 'cfg')

        if os.path.exists(tmp_app_path):
            utils.remove(tmp_app_path)

        utils.makedirs(tmp_app_path)
        utils.makedirs(tmp_cfg_path)

        utils.copy_file(os.path.join(env.root_path, 'out', 'client', ctx.bits_path, ctx.target_path), tmp_app_path, 'tp_assist.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tp_assist_win', 'cfg'), tmp_cfg_path, ('tp-assist.default.json', 'tp-assist.json'))

        utils.copy_ex(os.path.join(env.root_path, 'client', 'tp_assist_win'), tmp_app_path, 'site')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'putty'))
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'putty'), os.path.join(tmp_app_path, 'tools', 'putty'), 'putty.exe')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'winscp'))
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'winscp'), os.path.join(tmp_app_path, 'tools', 'winscp'), 'WinSCP.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'winscp'), os.path.join(tmp_app_path, 'tools', 'winscp'), 'license.txt')

        utils.makedirs(os.path.join(tmp_app_path, 'tools', 'tprdp'))
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'tprdp-client.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'tprdp-replay.exe')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'libeay32.dll')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'ssleay32.dll')
        utils.copy_file(os.path.join(env.root_path, 'client', 'tools', 'tprdp'), os.path.join(tmp_app_path, 'tools', 'tprdp'), 'msvcr120.dll')

        utils.copy_file(os.path.join(env.root_path, 'client', 'tools'), os.path.join(tmp_app_path, 'tools'), 'securecrt-telnet.vbs')

        utils.nsis_build(os.path.join(env.root_path, 'dist', 'client', 'windows', 'assist', 'installer.nsi'))
Example #22
0
    def _build_mbedtls(self, file_name):
        if not os.path.exists(self.MBEDTLS_PATH_SRC):
            # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP))
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))

        cc.n('build mbedtls...', end='')
        if os.path.exists(
                os.path.join(self.PATH_RELEASE, 'lib', 'libmbedtls.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        # fix the Makefile
        mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'Makefile')
        f = open(mkfile)
        fl = f.readlines()
        f.close()

        fixed = False
        for i in range(len(fl)):
            x = fl[i].split('=')
            if x[0] == 'DESTDIR':
                fl[i] = 'DESTDIR={}\n'.format(self.PATH_RELEASE)
                fixed = True
                break

        if not fixed:
            cc.e('can not fix Makefile of mbedtls.')
            return

        f = open(mkfile, 'w')
        f.writelines(fl)
        f.close()

        # # fix config.h
        # mkfile = os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls', 'config.h')
        # f = open(mkfile)
        # fl = f.readlines()
        # f.close()
        #
        # for i in range(len(fl)):
        #     if fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED') >= 0:
        #         fl[i] = '//#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED\n'
        #     elif fl[i].find('#define MBEDTLS_SELF_TEST') >= 0:
        #         fl[i] = '//#define MBEDTLS_SELF_TEST\n'
        #     elif fl[i].find('#define MBEDTLS_SSL_RENEGOTIATION') >= 0:
        #         fl[i] = '//#define MBEDTLS_SSL_RENEGOTIATION\n'
        #     elif fl[i].find('#define MBEDTLS_ECDH_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECDH_C\n'
        #     elif fl[i].find('#define MBEDTLS_ECDSA_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECDSA_C\n'
        #     elif fl[i].find('#define MBEDTLS_ECP_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_ECP_C\n'
        #     elif fl[i].find('#define MBEDTLS_NET_C') >= 0:
        #         fl[i] = '//#define MBEDTLS_NET_C\n'
        #
        #     elif fl[i].find('#define MBEDTLS_RSA_NO_CRT') >= 0:
        #         fl[i] = '#define MBEDTLS_RSA_NO_CRT\n'
        #     elif fl[i].find('#define MBEDTLS_SSL_PROTO_SSL3') >= 0:
        #         fl[i] = '#define MBEDTLS_SSL_PROTO_SSL3\n'
        #
        # f = open(mkfile, 'w')
        # f.writelines(fl)
        # f.close()

        # fix source file
        utils.ensure_file_exists(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include',
                         'mbedtls', 'config.h'))
        utils.copy_file(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'include',
                         'mbedtls'),
            os.path.join(self.MBEDTLS_PATH_SRC, 'include', 'mbedtls'),
            'config.h')
        utils.ensure_file_exists(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library',
                         'rsa.c'))
        utils.copy_file(
            os.path.join(PATH_EXTERNAL, 'fix-external', 'mbedtls', 'library'),
            os.path.join(self.MBEDTLS_PATH_SRC, 'library'), 'rsa.c')

        old_p = os.getcwd()
        os.chdir(self.MBEDTLS_PATH_SRC)
        os.system('make CFLAGS="-fPIC" lib')
        os.system('make install')
        os.chdir(old_p)
Example #23
0
    def _build_libssh(self, file_name):
        if not os.path.exists(self.LIBSSH_PATH_SRC):
            # os.system('tar -zxvf "{}/{}" -C "{}"'.format(PATH_DOWNLOAD, file_name, PATH_TMP))
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))
            # os.rename(os.path.join(self.PATH_TMP, 'master'), os.path.join(self.PATH_TMP, 'libssh-{}'.format(LIBSSH_VER)))

        cc.n('build libssh...', end='')
        if os.path.exists(os.path.join(
                self.PATH_RELEASE, 'lib', 'libssh.a')) and os.path.exists(
                    os.path.join(self.PATH_RELEASE, 'lib',
                                 'libssh_threads.a')):
            cc.w('already exists, skip.')
            return
        cc.v('')

        build_path = os.path.join(self.LIBSSH_PATH_SRC, 'build')
        # utils.makedirs(build_path)

        # here is a bug in cmake v2.8.11 (default on ubuntu14), in FindOpenSSL.cmake,
        # it parse opensslv.h, use regex like this:
        #   REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*")
        # but in openssl-1.0.2h, the version define line is:
        #   # define OPENSSL_VERSION_NUMBER  0x1000208fL
        # notice there is a space char between # and define, so find openssl always fail.

        # old_p = os.getcwd()
        # os.chdir(build_path)
        # cmd = 'cmake' \
        #       ' -DCMAKE_INSTALL_PREFIX={}' \
        #       ' -D_OPENSSL_VERSION={}' \
        #       ' -DOPENSSL_INCLUDE_DIR={}/include' \
        #       ' -DOPENSSL_LIBRARIES={}/lib' \
        #       ' -DCMAKE_BUILD_TYPE=Release' \
        #       ' -DWITH_GSSAPI=OFF' \
        #       ' -DWITH_ZLIB=OFF' \
        #       ' -DWITH_STATIC_LIB=ON' \
        #       ' -DWITH_PCAP=OFF' \
        #       ' -DWITH_EXAMPLES=OFF' \
        #       ' -DWITH_NACL=OFF' \
        #       ' ..'.format(self.PATH_RELEASE, OPENSSL_VER, self.PATH_RELEASE, self.PATH_RELEASE)
        # cc.n(cmd)
        # os.system(cmd)
        # # os.system('make ssh_static ssh_threads_static')
        # os.system('make ssh_static')
        # # os.system('make install')
        # os.chdir(old_p)

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={}' \
                       ' -D_OPENSSL_VERSION={}' \
                       ' -DOPENSSL_INCLUDE_DIR={}/include' \
                       ' -DOPENSSL_LIBRARIES={}/lib' \
                       ' -DWITH_GSSAPI=OFF' \
                       ' -DWITH_ZLIB=OFF' \
                       ' -DWITH_STATIC_LIB=ON' \
                       ' -DWITH_PCAP=OFF' \
                       ' -DWITH_TESTING=OFF' \
                       ' -DWITH_CLIENT_TESTING=OFF' \
                       ' -DWITH_EXAMPLES=OFF' \
                       ' -DWITH_BENCHMARKS=OFF' \
                       ' -DWITH_NACL=OFF' \
                       ' ..'.format(self.PATH_RELEASE, env.ver_openssl_number, self.PATH_RELEASE, self.PATH_RELEASE)

        try:
            utils.cmake(build_path, 'Release', False, cmake_define)
        except:
            pass

        # because make install will fail because we can not disable ssh_shared target,
        # so we copy necessary files ourselves.
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a'))
        utils.ensure_file_exists(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads',
                         'libssh_threads.a'))
        utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'),
                        os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        utils.copy_file(
            os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src', 'threads'),
            os.path.join(self.PATH_RELEASE, 'lib'), 'libssh_threads.a')
        utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'),
                      os.path.join(self.PATH_RELEASE, 'include'), 'libssh')
Example #24
0
    def build_installer(self):
        cc.n('make teleport installer package...')

        if os.path.exists(self.base_tmp):
            utils.remove(self.base_tmp)

        self._build_web(self.base_path, 'linux', self.path_tmp_data)

        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'),
                        os.path.join(self.path_tmp_data, 'tmp', 'etc'),
                        ('web.ini.in', 'web.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'),
                        os.path.join(self.path_tmp_data, 'tmp', 'etc'),
                        ('core.ini.in', 'core.ini'))
        utils.copy_file(os.path.join(env.root_path, 'server', 'share', 'etc'),
                        os.path.join(self.path_tmp_data, 'tmp', 'etc'),
                        'tp_ssh_server.key')

        # out_path = os.path.join(env.root_path, 'out', 'eom_ts', ctx.target_path, ctx.dist_path)
        # out_path = os.path.join(env.root_path, 'out', 'eom_ts', ctx.bits_path, 'bin')
        # bin_path = os.path.join(self.tmp_path, 'bin')
        # utils.copy_file(out_path, bin_path, 'eom_ts')

        out_path = os.path.join(env.root_path, 'out', 'server', ctx.bits_path,
                                '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')
        utils.copy_ex(out_path, bin_path, 'libtpssh.so')
        utils.copy_ex(out_path, bin_path, 'libtprdp.so')

        utils.copy_ex(os.path.join(env.root_path, 'out', 'pysrt'), bin_path,
                      (ctx.dist_path, 'pysrt'))

        # utils.copy_file(os.path.join(env.root_path, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'eom_ts.ini')
        # utils.copy_file(os.path.join(env.root_path, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'license.key')
        # utils.copy_ex(os.path.join(env.root_path, 'share', 'etc'), os.path.join(self.tmp_path, 'tmp', 'etc'), 'ssl')

        # utils.copy_ex(os.path.join(env.root_path, 'share', 'data'), os.path.join(self.tmp_path, 'tmp', 'data'), ('ts_db_release.db', 'ts_db.db'))
        # utils.copy_ex(os.path.join(env.root_path, 'server', 'share', 'data'), os.path.join(self.tmp_path, 'tmp', 'data'), 'main.sql')

        # utils.make_zip(self.tmp_path, os.path.join(self.tmp_path, '..', 'eom_ts.zip'))
        # utils.make_targz(os.path.join(self.tmp_path, '..'), 'teleport', 'teleport.tar.gz')
        # utils.remove(self.tmp_path)

        # make final installer.
        # cc.n('pack final server installer...')
        # out_file = os.path.join(env.root_path, 'dist', '{}.zip'.format(self.name))
        # out_file = os.path.join(env.root_path, 'out', 'installer', '{}.tar.gz'.format(self.name))

        # if os.path.exists(out_file):
        #     utils.remove(out_file)

        # # copy installer scripts.
        # for i in ['daemon', 'start.sh', 'stop.sh', 'status.sh']:
        # # for i in ['daemon_web', 'daemon_core', 'teleport.sh']:
        #     shutil.copy(os.path.join(self.dist_path, 'script', i), os.path.abspath(os.path.join(self.tmp_path, '..', i)))
        # for i in ['install.sh', 'uninst.sh']:
        #     shutil.copy(os.path.join(self.dist_path, 'script', i), os.path.abspath(os.path.join(self.tmp_path, '..', '..', i)))

        # 复制安装所需的脚本
        # utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'install.sh')
        # utils.copy_ex(os.path.join(self.dist_path, 'script'), self.path_tmp, 'uninst.sh')
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'setup.sh')
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'script')
        utils.copy_ex(os.path.join(self.dist_path), self.path_tmp, 'daemon')

        if os.path.exists(self._final_file):
            utils.remove(self._final_file)

        utils.make_targz(self.base_tmp, self.name, self._final_file)