예제 #1
0
def start_server():
    try:
        client = docker.from_env()

        container = 'httpd:latest'
        if platform.machine() == 'armv6l':
            container = 'arm32v6/httpd:alpine'

        try:
            os.mkdir('apache2')
        except FileExistsError:
            pass
        except OSError as error:
            logger.info(error)
            return
        Singletons.httpd_container = client.containers.run(container, \
            detach=True, ports={'80/tcp': 8080}, read_only=True, \
            volumes={'apache2': \
                {'bind': '/usr/local/apache2/logs', 'mode': 'rw'}})
        logger.info('Created: %s', Singletons.httpd_container)
        # Can't close the bridge because we need it to connect to the
        # container.

    except OSError as err:
        logger.info(err)
        if Singletons.httpd_container:
            logger.info(Singletons.httpd_container.logs())
            rm_container()
        return

    Singletons.httpd_thread = PipeThread(('0.0.0.0', 80), \
        ('127.0.0.1', 8080), Requests, COMMAND_LENGTH, request_type='Web')
    Singletons.httpd_thread.start()
예제 #2
0
파일: httpipe.py 프로젝트: tmadsen4/HPotter
def start_server():  # leave these two in place
    try:
        client = docker.from_env()

        container = 'httpd:latest'
        if platform.machine() == 'armv6l':
            container = 'arm32v6/httpd:alpine'

        try:
            os.mkdir('apache2')
        except FileExistsError:
            pass
        except OSError as error:
            logger.info(error)
            return

        Singletons.httpd_container = client.containers.run(container, \
            detach=True, ports={'80/tcp': 8080}, read_only=True, \
            volumes={'apache2': \
                {'bind': '/usr/local/apache2/logs', 'mode': 'rw'}})
        logger.info('Created: %s', Singletons.httpd_container)

    except OSError as err:
        logger.info(err)
        if Singletons.httpd_container:
            logger.info(Singletons.httpd_container.logs())
            rm_container()
        return

    Singletons.httpd_thread = PipeThread(('0.0.0.0', 80), \
        ('127.0.0.1', 8080), HTTPCommands, 4096)
    Singletons.httpd_thread.start()
예제 #3
0
def start_server():
    try:
        client = docker.from_env()

        container = 'mariadb:latest'
        if platform.machine() == 'armv6l':
            container = 'apcheamitru/arm32v6-mariadb:latest'

        try:
            os.mkdir('tmp')
            os.mkdir('mysqld')
        except FileExistsError:
            pass
        except OSError as error:
            logger.info(error)
            return

        Singletons.mariadb_container = client.containers.run(container, \
            detach=True, ports={'3306/tcp': 33060}, \
            environment=['MYSQL_ALLOW_EMPTY_PASSWORD=yes'])
        logger.info('Created: %s', Singletons.mariadb_container)

    except OSError as err:
        logger.info(err)
        if Singletons.mariadb_container:
            logger.info(Singletons.mariadb_container.logs())
            rm_container()
        return

    di = lambda a: re.sub(b'([\x00-\x20]|[\x7f-\xff])+', b' ', a)
    Singletons.mariadb_thread = PipeThread(('0.0.0.0', 3306), \
        ('127.0.0.1', 33060), SQL, SQL_COMMAND_LENGTH, di=di)
    Singletons.mariadb_thread.start()
예제 #4
0
def start_server():  # leave these two in place
    try:
        client = docker.from_env()

        container = 'mariadb:latest'
        if platform.machine() == 'armv6l':
            container = 'apcheamitru/arm32v6-mariadb:latest'

        try:
            os.mkdir('tmp')
            os.mkdir('mysqld')
        except FileExistsError:
            pass
        except OSError as error:
            logger.info(error)
            return

        Singletons.mariadb_container = client.containers.run(container, \
            detach=True, ports={'3306/tcp': 33060}, read_only=True, \
            environment=['MYSQL_ALLOW_EMPTY_PASSWORD=yes'], \
            volumes={'tmp': {'bind': '/tmp', 'mode': 'rw'}, \
                'mysqld': {'bind': '/var/run/mysqld', 'mode': 'rw'}
            })
        logger.info('Created: %s', Singletons.mariadb_container)

    except OSError as err:
        logger.info(err)
        if Singletons.mariadb_container:
            logger.info(Singletons.mariadb_container.logs())
            rm_container()
        return

    Singletons.mariadb_thread = PipeThread(('0.0.0.0', 3306), \
        ('127.0.0.1', 33060), SQL, 4096)
    Singletons.mariadb_thread.start()
예제 #5
0
def start_plugins():
    # create network
    start_network("net_1", "10.3.3.0")
    # ensure Docker is running
    try:
        s = subprocess.check_output('docker ps', shell=True)
    except subprocess.CalledProcessError:
        print("Ensure Docker is running, and please try again.")
        sys.exit()

    config = read_in_config()
    start_services(parse_services(config[0]))
    all_plugins = parse_plugins(config[1])
    current_thread = None
    current_container = None

    for plugin in all_plugins:
        if plugin is not None:
            try:

                check_certs(plugin.cert)
                client = docker.from_env()

                container = plugin.container
                if platform.machine() == 'armv6l':
                    container = plugin.alt_container

                try:
                    for cmd in plugin.setup['mkdir']:
                        logger.info("%s created the %s directory", plugin.name,
                                    cmd)
                        os.mkdir(cmd)
                except FileExistsError:
                    pass
                except OSError as error:
                    logger.info(error)
                    return

                if (plugin.volumes):
                    current_container = client.containers.run(container, \
                        detach=plugin.detach, ports=plugin.makeports(), \
                        environment=[plugin.environment])

                else:
                    current_container = client.containers.run(container, \
                        detach=plugin.detach, ports=plugin.makeports(), \
                        read_only=True)

                logger.info('Created: %s', plugin.name)
                network.connect(current_container)
                logger.info('Connected %s to %s network', plugin.name,
                            network.name)
            except OSError as err:

                logger.info(err)
                if current_container:
                    logger.info(current_container.logs())
                    # rm_container()
                return

            di = lambda a: re.sub(b'([\x00-\x20]|[\x7f-xff])+', b' ', a)

            current_thread = PipeThread((plugin.listen_address, \
                plugin.listen_port), (plugin.ports['connect_address'], \
                plugin.ports['connect_port']), plugin.table, \
                plugin.capture_length, request_type=plugin.request_type, tls=plugin.tls)

            current_thread.start()
            p_dict = {
                "plugin": plugin,
                "container": current_container,
                "thread": current_thread
            }
            Singletons.active_plugins[plugin.name] = p_dict
        else:
            logger.info(
                "yaml configuration seems to be missing some important information"
            )