Spaces:
Running
Running
raannakasturi
commited on
Commit
•
89ccdca
1
Parent(s):
9ebf67f
Upload 2 files
Browse files- app.py +27 -0
- generate_cnames.py +51 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from generate_cnames import generate_cnames
|
3 |
+
|
4 |
+
def generate_cnames(i_domains):
|
5 |
+
cf_domain = "silerudaagartha.eu.org"
|
6 |
+
cname_recs, cname_values = generate_cnames(i_domains, cf_domain)
|
7 |
+
table_data = []
|
8 |
+
for rec, value in zip(cname_recs, cname_values):
|
9 |
+
table_data.append([rec, value])
|
10 |
+
return table_data
|
11 |
+
|
12 |
+
def app():
|
13 |
+
with gr.Blocks(title="Generate CNAMES for Project Gatekeeper") as webui:
|
14 |
+
with gr.Tab("STEP 1: Generate CNAME Records"):
|
15 |
+
with gr.Row():
|
16 |
+
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)
|
17 |
+
btn1 = gr.Button(value="Generate CNAME Records & Values")
|
18 |
+
with gr.Row():
|
19 |
+
records = gr.Dataframe(label="CNAME Records", headers=["CNAME", "CNAME VALUE"], row_count=(1), col_count=(2))
|
20 |
+
btn1.click(generate_cnames, inputs=cname_domains, outputs=records)
|
21 |
+
try:
|
22 |
+
webui.queue(default_concurrency_limit=25).launch(share=True)
|
23 |
+
except Exception as e:
|
24 |
+
print(f"Error: {e}")
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
app()
|
generate_cnames.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
import hashlib
|
5 |
+
|
6 |
+
|
7 |
+
def get_domains(i_domains):
|
8 |
+
domains = []
|
9 |
+
for domain in i_domains.split(","):
|
10 |
+
domain = domain.strip()
|
11 |
+
domains.append(domain)
|
12 |
+
return domains
|
13 |
+
|
14 |
+
def extract_subdomains(domains):
|
15 |
+
exchange = min(domains, key=len)
|
16 |
+
return exchange
|
17 |
+
|
18 |
+
def prefix(domain):
|
19 |
+
domain_bytes = domain.encode()
|
20 |
+
prefix = hashlib.blake2b(domain_bytes, digest_size=12).hexdigest()
|
21 |
+
return prefix
|
22 |
+
|
23 |
+
def gen_cname_recs(domains):
|
24 |
+
cname_recs = []
|
25 |
+
for domain in domains:
|
26 |
+
cname_rec = f"_acme-challenge.{domain}"
|
27 |
+
cname_recs.append(cname_rec)
|
28 |
+
return cname_recs
|
29 |
+
|
30 |
+
def gen_cname_values(domains, cf_domain, exchange):
|
31 |
+
temp_cname_values = []
|
32 |
+
cname_values = []
|
33 |
+
for domain in domains:
|
34 |
+
cname_value = prefix(domain)
|
35 |
+
cname_value = f"{cname_value}.{domain}"
|
36 |
+
temp_cname_values.append(cname_value)
|
37 |
+
for cname_value in temp_cname_values:
|
38 |
+
modified_cname_value = cname_value.replace(exchange, cf_domain)
|
39 |
+
cname_values.append(modified_cname_value)
|
40 |
+
return cname_values
|
41 |
+
|
42 |
+
def gen_cname(domains, cf_domain, exchange):
|
43 |
+
cname_recs = gen_cname_recs(domains)
|
44 |
+
cname_values = gen_cname_values(domains, cf_domain, exchange)
|
45 |
+
return cname_recs, cname_values
|
46 |
+
|
47 |
+
def generate_cnames(i_domains, cf_domain):
|
48 |
+
domains = get_domains(i_domains)
|
49 |
+
exchange = extract_subdomains(domains=domains)
|
50 |
+
cname_recs, cname_values = gen_cname(domains, cf_domain, exchange)
|
51 |
+
return cname_recs, cname_values
|