feature: the name server's domains have wan.local_fqdn and dns.secondary as their name servers, and a site with dns router gets records of the router's public, internal or external address.
Release / release (push) Successful in 35s

This commit is contained in:
slawek committed 2026-11-06 19:06:48 +01:00
1 parent c2c33cfca0
commit 7f85a1a2e5
16 files changed
+497 -304

No files matched your search

@@ -3,7 +3,9 @@
SELECT pg_advisory_xact_lock(hashtext('vpn-router sites schema'));
-- A static web site: its host names, port, interfaces and TLS, and the group whose members change its files.
-- A static web site: its host names, port, interfaces and TLS, the group whose members change its files, and its
-- DNS: user, the router serves no records of its host names, or router, its name server serves A or AAAA records of
-- them with the router's public, internal or external address (dns_address).
CREATE TABLE IF NOT EXISTS sites (
name text PRIMARY KEY,
enabled boolean NOT NULL,
@@ -19,44 +21,60 @@ CREATE TABLE IF NOT EXISTS sites (
editors text NOT NULL,
modified timestamptz NOT NULL
);
ALTER TABLE sites ADD COLUMN IF NOT EXISTS dns text NOT NULL DEFAULT 'user' CHECK (dns IN ('user', 'router'));
ALTER TABLE sites ADD COLUMN IF NOT EXISTS dns_address text NOT NULL DEFAULT 'public'
CHECK (dns_address IN ('public', 'internal', 'external'));
-- The functions whose columns and the procedure whose arguments changed with dns and dns_address.
DROP FUNCTION IF EXISTS sites_list();
DROP FUNCTION IF EXISTS site_get(text);
DROP FUNCTION IF EXISTS sites_served();
DROP PROCEDURE IF EXISTS site_put(text, boolean, text[], integer, text, text, text, text, text, text, boolean, text);
-- Every site, by name; the private key is left out.
CREATE OR REPLACE FUNCTION sites_list()
CREATE FUNCTION sites_list()
RETURNS TABLE (name text, enabled boolean, hosts text[], port integer, listen text, tls text, ca text,
certificate text, index_file text, spa boolean, editors text, modified timestamptz)
certificate text, index_file text, spa boolean, editors text, dns text, dns_address text,
modified timestamptz)
LANGUAGE sql STABLE AS $$
SELECT name, enabled, hosts, port, listen, tls, ca, certificate, index_file, spa, editors, modified
SELECT name, enabled, hosts, port, listen, tls, ca, certificate, index_file, spa, editors, dns, dns_address, modified
FROM sites ORDER BY name;
$$;
-- The site with its private key.
CREATE OR REPLACE FUNCTION site_get(p_name text)
CREATE FUNCTION site_get(p_name text)
RETURNS TABLE (name text, enabled boolean, hosts text[], port integer, listen text, tls text, ca text,
certificate text, private_key text, index_file text, spa boolean, editors text, modified timestamptz)
certificate text, private_key text, index_file text, spa boolean, editors text, dns text,
dns_address text, modified timestamptz)
LANGUAGE sql STABLE AS $$
SELECT name, enabled, hosts, port, listen, tls, ca, certificate, private_key, index_file, spa, editors, modified
SELECT name, enabled, hosts, port, listen, tls, ca, certificate, private_key, index_file, spa, editors, dns,
dns_address, modified
FROM sites WHERE name = p_name;
$$;
-- The enabled sites with their private keys, by name, for Caddy's configuration and certificate files.
CREATE OR REPLACE FUNCTION sites_served()
CREATE FUNCTION sites_served()
RETURNS TABLE (name text, enabled boolean, hosts text[], port integer, listen text, tls text, ca text,
certificate text, private_key text, index_file text, spa boolean, editors text, modified timestamptz)
certificate text, private_key text, index_file text, spa boolean, editors text, dns text,
dns_address text, modified timestamptz)
LANGUAGE sql STABLE AS $$
SELECT name, enabled, hosts, port, listen, tls, ca, certificate, private_key, index_file, spa, editors, modified
SELECT name, enabled, hosts, port, listen, tls, ca, certificate, private_key, index_file, spa, editors, dns,
dns_address, modified
FROM sites WHERE enabled ORDER BY name;
$$;
-- Add the site, or replace all its settings.
CREATE OR REPLACE PROCEDURE site_put(p_name text, p_enabled boolean, p_hosts text[], p_port integer, p_listen text,
p_tls text, p_ca text, p_certificate text, p_private_key text, p_index_file text,
p_spa boolean, p_editors text)
CREATE PROCEDURE site_put(p_name text, p_enabled boolean, p_hosts text[], p_port integer, p_listen text, p_tls text,
p_ca text, p_certificate text, p_private_key text, p_index_file text, p_spa boolean,
p_editors text, p_dns text, p_dns_address text)
LANGUAGE sql AS $$
INSERT INTO sites VALUES (p_name, p_enabled, p_hosts, p_port, p_listen, p_tls, p_ca, p_certificate, p_private_key,
p_index_file, p_spa, p_editors, now())
INSERT INTO sites (name, enabled, hosts, port, listen, tls, ca, certificate, private_key, index_file, spa, editors,
dns, dns_address, modified)
VALUES (p_name, p_enabled, p_hosts, p_port, p_listen, p_tls, p_ca, p_certificate, p_private_key, p_index_file,
p_spa, p_editors, p_dns, p_dns_address, now())
ON CONFLICT (name) DO UPDATE SET enabled = p_enabled, hosts = p_hosts, port = p_port, listen = p_listen,
tls = p_tls, ca = p_ca, certificate = p_certificate, private_key = p_private_key, index_file = p_index_file,
spa = p_spa, editors = p_editors, modified = now();
spa = p_spa, editors = p_editors, dns = p_dns, dns_address = p_dns_address, modified = now();
$$;
CREATE OR REPLACE PROCEDURE site_remove(p_name text)