コード例 #1
0
    def _get(self, request, name_obj, timestamp, url_subdir, date_form):
        options_form, values = get_dnssec_options_form_data(request.GET)

        use_js = 'no_js' not in request.GET

        if use_js:
            notices = {}
        else:
            rdtypes = set(values['rr'])
            denial_of_existence = values['doe']
            dnssec_algorithms = set(values['a'])
            ds_algorithms = set(values['ds'])
            trusted_keys_explicit = values['tk']
            trusted_zones = values['ta']
            redundant_edges = values['red']

            # disable IANA root keys, if there is an explicit delegation of the root
            # (i.e., ignore root KSK ta setting)
            if name_obj.group is not None and name_obj.group.name == dns.name.root and \
                    name_obj.group.analysis_type == ANALYSIS_TYPE_AUTHORITATIVE and name_obj.group.explicit_delegation:
                trusted_zones = filter(lambda x: x[0] != dns.name.root,
                                       trusted_zones)
                if '.' in options_form.fields['ta'].initial:
                    options_form.fields['ta'].initial.remove('.')

            trusted_keys = trusted_keys_explicit + trusted_zones

            G = DNSAuthGraph()

            name_obj.retrieve_all()
            name_obj.populate_status(trusted_keys,
                                     supported_algs=dnssec_algorithms,
                                     supported_digest_algs=ds_algorithms)
            G = self._graph_name(name_obj, trusted_keys, rdtypes,
                                 denial_of_existence)
            G.add_trust(trusted_keys, supported_algs=dnssec_algorithms)
            #G.remove_extra_edges(redundant_edges)
            notices = get_notices(G.node_info)

        analyzed_name_obj = name_obj
        template = 'dnssec.html'

        return render_to_response(template, {
            'name_obj': name_obj,
            'analyzed_name_obj': analyzed_name_obj,
            'timestamp': timestamp,
            'url_subdir': url_subdir,
            'title': name_obj,
            'options_form': options_form,
            'date_form': date_form,
            'notices': notices,
            'use_js': use_js,
            'query_string': request.META['QUERY_STRING']
        },
                                  context_instance=RequestContext(request))
コード例 #2
0
def plaintext():
    if 'date' in request.args:
        date = request.args['date']
    else:
        date = ''

    raw_json = notices.get_notices(date)

    out = notices.parse_text(raw_json)

    return render_template('rawtext.html', content=out)
コード例 #3
0
def main():
    arg_parser = argparse.ArgumentParser(description="""Generate nonsense based
            on a StatusNet user's notices.""")
    arg_parser.add_argument("-f", "--force-fetch", action="store_true",
            help="""Force the notices to be fetched, even if a cached copy
            exists.""", dest="force_fetch")
    arg_parser.add_argument("-s", "--use-https", action="store_true",
            help="""Use HTTPS to fetch notices.""", dest="use_https")
    arg_parser.add_argument("-n", "--nonsense-count", dest="nonsense_count",
            type=int, help="""Number of nonsense notices to generate per
            user.""", default=1)
    arg_parser.add_argument("-p", "--prefix-length", dest="prefix_length",
            type=int, help="""Size of prefix to use (internally, ngrams will be
            this + 1). Generally, lower sizes => more randomness.""", default=2)
    arg_parser.add_argument("users", metavar="USER@HOST", nargs="+",
            help="""User to generate nonsense notices for.""")

    args = arg_parser.parse_args()

    for user in args.users:
        try:
            username, host = split_uri(user)
        except ValueError:
            sys.stderr.write("User given in invalid format: {0}\n. Skipping.\n")
            continue

        user_notices = notices.get_notices(username, host, args.use_https,
                args.force_fetch)

        if user_notices == []:
            sys.stderr.write("No notices fetched. Cannot generate nonsense.\n")
            sys.exit(1)

        user_markov_table = {}
        for notice in user_notices:
            ngrams = markov.make_ngrams(notice.split(), n=args.prefix_length,
                    **markers)
            user_markov_table = markov.make_markov_table(ngrams,
                    user_markov_table)

        for i in range(0, args.nonsense_count):
            while True:
                nonsense = " ".join(markov.generate_output(user_markov_table,
                    **markers))
                if not nonsense in user_notices:
                    break
            print(nonsense)
コード例 #4
0
def output():
    if 'key' in request.args:
        user_key = request.args['key']
    else:
        return render_template('error.html',
                               title="Bruh.",
                               subtitle="You need an API key")
    if user_key not in valid_keys:
        return render_template('error.html',
                               title="Oof.",
                               subtitle="That's an invalid API key")

    if 'date' in request.args:
        date = request.args['date']
    else:
        date = ''

    notices_table = notices.get_notices(date)
    return jsonify(notices_table)
コード例 #5
0
    def dnssec_auth_graph(self, request, name_obj, G, format):
        img = G.draw(format)
        #XXX currently, graphviz only supports local files, so the
        #XXX following two lines are necessary
        if format not in ('png', 'jpg'):
            img = codecs.decode(img, 'utf-8')
            img = img.replace(
                os.path.join(DNSVIZ_SHARE_PATH, 'icons'),
                os.path.join(settings.STATIC_URL, 'images', 'dnssec_legend'))
            img = codecs.encode(img, 'utf-8')
        if format == 'dot':
            content_type = 'text/plain'
        elif format == 'jpg':
            content_type = 'image/jpeg'
        elif format == 'png':
            content_type = 'image/png'
        elif format == 'svg':
            content_type = 'image/svg+xml'
        elif format == 'js':
            content_type = 'application/javascript'
            img += notices_to_javascript(get_notices(G.node_info))
        else:
            raise Exception('Unknown file type!')

        response = HttpResponse(img, content_type=content_type)
        if 'download' in request.GET:
            filename_base = name_obj.name.canonicalize().to_text().rstrip('.')
            if not filename_base:
                filename_base = 'root'
            response[
                'Content-Disposition'] = 'attachment; filename=%s-%s.%s' % (
                    filename_base, fmt.datetime_to_str(
                        name_obj.analysis_end).replace(' ', '-'), format)

        if 'err' in request.GET:
            logger = logging.getLogger('django.request')
            logger.error('Graph load errors\n  Path: %s\n  User-agent: %s\n  Referer: %s\n  Remote host: %s\n  Error: %s\n' % \
                    (request.path, request.META.get('HTTP_USER_AGENT', ''), request.META.get('HTTP_REFERER', ''),
                    request.META.get('REMOTE_ADDR', ''), request.GET['err']))

        return response