From 1b1da88281c163222e544ddf09ed53213fdff69a Mon Sep 17 00:00:00 2001
From: Nicolas Wavrant <nicolas.wavrant@tiolive.com>
Date: Fri, 21 Feb 2014 11:26:43 +0100
Subject: [PATCH] slaprunner: now includes webdav support

Conflicts:
	software/slaprunner/common.cfg
	software/slaprunner/instance-resilient.cfg.jinja2
	software/slaprunner/instance-runner.cfg
---
 software/slaprunner/common.cfg                | 19 -------------------
 .../slaprunner/instance-resilient.cfg.jinja2  |  3 ++-
 software/slaprunner/instance-runner.cfg       |  7 ++++---
 software/slaprunner/nginx_conf.in             | 13 +++++++++++++
 4 files changed, 19 insertions(+), 23 deletions(-)

diff --git a/software/slaprunner/common.cfg b/software/slaprunner/common.cfg
index ecdde5c0f..492e79b2a 100644
--- a/software/slaprunner/common.cfg
+++ b/software/slaprunner/common.cfg
@@ -25,8 +25,6 @@ extends =
 parts =
   template
   eggs
-  nginx
-  webdav-module
   instance-runner-import
   instance-runner-export
   slapos-cookbook
@@ -35,23 +33,6 @@ parts =
   rdiff-backup
   collective.recipe.template-egg
 
-[webdav-module]
-recipe = hexagonit.recipe.download
-url = https://github.com/arut/nginx-dav-ext-module/archive/master.zip
-strip-top-level-dir = true
-#md5sum =
-mode = 0644
-
-[nginx]
-configure-options =
-  --with-ipv6
-  --with-http_ssl_module
-  --with-mail
-  --with-mail_ssl_module
-  --with-ld-opt="-L ${zlib:location}/lib -L ${openssl:location}/lib -L ${pcre:location}/lib  -Wl,-rpath=${pcre:location}/lib -Wl,-rpath=${zlib:location}/lib -Wl,-rpath=${openssl:location}/lib -L ${libexpat:location}/lib"
-  --with-cc-opt="-I ${pcre:location}/include -I ${openssl:location}/include -I ${zlib:location}/include -I ${libexpat:location}/include"
-  --with-http_dav_module 
-  --add-module='${webdav-module:location}'
 
 
 [template]
diff --git a/software/slaprunner/instance-resilient.cfg.jinja2 b/software/slaprunner/instance-resilient.cfg.jinja2
index 213f5e4ef..505484bb8 100644
--- a/software/slaprunner/instance-resilient.cfg.jinja2
+++ b/software/slaprunner/instance-resilient.cfg.jinja2
@@ -17,7 +17,7 @@ parts +=
 
 # Bubble up the parameters
 [request-runner]
-return = url ssh-public-key ssh-url notification-id ip backend_url url ssh_command access_url 1_info 2_info monitor_url IMPORTANT_monitor_info 
+return = url ssh-public-key ssh-url notification-id ip backend_url url ssh_command access_url 1_info 2_info monitor_url IMPORTANT_monitor_info webdav_url
 
 [publish-connection-informations]
 recipe = slapos.cookbook:publish
@@ -29,6 +29,7 @@ url = ${request-runner:connection-url}
 ssh_command = ${request-runner:connection-ssh_command}
 monitor_url = ${request-runner:connection-monitor_url}
 IMPORTANT_monitor_info = ${request-runner:connection-IMPORTANT_monitor_info}
+webdav_url = ${request-runner:connection-webdav_url}
 
 [slap-parameter]
 # Default parameters for distributed deployment
diff --git a/software/slaprunner/instance-runner.cfg b/software/slaprunner/instance-runner.cfg
index 3f7f0c5a5..23b457f3f 100644
--- a/software/slaprunner/instance-runner.cfg
+++ b/software/slaprunner/instance-runner.cfg
@@ -250,13 +250,13 @@ path_tmp = $${directory:tmp}/
 # Config files
 path_nginx_conf = $${directory:etc}/nginx.conf
 # Executables
-bin_nginx = ${nginx:location}/sbin/nginx
+bin_nginx = ${nginx-webdav:location}/sbin/nginx
 bin_launcher = $${directory:bin}/launcher
 # Utils
 path_shell = ${dash:location}/bin/dash
 # Misc.
 etc_dir = $${directory:etc}
-
+work_dir = $${slaprunner:working-directory}
 
 [nginx_conf]
 recipe = slapos.recipe.template:jinja2
@@ -361,13 +361,14 @@ return = site_url domain
 
 [publish-connection-informations]
 recipe = slapos.cookbook:publish
-1_info = On your first run, Use "access_url" to setup you account.Then you can use both "url" or "access_url". Or "backend_url" if you want to use ipv6.
+1_info = On your first run, Use "access_url" to setup you account.Then you can use both "url" or "access_url". Or "backend_url" if you want to use ipv6. Set your account in the webrunner in order to use webdav.
 2_info = In order to set up your account, get the recovery-code from the monitoring interface. Before read the notification on monitor_info
 backend_url = $${slaprunner:access-url}
 access_url = $${:url}/login
 url =  https://$${request-frontend:connection-domain}
 ssh_command = ssh $${dropbear-runner-server:host} -p $${dropbear-runner-server:port}
 monitor_url = $${:url}:$${cgi-httpd-configuration-file:listening-port}/$${deploy-index:filename}
+webdav_url = https://$${request-frontend:connection-domain}/share
 
 #---------------------------
 #--
diff --git a/software/slaprunner/nginx_conf.in b/software/slaprunner/nginx_conf.in
index 080e5502f..55a5b5799 100644
--- a/software/slaprunner/nginx_conf.in
+++ b/software/slaprunner/nginx_conf.in
@@ -64,5 +64,18 @@ http {
             proxy_set_header        X-Forwarded-For   $proxy_add_x_forwarded_for;
 	    proxy_set_header        X-Forwarded-Host  $http_host;
 	}
+        location /share {
+            rewrite ^/share / break;
+
+            auth_basic "Restricted";
+            auth_basic_user_file {{ param_nginx_frontend['etc_dir'] }}/.htpasswd;
+
+            dav_methods PUT DELETE MKCOL COPY MOVE;
+            dav_ext_methods PROPFIND OPTIONS;
+
+            root {{ param_nginx_frontend['work_dir'] }};
+
+            create_full_put_path   on;
+        }
     }
 }
-- 
2.30.9