def setupGlobalOptions(logging, start_tor, check_incoherences): global_options = parseOptions() config.global_options = global_options config.set_paths() config.initialize_ooni_home() try: config.read_config_file(check_incoherences=check_incoherences) except errors.ConfigFileIncoherent: sys.exit(6) if not config.is_initialized(): initializeOoniprobe(global_options) if global_options['verbose']: config.advanced.debug = True if not start_tor: config.advanced.start_tor = False if logging: log.start(global_options['logfile']) if config.privacy.includepcap or global_options['pcapfile']: from ooni.utils.net import hasRawSocketPermission if hasRawSocketPermission(): from ooni.utils.txscapy import ScapyFactory config.scapyFactory = ScapyFactory(config.advanced.interface) else: log.err("Insufficient Privileges to capture packets." " See ooniprobe.conf privacy.includepcap") sys.exit(2) global_options['check_incoherences'] = check_incoherences return global_options
def __init__(self, config, director, scheduler, _reactor=reactor): self._reactor = reactor self.director = director self.scheduler = scheduler self.config = config self.measurement_path = FilePath(config.measurements_directory) # We use a double submit token to protect against XSRF rng = SystemRandom() token_space = string.letters + string.digits self._xsrf_token = b''.join( [rng.choice(token_space) for _ in range(30)]) self._director_started = False self._is_initialized = config.is_initialized() # We use exponential backoff to trigger retries of the startup of # the director. self._director_startup_retries = 0 # Maximum delay should be 30 minutes self._director_max_retry_delay = 30 * 60 self.status_poller = LongPoller(self._long_polling_timeout, _reactor) self.director_event_poller = LongPoller(self._long_polling_timeout, _reactor) # XXX move this elsewhere self.director_event_poller.start() self.status_poller.start() self.director.subscribe(self.handle_director_event) if self._is_initialized: self.start_director()
def __init__(self, config, director, scheduler, _reactor=reactor): self._reactor = reactor self.director = director self.scheduler = scheduler self.config = config self.measurement_path = FilePath(config.measurements_directory) # We use a double submit token to protect against XSRF rng = SystemRandom() token_space = string.letters+string.digits self._xsrf_token = b''.join([rng.choice(token_space) for _ in range(30)]) self._director_started = False self._is_initialized = config.is_initialized() # We use exponential backoff to trigger retries of the startup of # the director. self._director_startup_retries = 0 # Maximum delay should be 30 minutes self._director_max_retry_delay = 30*60 self.status_poller = LongPoller( self._long_polling_timeout, _reactor) self.director_event_poller = LongPoller( self._long_polling_timeout, _reactor) # XXX move this elsewhere self.director_event_poller.start() self.status_poller.start() self.director.subscribe(self.handle_director_event) if self._is_initialized: self.start_director()
def refresh_deck_list(self): """ This checks if there are some decks that have been enabled and should be scheduled as periodic tasks to run on the next scheduler cycle and if some have been disabled and should not be run. It does so by listing the enabled decks and checking if the enabled ones are already scheduled or if some of the scheduled ones are not amongst the enabled decks. """ to_enable = [] for deck_id, deck in deck_store.list_enabled(): if deck.schedule is None: continue to_enable.append((deck_id, deck.schedule)) # If we are not initialized we should not enable anything if not config.is_initialized(): log.msg("We are not initialized skipping setup of decks") to_enable = [] for scheduled_task in self._scheduled_tasks[:]: if not isinstance(scheduled_task, RunDeck): continue info = (scheduled_task.deck_id, scheduled_task.schedule) if info in to_enable: # If the task is already scheduled there is no need to # enable it. log.debug("The deck {0} is already scheduled".format(deck_id)) to_enable.remove(info) else: # If one of the tasks that is scheduled is no longer in the # scheduled tasks. We should disable it. log.debug( "The deck task {0} should be disabled".format(deck_id)) self.unschedule(scheduled_task) for deck_id, schedule in to_enable: log.debug("Scheduling to run {0}".format(deck_id)) self.schedule(RunDeck(self.director, deck_id, schedule))
def refresh_deck_list(self): """ This checks if there are some decks that have been enabled and should be scheduled as periodic tasks to run on the next scheduler cycle and if some have been disabled and should not be run. It does so by listing the enabled decks and checking if the enabled ones are already scheduled or if some of the scheduled ones are not amongst the enabled decks. """ to_enable = [] for deck_id, deck in deck_store.list_enabled(): if deck.schedule is None: continue to_enable.append((deck_id, deck.schedule)) # If we are not initialized we should not enable anything if not config.is_initialized(): log.msg("We are not initialized skipping setup of decks") to_enable = [] for scheduled_task in self._scheduled_tasks[:]: if not isinstance(scheduled_task, RunDeck): continue info = (scheduled_task.deck_id, scheduled_task.schedule) if info in to_enable: # If the task is already scheduled there is no need to # enable it. log.debug("The deck {0} is already scheduled".format(scheduled_task.deck_id)) to_enable.remove(info) else: # If one of the tasks that is scheduled is no longer in the # scheduled tasks. We should disable it. log.debug("The deck task {0} should be disabled".format(scheduled_task.deck_id)) self.unschedule(scheduled_task) for deck_id, schedule in to_enable: log.debug("Scheduling to run {0}".format(deck_id)) self.schedule(RunDeck(self.director, deck_id, schedule))