import hmac import re import secrets import time from dataclasses import dataclass, field from html import escape from http.cookies import CookieError, SimpleCookie from http.server import BaseHTTPRequestHandler, HTTPServer from threading import Thread from urllib.parse import parse_qs from .cli import comma_separated, number from .config import REMOTE_MODES, InstallError, parse_plan, port from .engine import Installer COOKIE = "coulobre_installer" MAX_FORM = 16384 FORM = """

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.

Panel
Administrator
{dns}{mail}
New hosting accounts

Separate multiple values with commas. You can also set these later.

""" STYLE = """body{font:1rem system-ui,sans-serif;max-width:46rem;margin:auto; padding:1rem;color:#14372e} fieldset{margin:1rem 0;border:1px solid #a9beb2; border-radius:.4rem;padding:1rem} label{display:block;margin-bottom:.75rem} input,select{display:block;box-sizing:border-box;width:100%;padding:.45rem; margin-top:.25rem} button{background:#195a46;color:white;border:0; border-radius:.3rem;padding:.75rem 1.1rem;font:inherit} summary{cursor:pointer} :focus-visible{outline:3px solid #20875d;outline-offset:2px} [role=alert]{color:#8c2828}""" def role_form(name): title = name.upper() if name == "dns" else "Mail" local = ( "' '" "' "' if name == "mail" else "" ) return f"""
{title} {local}
Separate node settings
""" def form_plan(fields): access = fields.get("access", "") panel = {"hostname": fields.get("hostname", ""), "access": access} if access == "tls": panel.update( certificate=fields.get("certificate", ""), key=fields.get("key", ""), ) elif access == "proxy": panel.update( origin_ip=fields.get("origin_ip", ""), proxy_ip=fields.get("proxy_ip", ""), origin_port=number( fields.get("origin_port") or "8080", "the origin" ), ) data = { "panel": panel, "hosting": { name: comma_separated(fields.get(name, "")) for name in ( "public_addresses", "nameservers", "mail_sending_addresses", ) }, "admin": { "username": fields.get("username", ""), "email": fields.get("email", ""), }, } for name in ("dns", "mail"): mode = fields.get(f"{name}_mode", "off") target = data[name] = {"mode": mode} if mode in REMOTE_MODES: target.update( host=fields.get(f"{name}_host", ""), host_key=fields.get(f"{name}_host_key", ""), port=number( fields.get(f"{name}_port") or "22", f"the {name} node" ), ) if mode == "remote-install": target.update( ssh_user=fields.get(f"{name}_ssh_user", ""), ssh_identity=fields.get(f"{name}_ssh_identity", ""), ) if name == "mail" and mode in {"local", "remote-install"}: field = "host" if mode == "local" else "mail_hostname" 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( certificate=fields.get("mail_certificate", ""), key=fields.get("mail_key", ""), ) 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("' options = f'