Exemple #1
0
def SendCertificateData(obj, request):
    """Send the zipped certificate data as email.
    
    Verify that the given object has all the flags set, create a zipfile and mail it to the
    email address from the certificate.
    """
    
    ## Check that email flag is set in the DB
    if obj.email:
        zip_f = build_zip_for_object(obj, request)
        
        ## Read ZIP content and remove it
        try:
            if os.path.exists(zip_f):
                f = open(zip_f)
                x = f.read()
                f.close()
                
                os.remove(zip_f)
        except OSError,e:
            logger.error( "Failed to read zipfile: %s" % e)
            raise Exception( e )
        
        ## Build email obj and send it out
        parent_name = 'self-signed'
        if obj.parent:
            parent_name = obj.parent.common_name
        
        subj_msg = subject_for_object(obj)
        body_msg = "Certificate data sent by django-pki:\n\n  * subject: %s\n  * parent: %s\n" % (subj_msg, parent_name)
        
        email = EmailMessage( to=[obj.email,], subject="Certificate data for \"%s\"" % subj_msg, body=body_msg,  )
        email.attach( 'PKI_DATA_%s.zip' % obj.name, x, 'application/zip' )
        email.send(fail_silently=False)
Exemple #2
0
def pki_download(request, type, id):
    """Download PKI data.
    
    Type (ca/cert) and ID are used to determine the object to download.
    """
    
    if type == "ca":
        c = get_object_or_404(CertificateAuthority, pk=id)
    elif type == "cert":
        c = get_object_or_404(Certificate, pk=id)
    else:
        logger.error( "Unsupported type %s requested!" % type )
        return HttpResponseBadRequest()
    
    if not c.active:
        raise Http404
    
    zip = build_zip_for_object(c, request)
    
    ## open and read the file if it exists
    if os.path.exists(zip):
        f = open(zip)
        x = f.readlines()
        f.close()
        
        ## return the HTTP response
        response = HttpResponse(x, mimetype='application/force-download')
        response['Content-Disposition'] = 'attachment; filename="PKI_DATA_%s.zip"' % c.name
        
        return response
    else:
        logger.error( "File not found: %s" % zip )
        raise Http404
Exemple #3
0
def SendCertificateData(obj, request):
    """Send the zipped certificate data as email.
    
    Verify that the given object has all the flags set, create a zipfile and mail it to the
    email address from the certificate.
    """

    ## Check that email flag is set in the DB
    if obj.email:
        zip_f = build_zip_for_object(obj, request)

        ## Read ZIP content and remove it
        try:
            if os.path.exists(zip_f):
                f = open(zip_f)
                x = f.read()
                f.close()

                os.remove(zip_f)
        except OSError, e:
            logger.error("Failed to read zipfile: %s" % e)
            raise Exception(e)

        ## Build email obj and send it out
        parent_name = 'self-signed'
        if obj.parent:
            parent_name = obj.parent.common_name

        subj_msg = subject_for_object(obj)
        body_msg = "Certificate data sent by django-pki:\n\n  * subject: %s\n  * parent: %s\n" % (
            subj_msg, parent_name)

        email = EmailMessage(
            to=[
                obj.email,
            ],
            subject="Certificate data for \"%s\"" % subj_msg,
            body=body_msg,
        )
        email.attach('PKI_DATA_%s.zip' % obj.name, x, 'application/zip')
        email.send(fail_silently=False)
def pki_download(request, model, id):
    """Download PKI data.
    
    Type (ca/cert) and ID are used to determine the object to download.
    """

    if not request.user.has_perm('pki.can_download'):
        messages.error(request, "Permission denied!")
        return HttpResponseRedirect(
            urlresolvers.reverse('admin:pki_%s_changelist' % model))

    if model == "certificateauthority":
        c = get_object_or_404(CertificateAuthority, pk=id)
    elif model == "certificate":
        c = get_object_or_404(Certificate, pk=id)
    else:
        logger.error("Unsupported type %s requested!" % type)
        return HttpResponseBadRequest()

    if not c.active:
        raise Http404

    zip = build_zip_for_object(c, request)

    ## open and read the file if it exists
    if os.path.exists(zip):
        f = open(zip)
        x = f.readlines()
        f.close()

        ## return the HTTP response
        response = HttpResponse(x, mimetype='application/force-download')
        response[
            'Content-Disposition'] = 'attachment; filename="PKI_DATA_%s.zip"' % c.name

        return response
    else:
        logger.error("File not found: %s" % zip)
        raise Http404
Exemple #5
0
def pki_download(request, model, id):
    """Download PKI data.
    
    Type (ca/cert) and ID are used to determine the object to download.
    """
    
    if not request.user.has_perm('pki.can_download'):
        messages.error(request, "Permission denied!")
        return HttpResponseRedirect(urlresolvers.reverse('admin:pki_%s_changelist' % model))
    
    if model == "certificateauthority":
        c = get_object_or_404(CertificateAuthority, pk=id)
    elif model == "certificate":
        c = get_object_or_404(Certificate, pk=id)
    else:
        logger.error( "Unsupported type %s requested!" % type )
        return HttpResponseBadRequest()
    
    if not c.active:
        raise Http404
    
    zip = build_zip_for_object(c, request)
    
    ## open and read the file if it exists
    if os.path.exists(zip):
        f = open(zip)
        x = f.readlines()
        f.close()
        
        ## return the HTTP response
        response = HttpResponse(x, mimetype='application/force-download')
        response['Content-Disposition'] = 'attachment; filename="PKI_DATA_%s.zip"' % c.name
        
        return response
    else:
        logger.error( "File not found: %s" % zip )
        raise Http404