Update server.py
This commit is contained in:
parent
97b9a37add
commit
d4dc2f603b
1 changed files with 5 additions and 2 deletions
|
@ -39,16 +39,17 @@ def style():
|
||||||
@app.route("/gem")
|
@app.route("/gem")
|
||||||
def relay():
|
def relay():
|
||||||
url = request.args.get('gemini')
|
url = request.args.get('gemini')
|
||||||
|
queries = request.args.get('query')
|
||||||
if url == None:
|
if url == None:
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
code = "<h1>Something went wrong...</h1>\n"
|
code = "<h1>Something went wrong...</h1>\n"
|
||||||
title = "Something went wrong..."
|
title = "Something went wrong..."
|
||||||
try:
|
try:
|
||||||
gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
fulladdr = "gemini://" + url
|
fulladdr = "gemini://" + url + ("?" + queries if queries != None else "")
|
||||||
gemsocket = ssl._create_unverified_context().wrap_socket(gsocket, server_hostname=urlparse(fulladdr).hostname)
|
gemsocket = ssl._create_unverified_context().wrap_socket(gsocket, server_hostname=urlparse(fulladdr).hostname)
|
||||||
gemsocket.connect((urlparse(fulladdr).hostname, 1965))
|
gemsocket.connect((urlparse(fulladdr).hostname, 1965))
|
||||||
gemsocket.send(bytes("gemini://" + url + "\r\n", "UTF-8"))
|
gemsocket.send(bytes(fulladdr + "\r\n", "UTF-8"))
|
||||||
received = ""
|
received = ""
|
||||||
while True:
|
while True:
|
||||||
gemresponse = gemsocket.recv(2048)
|
gemresponse = gemsocket.recv(2048)
|
||||||
|
@ -70,6 +71,8 @@ def relay():
|
||||||
if firstline:
|
if firstline:
|
||||||
if i.split(" ")[0][0] == "3":
|
if i.split(" ")[0][0] == "3":
|
||||||
return redirect("/gem?gemini=" + i.split(" ")[1][9:])
|
return redirect("/gem?gemini=" + i.split(" ")[1][9:])
|
||||||
|
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><br><form action="/gem"><input hidden class="input" value="{url}" type="text" name="gemini"><input hidden class="input" type="text" name="query"><br><input type="submit" class="go" value="Go!"><br></form></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"><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:
|
||||||
|
|
Loading…
Add table
Reference in a new issue