X-Git-Url: https://git.hcoop.net/hcoop/domtool2.git/blobdiff_plain/60695e9923af9e74160575b5de0d5549808294b4..77a8fca278b561808959fa1aa7d9f02c5cfe7720:/src/plugins/apache.sml diff --git a/src/plugins/apache.sml b/src/plugins/apache.sml index 079afca..65ba7fb 100644 --- a/src/plugins/apache.sml +++ b/src/plugins/apache.sml @@ -26,9 +26,13 @@ val _ = Env.type_one "web_node" Env.string (fn node => List.exists (fn x => x = node) Config.Apache.webNodes_all - orelse (Domain.inGroup "www" + orelse (Domain.hasPriv "www" andalso List.exists (fn x => x = node) Config.Apache.webNodes_admin)) +val _ = Env.registerFunction ("web_node_to_node", + fn [e] => SOME e + | _ => NONE) + val _ = Env.type_one "proxy_port" Env.int (fn n => n > 1024) @@ -68,10 +72,6 @@ val _ = Env.type_one "location" val dl = ErrorMsg.dummyLoc -val _ = Env.registerFunction ("web_node_to_node", - fn [e] => SOME e - | _ => NONE) - val _ = Defaults.registerDefault ("WebNodes", (TList (TBase "web_node", dl), dl), (fn () => (EList (map (fn s => (EString s, dl)) Config.Apache.webNodes_default), dl))) @@ -180,9 +180,11 @@ val autoindex_option = fn (EApp ((EVar "descriptionWidth", _), w), _) => | _ => NONE val vhostsChanged = ref false +val logDeleted = ref false val () = Slave.registerPreHandler - (fn () => vhostsChanged := false) + (fn () => (vhostsChanged := false; + logDeleted := false)) fun findVhostUser fname = let @@ -234,7 +236,12 @@ val () = Slave.registerFileHandler (fn fs => vhostsChanged := true; case #action fs of Slave.Delete => - (ignore (OS.Process.system (Config.rm + (if !logDeleted then + () + else + (ignore (OS.Process.system Config.Apache.down); + logDeleted := true); + ignore (OS.Process.system (Config.rm ^ " -rf " ^ realVhostFile)); ignore (OS.Process.system (Config.rm @@ -246,7 +253,10 @@ val () = Slave.registerFileHandler (fn fs => ^ #file fs ^ " " ^ realVhostFile)); - OS.FileSys.mkDir realLogDir) + if Posix.FileSys.access (realLogDir, []) then + () + else + OS.FileSys.mkDir realLogDir) | _ => ignore (OS.Process.system (Config.cp @@ -262,7 +272,7 @@ val () = Slave.registerFileHandler (fn fs => val () = Slave.registerPostHandler (fn () => (if !vhostsChanged then - Slave.shellF ([Config.Apache.reload], + Slave.shellF ([if !logDeleted then Config.Apache.undown else Config.Apache.reload], fn cl => "Error reloading Apache with " ^ cl) else ())) @@ -272,6 +282,7 @@ fun write' s = app (fn (node, file) => TextIO.output (file, s node)) (!vhostFile fun write s = app (fn (_, file) => TextIO.output (file, s)) (!vhostFiles) val rewriteEnabled = ref false +val localRewriteEnabled = ref false val currentVhost = ref "" val currentVhostId = ref "" @@ -319,6 +330,7 @@ val () = Env.containerV_one "vhost" currentVhostId := vhostId; rewriteEnabled := false; + localRewriteEnabled := false; vhostFiles := map (fn node => let val file = Domain.domainFile {node = node, @@ -370,24 +382,38 @@ val () = Env.containerV_one "vhost" write "\n"; app (TextIO.closeOut o #2) (!vhostFiles))) +val inLocal = ref false + val () = Env.container_one "location" ("prefix", Env.string) (fn prefix => (write "\t\n"), - fn () => write "\t\n") + write ">\n"; + inLocal := true), + fn () => (write "\t\n"; + inLocal := false; + localRewriteEnabled := false)) val () = Env.container_one "directory" ("directory", Env.string) (fn directory => (write "\t\n"), - fn () => write "\t\n") + write ">\n"; + inLocal := true), + fn () => (write "\t\n"; + inLocal := false; + localRewriteEnabled := false)) fun checkRewrite () = - if !rewriteEnabled then + if !inLocal then + if !rewriteEnabled orelse !localRewriteEnabled then + () + else + (write "\tRewriteEngine on\n"; + localRewriteEnabled := true) + else if !rewriteEnabled then () else (write "\tRewriteEngine on\n"; @@ -713,4 +739,7 @@ val () = Env.action_one "readmeName" write name; write "\n")) +val () = Domain.registerResetLocal (fn () => + ignore (OS.Process.system (Config.rm ^ " -rf /var/domtool/vhosts/*"))) + end