__COULOBRE_HOSTNAME__
+This website is coming soon
+Hosting is set up. The site owner hasn’t published the website yet.
+ +diff --git a/src/coulobre/hosting/templates/hosting/website_starter.html b/src/coulobre/hosting/templates/hosting/website_starter.html new file mode 100644 index 0000000..e4a8692 --- /dev/null +++ b/src/coulobre/hosting/templates/hosting/website_starter.html @@ -0,0 +1,89 @@ + + +
+ + + + +__COULOBRE_HOSTNAME__
+Hosting is set up. The site owner hasn’t published the website yet.
+ +([a-z0-9.-]{1,253})
') + + +@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) diff --git a/src/coulobre/wordpress_node.py b/src/coulobre/wordpress_node.py index ee759d8..28c7e98 100644 --- a/src/coulobre/wordpress_node.py +++ b/src/coulobre/wordpress_node.py @@ -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):