Give empty hosted websites a branded starter page
This commit is contained in:
1 parent
b2cfb25f7b
commit
84173c67d3
4 files changed
+168
-12
No files matched your search
@@ -0,0 +1,89 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<title>This website is coming soon · __COULOBRE_HOSTNAME__</title>
|
||||
<style>
|
||||
:root {
|
||||
color-scheme: light dark;
|
||||
--text: #172f28;
|
||||
--muted: #38564b;
|
||||
--accent: #205943;
|
||||
--canvas: #edf4ef;
|
||||
--paper: #fcfffc;
|
||||
--line: #c9dbce;
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--text: #edf7f0;
|
||||
--muted: #c0d5c9;
|
||||
--accent: #b6e2c9;
|
||||
--canvas: #12241d;
|
||||
--paper: #1b3127;
|
||||
--line: #4a6557;
|
||||
}
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
min-height: 100vh;
|
||||
min-height: 100svh;
|
||||
margin: 0;
|
||||
padding: clamp(1rem, 5vw, 3rem);
|
||||
background: var(--canvas);
|
||||
color: var(--text);
|
||||
font: 1rem/1.6 system-ui, sans-serif;
|
||||
}
|
||||
main {
|
||||
width: min(100%, 38rem);
|
||||
padding: clamp(1.5rem, 6vw, 3.75rem);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 1.25rem;
|
||||
background: var(--paper);
|
||||
}
|
||||
.domain {
|
||||
margin: 0 0 .75rem;
|
||||
color: var(--accent);
|
||||
font-weight: 650;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
h1 {
|
||||
margin: 0;
|
||||
font-size: clamp(1.85rem, 7vw, 3rem);
|
||||
line-height: 1.12;
|
||||
letter-spacing: -.035em;
|
||||
}
|
||||
p { margin: 1rem 0 0; color: var(--muted); }
|
||||
footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: .55rem;
|
||||
margin-top: 2rem;
|
||||
padding-top: 1rem;
|
||||
border-top: 1px solid var(--line);
|
||||
color: var(--muted);
|
||||
font-size: .875rem;
|
||||
}
|
||||
footer svg { flex: none; color: var(--accent); }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<p class="domain">__COULOBRE_HOSTNAME__</p>
|
||||
<h1>This website is coming soon</h1>
|
||||
<p>Hosting is set up. The site owner hasn’t published the website yet.</p>
|
||||
<footer>
|
||||
<svg aria-hidden="true" focusable="false" width="22" height="22" viewBox="-12 -12 312 312">
|
||||
<path d="M0 199 V132 C0 104 27 89 61 78 L217 36 C245 28 263 19 263 0 C272 1 279 11 279 21 V73 C279 91 267 101 244 108 L48 169 C24 177 8 186 0 199 Z" fill="currentColor"/>
|
||||
<path d="M208 124 C246 136 288 151 288 178 V239 C277 221 246 211 208 202 Z" fill="currentColor"/>
|
||||
<path d="M46 175 L218 211 C259 220 280 233 286 246 C294 266 269 288 228 288 C217 288 207 287 195 284 L45 249 C16 242 0 227 0 212 C0 197 18 185 46 175 Z" fill="currentColor"/>
|
||||
</svg>
|
||||
<span>Hosted with Coulobre Panel</span>
|
||||
</footer>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,7 +3,13 @@ from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from unittest import TestCase
|
||||
|
||||
from .web_node_apply import STARTER_PAGE, install_starter_page
|
||||
from .web_node_apply import (
|
||||
LEGACY_STARTER_PAGE,
|
||||
STARTER_PAGE,
|
||||
install_starter_page,
|
||||
render_starter_page,
|
||||
)
|
||||
from .wordpress_node import check_install_target
|
||||
|
||||
|
||||
class WebsiteStarterTests(TestCase):
|
||||
@@ -14,12 +20,16 @@ class WebsiteStarterTests(TestCase):
|
||||
self.index = self.public / "index.html"
|
||||
|
||||
def install(self):
|
||||
install_starter_page(self.public, os.getuid(), os.getgid())
|
||||
install_starter_page(
|
||||
self.public, os.getuid(), os.getgid(), "site.example"
|
||||
)
|
||||
|
||||
def test_empty_root_gets_a_neutral_page_only_once(self):
|
||||
self.install()
|
||||
self.assertEqual(self.index.read_text(), STARTER_PAGE)
|
||||
self.assertIn('name="robots" content="noindex"', STARTER_PAGE)
|
||||
page = self.index.read_text()
|
||||
self.assertEqual(page, render_starter_page("site.example"))
|
||||
self.assertIn("site.example", page)
|
||||
self.assertIn('name="robots" content="noindex"', page)
|
||||
self.assertEqual(self.index.stat().st_mode & 0o777, 0o644)
|
||||
self.index.write_text("Published customer site")
|
||||
self.install()
|
||||
@@ -45,3 +55,16 @@ class WebsiteStarterTests(TestCase):
|
||||
with self.assertRaises(OSError):
|
||||
self.install()
|
||||
self.assertFalse((actual / "index.html").exists())
|
||||
|
||||
def test_wordpress_accepts_only_unchanged_starter_pages(self):
|
||||
for starter in (
|
||||
LEGACY_STARTER_PAGE,
|
||||
STARTER_PAGE,
|
||||
render_starter_page("host.example.test"),
|
||||
):
|
||||
with self.subTest(starter=starter[:60]):
|
||||
self.index.write_text(starter)
|
||||
check_install_target(self.public)
|
||||
self.index.write_text(starter + " ")
|
||||
with self.assertRaisesRegex(ValueError, "original.*starter"):
|
||||
check_install_target(self.public)
|
||||
@@ -3,14 +3,18 @@ import grp
|
||||
import json
|
||||
import os
|
||||
import pwd
|
||||
import re
|
||||
import socket
|
||||
import stat
|
||||
import subprocess
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from functools import cache
|
||||
from html import escape
|
||||
from pathlib import Path
|
||||
|
||||
from .domain_names import canonical_domain
|
||||
from .node_files import (
|
||||
check_root_file,
|
||||
read_root_file,
|
||||
@@ -48,6 +52,46 @@ STARTER_PAGE = (
|
||||
)
|
||||
|
||||
|
||||
STARTER_TEMPLATE = (
|
||||
Path(__file__).parent / "hosting/templates/hosting/website_starter.html"
|
||||
)
|
||||
STARTER_HOST = re.compile(rb'<p class="domain">([a-z0-9.-]{1,253})</p>')
|
||||
|
||||
|
||||
@cache
|
||||
def starter_page_template():
|
||||
return STARTER_TEMPLATE.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def render_starter_page(hostname):
|
||||
return starter_page_template().replace(
|
||||
"__COULOBRE_HOSTNAME__", escape(canonical_domain(hostname))
|
||||
)
|
||||
|
||||
|
||||
def starter_page_matches(page):
|
||||
if page in (STARTER_PAGE.encode(), LEGACY_STARTER_PAGE.encode()):
|
||||
return True
|
||||
if match := STARTER_HOST.search(page):
|
||||
try:
|
||||
expected = render_starter_page(match[1].decode("ascii"))
|
||||
except ValueError:
|
||||
return False
|
||||
return page == expected.encode()
|
||||
return False
|
||||
|
||||
|
||||
def starter_page_read_limit():
|
||||
return (
|
||||
max(
|
||||
len(STARTER_PAGE.encode()),
|
||||
len(LEGACY_STARTER_PAGE.encode()),
|
||||
len(starter_page_template().encode()) + 2 * 253,
|
||||
)
|
||||
+ 1
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SitePaths:
|
||||
account: Path
|
||||
@@ -182,20 +226,21 @@ def install_site(site, *, php_settings=None, allowed=(), starter_page=False):
|
||||
document_root = paths.account / "public"
|
||||
ensure_public_directory(document_root, uid, web_gid)
|
||||
if starter_page:
|
||||
install_starter_page(document_root, uid, web_gid)
|
||||
install_starter_page(document_root, uid, web_gid, site.domain)
|
||||
if create_route:
|
||||
paths.route.symlink_to(paths.socket)
|
||||
applied = install_configurations(site, paths, php_settings=php_settings)
|
||||
return applied, paths.runtime.version
|
||||
|
||||
|
||||
def install_starter_page(document_root, uid, gid):
|
||||
def install_starter_page(document_root, uid, gid, hostname):
|
||||
directory = os.open(
|
||||
document_root, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW
|
||||
)
|
||||
try:
|
||||
if os.listdir(directory):
|
||||
return
|
||||
content = render_starter_page(hostname)
|
||||
try:
|
||||
file = os.open(
|
||||
"index.html",
|
||||
@@ -206,7 +251,7 @@ def install_starter_page(document_root, uid, gid):
|
||||
except FileExistsError:
|
||||
return
|
||||
with os.fdopen(file, "w", encoding="utf-8") as page:
|
||||
page.write(STARTER_PAGE)
|
||||
page.write(content)
|
||||
page.flush()
|
||||
os.fchown(page.fileno(), uid, gid)
|
||||
os.fchmod(page.fileno(), 0o644)
|
||||
|
||||
@@ -147,12 +147,11 @@ def is_starter_page(index):
|
||||
)
|
||||
except OSError:
|
||||
return False
|
||||
expected = (web.STARTER_PAGE.encode(), web.LEGACY_STARTER_PAGE.encode())
|
||||
with os.fdopen(descriptor, "rb") as page:
|
||||
return (
|
||||
stat.S_ISREG(os.fstat(page.fileno()).st_mode)
|
||||
and page.read(max(map(len, expected)) + 1) in expected
|
||||
)
|
||||
if not stat.S_ISREG(os.fstat(page.fileno()).st_mode):
|
||||
return False
|
||||
contents = page.read(web.starter_page_read_limit())
|
||||
return web.starter_page_matches(contents)
|
||||
|
||||
|
||||
def check_install_target(public):
|
||||
|
||||
Reference in new issue
Block a user