Update server.py
This commit is contained in:
parent
d8af49a62b
commit
3262816778
1 changed files with 11 additions and 5 deletions
16
server.py
16
server.py
|
@ -37,10 +37,16 @@ def loadcert_backend():
|
||||||
if cert.filename == '' or privkey.filename == '':
|
if cert.filename == '' or privkey.filename == '':
|
||||||
return "Please upload a certificate and private key."
|
return "Please upload a certificate and private key."
|
||||||
if allowed_file(cert.filename) and allowed_file(privkey.filename):
|
if allowed_file(cert.filename) and allowed_file(privkey.filename):
|
||||||
|
for i in os.listdir(homefolder + "/certs/"):
|
||||||
|
thisname = "-".join(i.split("-")[:-1])
|
||||||
|
if open(homefolder + "/certs/" + thisname + "-privkey.pem").read() == privkey.read() and open(homefolder + "/certs/" + thisname + "-chain.pem").read() == cert.read():
|
||||||
|
resp = make_response('<meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="/style.css">The certificate seems to already exist, loading the used file.<br><br><p><a href="/" class=go style="color: white;">Go home</a></p>')
|
||||||
|
resp.set_cookie('certname',thisname)
|
||||||
|
return resp
|
||||||
random_name = str(uuid.uuid4())
|
random_name = str(uuid.uuid4())
|
||||||
cert.save(homefolder + "/certs/" + random_name + "-chain.pem")
|
cert.save(homefolder + "/certs/" + random_name + "-chain.pem")
|
||||||
privkey.save(homefolder + "/certs/" + random_name + "-privkey.pem")
|
privkey.save(homefolder + "/certs/" + random_name + "-privkey.pem")
|
||||||
resp = make_response('<link rel="stylesheet" href="/style.css">Success!<br><br><p><a href="/" class=go style="color: white;">Go home</a></p>')
|
resp = make_response('<meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="/style.css">Success!<br><br><p><a href="/" class=go style="color: white;">Go home</a></p>')
|
||||||
resp.set_cookie('certname',random_name)
|
resp.set_cookie('certname',random_name)
|
||||||
return resp
|
return resp
|
||||||
else:
|
else:
|
||||||
|
@ -158,11 +164,11 @@ def relay():
|
||||||
return redirect("/gem?gemini=" + urlparse(fulladdr).hostname + quote(i.split(" ")[1], safe=''))
|
return redirect("/gem?gemini=" + urlparse(fulladdr).hostname + quote(i.split(" ")[1], safe=''))
|
||||||
return redirect("/gem?gemini=" + quote(i.split(" ")[1][9:], safe=''))
|
return redirect("/gem?gemini=" + quote(i.split(" ")[1][9:], safe=''))
|
||||||
elif i.split(" ")[0][0] == "1":
|
elif i.split(" ")[0][0] == "1":
|
||||||
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="/style.css"><title>Input required</title></head><body><h1>Input required</h1><p>The specified Gemini server wants more data: <pre>{i}</pre></p><form action="/gem"><input hidden class="input" value="{url}" type="text" name="gemini"><input class="input" type="{"password" if i.split(" ")[0][1] == "1" else "text"}" name="query" autocomplete="on"><br><input type="submit" class="go" value="Go!"><br><br></form></body></html>'
|
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="/style.css"><title>Input required</title></head><body><h1>Input required</h1><p>The specified Gemini server wants more data: <pre>{i}</pre></p><form action="/gem"><input hidden class="input" value="{url}" type="text" name="gemini"><input class="input" type="{"password" if i.split(" ")[0][1] == "1" else "text"}" name="query" autocomplete="on"><br><input type="submit" class="go" value="Go!"><br><br></form></body></html>'
|
||||||
elif i.split(" ")[0][0] == "6":
|
elif i.split(" ")[0][0] == "6":
|
||||||
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="/style.css"><title>Certificate requested</title></head><body><h1>Certificate requested</h1><p>The specified Gemini server wants a client certificate, or the certificate is invalid. <pre>{i}</pre></p><br><br><p>You can load a certificate in <a href="/">home page.</a></p></body></html>'
|
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="/style.css"><title>Certificate requested</title></head><body><h1>Certificate requested</h1><p>The specified Gemini server wants a client certificate, or the certificate is invalid. <pre>{i}</pre></p><br><br><p>You can load a certificate in <a href="/">home page.</a></p></body></html>'
|
||||||
elif i.split(" ")[0][0] != "2":
|
elif i.split(" ")[0][0] != "2":
|
||||||
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="/style.css"><title>Something went wrong...</title></head><body><h1>Something went wrong...</h1><p>The specified Gemini server returned a status of: {i}</p></body></html>'
|
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="/style.css"><title>Something went wrong...</title></head><body><h1>Something went wrong...</h1><p>The specified Gemini server returned a status of: {i}</p></body></html>'
|
||||||
else:
|
else:
|
||||||
firstline = False
|
firstline = False
|
||||||
if i.split(" ")[1].split(";")[0] != "text/gemini":
|
if i.split(" ")[1].split(";")[0] != "text/gemini":
|
||||||
|
@ -246,7 +252,7 @@ def relay():
|
||||||
title = "gemini://" + url
|
title = "gemini://" + url
|
||||||
except:
|
except:
|
||||||
code += "<pre>" + traceback.format_exc() + "</pre>"
|
code += "<pre>" + traceback.format_exc() + "</pre>"
|
||||||
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><link rel="stylesheet" href="/style.css"><title>{title}</title></head><body>{code}</body></html>'
|
return f'<!DOCTYPE html>\n<html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="/style.css"><title>{title}</title></head><body>{code}</body></html>'
|
||||||
|
|
||||||
# Run the Hypercorn ASGI server
|
# Run the Hypercorn ASGI server
|
||||||
conf = Config()
|
conf = Config()
|
||||||
|
|
Loading…
Add table
Reference in a new issue