easy_domain: fix argument
[hcoop/domtool2.git] / lib / easy_domain.dtl
1 {{The most common kinds of domain configuration}}
2
3 val web_node : (web_node) = "shelob";
4 val default_node : (node) = web_node_to_node web_node;
5 val web_ip = ip_of_node (web_node_to_node web_node);
6 val web_ipv6 = ipv6_of_node (web_node_to_node web_node);
7
8 var WebPlaces = [web_place_default web_node];
9
10 val webAt =
11 \ n : (web_node) ->
12 \ host : (host) ->
13 \\ config : Vhost -> begin
14 dns (dnsA (literal host) (ip_of_node (web_node_to_node n)));
15 dns (dnsAAAA (literal host) (ipv6_of_node (web_node_to_node n)));
16
17 vhost host where
18 WebPlaces = [web_place_default n]
19 with
20 config
21 end
22 end;
23
24 val web = \ host -> \\ config : Vhost -> begin
25 n <- DefaultWebNode;
26 webAt n host with config end;
27 end;
28
29 val webAtIp =
30 \ ip : (your_ip) ->
31 \ ipv6 : (your_ipv6) ->
32 \ host : (host) ->
33 \\ config : Vhost -> begin
34 dns (dnsA (literal host) (your_ip_to_ip ip));
35 dns (dnsAAAA (literal host) (your_ipv6_to_ipv6 ipv6));
36
37 vhost host where
38 WebPlaces = [web_place web_node ip ipv6]
39 with
40 config
41 end
42 end;
43
44 val webSsl = \ host -> \ certFile -> \\ config : Vhost -> begin
45 n <- DefaultWebNode;
46 webAt n host where
47 SSL = certFile;
48 with config end;
49
50 force_ssl <- ForceSSL;
51 if force_ssl then
52 webAt n host where
53 SSL = no_ssl;
54 with
55 rewriteRule "^(.*)$" "https://%{HTTP_HOST}$1" [redirect];
56 end;
57 else
58 webAt n host where
59 SSL = no_ssl;
60 with config end;
61 end;
62 end;
63
64 val addDefaultAlias = begin
65 mailbox <- Mailbox;
66 source <- DefaultAliasSource;
67 aliasPrim source (addressTarget mailbox)
68 end;
69
70 val addWww = begin
71 web "www" with
72 serverAliasDefault;
73 www : [Vhost] <- WWW;
74 www
75 end
76 end;
77
78 val dom =
79 \ d : (your_domain) ->
80 \\ config : Domain ->
81 domain d with
82 dns (dnsNS "ns1.hcoop.net");
83 dns (dnsNS "ns2.hcoop.net");
84
85 user_web_node <- DefaultWebNode;
86
87 defa : bool <- DefaultA;
88 if defa then
89 dns (dnsA default (ip_of_node (web_node_to_node user_web_node)));
90 dns (dnsAAAA default (ipv6_of_node (web_node_to_node user_web_node)))
91 else
92 Skip
93 end;
94
95 hmail : bool <- HandleMail;
96 if hmail then
97 handleMail
98 else
99 Skip
100 end;
101
102 amx : bool <- AddMX;
103 if amx then
104 dns (dnsMX 1 "mail.hcoop.net");
105 else
106 Skip
107 end;
108
109 createWWW : bool <- CreateWWW;
110 if createWWW then
111 addWww
112 else
113 Skip
114 end;
115
116 defAl : bool <- DefaultAlias;
117 if defAl then
118 addDefaultAlias
119 else
120 Skip
121 end;
122
123 config
124 end;
125
126 val nameserver = \host -> dns (dnsNS host);
127 val dnsIP = \from -> \to -> dns (dnsA (literal from) to);
128 val dnsIPv6 = \from -> \to -> dns (dnsAAAA (literal from) to);
129 val dnsMail = \num -> \host -> dns (dnsMX num host);
130 val dnsAlias = \from -> \to -> dns (dnsCNAME (literal from) to);
131 val dnsDefault = \to -> dns (dnsA default to);
132 val dnsDefaultv6 = \to -> dns (dnsAAAA default to);
133 val dnsText = \from -> \to -> dns (dnsTXT (srv_literal from) to);
134 val dnsDefaultText = \to -> dns (dnsTXT srv_default to);
135
136 val dnsWildcardIP = \to -> dns (dnsA wildcard to);
137
138 val addDefaultSPF = dnsDefaultText "v=spf1 mx -all";