raannakasturi's picture
refactor: Update dropdown choices for CA server in app.py
a762f4e
import os
import sys
import gradio as gr
from main import main
from tools import write_file, get_domains
from gen_client_cnames import gen_client_cnames
from verify_cname import verify_cname
def gen_cname(i_domains):
cf_domain = "silerudaagartha.eu.org"
cname_recs, cname_values = gen_client_cnames(i_domains, cf_domain)
table_data = []
for rec, value in zip(cname_recs, cname_values):
table_data.append([rec, value])
return table_data
def check_cname(domains):
data = verify_cname(domains)
return data
def gen_ssl(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_curve=None):
if key_type == "rsa":
key_curve = None
elif key_type == "ec":
key_size = None
else:
key_curve = None
if key_size is not None:
key_size = int(key_size)
pvt, csr, cert = main(i_domains, wildcard, email, ca_server, key_type, key_size, key_curve)
path = email.split("@")[0]
os.makedirs(path, exist_ok=True)
write_file(f"{path}/private.pem", pvt)
write_file(f"{path}/domain.csr", csr)
write_file(f"{path}/cert.pem", cert)
return pvt.decode('utf-8'), f"{path}/private.pem", csr.decode('utf-8'), f"{path}/domain.csr", cert.decode('utf-8'), f"{path}/cert.pem"
def update_key_options(key_type):
if key_type == "rsa":
return gr.update(visible=True), gr.update(visible=False)
else:
return gr.update(visible=False), gr.update(visible=True)
def update_ca_server(wildcard: bool):
if wildcard == False:
return gr.update(choices=["Let's Encrypt (Testing)","Let's Encrypt", "Buypass (Testing)", "Buypass", "ZeroSSL", "Google (Testing)","Google", "SSL.com"], value="Let's Encrypt (Testing)")
else:
return gr.update(choices=["Let's Encrypt (Testing)","Let's Encrypt", "ZeroSSL", "Google (Testing)","Google", "SSL.com"], value="Let's Encrypt")
def update_buypass_options(ca_server):
if ca_server == "Buypass (Testing)" or ca_server == "Buypass":
return gr.update(choices=['SECP256R1'])
else:
return gr.update(choices=['SECP256R1', 'SECP384R1'])
def app():
with gr.Blocks(title="Project Gatekeeper - Get free SSL Certificates") as webui:
with gr.Tab("STEP 1: Generate CNAME Records"):
with gr.Row():
cname_domains = gr.Textbox(value="thenayankasturi.eu.org, dash.thenayankasturi.eu.org, www.thenayankasturi.eu.org", label="Enter Domains", placeholder="thenayankasturi.eu.org, dash.thenayankasturi.eu.org, www.thenayankasturi.eu.org", type="text", interactive=True)
btn1 = gr.Button(value="Generate CNAME Records & Values")
with gr.Row():
records = gr.Dataframe(label="CNAME Records", headers=["CNAME", "CNAME VALUE"], row_count=(1), col_count=(2))
btn1.click(gen_cname, inputs=cname_domains, outputs=records)
with gr.Tab("STEP 2: Check CNAME Propagation"):
with gr.Row():
check_domains = gr.Textbox(label="Enter CNAME", placeholder="thenayankasturi.eu.org, dash.thenayankasturi.eu.org, www.thenayankasturi.eu.org", type="text", interactive=True)
btn2 = gr.Button(value="Check CNAME Propagation")
with gr.Row():
data = gr.Dataframe(label="CNAME Records", headers=["CNAME", "Expected CNAME Value", "Found CNAME Value", "CNAME Status"], row_count=(1), col_count=(4))
btn2.click(verify_cname, inputs=check_domains, outputs=data)
with gr.Tab("STEP 3: Generate SSL"):
with gr.Row():
with gr.Column():
domains_input = gr.Textbox(label="Enter Domains", placeholder="thenayankasturi.eu.org, dash.thenayankasturi.eu.org, www.thenayankasturi.eu.org", type="text", interactive=True)
wildcard = gr.Checkbox(label="Wildcard SSL", interactive=True, value=False)
email_input = gr.Textbox(label="Enter your Email ID", placeholder="[email protected]", type="text", interactive=True)
with gr.Row():
ca_server = gr.Dropdown(label="Select Certificate Authority", choices=["Let's Encrypt (Testing)","Let's Encrypt", "Google (Testing)","Google", "Buypass (Testing)", "Buypass", "ZeroSSL", "SSL.com"], interactive=True, value="Let's Encrypt (Testing)")
key_type = gr.Radio(label="Select SSL key type", choices=["rsa", "ec"], interactive=True, value='ec')
key_size_dropdown = gr.Dropdown(label="Select Key Size", choices=['2048', '4096'], value='4096', visible=False) # Initially visible
key_curve_dropdown = gr.Dropdown(label="Select Key Curve", choices=['SECP256R1', 'SECP384R1'], value='SECP256R1', visible=True) # Initially hidden
ca_server.change(fn=update_buypass_options, inputs=ca_server, outputs=key_curve_dropdown)
key_type.change(fn=update_key_options, inputs=key_type, outputs=[key_size_dropdown, key_curve_dropdown])
wildcard.change(fn=update_ca_server, inputs=wildcard, outputs=ca_server)
btn3 = gr.Button(value="Generate SSL Certificate")
with gr.Row():
with gr.Column():
pvt = gr.Textbox(label="Your Private Key", placeholder="Your Private Key will appear here, after successful SSL generation", type="text", interactive=False, show_copy_button=True, lines=10, max_lines=10)
pvtfile = gr.File(label="Download your Private Key")
with gr.Column():
csr = gr.Textbox(label="Your CSR", placeholder="Your CSR will appear here, after successful SSL generation", type="text", interactive=False, show_copy_button=True, lines=10, max_lines=10)
csrfile = gr.File(label="Download your CSR")
with gr.Column():
crt = gr.Textbox(label="Your SSL Certificate", placeholder="Your SSL Certificate will appear here, after successful SSL generation", type="text", interactive=False, show_copy_button=True, lines=10, max_lines=10)
crtfile = gr.File(label="Download your SSL Certificate")
btn3.click(gen_ssl, inputs=[domains_input, wildcard, email_input, ca_server, key_type, key_size_dropdown, key_curve_dropdown], outputs=[pvt, pvtfile, csr, csrfile, crt, crtfile])
try:
webui.queue(default_concurrency_limit=15).launch()
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
try:
app()
except Exception as e:
print(f"Error: {e}")