yolo changes
This commit is contained in:
parent
38e8972b99
commit
6b67bd9d7b
|
|
@ -50,6 +50,6 @@ for msg in reversed(r.lrange(CHAT_NAME, 0, -1)):
|
||||||
delbtn = ""
|
delbtn = ""
|
||||||
if hswro.is_admin():
|
if hswro.is_admin():
|
||||||
delbtn = f"`B400`FAAA`!`[DEL`:/page/chat.mu`delete={m['id']}]`!"
|
delbtn = f"`B400`FAAA`!`[DEL`:/page/chat.mu`delete={m['id']}]`!"
|
||||||
print(f"{delbtn}`BCCC`F333{m['when']}`BAAA`F444{'<'+m['who']+'>':>16}`B333`FCCC{m['msg']}")
|
print(f"{delbtn}`BCCC`F333{m['when']}`BAAA`F444{'<'+m['who']+'>':>16}`B888`F000{m['msg']}")
|
||||||
hswro.reset_colors()
|
hswro.reset_colors()
|
||||||
hswro.footer()
|
hswro.footer()
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,18 @@ FORBIDDEN_INPUT = [
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MENU_ITEMS = [
|
||||||
|
("Home", "/page/index.mu]"),
|
||||||
|
("Status", "/page/status.mu"),
|
||||||
|
("Shoutbox", "/page/chat.mu]")
|
||||||
|
]
|
||||||
|
|
||||||
ADMIN_IDENTITIES = [
|
ADMIN_IDENTITIES = [
|
||||||
"e6c72573bb91d48338dbcc57d0223b81",
|
"e6c72573bb91d48338dbcc57d0223b81",
|
||||||
"70c9608c9a0f4ae895f7fab406554e1c"
|
"70c9608c9a0f4ae895f7fab406554e1c"
|
||||||
]
|
]
|
||||||
BGCOLOR = "`F333`BDDD"
|
BGCOLOR = "`F333`BDDD"
|
||||||
|
MENUBGCOLOR = "`FEEE`B333"
|
||||||
|
|
||||||
def is_admin() -> bool:
|
def is_admin() -> bool:
|
||||||
remote_identity = environ.get("remote_identity", None)
|
remote_identity = environ.get("remote_identity", None)
|
||||||
|
|
@ -81,36 +88,51 @@ def login_button() -> str:
|
||||||
else:
|
else:
|
||||||
return f"Welcome, {l[0]} | [`[Forget`:/page/logout.mu`]]"
|
return f"Welcome, {l[0]} | [`[Forget`:/page/logout.mu`]]"
|
||||||
|
|
||||||
|
def render_menu_item(active_title: Optional[str]) -> str:
|
||||||
|
def f(current: Tuple[str, str]) -> str:
|
||||||
|
current_title = current[0]
|
||||||
|
href = current[1]
|
||||||
|
retval = " "
|
||||||
|
if current_title == active_title:
|
||||||
|
retval += "`!"
|
||||||
|
retval += f"`[{current_title}`:{href}`]"
|
||||||
|
if current_title == active_title:
|
||||||
|
retval += "`!"
|
||||||
|
return retval + " "
|
||||||
|
return f
|
||||||
|
|
||||||
|
def render_menu(title: Optional[str] = None) -> str:
|
||||||
|
LEFT_MARGIN = 2
|
||||||
|
retval = "\n`l" + " "*LEFT_MARGIN
|
||||||
|
retval += "│".join(map(render_menu_item(title), MENU_ITEMS))
|
||||||
|
retval += "\n"
|
||||||
|
return retval
|
||||||
|
|
||||||
|
|
||||||
def header(title: Optional[str] = None):
|
def header(title: Optional[str] = None):
|
||||||
if title is None:
|
ftitle = ""
|
||||||
title = ""
|
if title is not None:
|
||||||
else:
|
ftitle = ": `i" + title
|
||||||
title = ": `i" + title
|
|
||||||
print(f"""`F000`BFB1
|
print(f"""`F000`BFB1
|
||||||
`c
|
`c
|
||||||
-*abc
|
|
||||||
`r {login_button()}
|
`r {login_button()}
|
||||||
`l `!Hackerspace`!Wrocław{title}
|
`l `!Hackerspace`!Wrocław{ftitle}
|
||||||
`a
|
`a
|
||||||
|
|
||||||
-_
|
|
||||||
`a
|
`a
|
||||||
``
|
``
|
||||||
`FEEE`B333
|
{MENUBGCOLOR}
|
||||||
`c
|
`c
|
||||||
|
{render_menu(title)}
|
||||||
`l `[Home`:/page/index.mu]` | `[Status`:/page/status.mu]` | `[Shoutbox`:/page/chat.mu]`
|
{BGCOLOR}""")
|
||||||
|
|
||||||
`a
|
|
||||||
``
|
|
||||||
{BGCOLOR}
|
|
||||||
""")
|
|
||||||
|
|
||||||
def reset_colors() -> str:
|
def reset_colors() -> str:
|
||||||
print(BGCOLOR)
|
print(BGCOLOR)
|
||||||
|
|
||||||
def footer():
|
def footer():
|
||||||
print(f"{BGCOLOR}`r Rendered in: {(datetime.now()-s).total_seconds()}s")
|
print(f"\n{BGCOLOR}`r Rendered in: {(datetime.now()-s).total_seconds()}s")
|
||||||
print(f"{datetime.now()}")
|
print(f"{datetime.now()}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
import hswro
|
import hswro
|
||||||
|
|
||||||
hswro.header()
|
hswro.header("Home")
|
||||||
print("Nothing to see here... yet")
|
print("Nothing to see here... yet")
|
||||||
hswro.footer()
|
hswro.footer()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import hswro
|
||||||
|
import os
|
||||||
|
from pathlib import PurePosixPath
|
||||||
|
from typing import List
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
LIBRARY_DIR = "/home/reticulum/library"
|
||||||
|
|
||||||
|
library_contents = [""]
|
||||||
|
|
||||||
|
|
||||||
|
def get_from_list(l: List[str], i: int) -> str:
|
||||||
|
try:
|
||||||
|
return l[i]
|
||||||
|
except IndexError:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
with os.scandir(LIBRARY_DIR) as it:
|
||||||
|
for entry in it:
|
||||||
|
if not entry.name.startswith('.') and entry.is_file():
|
||||||
|
library_contents.append(PurePosixPath(entry.path).stem)
|
||||||
|
|
||||||
|
content_lines = ["", "Select a file to begin reading."]
|
||||||
|
|
||||||
|
if "var_view" in environ:
|
||||||
|
document_name = environ["var_view"]
|
||||||
|
if len(document_name) > 20:
|
||||||
|
raise ValueError("Document name is too long, rejecting")
|
||||||
|
if not all(map(lambda c: c.isalnum(), document_name)):
|
||||||
|
raise ValueError("Document name contains not allowed characters, rejecting")
|
||||||
|
content_lines = []
|
||||||
|
with open(f"{LIBRARY_DIR}/{document_name}.txt") as file:
|
||||||
|
content_lines = [line.rstrip() for line in file]
|
||||||
|
|
||||||
|
page_len = max(len(library_contents), len(content_lines)) + 2
|
||||||
|
|
||||||
|
hswro.header("Library")
|
||||||
|
for i in range(page_len):
|
||||||
|
menuitem = " "*23
|
||||||
|
item_name = get_from_list(library_contents, i)
|
||||||
|
if item_name != "":
|
||||||
|
menuitem = f" `[{item_name:<20}`:/page/library.mu`view={item_name}] "
|
||||||
|
content = get_from_list(content_lines, i)
|
||||||
|
print(f"{hswro.MENUBGCOLOR}{menuitem}{hswro.BGCOLOR} {content}")
|
||||||
|
print("-.")
|
||||||
|
hswro.footer()
|
||||||
|
|
@ -4,10 +4,10 @@ import hswro
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
def login_form():
|
def login_form():
|
||||||
print("`c `!Login:`")
|
print(" `!Login:`")
|
||||||
print("Username: `<16|username`>")
|
print(f" Username: `BFFF`F000`<16|username`>{hswro.BGCOLOR}")
|
||||||
print("Password: `<!16|pass`>")
|
print(f" Password: `BFFF`F000`<!16|pass`>{hswro.BGCOLOR}")
|
||||||
print("[`[Submit`:/page/login.mu`*]]")
|
print(" [`[Submit`:/page/login.mu`*]]")
|
||||||
|
|
||||||
l = hswro.get_login_info()
|
l = hswro.get_login_info()
|
||||||
form_login = environ.get('field_username', None)
|
form_login = environ.get('field_username', None)
|
||||||
|
|
@ -26,6 +26,5 @@ if l[0] is None:
|
||||||
login_form()
|
login_form()
|
||||||
else:
|
else:
|
||||||
print(f"Welcome, {l[0]}.")
|
print(f"Welcome, {l[0]}.")
|
||||||
#print("`l\n\n\n\n\n")
|
|
||||||
#print(environ)
|
|
||||||
hswro.footer()
|
hswro.footer()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import subprocess
|
||||||
import json
|
import json
|
||||||
import hswro
|
import hswro
|
||||||
|
|
||||||
|
UNIT_STATUS_ALLOWED_LINES = ["Active:", "Tasks:", "Memory:", "CPU:"]
|
||||||
|
|
||||||
def sizeof_fmt(num, suffix="B"):
|
def sizeof_fmt(num, suffix="B"):
|
||||||
for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"):
|
for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"):
|
||||||
if abs(num) < 1024.0:
|
if abs(num) < 1024.0:
|
||||||
|
|
@ -13,16 +15,38 @@ def sizeof_fmt(num, suffix="B"):
|
||||||
num /= 1024.0
|
num /= 1024.0
|
||||||
return f"{num:.1f}Yi{suffix}"
|
return f"{num:.1f}Yi{suffix}"
|
||||||
|
|
||||||
|
def systemd_unit_status(unit_name: str):
|
||||||
|
unit_status_raw = subprocess.run(["systemctl", "status", unit_name], capture_output=True)
|
||||||
|
for allowed in UNIT_STATUS_ALLOWED_LINES:
|
||||||
|
for line in unit_status_raw.stdout.splitlines():
|
||||||
|
line = line.decode('utf-8')
|
||||||
|
if allowed in line:
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
def get_temp():
|
||||||
|
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
|
||||||
|
t = f.read()
|
||||||
|
t = float(t) / 1000
|
||||||
|
print(f" CPU Temp: {t:.1f}°C")
|
||||||
|
|
||||||
status_raw = subprocess.run(["/home/reticulum/venv/bin/rnstatus", "-j"], capture_output=True)
|
status_raw = subprocess.run(["/home/reticulum/venv/bin/rnstatus", "-j"], capture_output=True)
|
||||||
status = json.loads(status_raw.stdout)
|
status = json.loads(status_raw.stdout)
|
||||||
|
|
||||||
hswro.header("Node Status")
|
hswro.header("Status")
|
||||||
|
|
||||||
|
get_temp()
|
||||||
|
print(subprocess.run(["uptime"], capture_output=True).stdout.decode('utf-8'))
|
||||||
|
print("> Service status")
|
||||||
|
print(">> rnst status")
|
||||||
|
systemd_unit_status("rnsd")
|
||||||
|
print(">> nomadnet status")
|
||||||
|
systemd_unit_status("nomadnet")
|
||||||
|
|
||||||
print("> Interfaces")
|
print("> Interfaces")
|
||||||
|
|
||||||
for i in status['interfaces']:
|
for i in status['interfaces']:
|
||||||
print(">> ", i['short_name'])
|
print(">> ", i['short_name'])
|
||||||
print("`!Clients:`! ", i['clients'])
|
print("`!Clients:`! ", i['clients'])
|
||||||
print("`!Current RX:`! ", i['rxs'])
|
print("`!Current RX:`! ", i['rxs'])
|
||||||
print("`!Current TX:`! ", i['txs'])
|
print("`!Current TX:`! ", i['txs'])
|
||||||
print("`!Total RX:`! ", sizeof_fmt(i['rxb']))
|
print("`!Total RX:`! ", sizeof_fmt(i['rxb']))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue