コード例 #1
0
ファイル: settings.py プロジェクト: code4romania/GlobaLeaks
    def load_cmdline_options(self):
        self.nodaemon = self.cmdline_options.nodaemon

        if self.cmdline_options.disable_swap:
            self.disable_swap = True

        log.setloglevel(verbosity_dict[self.cmdline_options.loglevel])

        self.bind_address = self.cmdline_options.ip

        self.disable_backend_exception_notification = self.cmdline_options.disable_backend_exception_notification
        self.disable_client_exception_notification = self.cmdline_options.disable_client_exception_notification

        self.socks_host = self.cmdline_options.socks_host

        if not self.validate_port(self.cmdline_options.socks_port):
            sys.exit(1)
        self.socks_port = self.cmdline_options.socks_port

        if self.cmdline_options.ramdisk:
            self.ramdisk_path = self.cmdline_options.ramdisk

        if self.cmdline_options.user and self.cmdline_options.group:
            self.user = self.cmdline_options.user
            self.group = self.cmdline_options.group
            self.uid = pwd.getpwnam(self.cmdline_options.user).pw_uid
            self.gid = grp.getgrnam(self.cmdline_options.group).gr_gid
        elif self.cmdline_options.user:
            # user selected: get also the associated group
            self.user = self.cmdline_options.user
            self.uid = pwd.getpwnam(self.cmdline_options.user).pw_uid
            self.gid = pwd.getpwnam(self.cmdline_options.user).pw_gid
        elif self.cmdline_options.group:
            # group selected: keep the current user
            self.group = self.cmdline_options.group
            self.gid = grp.getgrnam(self.cmdline_options.group).gr_gid
            self.uid = os.getuid()

        if self.uid == 0 or self.gid == 0:
            self.print_msg("Invalid user: cannot run as root")
            sys.exit(1)

        if self.cmdline_options.working_path:
            self.working_path = self.cmdline_options.working_path

        if self.cmdline_options.developer_name:
            self.print_msg("Enabling development mode for %s" %
                           self.cmdline_options.developer_name)
            self.developer_name = unicode(self.cmdline_options.developer_name)
            self.set_devel_mode()
            self.orm_debug = self.cmdline_options.orm_debug

        self.api_prefix = self.cmdline_options.api_prefix

        if self.cmdline_options.client_path:
            self.set_client_path(self.cmdline_options.client_path)

        self.eval_paths()

        if self.nodaemon:
            self.print_msg("Going in background; log available at %s" %
                           GLSettings.logfile)

        # special evaluation of client directory:
        indexfile = os.path.join(self.client_path, 'index.html')
        if os.path.isfile(indexfile):
            self.print_msg("Serving the client from directory: %s" %
                           self.client_path)
        else:
            self.print_msg(
                "Unable to find a directory to load the client from")
            sys.exit(1)
コード例 #2
0
ファイル: settings.py プロジェクト: SamiMnassri/GlobaLeaks
    def load_cmdline_options(self):
        self.nodaemon = self.cmdline_options.nodaemon

        if self.cmdline_options.disable_swap:
            self.disable_swap = True

        log.setloglevel(verbosity_dict[self.cmdline_options.loglevel])

        self.bind_address = self.cmdline_options.ip

        self.socks_host = self.cmdline_options.socks_host

        if not self.validate_port(self.cmdline_options.socks_port):
            sys.exit(1)

        self.socks_port = self.cmdline_options.socks_port

        if platform.system() != 'Windows':
            if (self.cmdline_options.user and self.cmdline_options.group is None) or \
               (self.cmdline_options.group and self.cmdline_options.user is None):
                self.print_msg("Error: missing user or group option")
                sys.exit(1)

            if self.cmdline_options.user and self.cmdline_options.group:
                import grp
                import pwd

                self.user = self.cmdline_options.user
                self.group = self.cmdline_options.group

                self.uid = pwd.getpwnam(self.cmdline_options.user).pw_uid
                self.gid = grp.getgrnam(self.cmdline_options.group).gr_gid

            if self.uid == 0 or self.gid == 0:
                self.print_msg("Invalid user: cannot run as root")
                sys.exit(1)

        if self.cmdline_options.devel_mode:
            self.set_devel_mode()

        self.orm_debug = self.cmdline_options.orm_debug

        if self.cmdline_options.working_path:
            self.working_path = self.cmdline_options.working_path

        self.api_prefix = self.cmdline_options.api_prefix

        if self.cmdline_options.client_path:
            self.client_path = os.path.abspath(
                os.path.join(self.src_path, self.cmdline_options.client_path))

        self.eval_paths()

        if self.nodaemon:
            self.print_msg("Going in background; log available at %s" %
                           Settings.logfile)

        # special evaluation of client directory:
        indexfile = os.path.join(self.client_path, 'index.html')
        if os.path.isfile(indexfile):
            self.print_msg("Serving the client from directory: %s" %
                           self.client_path)
        else:
            self.print_msg(
                "Unable to find a directory to load the client from")
            sys.exit(1)