dns.scm
1 | ;;; Tyreunom's system administration and configuration tools. |
2 | ;;; |
3 | ;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu> |
4 | ;;; |
5 | ;;; This program is free software: you can redistribute it and/or modify |
6 | ;;; it under the terms of the GNU General Public License as published by |
7 | ;;; the Free Software Foundation, either version 3 of the License, or |
8 | ;;; (at your option) any later version. |
9 | ;;; |
10 | ;;; This program is distributed in the hope that it will be useful, |
11 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | ;;; GNU General Public License for more details. |
14 | ;;; |
15 | ;;; You should have received a copy of the GNU General Public License |
16 | ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | ;; |
19 | ;; DNS services |
20 | ;; |
21 | |
22 | (define-module (config dns) |
23 | #:use-module (data dns) |
24 | #:use-module (gnu services) |
25 | #:use-module (gnu services dns) |
26 | #:use-module (srfi srfi-1) |
27 | #:use-module (ice-9 textual-ports) |
28 | #:export (ipv4-reverse-master-zone |
29 | ipv6-reverse-master-zone |
30 | lepiller-master-zone |
31 | lepiller-slave-zone |
32 | master-acl |
33 | slave-acl |
34 | hermes |
35 | ene)) |
36 | |
37 | (define public-dkim |
38 | (apply |
39 | string-append |
40 | (string-split |
41 | (call-with-input-file "/etc/mail/dkim/public.key" get-string-all) |
42 | #\newline))) |
43 | |
44 | (define-zone-entries lepiller.eu.zone |
45 | ;; Name TTL Class Type Data |
46 | ("ene" "" "IN" "A" ene-ip4) |
47 | ("hermes" "" "IN" "A" hermes-ip4) |
48 | ("hermes" "" "IN" "AAAA" hermes-ip6) |
49 | ("xana" "" "IN" "A" xana-ip4) |
50 | ("@" "" "IN" "A" hermes-ip4) |
51 | ("@" "" "IN" "AAAA" hermes-ip6) |
52 | ("www" "" "IN" "CNAME" "lepiller.eu.") |
53 | |
54 | ("avatar" "" "IN" "CNAME" "ene") |
55 | ("rennes" "" "IN" "CNAME" "ene") |
56 | ("nani" "" "IN" "CNAME" "xana") |
57 | ("i18n" "" "IN" "CNAME" "xana") |
58 | |
59 | ("@" "" "IN" "NS" "ns") |
60 | ("@" "" "IN" "NS" "ns2") |
61 | ("ns" "" "IN" "A" hermes-ip4) |
62 | ("ns" "" "IN" "AAAA" hermes-ip6) |
63 | ("ns2" "" "IN" "A" ene-ip4) |
64 | |
65 | ("@" "" "IN" "MX" "10 courriel") |
66 | ("@" "" "IN" "MX" "50 b.courriel") |
67 | ("b.courriel" "" "IN" "A" hermes-ip4) |
68 | ("b.courriel" "" "IN" "AAAA" hermes-ip6) |
69 | ("courriel" "" "IN" "A" ene-ip4) |
70 | ("imap" "" "IN" "CNAME" "courriel") |
71 | ("smtp" "" "IN" "CNAME" "b.courriel") |
72 | ("@" "" "IN" "TXT" "v=spf1 mx a ~all") |
73 | ("@" "" "IN" "SPF" "v=spf1 mx a ~all") |
74 | |
75 | ("dkim._domainkey" "" "IN" "TXT" (string-append "v=DKIM1; p=" public-dkim "; s=email; t=s"))) |
76 | |
77 | (define-zone-entries ipv4-reverse.zone |
78 | ("@" "" "IN" "PTR" "lepiller.eu.") |
79 | ("@" "" "IN" "NS" "ns.lepiller.eu.") |
80 | ("@" "" "IN" "NS" "ns2.lepiller.eu.")) |
81 | |
82 | (define-zone-entries ipv6-reverse.zone |
83 | ("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" "" "IN" "PTR" "lepiller.eu.") |
84 | ("@" "" "IN" "NS" "ns.lepiller.eu.") |
85 | ("@" "" "IN" "NS" "ns2.lepiller.eu.")) |
86 | |
87 | (define ene |
88 | (knot-remote-configuration |
89 | (id "ene") |
90 | (address (list ene-ip4)) |
91 | (key "lepiller-key"))) |
92 | |
93 | (define hermes |
94 | (knot-remote-configuration |
95 | (id "hermes") |
96 | (address (list hermes-ip4)) |
97 | (key "lepiller-key"))) |
98 | |
99 | (define master-acl |
100 | (knot-acl-configuration |
101 | (id "master-acl") |
102 | (address (list hermes-ip4)) |
103 | (key '("lepiller-key")) |
104 | (action '(transfer)))) |
105 | |
106 | (define slave-acl |
107 | (knot-acl-configuration |
108 | (id "slave-acl") |
109 | (address (list ene-ip4)) |
110 | (key '("lepiller-key")) |
111 | (action '(notify)))) |
112 | |
113 | (define lepiller-master-zone |
114 | (knot-zone-configuration |
115 | (domain "lepiller.eu") |
116 | (notify '("hermes")) |
117 | (dnssec-policy "default") |
118 | (acl '("master-acl")) |
119 | (zonefile-load 'difference) |
120 | (zone (zone-file |
121 | (origin "lepiller.eu") |
122 | (entries lepiller.eu.zone) |
123 | (serial 2019072401))))) |
124 | |
125 | (define lepiller-slave-zone |
126 | (knot-zone-configuration |
127 | (domain "lepiller.eu") |
128 | (acl '("slave-acl")) |
129 | (master '("ene")))) |
130 | |
131 | (define ipv6-reverse-master-zone |
132 | (let* ((ip6 (string->list (substring (string-delete hermes-ip6 #\:) 0 12))) |
133 | (rev-ip6-lst (fold (lambda (elem acc) |
134 | (cons* #\. elem acc)) |
135 | '() |
136 | ip6)) |
137 | (rev-ip6 (list->string (cdr rev-ip6-lst))) |
138 | (domain (string-append rev-ip6 ".ip6.arpa"))) |
139 | (knot-zone-configuration |
140 | (domain domain) |
141 | (zone (zone-file |
142 | (origin domain) |
143 | (entries ipv6-reverse.zone) |
144 | (ns "ns.lepiller.eu.") |
145 | (mail "hostmaster.lepiller.eu.") |
146 | (serial 1)))))) |
147 | |
148 | (define ipv4-reverse-master-zone |
149 | (let ((domain (string-append |
150 | (string-join (reverse (string-split hermes-ip4 #\.)) ".") |
151 | ".in-addr.arpa"))) |
152 | (knot-zone-configuration |
153 | (domain domain) |
154 | (zone (zone-file |
155 | (origin domain) |
156 | (entries ipv4-reverse.zone) |
157 | (ns "ns.lepiller.eu.") |
158 | (mail "hostmaster.lepiller.eu.") |
159 | (serial 1)))))) |
160 |