lib: add webSsl directive
authorClinton Ebadi <clinton@unknownlamer.org>
Thu, 6 Sep 2018 01:42:05 +0000 (21:42 -0400)
committerClinton Ebadi <clinton@unknownlamer.org>
Thu, 6 Sep 2018 01:46:53 +0000 (21:46 -0400)
Allows sharing config between http/https vhosts and optionally can
force https.

lib/defaults.dtl
lib/easy_domain.dtl

index 6b6fbe7..38857ed 100644 (file)
@@ -34,6 +34,7 @@ var TTL : int = defaultTTL;
 
 var WWW : [Vhost] = Skip;
 var CreateWWW : bool = true;
 
 var WWW : [Vhost] = Skip;
 var CreateWWW : bool = true;
+var ForceSSL : bool = true;
 var DefaultA : bool = true;
 var DefaultAlias : bool = true;
 var DefaultAliasSource : aliasSource = userSource defaultMailUser;
 var DefaultA : bool = true;
 var DefaultAlias : bool = true;
 var DefaultAliasSource : aliasSource = userSource defaultMailUser;
index 61ae8f8..0f05a7c 100644 (file)
@@ -37,6 +37,26 @@ val webAtIp =
     end
   end;
 
     end
   end;
 
+val webSsl = \ host -> \ certFile -> \\ config : Vhost -> begin
+  n <- DefaultWebNode;
+  webAt n host where
+    SSL = certFile;
+  with config end;
+
+  force_ssl <- ForceSSL;
+  if force_ssl then
+    webAt n host where
+      SSL = no_ssl;
+    with
+      rewriteRule "^(.*)$" "https://%{HTTP_HOST}$1" [redirect];
+    end;
+  else
+    webAt n host where
+      SSL = no_ssl;
+    with config end;
+  end;
+end;
+
 val addDefaultAlias = begin
   mailbox <- Mailbox;
   source <- DefaultAliasSource;
 val addDefaultAlias = begin
   mailbox <- Mailbox;
   source <- DefaultAliasSource;