poudriere’s local web UI

The html is under /usr/local/share/poudriere/html directory.

If you point a browser at this directory it does not load because privacy.file_unique_origin treats every file:// document as its own origin, so the page’s fetch of /data/…/.data.json is blocked.

The privacy.file_unique_origin feature: it was added in Firefox 68 to improve local file security and prevent data theft but consequently dropped in Firefox 95 because it posed a major security risk.

Save the following script as poudriere-web.py and run it with python3 poudriere-web.py

#!/usr/bin/env python3
"""Poudriere local web UI"""
import functools
import http.server
import os
import re
import sys
CONF = "/usr/local/etc/poudriere.conf"
HTML = "/usr/local/share/poudriere/html"
ROOT = os.path.expanduser("~/.cache/poudriere-web")
PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8088
def basefs(path=CONF, default="/usr/local/poudriere"):
"""BASEFS is configurable, so read it rather than hardcoding it."""
try:
with open(path) as conf:
for line in conf:
match = re.match(r'\s*BASEFS=["\']?([^"\'#\s]+)', line)
if match:
return match.group(1)
except OSError:
pass
return default
class Handler(http.server.SimpleHTTPRequestHandler):
# .log is in no standard MIME table, so it would be served as
# application/octet-stream and the browser would download build logs
# instead of displaying them.
extensions_map = {
**http.server.SimpleHTTPRequestHandler.extensions_map,
".log": "text/plain",
}
def link(target, name):
path = os.path.join(ROOT, name)
if not os.path.lexists(path):
os.symlink(target, path)
logs = os.path.join(basefs(), "data", "logs", "bulk")
for required in (HTML, logs):
if not os.path.isdir(required):
sys.exit(f"{required} does not exist -- is poudriere installed and has a build run?")
os.makedirs(ROOT, exist_ok=True)
for entry in os.listdir(HTML):
link(os.path.join(HTML, entry), entry)
link(logs, "data")
print(f"serving {HTML}\n and {logs}\n at http://127.0.0.1:{PORT}/")
http.server.test(
HandlerClass=functools.partial(Handler, directory=ROOT),
bind="127.0.0.1",
port=PORT,
)

Leave a comment

Discover more from /root

Subscribe now to keep reading and get access to the full archive.

Continue reading