val () = Slave.registerPreHandler
(fn () => vhostsChanged := false)
+fun findVhostUser fname =
+ let
+ val inf = TextIO.openIn fname
+
+ fun loop () =
+ case TextIO.inputLine inf of
+ NONE => NONE
+ | SOME line =>
+ case String.tokens Char.isSpace line of
+ ["SuexecUserGroup", user, _] => SOME user
+ | _ => loop ()
+ in
+ loop ()
+ before TextIO.closeIn inf
+ end
+
val () = Slave.registerFileHandler (fn fs =>
- let
- val spl = OS.Path.splitDirFile (#file fs)
- in
- if String.isSuffix ".vhost" (#file spl)
- orelse String.isSuffix ".vhost_ssl" (#file spl) then
- (vhostsChanged := true;
- case #action fs of
- Slave.Delete =>
- (ignore (OS.Process.system (Config.rm
- ^ " -rf "
- ^ Config.Apache.confDir
- ^ "/"
- ^ #file spl));
- ignore (OS.Process.system (Config.rm
- ^ " -rf "
- ^ Config.Apache.logDir
- ^ "/"
- ^ #base (OS.Path.splitBaseExt
- (#file spl)))))
-
- | _ =>
- ignore (OS.Process.system (Config.cp
- ^ " "
- ^ #file fs
- ^ " "
- ^ Config.Apache.confDir
- ^ "/"
- ^ #file spl)))
- else
- ()
- end)
+ case findVhostUser (#file fs) of
+ NONE => print ("Can't find user in " ^ #file fs ^ "! Taking no action.\n")
+ | SOME user =>
+ let
+ val spl = OS.Path.splitDirFile (#file fs)
+ in
+ if String.isSuffix ".vhost" (#file spl)
+ orelse String.isSuffix ".vhost_ssl" (#file spl) then
+ (vhostsChanged := true;
+ case #action fs of
+ Slave.Delete =>
+ let
+ val {base, ...} = OS.Path.splitBaseExt (#file spl)
+
+ val logname = OS.Path.joinDirFile
+ {dir = Config.Apache.logDir,
+ file = user}
+ in
+ ignore (OS.Process.system (Config.rm
+ ^ " -rf "
+ ^ Config.Apache.confDir
+ ^ "/"
+ ^ #file spl));
+ Slave.writeList (logname,
+ List.filter (fn s => s <> base)
+ (Slave.readList logname))
+ end
+
+ | Slave.Add =>
+ let
+ val _ =
+ OS.Process.system (Config.cp
+ ^ " "
+ ^ #file fs
+ ^ " "
+ ^ Config.Apache.confDir
+ ^ "/"
+ ^ #file spl)
+
+ val {base, ...} = OS.Path.splitBaseExt (#file spl)
+
+ val logname = OS.Path.joinDirFile
+ {dir = Config.Apache.logDir,
+ file = user}
+
+ val outf = TextIO.openAppend logname
+ in
+ TextIO.output (outf, base);
+ TextIO.output1 (outf, #"\n");
+ TextIO.closeOut outf
+ end
+
+ | _ =>
+ ignore (OS.Process.system (Config.cp
+ ^ " "
+ ^ #file fs
+ ^ " "
+ ^ Config.Apache.confDir
+ ^ "/"
+ ^ #file spl)))
+ else
+ ()
+ end)
val () = Slave.registerPostHandler
(fn () =>
TextIO.closeOut outf
end
+fun readList fname =
+ let
+ val inf = TextIO.openIn fname
+
+ fun loop acc =
+ case TextIO.inputLine inf of
+ NONE => rev acc
+ | SOME line => loop (String.substring (line, 0, size line - 1) :: acc)
+ in
+ loop []
+ before TextIO.closeIn inf
+ end
+
+fun writeList (fname, ls) =
+ let
+ val outf = TextIO.openOut fname
+ in
+ app (fn s => (TextIO.output (outf, s);
+ TextIO.output1 (outf, #"\n"))) ls;
+ TextIO.closeOut outf
+ end
+
end