From cc124a9add6c76aac2106469e94d178bf38b072f Mon Sep 17 00:00:00 2001
From: eteri <eteri.sokhoyan@nexedi.com>
Date: Mon, 12 Mar 2018 10:15:54 +0100
Subject: [PATCH] caddy: add new release

---
 stack/caddy/Caddyfile.in                 | 47 ++++++++++++++++++++----
 stack/caddy/buildout.cfg                 |  8 ++--
 stack/caddy/gowork.cfg                   |  4 +-
 stack/caddy/instance-caddy.cfg.in        | 13 +++++--
 stack/caddy/template-caddy-service.sh.in |  6 ++-
 5 files changed, 58 insertions(+), 20 deletions(-)

diff --git a/stack/caddy/Caddyfile.in b/stack/caddy/Caddyfile.in
index ae23a62e8..0e54b2eb3 100644
--- a/stack/caddy/Caddyfile.in
+++ b/stack/caddy/Caddyfile.in
@@ -3,7 +3,7 @@
 {{ parameter_dict['domain'] }} {
 
 tls {{ custom_cert_dict['cert-file'] }} {{ custom_cert_dict['key-file'] }} {
-  
+
   ca {{ca_custom_frontend_dict['rendered']}}
 
 }
@@ -16,20 +16,37 @@ root {{ directory_dict['public_html'] }}
 
 {% if parameter_dict['enable-basic-auth'] == 'true'  -%}
 basicauth / {{ parameter_dict['username'] }} {{parameter_dict['password']}}
+
 {%- endif %}
 
-}
+{% if parameter_dict['proxy'] == 'true'  -%}
+
+  {% if parameter_dict['type'] == 'zope'  -%}
+
+  proxy / {{parameter_dict['url']}}/VirtualHostBase/https/{{ parameter_dict['domain'] }}/VirtualHostRoot/ {
+
+  insecure_skip_verify
+
+  }
+
+  {% else %}
+    proxy / 	{{parameter_dict['url']}}
+  {%- endif %}
+
+  {%- endif %}
+
+  bind {{caddy_configuration_dict['ipv6']}}
 
-bind {{caddy_configuration_dict['ipv6']}}
+}
 
 {%- endif %}
 
-[{{caddy_configuration_dict['ipv6']}}]:{{parameter_dict['port-ipv6']}} {
+[{{caddy_configuration_dict['ipv6']}}]:{{parameter_dict['port']}} {
 
   tls {{ custom_cert_dict['cert-file'] }} {{ custom_cert_dict['key-file'] }} {
-  
+
     ca {{ certificate_authority_dict['ca-cert-file'] }}
-  
+
   }
 
   log {{caddy_configuration_dict['access_log']}}
@@ -42,11 +59,25 @@ bind {{caddy_configuration_dict['ipv6']}}
   basicauth / {{ parameter_dict['username'] }} {{parameter_dict['password']}}
   {%- endif %}
   
-  bind {{caddy_configuration_dict['ipv6']}}
+  {% if parameter_dict['proxy'] == 'true'  -%}
+
+  {% if parameter_dict['type'] == 'zope'  -%}
+
+  proxy / {{parameter_dict['url']}}/VirtualHostBase/https/[{{caddy_configuration_dict['ipv6']}}]:{{parameter_dict['port']}}/VirtualHostRoot/ {
 
+  insecure_skip_verify
+
+  }
+
+  {% else %}
+    proxy / 	{{parameter_dict['url']}}
+  {%- endif %}
+
+  {%- endif %}
+  bind {{caddy_configuration_dict['ipv6']}}
 }
 
-[{{caddy_configuration_dict['local_ip']}}]:{{parameter_dict['port-ipv4']}} {
+[{{caddy_configuration_dict['local_ip']}}]:{{parameter_dict['port']}} {
 
   log {{caddy_configuration_dict['access_log']}}
   
diff --git a/stack/caddy/buildout.cfg b/stack/caddy/buildout.cfg
index f67111f1e..30c92aaae 100644
--- a/stack/caddy/buildout.cfg
+++ b/stack/caddy/buildout.cfg
@@ -27,7 +27,7 @@ mode = 0644
 [template-caddyfile]
 recipe = slapos.recipe.build:download
 url = ${:_profile_base_location_}/Caddyfile.in
-md5sum = 88c4c33e374ea3f61cdd36b2816d24ba
+md5sum = 05b8347df3c5803a18a515687a3504e3
 filename = Caddyfile.in
 location = ${buildout:parts-directory}/${:_buildout_section_name_}
 mode = 0644
@@ -35,7 +35,7 @@ mode = 0644
 [template-caddy]
 recipe = slapos.recipe.template
 url = ${:_profile_base_location_}/instance-caddy.cfg.in
-md5sum = 3b796dee5c509393fd396fd019914a2e
+md5sum = 4ed3a50a15a793fec330332be30a9f3a
 output = ${buildout:directory}/instance-caddy.cfg.in
 mode = 0644
 
@@ -49,7 +49,7 @@ mode = 0644
 [template-caddy-service]
 recipe = slapos.recipe.template
 url = ${:_profile_base_location_}/template-caddy-service.sh.in
-md5sum = 5467fac7b95acde681e613ae98ce990d
+md5sum = 1736f72c7c76afe133753389da7c0b1f
 output = ${buildout:directory}/template-caddy-service.sh.in
 mode = 0644
 
@@ -59,7 +59,7 @@ path    = ${go_github.com_mholt_caddy:location}
 go      = ${gowork:golang}/bin/go
 configure-command = :
 make-targets =
-make-binary = cd ${:path}/caddy && ${:go} install -v
+make-binary = cd ${:path}/caddy  && ${:go} install -v
 environment =
   PATH=${pkgconfig:location}/bin:${gowork:golang}/bin:${buildout:bin-directory}:%(PATH)s
   GOPATH=${gowork:directory}
diff --git a/stack/caddy/gowork.cfg b/stack/caddy/gowork.cfg
index 0a812413f..22e13bb45 100644
--- a/stack/caddy/gowork.cfg
+++ b/stack/caddy/gowork.cfg
@@ -9,5 +9,5 @@ depends_gitfetch  =
 [go_github.com_mholt_caddy]
 <= go-git-package
 go.importpath = github.com/mholt/caddy
-repository    = https://github.com/mholt/caddy.git
-revision  = v0.10.10-0-gc4dfbb9956
+repository    = https://github.com/mholt/caddy
+revision      = v0.10.11-0-gd3f338ddab
diff --git a/stack/caddy/instance-caddy.cfg.in b/stack/caddy/instance-caddy.cfg.in
index 85b5f1da7..1320e2962 100644
--- a/stack/caddy/instance-caddy.cfg.in
+++ b/stack/caddy/instance-caddy.cfg.in
@@ -116,16 +116,21 @@ mode = 0600
 recipe = slapos.cookbook:publish
 password = $${slap-parameter:password}
 user = $${slap-parameter:username}
-secure_access = https://[$${caddy-configuration:ipv6}]:$${slap-parameter:port-ipv6}
+#secure_access = https://[$${caddy-configuration:ipv6}]:$${slap-parameter:port-ipv6}
+secure_access = https://[$${caddy-configuration:ipv6}]:$${slap-parameter:port}
 
 [slap-parameter]
 domain =
 key-content =
 cert-content =
 caddy-ca-certificate =
-port-ipv6 = 9443
-port-ipv4 = 4443
+#port-ipv6 = 9443
+#port-ipv4 = 4443
+port = 9443
 enable-quic = true
 enable-basic-auth =
 username = admin
-password = $${htpasswd:passwd}
\ No newline at end of file
+password = $${htpasswd:passwd}
+proxy = false
+type = zope
+url =
\ No newline at end of file
diff --git a/stack/caddy/template-caddy-service.sh.in b/stack/caddy/template-caddy-service.sh.in
index 4d572e87f..715e73922 100644
--- a/stack/caddy/template-caddy-service.sh.in
+++ b/stack/caddy/template-caddy-service.sh.in
@@ -2,8 +2,10 @@
 # BEWARE: This file is operated by slapgrid
 # BEWARE: It will be overwritten automatically
 
-{{ caddy_exec }} -conf {{caddy_configuration_dict['rendered']}}
+{{ caddy_exec }}  -conf {{caddy_configuration_dict['rendered']}} \
  {%- if parameter_dict['enable-quic'] != 'false'  %}
  -quic
- {%- endif -%}
+ {%- endif -%} 
+ 
+ 
  
\ No newline at end of file
-- 
2.30.9