Esempio n. 1
0
def createDeck(global_options, url=None):
    from ooni.deck import NGDeck
    from ooni.deck.legacy import subargs_to_options

    if url:
        log.msg("Creating deck for: %s" % (url))

    test_deck_path = global_options.pop('testdeck', None)
    test_name = global_options.pop('test_file', None)
    no_collector = global_options.pop('no-collector', False)
    try:
        if test_deck_path is not None:
            deck = NGDeck(
                global_options=global_options,
                no_collector=no_collector
            )
            deck.open(test_deck_path)
        else:
            deck = NGDeck(
                global_options=global_options,
                no_collector=no_collector,
                arbitrary_paths=True
            )
            log.debug("No test deck detected")
            if url is not None:
                args = ('-u', url)
            else:
                args = tuple()
            if any(global_options['subargs']):
                args = global_options['subargs'] + args

            test_options = subargs_to_options(args)
            test_options['test_name'] = test_name

            deck.load({
                "tasks": [
                    {"ooni": test_options}
                ]
            })
    except errors.MissingRequiredOption as option_name:
        log.err('Missing required option: "%s"' % option_name)
        incomplete_net_test_loader = option_name.net_test_loader
        map(log.msg, incomplete_net_test_loader.usageOptions().getUsage().split("\n"))
        raise SystemExit(2)

    except errors.NetTestNotFound as path:
        log.err('Requested NetTest file not found (%s)' % path)
        raise SystemExit(3)

    except errors.OONIUsageError as e:
        log.exception(e)
        map(log.msg, e.net_test_loader.usageOptions().getUsage().split("\n"))
        raise SystemExit(4)

    except errors.HTTPSCollectorUnsupported:
        log.err("HTTPS collectors require a twisted version of at least 14.0.2.")
        raise SystemExit(6)
    except errors.InsecureBackend:
        log.err("Attempting to report to an insecure collector.")
        log.err("To enable reporting to insecure collector set the "
                "advanced->insecure_backend option to true in "
                "your ooniprobe.conf file.")
        raise SystemExit(7)
    except Exception as e:
        if config.advanced.debug:
            log.exception(e)
        log.err(e)
        raise SystemExit(5)

    return deck
Esempio n. 2
0
def createDeck(global_options, url=None):
    from ooni.deck import NGDeck
    from ooni.deck.legacy import subargs_to_options

    if url:
        log.msg("Creating deck for: %s" % (url))

    test_deck_path = global_options.pop('testdeck', None)
    test_name = global_options.pop('test_file', None)
    no_collector = global_options.pop('no-collector', False)
    try:
        if test_deck_path is not None:
            deck = NGDeck(global_options=global_options,
                          no_collector=no_collector)
            deck.open(test_deck_path)
        else:
            deck = NGDeck(global_options=global_options,
                          no_collector=no_collector,
                          arbitrary_paths=True)
            log.debug("No test deck detected")
            if url is not None:
                args = ('-u', url)
            else:
                args = tuple()
            if any(global_options['subargs']):
                args = global_options['subargs'] + args

            test_options = subargs_to_options(args)
            test_options['test_name'] = test_name

            deck.load({"tasks": [{"ooni": test_options}]})
    except errors.MissingRequiredOption as option_name:
        log.err('Missing required option: "%s"' % option_name)
        incomplete_net_test_loader = option_name.net_test_loader
        map(log.msg,
            incomplete_net_test_loader.usageOptions().getUsage().split("\n"))
        raise SystemExit(2)

    except errors.NetTestNotFound as path:
        log.err('Requested NetTest file not found (%s)' % path)
        raise SystemExit(3)

    except errors.OONIUsageError as e:
        log.exception(e)
        map(log.msg, e.net_test_loader.usageOptions().getUsage().split("\n"))
        raise SystemExit(4)

    except errors.HTTPSCollectorUnsupported:
        log.err(
            "HTTPS collectors require a twisted version of at least 14.0.2.")
        raise SystemExit(6)
    except errors.InsecureBackend:
        log.err("Attempting to report to an insecure collector.")
        log.err("To enable reporting to insecure collector set the "
                "advanced->insecure_backend option to true in "
                "your ooniprobe.conf file.")
        raise SystemExit(7)
    except Exception as e:
        if config.advanced.debug:
            log.exception(e)
        log.err(e)
        raise SystemExit(5)

    return deck