raannakasturi commited on
Commit
d7d7109
·
1 Parent(s): 77c46b1

chore: Refactor key_type logic in run function

Browse files
Files changed (2) hide show
  1. app.py +49 -31
  2. gen_client_cnames.py +8 -0
app.py CHANGED
@@ -3,8 +3,17 @@ import sys
3
  import gradio as gr
4
  from main import main
5
  from tools import write_file
 
6
 
7
- def run(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_curve=None):
 
 
 
 
 
 
 
 
8
  if key_type == "rsa":
9
  key_curve = None
10
  elif key_type == "ec":
@@ -28,41 +37,50 @@ def update_key_options(key_type):
28
  return gr.update(visible=False), gr.update(visible=True)
29
 
30
  def update_ca_server(wildcard: bool):
31
- if wildcard:
32
- return gr.update(choices=["Let's Encrypt (Testing)","Let's Encrypt", "ZeroSSL", "Google (Testing)","Google", "SSL.com"], value="Let's Encrypt (Testing)")
33
  else:
34
- return gr.update(choices=["Let's Encrypt (Testing)","Let's Encrypt", "Buypass (Testing)", "Buypass", "ZeroSSL", "Google (Testing)","Google", "SSL.com"], value="Let's Encrypt")
35
 
36
  def app():
37
  with gr.Blocks() as webui:
38
- with gr.Row():
39
- with gr.Column():
40
- domains_input = gr.Textbox(label="Enter Domains", placeholder="thenayankasturi.eu.org, dash.thenayankasturi.eu.org, www.thenayankasturi.eu.org", type="text", interactive=True)
41
- wildcard = gr.Checkbox(label="Wildcard SSL", interactive=True, value=False)
42
- email_input = gr.Textbox(label="Enter your Email ID", placeholder="nayankasturi@gmail.com", type="text", interactive=True)
43
- with gr.Row():
44
- ca_server = gr.Dropdown(label="Select Certificate Authority", choices=["Let's Encrypt (Testing)","Let's Encrypt", "Buypass (Testing)", "Buypass", "ZeroSSL", "Google (Testing)","Google", "SSL.com"], interactive=True, value="Let's Encrypt (Testing)")
45
- key_type = gr.Radio(label="Select SSL key type", choices=["rsa", "ec"], interactive=True, value='ec')
46
- key_size_dropdown = gr.Dropdown(label="Select Key Size", choices=['2048', '4096'], value='4096', visible=False) # Initially visible
47
- key_curve_dropdown = gr.Dropdown(label="Select Key Curve", choices=['SECP256R1', 'SECP384R1'], value='SECP384R1', visible=True) # Initially hidden
48
-
49
- key_type.change(fn=update_key_options, inputs=key_type, outputs=[key_size_dropdown, key_curve_dropdown])
50
- btn = gr.Button(value="Generate SSL Certificate")
51
-
52
- with gr.Row():
53
- with gr.Column():
54
- 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)
55
- pvtfile = gr.File(label="Download your Private Key")
56
- with gr.Column():
57
- 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)
58
- csrfile = gr.File(label="Download your CSR")
59
- with gr.Column():
60
- 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)
61
- crtfile = gr.File(label="Download your SSL Certificate")
62
-
63
- btn.click(run, inputs=[domains_input, wildcard, email_input, ca_server, key_type, key_size_dropdown, key_curve_dropdown], outputs=[pvt, pvtfile, csr, csrfile, crt, crtfile])
 
 
 
 
 
 
 
 
 
64
  try:
65
- webui.queue(default_concurrency_limit=15).launch(share=True, server_port=7860)
66
  except Exception as e:
67
  print(f"Error: {e}")
68
  sys.exit(1)
 
3
  import gradio as gr
4
  from main import main
5
  from tools import write_file
6
+ from gen_client_cnames import gen_client_cnames
7
 
8
+ def gen_cname(i_domains):
9
+ cf_domain = "sileruagartha.eu.org"
10
+ cname_recs, cname_values = gen_client_cnames(i_domains, cf_domain)
11
+ table_data = []
12
+ for x, y in zip(cname_recs, cname_values):
13
+ table_data.append([x, y])
14
+ return table_data
15
+
16
+ def gen_ssl(i_domains, wildcard, email, ca_server, key_type, key_size=None, key_curve=None):
17
  if key_type == "rsa":
18
  key_curve = None
19
  elif key_type == "ec":
 
37
  return gr.update(visible=False), gr.update(visible=True)
38
 
39
  def update_ca_server(wildcard: bool):
40
+ if wildcard == False:
41
+ 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)")
42
  else:
43
+ return gr.update(choices=["Let's Encrypt (Testing)","Let's Encrypt", "ZeroSSL", "Google (Testing)","Google", "SSL.com"], value="Let's Encrypt")
44
 
45
  def app():
46
  with gr.Blocks() as webui:
47
+ with gr.Tab("STEP 1: Generate CNAME Records"):
48
+ with gr.Row():
49
+ domains_input = 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)
50
+ btn = gr.Button(value="Generate CNAME Records & Values")
51
+ with gr.Row():
52
+ records = gr.Dataframe(label="CNAME Records", headers=["CNAME", "CNAME VALUE"], row_count=(1), col_count=(2))
53
+ btn.click(gen_cname, inputs=domains_input, outputs=records)
54
+ with gr.Tab("STEP 3: Generate SSL"):
55
+ with gr.Row():
56
+ with gr.Column():
57
+ domains_input = gr.Textbox(label="Enter Domains", placeholder="thenayankasturi.eu.org, dash.thenayankasturi.eu.org, www.thenayankasturi.eu.org", type="text", interactive=True)
58
+ wildcard = gr.Checkbox(label="Wildcard SSL", interactive=True, value=False)
59
+ email_input = gr.Textbox(label="Enter your Email ID", placeholder="nayankasturi@gmail.com", type="text", interactive=True)
60
+ with gr.Row():
61
+ ca_server = gr.Dropdown(label="Select Certificate Authority", choices=["Let's Encrypt (Testing)","Let's Encrypt", "Buypass (Testing)", "Buypass", "ZeroSSL", "Google (Testing)","Google", "SSL.com"], interactive=True, value="Let's Encrypt (Testing)")
62
+ key_type = gr.Radio(label="Select SSL key type", choices=["rsa", "ec"], interactive=True, value='ec')
63
+ key_size_dropdown = gr.Dropdown(label="Select Key Size", choices=['2048', '4096'], value='4096', visible=False) # Initially visible
64
+ key_curve_dropdown = gr.Dropdown(label="Select Key Curve", choices=['SECP256R1', 'SECP384R1'], value='SECP384R1', visible=True) # Initially hidden
65
+
66
+ key_type.change(fn=update_key_options, inputs=key_type, outputs=[key_size_dropdown, key_curve_dropdown])
67
+ wildcard.change(fn=update_ca_server, inputs=wildcard, outputs=ca_server)
68
+ btn = gr.Button(value="Generate SSL Certificate")
69
+
70
+ with gr.Row():
71
+ with gr.Column():
72
+ 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)
73
+ pvtfile = gr.File(label="Download your Private Key")
74
+ with gr.Column():
75
+ 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)
76
+ csrfile = gr.File(label="Download your CSR")
77
+ with gr.Column():
78
+ 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)
79
+ crtfile = gr.File(label="Download your SSL Certificate")
80
+
81
+ btn.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])
82
  try:
83
+ webui.queue(default_concurrency_limit=15).launch()
84
  except Exception as e:
85
  print(f"Error: {e}")
86
  sys.exit(1)
gen_client_cnames.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from gen_records import gen_cname
2
+ from tools import get_domains, extract_subdomains
3
+
4
+ def gen_client_cnames(i_domains, cf_domain):
5
+ domains = get_domains(i_domains)
6
+ exchange = extract_subdomains(domains=domains)
7
+ cname_recs, cname_values = gen_cname(domains, cf_domain, exchange)
8
+ return cname_recs, cname_values