Exemplo n.º 1
0
    def __init__(self, fd=42):
        self.pid = os.getpid()

        with os.fdopen(fd, 'r') as f:
            self.cfg = json.loads(f.read())

        self._log = os.fdopen(0, 'w', 1).write

        set_proc_title(self.name)
        set_pdeathsig(signal.SIGTERM)

        def _sigusr1(SIG, FRM):
            self.sigusr1()

        signal.signal(signal.SIGUSR1, _sigusr1)

        def _sigusr2(SIG, FRM):
            self.sigusr2()

        signal.signal(signal.SIGUSR2, _sigusr2)

        def excepthook(*exc_info):
            self.log("".join(traceback.format_exception(*exc_info)))

        sys.excepthook = excepthook

        reactor.addSystemEventTrigger("before", "shutdown", self.shutdown)
Exemplo n.º 2
0
    def __init__(self, fd=42):
        self.pid = os.getpid()

        with os.fdopen(fd, 'r') as f:
            self.cfg = json.loads(f.read())

        self._log = os.fdopen(0, 'w', 1).write

        set_proc_title(self.name)
        set_pdeathsig(signal.SIGTERM)

        def _sigusr1(SIG, FRM):
            self.sigusr1()

        signal.signal(signal.SIGUSR1, _sigusr1)

        def _sigusr2(SIG, FRM):
            self.sigusr2()

        signal.signal(signal.SIGUSR2, _sigusr2)

        def excepthook(*exc_info):
            self.log("".join(traceback.format_exception(*exc_info)))

        sys.excepthook = excepthook

        reactor.addSystemEventTrigger("before", "shutdown", self.shutdown)
Exemplo n.º 3
0
    def __init__(self):
        set_proc_title('globaleaks')

        self.state = State
        self.arw = resource.EncodingResourceWrapper(APIResourceWrapper(), [server.GzipEncoderFactory()])

        if Settings.nodaemon:
            self.api_factory = Site(self.arw, logFormatter=logFormatter)
        else:
            self.api_factory = Site(self.arw, logPath=Settings.accesslogfile, logFormatter=logFormatter)

        self.api_factory.displayTracebacks = False
Exemplo n.º 4
0
    def __init__(self):
        set_proc_title('globaleaks')

        self.state = State
        self.arw = APIResourceWrapper()

        if Settings.nodaemon:
            self.api_factory = Site(self.arw, logFormatter=logFormatter)
        else:
            self.api_factory = Site(self.arw,
                                    logPath=Settings.accesslogfile,
                                    logFormatter=logFormatter)

        if not Settings.devel_mode:
            self.api_factory.displayTracebacks = False
Exemplo n.º 5
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]

        if Settings.disable_swap:
            disable_swap()

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

        set_proc_title('globaleaks')

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

        reactor.callLater(0, self.deferred_start)