Esempio n. 1
0
    def build(self):
        self.py_dll_path = self._locate_dll_path()
        self.py_lib_path = self._locate_lib_path()

        cc.v('python dll path     :', self.py_dll_path)
        cc.v('python lib path     :', self.py_lib_path)

        cc.n('upgrade pip ...')
        utils.sys_exec(
            '{} -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip --upgrade'
            .format(env.py_exec))

        pip = self._get_pip()
        pypi_modules = [
            'ldap3', 'mako', 'Pillow', 'psutil', 'pymysql', 'qrcode',
            'tornado', 'wheezy.captcha'
        ]
        for p in pypi_modules:
            cc.n('install {} ...'.format(p))
            utils.sys_exec(
                '{} install -i https://pypi.tuna.tsinghua.edu.cn/simple {}'.
                format(pip, p),
                direct_output=True)

        self._make_base()
        self._make_python_zip()
        self._make_py_ver_file()
Esempio n. 2
0
    def _stop_service(self):
        cc.o(' - stop teleport core service ... ', end='')

        # old version, the daemon named `eom_ts`.
        if os.path.exists('/etc/init.d/eom_ts'):
            utils.sys_exec('/etc/init.d/eom_ts stop')
        # from 2.0.0.1, the daemon rename to `teleport`.
        if os.path.exists('/etc/init.d/teleport'):
            utils.sys_exec('/etc/init.d/teleport stop')

        cc.i('[done]')
Esempio n. 3
0
    def _stop_service(self):
        cc.o(' - stop teleport core service ... ', end='')

        # old version, the daemon named `eom_ts`.
        if os.path.exists('/etc/init.d/eom_ts'):
            utils.sys_exec('/etc/init.d/eom_ts stop')
        # from 2.0.0.1, the daemon rename to `teleport`.
        if os.path.exists('/etc/init.d/teleport'):
            utils.sys_exec('/etc/init.d/teleport stop')

        cc.i('[done]')
Esempio n. 4
0
    def _build_openssl(self, file_name):
        cc.n('build openssl static library from source code... ')

        if not super()._build_openssl(file_name):
            return

        _chk_output = [
            os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'libeay32.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'ssleay32.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'inc32', 'openssl',
                         'opensslconf.h'),
        ]

        need_build = False
        for f in _chk_output:
            if not os.path.exists(f):
                need_build = True
                break

        if not need_build:
            cc.n('build openssl static library from source code... ', end='')
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.n('prepare openssl source code...')
        _alt_ver = '_'.join(env.ver_ossl.split('.'))
        if not os.path.exists(self.OPENSSL_PATH_SRC):
            utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
            os.rename(
                os.path.join(PATH_EXTERNAL,
                             'openssl-OpenSSL_{}'.format(_alt_ver)),
                self.OPENSSL_PATH_SRC)
            if not os.path.exists(self.OPENSSL_PATH_SRC):
                raise RuntimeError('can not prepare openssl source code.')
        else:
            cc.w('already exists, skip.')

        os.chdir(self.OPENSSL_PATH_SRC)
        os.system('""{}" Configure VC-WIN32"'.format(env.perl))
        os.system(r'ms\do_nasm')
        # for vs2015
        # utils.sys_exec(r'"{}\VC\bin\vcvars32.bat" && nmake -f ms\nt.mak'.format(env.visual_studio_path), direct_output=True)
        # for vs2017 community
        utils.sys_exec(
            r'"{}VC\Auxiliary\Build\vcvars32.bat" && nmake -f ms\nt.mak'.
            format(env.visual_studio_path),
            direct_output=True)

        for f in _chk_output:
            if not os.path.exists(f):
                raise RuntimeError(
                    'build openssl static library from source code failed.')
Esempio n. 5
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('')

        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.LIBSSH_PATH_SRC, 'build', 'src', 'libssh.a'))
        # utils.copy_file(os.path.join(self.LIBSSH_PATH_SRC, 'build', 'src'), os.path.join(self.PATH_RELEASE, 'lib'), 'libssh.a')
        # utils.copy_ex(os.path.join(self.LIBSSH_PATH_SRC, 'include'), os.path.join(self.PATH_RELEASE, 'include'), 'libssh')

        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))
Esempio n. 6
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))
Esempio n. 7
0
    def _prepare_python(self):
        cc.n('prepare python header and lib files ...')

        if os.path.exists(os.path.join(self.PATH_RELEASE, 'include', 'python', 'Python.h')):
            cc.w(' - header file already exists, skip.')
        else:
            utils.ensure_file_exists(os.path.join(self.PATH_RELEASE, 'include', 'python{}m'.format(ctx.py_dot_ver), 'Python.h'))
            utils.sys_exec('ln -s "{}" "{}"'.format(
                os.path.join(self.PATH_RELEASE, 'include', 'python{}m'.format(ctx.py_dot_ver)),
                os.path.join(self.PATH_RELEASE, 'include', 'python')
            ))

        lib_file = 'libpython{}m.a'.format(env.py_ver_dot)
        utils.ensure_file_exists(os.path.join(self.PATH_RELEASE, 'lib', lib_file))
Esempio n. 8
0
    def _check_service(self):
        cc.o(' - check teleport core service status ... ', end='')
        _err, _o = utils.sys_exec(r'sc query "{}"'.format(self._core_service_name))
        if _err == 1060 or _err == 0:
            cc.i('[running]')
        else:
            cc.e('[not running]')

        cc.o(' - check teleport web service status ... ', end='')
        _err, _o = utils.sys_exec(r'sc query "{}"'.format(self._web_service_name))
        if _err == 1060 or _err == 0:
            cc.i('[running]')
        else:
            cc.e('[not running]')
Esempio n. 9
0
    def _get_service_exec(self, service_name):
        _err, _ = utils.sys_exec(r'sc query "{}"'.format(service_name))
        if 1060 == _err:
            return None
        else:
            _err, _o = utils.sys_exec(r'sc qc "{}"'.format(service_name))
            if _err != 0:
                raise RuntimeError('Can not get execute file path of service `{}`.'.format(service_name))
            for i in _o:
                _x = i.split(':', 1)
                if 'BINARY_PATH_NAME' == _x[0].strip():
                    _path = _x[1].strip()
                    return _path

        return None
Esempio n. 10
0
 def _start_service(self):
     cc.v('')
     cc.o('start services...')
     _ret, _ = utils.sys_exec('/etc/init.d/teleport start',
                              direct_output=True)
     if _ret != 0:
         raise RuntimeError('not all services started.')
Esempio n. 11
0
    def _check_service(self):
        cc.o(' - check teleport core service status ... ', end='')
        _err, _o = utils.sys_exec(r'sc query "{}"'.format(
            self._core_service_name))
        if _err == 1060 or _err == 0:
            cc.i('[running]')
        else:
            cc.e('[not running]')

        cc.o(' - check teleport web service status ... ', end='')
        _err, _o = utils.sys_exec(r'sc query "{}"'.format(
            self._web_service_name))
        if _err == 1060 or _err == 0:
            cc.i('[running]')
        else:
            cc.e('[not running]')
Esempio n. 12
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)
Esempio n. 13
0
    def _get_service_exec(self, service_name):
        _err, _ = utils.sys_exec(r'sc query "{}"'.format(service_name))
        if 1060 == _err:
            return None
        else:
            _err, _o = utils.sys_exec(r'sc qc "{}"'.format(service_name))
            if _err != 0:
                raise RuntimeError(
                    'Can not get execute file path of service `{}`.'.format(
                        service_name))
            for i in _o:
                _x = i.split(':', 1)
                if 'BINARY_PATH_NAME' == _x[0].strip():
                    _path = _x[1].strip()
                    return _path

        return None
Esempio n. 14
0
    def _start_service(self):
        cc.o(' - start teleport core service ... ', end='')
        _err, _o = utils.sys_exec(r'sc start "{}"'.format(self._core_service_name))
        # print('start core', _err, _o)
        if _err == 0:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError('Can not start core service.')

        cc.o(' - start teleport web service ...', end='')
        _err, _ = utils.sys_exec(r'sc start "{}"'.format(self._web_service_name))
        if _err == 0:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError('Can not start web service.')
Esempio n. 15
0
    def _build_openssl(self, file_name):
        cc.n('build openssl static library from source code... ')

        if not super()._build_openssl(file_name):
            return

        _chk_output = [
            os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'libeay32.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'out32', 'ssleay32.lib'),
            os.path.join(self.OPENSSL_PATH_SRC, 'inc32', 'openssl', 'opensslconf.h'),
            ]

        need_build = False
        for f in _chk_output:
            if not os.path.exists(f):
                need_build = True
                break

        if not need_build:
            cc.n('build openssl static library from source code... ', end='')
            cc.w('already exists, skip.')
            return
        cc.v('')

        cc.n('prepare openssl source code...')
        _alt_ver = '_'.join(env.ver_ossl.split('.'))
        if not os.path.exists(self.OPENSSL_PATH_SRC):
            utils.unzip(os.path.join(PATH_DOWNLOAD, file_name), PATH_EXTERNAL)
            os.rename(os.path.join(PATH_EXTERNAL, 'openssl-OpenSSL_{}'.format(_alt_ver)), self.OPENSSL_PATH_SRC)
            if not os.path.exists(self.OPENSSL_PATH_SRC):
                raise RuntimeError('can not prepare openssl source code.')
        else:
            cc.w('already exists, skip.')

        os.chdir(self.OPENSSL_PATH_SRC)
        os.system('""{}" Configure VC-WIN32"'.format(env.perl))
        os.system(r'ms\do_nasm')
        # for vs2015
        # utils.sys_exec(r'"{}\VC\bin\vcvars32.bat" && nmake -f ms\nt.mak'.format(env.visual_studio_path), direct_output=True)
        # for vs2017 community
        utils.sys_exec(r'"{}VC\Auxiliary\Build\vcvars32.bat" && nmake -f ms\nt.mak'.format(env.visual_studio_path), direct_output=True)

        for f in _chk_output:
            if not os.path.exists(f):
                raise RuntimeError('build openssl static library from source code failed.')
Esempio n. 16
0
    def _start_service(self):
        cc.o(' - start teleport core service ... ', end='')
        _err, _o = utils.sys_exec(r'sc start "{}"'.format(
            self._core_service_name))
        # print('start core', _err, _o)
        if _err == 0:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError('Can not start core service.')

        cc.o(' - start teleport web service ...', end='')
        _err, _ = utils.sys_exec(r'sc start "{}"'.format(
            self._web_service_name))
        if _err == 0:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError('Can not start web service.')
Esempio n. 17
0
    def _prepare_python(self):
        cc.n('prepare python header and lib files ...')

        if os.path.exists(
                os.path.join(self.PATH_RELEASE, 'include', 'python',
                             'Python.h')):
            cc.w('python header file already exists, skip.')
        else:
            utils.ensure_file_exists(
                os.path.join(self.PATH_RELEASE, 'include',
                             'python{}m'.format(ctx.py_dot_ver), 'Python.h'))
            utils.sys_exec('ln -s "{}" "{}"'.format(
                os.path.join(self.PATH_RELEASE, 'include',
                             'python{}m'.format(ctx.py_dot_ver)),
                os.path.join(self.PATH_RELEASE, 'include', 'python')))

        lib_file = 'libpython{}m.a'.format(env.py_ver_dot)
        utils.ensure_file_exists(
            os.path.join(self.PATH_RELEASE, 'lib', lib_file))
Esempio n. 18
0
    def build(self):
        self.py_dll_path = self._locate_dll_path()
        self.py_lib_path = self._locate_lib_path()

        cc.v('python dll path     :', self.py_dll_path)
        cc.v('python lib path     :', self.py_lib_path)

        cc.n('upgrade pip ...')
        utils.sys_exec('{} -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip --upgrade'.format(env.py_exec))

        pip = self._get_pip()
        pypi_modules = ['ldap3', 'mako', 'Pillow', 'psutil', 'pymysql', 'qrcode', 'tornado', 'wheezy.captcha']
        for p in pypi_modules:
            cc.n('install {} ...'.format(p))
            utils.sys_exec('{} install -i https://pypi.tuna.tsinghua.edu.cn/simple {}'.format(pip, p), direct_output=True)

        self._make_base()
        self._make_python_zip()
        self._make_py_ver_file()
Esempio n. 19
0
    def _install_service(self):
        cc.o(' - install teleport core service ... ', end='')
        _core = os.path.join(self._install_path, 'bin', 'tp_core.exe')
        _err, _ = utils.sys_exec(r'"{}" -i'.format(_core))
        if _err == 0 or _err == 1:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError('Install core service failed. error code: {}'.format(_err))

        cc.o(' - install teleport web service ... ', end='')
        _core = os.path.join(self._install_path, 'bin', 'tp_web.exe')
        _err, _ = utils.sys_exec(r'"{}" -i'.format(_core))
        if _err == 0 or _err == 1:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError('Install web service failed. error code: {}'.format(_err))

        return True
Esempio n. 20
0
    def _build_zlib(self, file_name):
        # cc.w('skip build zlib again.')
        if not self._download_zlib(file_name):
            return
        if not os.path.exists(self.ZLIB_PATH_SRC):
            os.system('unzip "{}/{}" -d "{}"'.format(PATH_DOWNLOAD, file_name,
                                                     self.PATH_TMP))

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

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

        cmake_define = ' -DCMAKE_INSTALL_PREFIX={path_release}' \
                       ' ..'.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')
            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('libz.so'):
                # use os.unlink() because some file should be a link.
                os.unlink(os.path.join(self.PATH_RELEASE, 'lib', i))
Esempio n. 21
0
    def _install_service(self):
        cc.o(' - install teleport core service ... ', end='')
        _core = os.path.join(self._install_path, 'bin', 'tp_core.exe')
        _err, _ = utils.sys_exec(r'"{}" -i'.format(_core))
        if _err == 0 or _err == 1:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError(
                'Install core service failed. error code: {}'.format(_err))

        cc.o(' - install teleport web service ... ', end='')
        _core = os.path.join(self._install_path, 'bin', 'tp_web.exe')
        _err, _ = utils.sys_exec(r'"{}" -i'.format(_core))
        if _err == 0 or _err == 1:
            cc.i('[done]')
        else:
            cc.e('[failed]')
            raise RuntimeError(
                'Install web service failed. error code: {}'.format(_err))

        return True
Esempio n. 22
0
    def _uninstall_service(self):
        _check_service_name = [self._old_core_service_name, self._old_web_service_name, self._core_service_name,
                               self._web_service_name]

        for _service_name in _check_service_name:
            cc.o(' - remove service [{}] ... '.format(_service_name), end='')
            _err, _ = utils.sys_exec(r'sc delete "{}"'.format(_service_name))
            if _err == 1060 or _err == 0:
                cc.i('[done]')
            elif _err == 1072:
                cc.e('[failed]')
                raise RuntimeError('can not remove service [{}]. please close Service Manager and try again.'.format(_service_name))
            else:
                cc.e('[failed]')
                raise RuntimeError('can not remove service [{}].'.format(_service_name))
Esempio n. 23
0
    def _uninstall_service(self):
        _check_service_name = [
            self._old_core_service_name, self._old_web_service_name,
            self._core_service_name, self._web_service_name
        ]

        for _service_name in _check_service_name:
            cc.o(' - remove service [{}] ... '.format(_service_name), end='')
            _err, _ = utils.sys_exec(r'sc delete "{}"'.format(_service_name))
            if _err == 1060 or _err == 0:
                cc.i('[done]')
            elif _err == 1072:
                cc.e('[failed]')
                raise RuntimeError(
                    'can not remove service [{}]. please close Service Manager and try again.'
                    .format(_service_name))
            else:
                cc.e('[failed]')
                raise RuntimeError(
                    'can not remove service [{}].'.format(_service_name))
Esempio n. 24
0
 def _start_service(self):
     cc.v('')
     cc.o('start services...')
     _ret, _ = utils.sys_exec('/etc/init.d/teleport start', direct_output=True)
     if _ret != 0:
         raise RuntimeError('not all services started.')
Esempio n. 25
0
 def _check_service(self):
     cc.v('')
     cc.o('check services status...')
     utils.sys_exec('/etc/init.d/teleport status', direct_output=True)
Esempio n. 26
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, 'lib64', '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' \
                       ' -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'

        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(out_file)
Esempio n. 27
0
 def _check_service(self):
     cc.v('')
     cc.o('check services status...')
     utils.sys_exec('/etc/init.d/teleport status', direct_output=True)