#!/usr/bin/python3 import subprocess import jinja2 import os import configparser import sys from colorama import Fore, Style import shutil import time config = configparser.ConfigParser() config.read('samba-pki-tools.ini') # # write config file # jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_3cx)) # template = jinja_env.get_template("3CXVoipPhone.j2") # template_variables = { # "name": "TIS (%s)" % get_current_user(), } class Printing(): def information(string): print(Fore.CYAN + '[i] ' + string) return print(Style.RESET_ALL) def success(string): print(Fore.GREEN + '[+] '+ string) return print(Style.RESET_ALL) def warning(string): print(Fore.YELLOW + '[!] ' + string) return print(Style.RESET_ALL) def error(string): print(Fore.RED + '[-] ' + string) return print(Style.RESET_ALL) class TisPKI: def pki_dir(): return config.get('general','pki_dir') def root_ca_certfile(): return os.path.join(TisPKI.pki_dir(),'certs','root_ca.crt') def root_ca_keyfile(): return os.path.join(TisPKI.pki_dir(),'private','root_ca.key') def root_ca_crlfile(): return os.path.join(TisPKI.root_crl_path(),'root_ca.crl') def root_ca_configfile(): return os.path.join(TisPKI.root_config_path(),'openssl_root_ca.ini') def root_keyout_path(): return os.path.join(TisPKI.pki_dir(),'private') def root_csr_path(): return os.path.join(TisPKI.pki_dir(),'csr') def root_cert_path(): return os.path.join(TisPKI.pki_dir(),'certs') def root_p12_path(): return os.path.join(TisPKI.pki_dir(),'p12') def root_config_path(): return os.path.join(TisPKI.pki_dir(),'config') def root_crl_path(): return os.path.join(TisPKI.pki_dir(),'crl') def intermediate_ca(): if config.getboolean('openssl_config','create_intermediate'): return True def pki_intermediate_dir(name): name = name.replace(' ','_') return os.path.join(config.get('general','pki_dir'),f'{name}_intermediate_ca') def intermediate_cert_path(name): return os.path.join(TisPKI.pki_intermediate_dir(name),'certs') def intermediate_keyout_path(name): return os.path.join(TisPKI.pki_intermediate_dir(name),'private') def intermediate_csr_path(name): return os.path.join(TisPKI.pki_intermediate_dir(name),'csr') def intermediate_p12_path(name): return os.path.join(TisPKI.pki_intermediate_dir(name),'p12') def intermediate_config_path(name): return os.path.join(TisPKI.pki_intermediate_dir(name),'config') def intermediate_crl_path(name): return os.path.join(TisPKI.pki_intermediate_dir(name),'crl') def intermediate_ca_certfile(name): name = name.replace(' ','_') return os.path.join(TisPKI.intermediate_cert_path(name),f'{name}_intermediate_ca.crt') def intermediate_ca_keyfile(name): name = name.replace(' ','_') return os.path.join(TisPKI.intermediate_keyout_path(name),f'{name}_intermediate_ca.key') def intermediate_ca_crlfile(name): name = name.replace(' ','_') return os.path.join(TisPKI.intermediate_crl_path(name),f'{name}.crl') def check_directories(path,verbose=False): if verbose: Printing.information('Check directories') directories_list = ['certs','config','crl','private','csr','p12','newcerts'] if not os.path.isdir(path): if verbose: Printing.information(f'Create { path } directory') os.makedirs(path) for directory in directories_list: directory_path = os.path.join(path,directory) if not os.path.isdir(directory_path): if verbose: Printing.information(f'Create { directory_path } directory') os.makedirs(directory_path) if not os.path.isfile(os.path.join(path,'index.txt')): with open(os.path.join(path,'index.txt'),'w') as file: pass