Update server.py
This commit is contained in:
parent
75be975517
commit
dd5c2920f2
1 changed files with 30 additions and 1 deletions
31
server.py
31
server.py
|
@ -1,9 +1,13 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import asyncio, traceback, socket, ssl
|
import asyncio, traceback, socket, ssl, zipfile
|
||||||
|
from OpenSSL import crypto
|
||||||
from urllib.parse import urlparse, quote
|
from urllib.parse import urlparse, quote
|
||||||
from flask import Flask, request, redirect, send_file, Response
|
from flask import Flask, request, redirect, send_file, Response
|
||||||
from hypercorn.config import Config
|
from hypercorn.config import Config
|
||||||
from hypercorn.asyncio import serve
|
from hypercorn.asyncio import serve
|
||||||
|
from pathlib import Path
|
||||||
|
homefolder = str(Path.home())
|
||||||
|
import uuid
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
|
@ -14,6 +18,31 @@ def external():
|
||||||
@app.route("/cross-server.png")
|
@app.route("/cross-server.png")
|
||||||
def crosserver():
|
def crosserver():
|
||||||
return send_file("cross-server.png")
|
return send_file("cross-server.png")
|
||||||
|
@app.route("/gencert.zip"):
|
||||||
|
random_name = str(uuid.uuid4())
|
||||||
|
k = crypto.PKey()
|
||||||
|
k.generate_key(crypto.TYPE_RSA, 1024)
|
||||||
|
cert = crypto.X509()
|
||||||
|
cert.get_subject().C = "Earth"
|
||||||
|
cert.get_subject().ST = "Earth"
|
||||||
|
cert.get_subject().L = "Earth"
|
||||||
|
cert.get_subject().O = "Gem2Browser " + random_name
|
||||||
|
cert.get_subject().OU = "Gem2Browser " + random_name
|
||||||
|
cert.get_subject().CN = "g2b.swee.codes"
|
||||||
|
cert.set_serial_number(1000)
|
||||||
|
cert.gmtime_adj_notBefore(0)
|
||||||
|
cert.gmtime_adj_notAfter(10*365*24*60*60)
|
||||||
|
cert.set_issuer(cert.get_subject())
|
||||||
|
cert.set_pubkey(k)
|
||||||
|
cert.sign(k, 'sha1')
|
||||||
|
#open(homefolder + "/" + random_name + "-privkey.pem", "wb").write(crypto.dump_privatekey(crypto.FILETYPE_PEM, k))
|
||||||
|
#open(homefolder + "/" + random_name + "-cert.pem", "wb").write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
|
||||||
|
zip_buffer = io.BytesIO()
|
||||||
|
with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, False) as zip_file:
|
||||||
|
for file_name, data in [('cert.pem', io.BytesIO(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))),
|
||||||
|
('privkey.pem', io.BytesIO(crypto.dump_privatekey(crypto.FILETYPE_PEM, k)))]:
|
||||||
|
zip_file.writestr(file_name, data.getvalue())
|
||||||
|
return zip_buffer.getvalue()
|
||||||
@app.route("/style.css")
|
@app.route("/style.css")
|
||||||
def style():
|
def style():
|
||||||
return send_file("style.css")
|
return send_file("style.css")
|
||||||
|
|
Loading…
Add table
Reference in a new issue