示例#1
0
    def get(self, request, name, url_subdir='', **kwargs):
        name = util.name_url_decode(name)
        options_form, values = get_dnssec_options_form_data(request.GET)

        name_obj = _OfflineDomainNameAnalysis(name)
        name_obj.analysis_end = datetime.datetime.now(
            fmt.utc).replace(microsecond=0)
        name_obj.base_url_with_timestamp = '../'
        name_obj.previous = OfflineDomainNameAnalysis.objects.latest(name)
        template = 'dnssec.html'

        analyzed_name_obj = name_obj

        date_form = domain_date_search_form(name)(
            initial={
                'date': fmt.datetime_to_str(name_obj.analysis_end)[:10]
            })

        return render_to_response(template, {
            'name_obj': name_obj,
            'analyzed_name_obj': analyzed_name_obj,
            'url_subdir': url_subdir,
            'title': name_obj,
            'options_form': options_form,
            'date_form': date_form,
            'use_js': True,
            'query_string': request.META['QUERY_STRING']
        },
                                  context_instance=RequestContext(request))
示例#2
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
示例#3
0
    def get(self, request, name, timestamp=None, url_subdir='', **kwargs):
        if 'reset_query' in request.GET:
            return reset_query_string(request)

        name = util.name_url_decode(name)
        if 'date_search' in request.GET:
            date_form = domain_date_search_form(name)(request.GET)
            if date_form.is_valid():
                return HttpResponseRedirect(
                    '%s%s' %
                    (date_form.name_obj.base_url_with_timestamp(), url_subdir))
        else:
            date_form = None

        if timestamp is None:
            name_obj = OfflineDomainNameAnalysis.objects.latest(name)
        else:
            date = util.datetime_url_decode(timestamp)
            name_obj = OfflineDomainNameAnalysis.objects.get_by_date(
                name, date)

        if name_obj is None:
            subdir_path_length = len(url_subdir.split('/')) - 1
            if timestamp is None:
                return HttpResponseRedirect(('../' * subdir_path_length) +
                                            'analyze/')
            else:
                raise Http404

        if date_form is None:
            date_form = domain_date_search_form(name)(
                initial={
                    'date': fmt.datetime_to_str(name_obj.analysis_end)[:10]
                })

        return self._get(request, name_obj, timestamp, url_subdir, date_form,
                         **kwargs)
示例#4
0
    def _get(self,
             request,
             name_obj,
             timestamp,
             url_subdir,
             date_form,
             rest_dir=None):
        options_form, values = get_dnssec_options_form_data({})

        trusted_keys_explicit = values['tk']
        trusted_zones = values['ta']
        trusted_keys = trusted_keys_explicit + trusted_zones

        loglevel = request.GET.get('l', '')
        if loglevel == 'error':
            loglevel = logging.ERROR
        elif loglevel == 'warning':
            loglevel = logging.WARNING
        elif loglevel == 'info':
            loglevel = logging.INFO
        else:
            loglevel = logging.DEBUG

        if request.GET.get('p', False):
            kwargs = {'indent': 4, 'separators': (',', ': ')}
        else:
            kwargs = {}

        d = collections.OrderedDict()
        if rest_dir == 'processed/':
            name_obj.retrieve_all()
            name_obj.populate_status(trusted_keys)
            name_obj.serialize_status(d, loglevel=loglevel)
        elif rest_dir == 'raw/':
            name_obj.retrieve_all()
            name_obj.serialize(d)
            d['_meta._dnsviz.'] = {
                'version': DNS_RAW_VERSION,
                'names': [name_obj.name.to_text()]
            }
        elif rest_dir == 'meta/':
            d['name'] = name_obj.name.to_text()
            d['type'] = analysis_types[name_obj.analysis_type]
            d['stub'] = name_obj.stub
            d['analysis_start'] = fmt.datetime_to_str(name_obj.analysis_start)
            d['analysis_end'] = fmt.datetime_to_str(name_obj.analysis_end)
            if name_obj.group is None:
                if name_obj.previous is not None:
                    d['previous_start'] = fmt.datetime_to_str(
                        name_obj.previous.analysis_start)
                    d['previous_end'] = fmt.datetime_to_str(
                        name_obj.previous.analysis_end)
                if name_obj.next is not None:
                    d['next_start'] = fmt.datetime_to_str(
                        name_obj.next.analysis_start)
                    d['next_end'] = fmt.datetime_to_str(
                        name_obj.next.analysis_end)
                if name_obj.first is not None:
                    d['first_start'] = fmt.datetime_to_str(
                        name_obj.first.analysis_start)
                    d['first_end'] = fmt.datetime_to_str(
                        name_obj.first.analysis_end)
                if name_obj.latest is not None:
                    d['latest_start'] = fmt.datetime_to_str(
                        name_obj.latest.analysis_start)
                    d['latest_end'] = fmt.datetime_to_str(
                        name_obj.latest.analysis_end)
        else:
            raise Http404

        return HttpResponse(json.dumps(d, **kwargs),
                            content_type='application/json')