X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/6b71895409837ee7ebea2a66f62d98dbee8b97e7..a40c6efee7b40e7ede9e39dcf84bc22e30a1e52f:/lib/easy_domain.dtl diff --git a/lib/easy_domain.dtl b/lib/easy_domain.dtl dissimilarity index 83% index aef0232..5335fbe 100644 --- a/lib/easy_domain.dtl +++ b/lib/easy_domain.dtl @@ -1,54 +1,133 @@ -{{The most common kinds of domain configuration}} - -val default_node : (node) = "mire"; -val web_node : (web_node) = "mire"; - -val webAt = - \ n : (web_node) -> - \ host : (host) -> - \\ config : Vhost -> - (dns (dnsA host (ip_of_node (web_node_to_node n))); - - vhost host where - WebNodes = [n] - with - config - end); - -val web = webAt web_node; - -val domNoDefaultAlias = - \ d : (your_domain) -> - \\ config : Domain -> - domain d with - dns (dnsNS "ns1.hcoop.net"); - dns (dnsNS "ns3.hcoop.net"); - - dns (dnsDefaultA (ip_of_node (web_node_to_node web_node))); - - handleMail; - dns (dnsMX 1 "deleuze.hcoop.net"); - - web "www" with - serverAliasDefault; - www : [Vhost] <- WWW; - www - end; - - config - end; - -val dom = - \ d : (your_domain) -> - \\ config : Domain -> - domNoDefaultAlias d with - config; - mailbox <- Mailbox; - defaultAlias mailbox; - end; - -val nameserver = \host -> dns (dnsNS host); -val dnsIP = \from -> \to -> dns (dnsA from to); -val dnsMail = \num -> \host -> dns (dnsMX num host); -val dnsAlias = \from -> \to -> dns (dnsCNAME from to); -val dnsDefault = \to -> dns (dnsDefaultA to); +{{The most common kinds of domain configuration}} + +val web_node : (web_node) = "shelob"; +val default_node : (node) = web_node_to_node web_node; +val web_ip = ip_of_node (web_node_to_node web_node); + +var WebPlaces = [web_place_default web_node]; + +val webAt = + \ n : (web_node) -> + \ host : (host) -> + \\ config : Vhost -> begin + dns (dnsA (literal host) (ip_of_node (web_node_to_node n))); + + vhost host where + WebPlaces = [web_place_default n] + with + config + end + end; + +val web = \ host -> \\ config : Vhost -> begin + n <- DefaultWebNode; + webAt n host with config end; +end; + +val webAtIp = + \ ip : (your_ip) -> + \ host : (host) -> + \\ config : Vhost -> begin + dns (dnsA (literal host) (your_ip_to_ip ip)); + + vhost host where + WebPlaces = [web_place web_node ip] + with + config + end + end; + +val webSsl = \ host -> \ certFile -> \\ config : Vhost -> begin + n <- DefaultWebNode; + webAt n host where + SSL = certFile; + with config end; + + force_ssl <- ForceSSL; + if force_ssl then + webAt n host where + SSL = no_ssl; + with + rewriteRule "^(.*)$" "https://%{HTTP_HOST}$1" [redirect]; + end; + else + webAt n host where + SSL = no_ssl; + with config end; + end; +end; + +val addDefaultAlias = begin + mailbox <- Mailbox; + source <- DefaultAliasSource; + aliasPrim source (addressTarget mailbox) +end; + +val addWww = begin + web "www" with + serverAliasDefault; + www : [Vhost] <- WWW; + www + end +end; + +val dom = + \ d : (your_domain) -> + \\ config : Domain -> + domain d with + dns (dnsNS "ns1.hcoop.net"); + dns (dnsNS "ns2.hcoop.net"); + + user_web_node <- DefaultWebNode; + + defa : bool <- DefaultA; + if defa then + dns (dnsA default (ip_of_node (web_node_to_node user_web_node))) + else + Skip + end; + + hmail : bool <- HandleMail; + if hmail then + handleMail + else + Skip + end; + + amx : bool <- AddMX; + if amx then + dns (dnsMX 1 "mail.hcoop.net"); + else + Skip + end; + + createWWW : bool <- CreateWWW; + if createWWW then + addWww + else + Skip + end; + + defAl : bool <- DefaultAlias; + if defAl then + addDefaultAlias + else + Skip + end; + + config +end; + +val nameserver = \host -> dns (dnsNS host); +val dnsIP = \from -> \to -> dns (dnsA (literal from) to); +val dnsIPv6 = \from -> \to -> dns (dnsAAAA (literal from) to); +val dnsMail = \num -> \host -> dns (dnsMX num host); +val dnsAlias = \from -> \to -> dns (dnsCNAME (literal from) to); +val dnsDefault = \to -> dns (dnsA default to); +val dnsDefaultv6 = \to -> dns (dnsAAAA default to); +val dnsText = \from -> \to -> dns (dnsTXT (srv_literal from) to); +val dnsDefaultText = \to -> dns (dnsTXT srv_default to); + +val dnsWildcardIP = \to -> dns (dnsA wildcard to); + +val addDefaultSPF = dnsDefaultText "v=spf1 mx -all";