# Path: pki/settings.py
# PKI_DIR = getattr(settings, 'PKI_DIR', os.path.join(PKI_APP_DIR, 'PKI'))
# 
# PKI_BASE_URL = getattr(settings, 'PKI_BASE_URL', get_script_prefix())
# 
# MEDIA_URL = getattr(settings, 'MEDIA_URL')


import os
import tempfile
import random
import zipfile
import logging
import string
import pki.models
from django.utils.safestring import mark_safe
from django.core import urlresolvers
from pki.settings import PKI_DIR, PKI_BASE_URL, MEDIA_URL



logger = logging.getLogger("pki")

def get_pki_icon_html(img, title="", css="centered", id=""):
        """Return HTML for given image.
        
        Can add optional alt and title parameters.
        """
        
        if css:
            css_class = 'class=%s' % css
        else:
            css_class = ''
        
        img_path = os.path.join(PKI_BASE_URL, MEDIA_URL, 'pki/img', img)
        return '<img id="%s" %s src="%s" alt="%s" title="%s"/>' % (id, css_class, img_path, title, title)

def files_for_object(obj):
    """Return files associated to object.
    
    Return dict containing all files associated to object. Dict contains
    chain, crl, pem, csr, der, pkcs12 and key
    """
    
    if isinstance(obj, pki.models.CertificateAuthority):
        chain   = c_name = obj.name

# Path: pki/settings.py
# PKI_DIR = getattr(settings, 'PKI_DIR', os.path.join(PKI_APP_DIR, 'PKI'))
# 
# PKI_BASE_URL = getattr(settings, 'PKI_BASE_URL', get_script_prefix())
# 
# MEDIA_URL = getattr(settings, 'MEDIA_URL')


# Path: pki/helper.py
import os
import tempfile
import random
import zipfile
import logging
import string
import pki.models
from django.utils.safestring import mark_safe
from django.core import urlresolvers
from pki.settings import PKI_DIR, PKI_BASE_URL, MEDIA_URL




logger = logging.getLogger("pki")

def get_pki_icon_html(img, title="", css="centered", id=""):
        """Return HTML for given image.
        
        Can add optional alt and title parameters.
        """
        
        if css:
            css_class = 'class=%s' % css
        else:
            css_class = ''
        
        img_path = os.path.join(PKI_BASE_URL, MEDIA_URL, 'pki/img', img)
        return '<img id="%s" %s src="%s" alt="%s" title="%s"/>' % (id, css_class, img_path, title, title)

def files_for_object(obj):
    """Return files associated to object.
    
    Return dict containing all files associated to object. Dict contains
    chain, crl, pem, csr, der, pkcs12 and key
    """
    
    if isinstance(obj, pki.models.CertificateAuthority):
        chain   = c_name = obj.name

        ca_dir  = os.path.join(PKI_DIR, obj.name)