+ val dir = Posix.FileSys.opendir tmpPath
+
+ fun loopTmp acts =
+ case Posix.FileSys.readdir dir of
+ NONE => (Posix.FileSys.closedir dir;
+ acts)
+ | SOME fname =>
+ let
+ val real = OS.Path.joinDirFile {dir = realPath,
+ file = fname}
+ val tmp = OS.Path.joinDirFile {dir = tmpPath,
+ file = fname}
+ in
+ if Posix.FileSys.ST.isDir (Posix.FileSys.stat tmp) then
+ loopTmp acts
+ else if Posix.FileSys.access (real, []) then
+ loopTmp acts
+ else
+ loopTmp ((site, dom, realPath, Add' {src = tmp, dst = real}) :: acts)
+ end
+
+ val acts = loopTmp acts
+ in
+ acts
+ end
+
+fun findAllDiffs () =
+ let
+ val dir = Posix.FileSys.opendir Config.tmpDir
+ val len = length (String.fields (fn ch => ch = #"/") Config.tmpDir) + 1
+
+ fun exploreSites diffs =
+ case Posix.FileSys.readdir dir of
+ NONE => diffs
+ | SOME site =>
+ let
+ fun explore (dname, diffs) =
+ let
+ val dir = Posix.FileSys.opendir dname
+
+ fun loop diffs =
+ case Posix.FileSys.readdir dir of
+ NONE => diffs
+ | SOME name =>
+ let
+ val fname = OS.Path.joinDirFile {dir = dname,
+ file = name}
+ in
+ loop (if Posix.FileSys.ST.isDir (Posix.FileSys.stat fname) then
+ let
+ val dom = String.fields (fn ch => ch = #"/") fname
+ val dom = List.drop (dom, len)
+ val dom = String.concatWith "." (rev dom)
+
+ val dname' = OS.Path.joinDirFile {dir = dname,
+ file = name}
+ in
+ explore (dname',
+ findDiffs (site, dom, diffs))
+ end
+ else
+ diffs)
+ end
+ in
+ loop diffs
+ before Posix.FileSys.closedir dir
+ end
+ in
+ exploreSites (explore (OS.Path.joinDirFile {dir = Config.tmpDir,
+ file = site}, diffs))
+ end
+ in
+ exploreSites []
+ before Posix.FileSys.closedir dir
+ end
+
+val masterNode : string option ref = ref NONE
+fun dnsMaster () = !masterNode
+
+val _ = Env.containerV_one "domain"
+ ("domain", Env.string)
+ (fn (evs, dom) =>
+ let
+ val kind = Env.env dnsKind (evs, "DNS")
+ val ttl = Env.env Env.int (evs, "TTL")
+
+ val path = getPath dom
+
+ val () = (current := dom;
+ currentPath := (fn site => path (Config.tmpDir, site)))
+
+ fun saveSoa (kind, soa : soa) node =
+ let
+ val outf = domainFile {node = node, name = "soa"}
+ in
+ TextIO.output (outf, kind);
+ TextIO.output (outf, "\n");
+ TextIO.output (outf, Int.toString ttl);
+ TextIO.output (outf, "\n");
+ TextIO.output (outf, #ns soa);
+ TextIO.output (outf, "\n");
+ case #serial soa of
+ NONE => ()
+ | SOME n => TextIO.output (outf, Int.toString n);
+ TextIO.output (outf, "\n");
+ TextIO.output (outf, Int.toString (#ref soa));
+ TextIO.output (outf, "\n");
+ TextIO.output (outf, Int.toString (#ret soa));
+ TextIO.output (outf, "\n");
+ TextIO.output (outf, Int.toString (#exp soa));
+ TextIO.output (outf, "\n");
+ TextIO.output (outf, Int.toString (#min soa));
+ TextIO.output (outf, "\n");
+ TextIO.closeOut outf
+ end
+
+ fun saveNamed (kind, soa : soa, masterIp) node =
+ let
+ val outf = domainFile {node = node, name = "named.conf"}
+ in
+ TextIO.output (outf, "\nzone \"");
+ TextIO.output (outf, dom);
+ TextIO.output (outf, "\" IN {\n\ttype ");
+ TextIO.output (outf, kind);
+ TextIO.output (outf, ";\n\tfile \"");
+ TextIO.output (outf, Config.Bind.zonePath_real);
+ TextIO.output (outf, "/");
+ TextIO.output (outf, dom);
+ TextIO.output (outf, ".zone\";\n");
+ case kind of
+ "master" => TextIO.output (outf, "\tallow-update { none; };\n")
+ | _ => (TextIO.output (outf, "\tmasters { ");
+ TextIO.output (outf, masterIp);
+ TextIO.output (outf, " };\n"));
+ TextIO.output (outf, "};\n");
+ TextIO.closeOut outf
+ end
+ in
+ case kind of
+ NoDns => masterNode := NONE
+ | UseDns dns =>
+ let
+ val masterIp =
+ case #master dns of
+ InternalMaster node => valOf (SM.find (nodeMap, node))
+ | ExternalMaster ip => ip
+ in
+ app (saveSoa ("slave", #soa dns)) (#slaves dns);
+ app (saveNamed ("slave", #soa dns, masterIp)) (#slaves dns);
+ case #master dns of
+ InternalMaster node =>
+ (masterNode := SOME node;
+ saveSoa ("master", #soa dns) node;
+ saveNamed ("master", #soa dns, masterIp) node)
+ | _ => masterNode := NONE;
+ !befores dom
+ end
+ end,