2 Domtool (http
://hcoop
.sf
.net
/)
3 Copyright (C
) 2004 Adam Chlipala
5 This program is free software
; you can redistribute it
and/or
6 modify it under the terms
of the GNU General Public License
7 as published by the Free Software Foundation
; either version
2
8 of the License
, or (at your option
) any later version
.
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
.
15 You should have received a copy
of the GNU General Public License
16 along
with this program
; if not
, write to the Free Software
17 Foundation
, Inc
., 59 Temple Place
- Suite
330, Boston
, MA
02111-1307, USA
.
20 (* Djbdns DNS mapping config
*)
22 structure Djbdns
:> DJBDNS
=
24 open Config DjbdnsConfig Util
26 val ldHandler
= ref (fn _
: string => ())
27 fun setLocalDomainHandler f
= ldHandler
:= f
29 val dns
= ref (NONE
: TextIO.outstream option
)
31 fun init () = dns
:= SOME (TextIO.openOut (scratchDir ^
"/data.shared"))
32 fun finish () = (TextIO.closeOut (valOf (!dns
));
35 fun handler
{path
, domain
, parent
, vars
, paths
, users
, groups
} =
37 val _
= Domtool
.dprint ("Reading dns " ^ path ^
" for " ^ parent ^
"....")
39 val dns
= valOf (!dns
)
41 val al
= TextIO.openIn path
43 val hasEmail
= ref
false
45 fun loop (line
, mxnum
) =
47 fun err () = (Domtool
.error (path
, "Invalid entry: " ^ trimLast line
);
50 case String.tokens
Char.isSpace line
of
52 |
["Default", addr
] =>
53 (case resolveAddr (vars
, addr
) of
55 | addr
=> (TextIO.output (dns
, "=" ^ parent ^
":" ^ addr ^
"\n");
70 (case resolveDomain (vars
, addr
) of
73 if validHost host
then
74 (TextIO.output (dns
, pre ^ host ^
"." ^ parent ^
":" ^ addr ^
"\n");
78 else case (resolveAddr (vars
, addr
), pre
) of
81 if validHost host
then
82 (TextIO.output (dns
, pre ^ parent ^
":" ^ addr ^
":" ^ host ^
"." ^ parent ^
"\n");
87 if validHost host
then
88 (TextIO.output (dns
, pre ^ parent ^
":" ^ addr ^
":" ^ host ^
"." ^ parent ^
"\n");
93 (if not (!hasEmail
) then
98 if validHost host
then
99 (TextIO.output (dns
, pre ^ parent ^
":" ^ addr ^
":" ^ host ^
"." ^ parent ^
":" ^
Int.toString mxnum ^
"\n");
104 if validHost host
then
105 (TextIO.output (dns
, pre ^ host ^
"." ^ parent ^
":" ^ addr ^
"\n");
110 if validHost host
then
111 (TextIO.output (dns
, pre ^ host ^
"." ^ parent ^
":" ^ addr ^
"\n");
120 ioLoop (fn () => Domtool
.inputLine al
) loop
0;
122 end handle Io
=> Domtool
.error (path
, "IO error")
125 if OS
.Process
.isSuccess (OS
.Process
.system
126 (diff ^
" " ^ scratchDir ^
"/data.shared " ^ dataFile
)) then
128 else if not (OS
.Process
.isSuccess (OS
.Process
.system
129 (cp ^
" " ^ scratchDir ^
"/data.shared " ^ dataFile
))) then
130 (print
"Error copying data.shared\n";
132 else if OS
.Process
.isSuccess (OS
.Process
.system pubCommand
) then
135 (print
"Error publishing data.shared\n";
138 fun mkdom
{path
, ...} = OS
.Process
.system (cp ^
" " ^ defaultFile ^
" " ^ path ^
"/.dns")
140 val _
= Domtool
.setHandler (".dns", {init
= init
,