Esempio n. 1
0
def pre_listen_startup():
    mask = 0
    if GLSettings.devel_mode:
        mask = 8000

    GLSettings.http_socks = []

    # Allocate local ports
    for port in GLSettings.bind_local_ports:
        http_sock, fail = reserve_port_for_ip('127.0.0.1', port)
        if fail is not None:
            log.err("Could not reserve socket for %s (error: %s)" % (fail[0], fail[1]))
        else:
            GLSettings.http_socks += [http_sock]

    # Allocate remote ports
    for port in GLSettings.bind_remote_ports:
        sock, fail = reserve_port_for_ip(GLSettings.bind_address, port+mask)
        if fail is not None:
            log.err("Could not reserve socket for %s (error: %s)" % (fail[0], fail[1]))
            continue

        if port == 80:
            GLSettings.http_socks += [sock]
        elif port == 443:
            GLSettings.https_socks += [sock]

    GLSettings.fix_file_permissions()
    GLSettings.drop_privileges()
    GLSettings.check_directories()
Esempio n. 2
0
def pre_listen_startup():
    mask = 0
    if GLSettings.devel_mode:
        mask = 9000

    GLSettings.http_socks = []
    for port in GLSettings.bind_ports:
        port = port + mask if port < 1024 else port
        http_sock, fail = reserve_port_for_ip(GLSettings.bind_address, port)
        if fail is not None:
            log.err("Could not reserve socket for %s (error: %s)" %
                    (fail[0], fail[1]))
        else:
            GLSettings.http_socks += [http_sock]

    https_sock, fail = reserve_port_for_ip(GLSettings.bind_address, 443 + mask)
    if fail is not None:
        log.err("Could not reserve socket for %s (error: %s)" %
                (fail[0], fail[1]))
    else:
        GLSettings.https_socks = [https_sock]

    GLSettings.fix_file_permissions()
    GLSettings.drop_privileges()
    GLSettings.check_directories()
Esempio n. 3
0
    def startService(self):
        mask = 0
        if Settings.devel_mode:
            mask = 8000

        # Allocate local ports
        for port in Settings.bind_local_ports:
            http_sock, fail = reserve_port_for_ip('127.0.0.1', port)
            if fail is not None:
                log.err("Could not reserve socket for %s (error: %s)",
                        fail.args[0], fail.args[1])
            else:
                self.state.http_socks += [http_sock]

        # Allocate remote ports
        for port in Settings.bind_remote_ports:
            sock, fail = reserve_port_for_ip(Settings.bind_address,
                                             port + mask)
            if fail is not None:
                log.err("Could not reserve socket for %s (error: %s)",
                        fail.args[0], fail.args[1])
                continue

            if port == 80:
                self.state.http_socks += [sock]
            elif port == 443:
                self.state.https_socks += [sock]

        fix_file_permissions(Settings.working_path, Settings.uid, Settings.gid,
                             0o700, 0o600)

        drop_privileges(Settings.user, Settings.uid, Settings.gid)

        reactor.callLater(0, self.deferred_start)
Esempio n. 4
0
    def setUp(self):
        super(TestSubprocessRun, self).setUp()

        with open('hello.txt', 'w') as f:
            f.write('Hello, world!\n')

        https_sock, _ = reserve_port_for_ip('127.0.0.1', 9443)
        self.https_socks = [https_sock]
        ssl._https_verify_certificates(enable=False)
        yield test_tls.commit_valid_config()
Esempio n. 5
0
    def setUp(self):
        super(TestSubprocessRun, self).setUp()

        with open('hello.txt', 'w') as f:
            f.write('Hello, world!\n')

        https_sock, _ = reserve_port_for_ip('127.0.0.1', 9443)
        self.https_socks = [https_sock]
        ssl._create_default_https_context = ssl._create_unverified_context

        yield test_tls.commit_valid_config()
Esempio n. 6
0
    def setUp(self):
        super(TestSubprocessRun, self).setUp()

        with open('hello.txt', 'w') as f:
            f.write('Hello, world!\n')

        https_sock, _ = reserve_port_for_ip('127.0.0.1', 9443)
        self.https_socks = [https_sock]
        ssl._create_default_https_context = ssl._create_unverified_context

        yield test_tls.commit_valid_config()
Esempio n. 7
0
    def startService(self):
        mask = 0
        if GLSettings.devel_mode:
            mask = 8000

        GLSettings.http_socks = []

        # Allocate local ports
        for port in GLSettings.bind_local_ports:
            http_sock, fail = reserve_port_for_ip('127.0.0.1', port)
            if fail is not None:
                log.err("Could not reserve socket for %s (error: %s)", fail[0],
                        fail[1])
            else:
                GLSettings.http_socks += [http_sock]

        # Allocate remote ports
        for port in GLSettings.bind_remote_ports:
            sock, fail = reserve_port_for_ip(GLSettings.bind_address,
                                             port + mask)
            if fail is not None:
                log.err("Could not reserve socket for %s (error: %s)", fail[0],
                        fail[1])
                continue

            if port == 80:
                GLSettings.http_socks += [sock]
            elif port == 443:
                GLSettings.https_socks += [sock]

        if GLSettings.disable_swap:
            disable_swap()

        GLSettings.fix_file_permissions()
        GLSettings.drop_privileges()
        GLSettings.check_directories()

        reactor.callLater(0, self.deferred_start)
Esempio n. 8
0
    def startService(self):
        mask = 0
        if Settings.devel_mode:
            mask = 8000

        # Allocate local ports
        for port in Settings.bind_local_ports:
            http_sock, fail = reserve_port_for_ip('127.0.0.1', port)
            if fail is not None:
                log.err("Could not reserve socket for %s (error: %s)", fail[0], fail[1])
            else:
                self.state.http_socks += [http_sock]

        # Allocate remote ports
        for port in Settings.bind_remote_ports:
            sock, fail = reserve_port_for_ip(Settings.bind_address, port+mask)
            if fail is not None:
                log.err("Could not reserve socket for %s (error: %s)", fail[0], fail[1])
                continue

            if port == 80:
                self.state.http_socks += [sock]
            elif port == 443:
                self.state.https_socks += [sock]

        if Settings.disable_swap:
            disable_swap()

        fix_file_permissions(Settings.working_path,
                             Settings.uid,
                             Settings.gid,
                             0o700,
                             0o600)

        drop_privileges(Settings.user, Settings.uid, Settings.gid)

        reactor.callLater(0, self.deferred_start)
Esempio n. 9
0
    def test_init_with_launch(self):
        yield toggle_https(enabled=True)
        sock, fail = reserve_port_for_ip('localhost', 43434)
        self.assertIsNone(fail)

        ip, port = '127.0.0.1', 43435

        p_s = supervisor.ProcessSupervisor([sock], ip, port)
        yield p_s.maybe_launch_https_workers()

        self.assertTrue(p_s.is_running())

        yield p_s.shutdown()

        self.assertFalse(p_s.shutting_down)
        self.assertFalse(p_s.is_running())
Esempio n. 10
0
    def test_launch_and_shutdown(self):
        yield tw(db_set_config_variable, 1, 'https_enabled', False)
        sock, fail = reserve_port_for_ip('127.0.0.1', 43434)
        self.assertIsNone(fail)

        ip, port = '127.0.0.1', 43435

        p_s = supervisor.ProcessSupervisor([sock], ip, port)
        yield p_s.maybe_launch_https_workers()

        self.assertFalse(p_s.is_running())

        p_s.shutdown()

        self.assertTrue(p_s.shutting_down)
        self.assertFalse(p_s.is_running())
Esempio n. 11
0
    def test_launch_and_shutdown(self):
        yield tw(db_set_config_variable, 1, 'https_enabled', False)
        sock, fail = reserve_port_for_ip('127.0.0.1', 43434)
        self.assertIsNone(fail)

        ip, port = '127.0.0.1', 43435

        p_s = supervisor.ProcessSupervisor([sock], ip, port)
        yield p_s.maybe_launch_https_workers()

        self.assertFalse(p_s.is_running())

        p_s.shutdown()

        self.assertTrue(p_s.shutting_down)
        self.assertFalse(p_s.is_running())