scripts/genstatusconf
Anthony Wang 4396f94dcc
Misc scripts fixes:
- Make genstatusconf ignore non-exozyme-hosted sites
- Fix shellcheck errors
- Format Python scripts with black
- Rewrite sysusers in bash to parse systemd-sysusers --tldr
2024-07-10 18:12:45 +00:00

52 lines
1.3 KiB
Python
Executable file

#!/usr/bin/env python
# Generate the status config based on the exozyme explore page
from re import search
from socket import getaddrinfo
from sys import argv
tld = "exozy.me"
ip = getaddrinfo(tld, 443)[0][4][0]
rules = {
"Status": None, # Make sure we don't include the status page itself!!
"PixivFE": "about",
"LiteXiv": "main.css",
"Priviblur": "priviblur/licences",
"Redlib": "info",
}
sites = []
with open("/srv/http/www/explore.html") as f:
for l in f.readlines():
m = search('<td><a href="https://(.*)">(.*)</a></td>', l)
if m is None:
continue
x = m.groups()
if not x[0].endswith(tld) and getaddrinfo(x[0], 443)[0][4][0] != ip:
continue
if x[1] in rules:
if rules[x[1]]:
sites.append((f"{x[0]}/{rules[x[1]]}", x[1]))
else:
sites.append(x)
newconf = []
with open(argv[1]) as f:
for l in f.readlines():
if "description = " not in l:
newconf.append(l)
if l == "service = [\n":
newconf += list(
map(
lambda x: f' {{ description = "{x[1]}", url = "https://{x[0]}" }},\n',
sites,
)
)
with open(argv[1], "w") as f:
f.write("".join(newconf))