|
|
|
@ -359,113 +359,6 @@ def get_default_kadmin_creds():
|
|
|
|
|
pw = ""
|
|
|
|
|
return (princ, pw)
|
|
|
|
|
|
|
|
|
|
css_style = """
|
|
|
|
|
<link rel="preload" href="https://s3.metznet.ca/static.metznet.ca/fonts/appleii/apple_-webfont.woff2" as="font" type="font/woff2" crossorigin />
|
|
|
|
|
<link rel="preload" href="https://s3.metznet.ca/static.metznet.ca/fonts/appleii/apple_-webfont.woff" as="font" type="font/woff" crossorigin />
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="https://s3.metznet.ca/static.metznet.ca/fonts/appleii/stylesheet.css"/>
|
|
|
|
|
<link rel="stylesheet" type="text/css" href="/static/metznet.css" />
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
torrents_js = """
|
|
|
|
|
<script type=text/javascript src="/static/torrents.js"></script>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
newline='\n'
|
|
|
|
|
|
|
|
|
|
class HTMLElement:
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return self.html
|
|
|
|
|
|
|
|
|
|
class InputField(HTMLElement):
|
|
|
|
|
def __init__(self, label, name, input_type, additional=""):
|
|
|
|
|
self.html = f"""
|
|
|
|
|
<div>
|
|
|
|
|
{label}
|
|
|
|
|
</div>
|
|
|
|
|
<div>
|
|
|
|
|
<input name="{name}" type="{input_type}" {additional} />
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class WebGridBox(HTMLElement):
|
|
|
|
|
def __init__(self, content, cols=None, rows=None, text_align="center"):
|
|
|
|
|
col_css = None
|
|
|
|
|
if cols is not None:
|
|
|
|
|
col_css = f"grid-column: span {cols}; "
|
|
|
|
|
row_css = None
|
|
|
|
|
if rows is not None:
|
|
|
|
|
row_css = f"grid-row: span {rows}; "
|
|
|
|
|
style_html = f"style=\"{col_css or ''}{row_css or ''}text-align: {text_align};\""
|
|
|
|
|
self.html = f"""
|
|
|
|
|
<div {style_html}>
|
|
|
|
|
{content}
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class WebGrid(HTMLElement):
|
|
|
|
|
def __init__(self, content: List[Any], grid_template_columns, grid_template_rows=None, cls="grid"):
|
|
|
|
|
col_css = f"grid-template-columns: {grid_template_columns};"
|
|
|
|
|
row_css = ""
|
|
|
|
|
if grid_template_rows is not None:
|
|
|
|
|
row_css = f"grid-template-rows: {grid_template_rows};"
|
|
|
|
|
self.html = f"""
|
|
|
|
|
<div class="grid" style="{col_css} {row_css}">
|
|
|
|
|
{newline.join([str(entry) for entry in content])}
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class WebForm(HTMLElement):
|
|
|
|
|
def __init__(self, action, name, fields: List[InputField], button_label=None):
|
|
|
|
|
self.html = f"""
|
|
|
|
|
<div class="form">
|
|
|
|
|
<form action="{action}" method="post" enctype="multipart/form-data">
|
|
|
|
|
<div class="form-fields">
|
|
|
|
|
<div style="grid-column: span 2; grid-row: span 2; text-align: center">
|
|
|
|
|
<header>{name}</header>
|
|
|
|
|
</div>
|
|
|
|
|
{newline.join([str(field) for field in fields])}
|
|
|
|
|
<div>
|
|
|
|
|
<button>{button_label}</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
resize_script = """
|
|
|
|
|
<script src="/static/resize.js"></script>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class WebPage(HTMLElement):
|
|
|
|
|
def __init__(self, bodies: List[Any] = [], headers: List [Any] = []):
|
|
|
|
|
self.html = f"""
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
{resize_script}
|
|
|
|
|
{css_style}
|
|
|
|
|
{newline.join([str(header) for header in headers])}
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
{newline.join([str(body) for body in bodies])}
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class WebDiv(HTMLElement):
|
|
|
|
|
def __init__(self, content=[], cls=None, id=None):
|
|
|
|
|
class_css = ""
|
|
|
|
|
if cls is not None:
|
|
|
|
|
class_css = f"class=\"{cls}\""
|
|
|
|
|
id_html = ""
|
|
|
|
|
if id is not None:
|
|
|
|
|
id_html = f"id=\"{id}\""
|
|
|
|
|
self.html = f"""
|
|
|
|
|
<div {class_css} {id_html}>
|
|
|
|
|
{newline.join([str(element) for element in content])}
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def metznet_webui(args):
|
|
|
|
|
from bottle import get, post, run, request, static_file
|
|
|
|
|
from os import getcwd
|
|
|
|
@ -489,27 +382,15 @@ def metznet_webui(args):
|
|
|
|
|
|
|
|
|
|
@get("/static/<filename>")
|
|
|
|
|
def static_files(filename):
|
|
|
|
|
return static_file(filename, root=f"{getcwd()}/src/")
|
|
|
|
|
return static_file(filename, root=f"{getcwd()}/src/static")
|
|
|
|
|
|
|
|
|
|
@get("/")
|
|
|
|
|
def root_page():
|
|
|
|
|
services = {
|
|
|
|
|
"Plex: Watch TV and Movies": "https://plex.metznet.ca",
|
|
|
|
|
"Torrents: Download Files": "/static/torrents.html",
|
|
|
|
|
"Raid: Access Files": "/raid",
|
|
|
|
|
"Mastodon: Social Media Site": "https://mastodon.metznet.ca",
|
|
|
|
|
"Nextcloud: Files and E-Mail": "https://cloud.metznet.ca",
|
|
|
|
|
"Password Change": "/changepw",
|
|
|
|
|
"Public Key Change": "/changekey",
|
|
|
|
|
}
|
|
|
|
|
service_boxes = []
|
|
|
|
|
for service in services:
|
|
|
|
|
service_boxes.append(WebGridBox(f"<a href=\"{services[service]}\">{service}</a>", text_align="left"))
|
|
|
|
|
boxes = [WebGridBox("<header>MetzNet<br>Service List</header>", 1, 2)] + service_boxes
|
|
|
|
|
return WebPage([WebGrid(boxes, "500px", f"repeat({len(services) + 2}, 50px)")]).html
|
|
|
|
|
|
|
|
|
|
@post("/changekey")
|
|
|
|
|
def do_changekey():
|
|
|
|
|
@get("/<filename>")
|
|
|
|
|
def root_files(filename="index.html"):
|
|
|
|
|
return static_file(filename, root=f"{getcwd()}/src")
|
|
|
|
|
|
|
|
|
|
@post("/changekey.html")
|
|
|
|
|
def post_changekey():
|
|
|
|
|
change = KeyChange()
|
|
|
|
|
change.uid = request.forms.get("username")
|
|
|
|
|
change.old_pw = request.forms.get("password")
|
|
|
|
@ -520,43 +401,20 @@ def metznet_webui(args):
|
|
|
|
|
pubkey_bytes.append(string)
|
|
|
|
|
change.pubkeys = pubkey_bytes
|
|
|
|
|
if changekey_account(change):
|
|
|
|
|
return WebPage(["<p>Success!</p>"]).html
|
|
|
|
|
return static_file("success.html", root=f"{getcwd()}/src")
|
|
|
|
|
else:
|
|
|
|
|
return WebPage(["<p>Fail :(</p>"]).html
|
|
|
|
|
|
|
|
|
|
@get("/changekey")
|
|
|
|
|
def changekey_form():
|
|
|
|
|
return WebPage([WebForm("/changekey",
|
|
|
|
|
"MetzNet<br>Key Change",
|
|
|
|
|
[
|
|
|
|
|
InputField("Username:", "username", "text"),
|
|
|
|
|
InputField("Password:", "password", "password"),
|
|
|
|
|
InputField("Public Keys:", "pubkeys", "file", "multiple")
|
|
|
|
|
],
|
|
|
|
|
"Change Keys")]).html
|
|
|
|
|
|
|
|
|
|
@post("/changepw")
|
|
|
|
|
def do_changepw():
|
|
|
|
|
return static_file("fail.html", root=f"{getcwd()}/src")
|
|
|
|
|
|
|
|
|
|
@post("/changepw.html")
|
|
|
|
|
def post_changepw():
|
|
|
|
|
change = PWChange()
|
|
|
|
|
change.uid = request.forms.get("username")
|
|
|
|
|
change.old_pw = request.forms.get("password")
|
|
|
|
|
change.new_pw = request.forms.get("new_password")
|
|
|
|
|
if changepw_account(change):
|
|
|
|
|
return WebPage(["<p>Success!</p>"]).html
|
|
|
|
|
return static_file("success.html", root=f"{getcwd()}/src")
|
|
|
|
|
else:
|
|
|
|
|
return WebPage(["<p>Fail :(</p>"]).html
|
|
|
|
|
|
|
|
|
|
@get("/changepw")
|
|
|
|
|
def changepw_form():
|
|
|
|
|
return WebPage([WebForm("/changepw",
|
|
|
|
|
"MetzNet<br>Password Change",
|
|
|
|
|
[
|
|
|
|
|
InputField("Username:", "username", "text"),
|
|
|
|
|
InputField("Password:", "password", "password"),
|
|
|
|
|
InputField("New Password:", "new_password", "password"),
|
|
|
|
|
],
|
|
|
|
|
"Change Password")]).html
|
|
|
|
|
|
|
|
|
|
return static_file("fail.html", root=f"{getcwd()}/src")
|
|
|
|
|
|
|
|
|
|
run(host='0.0.0.0', port=8024)
|
|
|
|
|
|
|
|
|
|