Guide full-service installs and report installer progress

This commit is contained in:
parkel committed 2026-11-22 21:27:29 +01:00
1 parent e68e54288f
commit 23adbe7b2d
4 files changed
+327 -81

No files matched your search

+62 -9
View File
@@ -1,4 +1,5 @@
import hmac
import re
import secrets
import time
from dataclasses import dataclass, field
@@ -15,11 +16,14 @@ from .engine import Installer
COOKIE = "coulobre_installer"
MAX_FORM = 16384
FORM = """<form method="post" action="/review">
<p>Full-service setup is recommended for a public single server. The panel,
websites, databases, DNS and mail run locally. Adjust the settings below
for a different deployment.</p>
<fieldset><legend>Panel</legend>
<label>Hostname<input name="hostname" autocomplete="off" required></label>
<label>Access<select name="access">
<option value="tls">HTTPS on this server</option>
<option value="acme">HTTPS with Let's Encrypt</option>
<option value="tls">HTTPS on this server</option>
<option value="proxy">Trusted external HTTPS proxy</option></select></label>
<label>Panel certificate path<input name="certificate"></label>
<label>Panel private key path<input name="key"></label>
@@ -49,8 +53,9 @@ def role_form(name):
"<label>Public mail hostname"
'<input name="mail_local_host"></label>'
'<label>Mail TLS<select name="mail_tls">'
'<option value="acme">Let&#39;s Encrypt</option>'
'<option value="provided">Existing certificate</option>'
'<option value="acme">Let&#39;s Encrypt</option></select></label>'
"</select></label>"
"<label>Certificate path on the mail host"
'<input name="mail_certificate"></label>'
"<label>Private key path on the mail host"
@@ -59,8 +64,9 @@ def role_form(name):
else ""
)
return f"""<fieldset><legend>{title}</legend>
<label>Role<select name="{name}_mode"><option value="off">Disabled</option>
<label>Role<select name="{name}_mode">
<option value="local">Local service</option>
<option value="off">Disabled</option>
<option value="remote">Connect an existing Coulobre node</option>
<option value="remote-install">Install and connect a Coulobre node</option>
</select></label>
@@ -117,7 +123,9 @@ def form_plan(fields):
)
if name == "mail" and mode in {"local", "remote-install"}:
field = "host" if mode == "local" else "mail_hostname"
target[field] = fields.get("mail_local_host", "")
target[field] = fields.get("mail_local_host") or (
panel["hostname"] if mode == "local" else ""
)
target["tls"] = fields.get("mail_tls", "provided")
if target["tls"] == "provided":
target.update(
@@ -127,6 +135,30 @@ def form_plan(fields):
return parse_plan(data)
def installation_form(values):
html = FORM.format(dns=role_form("dns"), mail=role_form("mail"))
def restore_field(match):
tag = match[0]
name = match["input"] or match["select"]
if name not in values:
return tag
value = values[name]
if tag.startswith("<input"):
tag = re.sub(r' value="[^"]*"', "", tag)
return f'{tag[:-1]} value="{escape(value, quote=True)}">'
options = f'<option value="{escape(value, quote=True)}"'
return tag.replace(options + ">", options + " selected>")
return re.sub(
r'<input name="(?P<input>[a-z_]+)"[^>]*>|'
r'<select name="(?P<select>[a-z_]+)">.*?</select>',
restore_field,
html,
flags=re.DOTALL,
)
@dataclass
class Wizard:
password: str = field(repr=False)
@@ -135,12 +167,15 @@ class Wizard:
)
session: str = field(default="", repr=False)
pending: object = None
form_values: dict[str, str] = field(default_factory=dict, repr=False)
thread: Thread | None = None
progress: list[str] = field(default_factory=list)
progress_at: float | None = None
finished: float | None = None
error: str = ""
def report(self, text):
self.progress_at = time.monotonic()
self.progress.append(text)
print(text, flush=True)
@@ -229,19 +264,36 @@ class WizardHandler(BaseHTTPRequestHandler):
)
self.page(f"<ol>{steps}")
else:
self.page(f"<ol>{steps}</ol>", refresh=state.finished is None)
elapsed = ""
if state.finished is None and state.progress_at is not None:
seconds = int(time.monotonic() - state.progress_at)
elapsed = (
f'<p role="status">Working for {seconds}s '
"since the last update.</p>"
)
self.page(
f"<ol>{steps}</ol>{elapsed}",
refresh=state.finished is None,
)
elif state.pending is not None:
prerequisites = ""
if (
state.pending.access == "acme"
or state.pending.mail.tls == "acme"
):
prerequisites = (
"<p>Let's Encrypt requires public DNS and inbound HTTP "
"for each selected hostname.</p>"
)
self.page(
f"<p>{escape(state.pending.description())}</p>"
f"<p>{escape(state.pending.description())}</p>{prerequisites}"
'<form method="post" action="/install">'
'<button type="submit">Install Coulobre</button></form>'
'<form method="post" action="/edit">'
'<button type="submit">Change settings</button></form>'
)
else:
self.page(
FORM.format(dns=role_form("dns"), mail=role_form("mail"))
)
self.page(installation_form(state.form_values))
def fields(self):
try:
@@ -305,6 +357,7 @@ class WizardHandler(BaseHTTPRequestHandler):
if self.path == "/edit":
state.pending = None
elif self.path == "/review":
state.form_values = data
state.pending = form_plan(data)
elif self.path == "/install" and state.pending is not None:
state.thread = Thread(target=state.install)