summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-06-30 12:15:39 -0700
committerMicah <micah@leap.se>2016-08-25 15:34:59 -0400
commitd54da335c73cc778aa3469c40bdd47413ad9534f (patch)
tree9a18120f4aaac7f4a44edad79b822d1aff38c7dd
parent86522e3205ff1596dbd687033080557034781d80 (diff)
fix static site apache config
-rw-r--r--puppet/modules/site_static/templates/amber.erb8
-rw-r--r--puppet/modules/site_static/templates/apache.conf.erb122
-rw-r--r--puppet/modules/site_static/templates/rack.erb6
3 files changed, 79 insertions, 57 deletions
diff --git a/puppet/modules/site_static/templates/amber.erb b/puppet/modules/site_static/templates/amber.erb
index 694f1136..b34458c3 100644
--- a/puppet/modules/site_static/templates/amber.erb
+++ b/puppet/modules/site_static/templates/amber.erb
@@ -4,10 +4,10 @@
<%- end -%>
<Directory "<%=@directory%>/">
AllowOverride FileInfo Indexes Options=All,MultiViews
-<% if scope.function_guess_apache_version([]) == '2.4' %>
+<%- if scope.function_guess_apache_version([]) == '2.4' -%>
Require all granted
-<% else %>
+<%- else -%>
Order deny,allow
Allow from all
-<% end %>
- </Directory>
+<%- end -%>
+ </Directory> \ No newline at end of file
diff --git a/puppet/modules/site_static/templates/apache.conf.erb b/puppet/modules/site_static/templates/apache.conf.erb
index bd088180..af9a520d 100644
--- a/puppet/modules/site_static/templates/apache.conf.erb
+++ b/puppet/modules/site_static/templates/apache.conf.erb
@@ -11,6 +11,9 @@
end
end
+ #
+ # document root
+ #
@document_root = begin
root = '/var/www'
@locations && @locations.each do |name, location|
@@ -19,8 +22,52 @@
root.gsub(%r{^/|/$}, '')
end
+ #
+ # provider.json
+ #
+ # if the domain is a bootstrap domain, we need to expose
+ # a /provider.json file.
+ #
bootstrap_domain = scope.lookupvar('site_static::bootstrap_domain')
bootstrap_client = scope.lookupvar('site_static::bootstrap_client')
+ if ([@aliases]+[@domain]).flatten.include?(bootstrap_domain)
+ provider_json = \
+%(
+ Alias /provider.json /srv/static/public/provider.json
+ <Location /provider.json>
+ Header set X-Minimum-Client-Version #{bootstrap_client['min']}
+ </Location>
+)
+ else
+ provider_json = ""
+ end
+
+ #
+ # locations
+ #
+ locations = ""
+ @locations && @locations.each do |name, location|
+ location_path = location['path'].gsub(%r{^/|/$}, '')
+ directory = location_directory(name, location)
+ local_vars = {'location_path'=>location_path, 'directory'=>directory, 'location'=>location, 'name'=>name}
+ template_path = File.join(File.dirname(__FILE__), location['format']) + '.erb'
+ break unless File.exists?(template_path)
+ locations += \
+%(
+ #
+ # #{name} (#{location['format']})
+ #
+#{scope.function_templatewlv([template_path, local_vars])}
+)
+ end
+
+ #
+ # allow custom apache config
+ #
+ custom_apache_config = if @apache_config
+ @apache_config.gsub(':percent:','%')
+ end
+
-%>
<Directory "/srv/static/public/">
@@ -28,6 +75,9 @@
</Directory>
<%- if @tor -%>
+##
+## Tor
+##
<VirtualHost 127.0.0.1:80>
ServerName <%= @tor_domain %>
ServerAlias www.<%= @tor_domain %>
@@ -41,31 +91,15 @@
DocumentRoot "/<%= @document_root %>/"
AccessFileName .htaccess
-<%- if ([@aliases]+[@domain]).flatten.include?(bootstrap_domain) -%>
- Alias /provider.json /srv/leap/provider.json
- <Location /provider.json>
- Header set X-Minimum-Client-Version <%= bootstrap_client['min'] %>
- </Location>
-<%- end -%>
-
-<%- if @apache_config -%>
-<%= @apache_config.gsub(':percent:','%') %>
-<%- end -%>
-
-<%- @locations && @locations.each do |name, location| -%>
-<%- location_path = location['path'].gsub(%r{^/|/$}, '') -%>
-<%- directory = location_directory(name, location) -%>
-<%- local_vars = {'location_path'=>location_path, 'directory'=>directory, 'location'=>location, 'name'=>name} -%>
-<%- template_path = File.join(File.dirname(__FILE__), location['format']) + '.erb' -%>
-<%- break unless File.exists?(template_path) -%>
- ##
- ## <%= name %> (<%= location['format'] %>)
- ##
-<%= scope.function_templatewlv([template_path, local_vars]) %>
-<%- end -%>
-<%- end -%>
+<%= provider_json %>
+<%= custom_apache_config %>
+<%= locations %>
</VirtualHost>
+<%- end -%>
+##
+## HTTP
+##
<VirtualHost *:80>
ServerName <%= @domain %>
ServerAlias www.<%= @domain %>
@@ -76,9 +110,16 @@
<%- if @tls_only -%>
RewriteEngine On
RewriteRule ^.*$ https://<%= @domain -%>%{REQUEST_URI} [R=permanent,L]
+<%- else -%>
+<%= provider_json %>
+<%= custom_apache_config %>
+<%= locations %>
<%- end -%>
</VirtualHost>
+##
+## HTTPS
+##
<VirtualHost *:443>
ServerName <%= @domain %>
ServerAlias www.<%= @domain %>
@@ -90,14 +131,14 @@
#RewriteLogLevel 3
Include include.d/ssl_common.inc
-
+
<IfModule mod_headers.c>
<%- if @tls_only -%>
- Header always set Strict-Transport-Security: "max-age=15768000;includeSubdomains"
+ Header always set Strict-Transport-Security: "max-age=15768000;includeSubdomains"
<%- end -%>
- Header set X-Frame-Options "deny"
- Header always unset X-Powered-By
- Header always unset X-Runtime
+ Header set X-Frame-Options "deny"
+ Header always unset X-Powered-By
+ Header always unset X-Runtime
</IfModule>
SSLCertificateKeyFile /etc/x509/keys/<%= @domain %>.key
@@ -108,26 +149,7 @@
DocumentRoot "/<%= @document_root %>/"
AccessFileName .htaccess
-<%- if ([@aliases]+[@domain]).flatten.include?(bootstrap_domain) -%>
- Alias /provider.json /srv/leap/provider.json
- <Location /provider.json>
- Header set X-Minimum-Client-Version <%= bootstrap_client['min'] %>
- </Location>
-<%- end -%>
-
-<%- if @apache_config -%>
-<%= @apache_config.gsub(':percent:','%') %>
-<%- end -%>
-
-<%- @locations && @locations.each do |name, location| -%>
-<%- location_path = location['path'].gsub(%r{^/|/$}, '') -%>
-<%- directory = location_directory(name, location) -%>
-<%- local_vars = {'location_path'=>location_path, 'directory'=>directory, 'location'=>location, 'name'=>name} -%>
-<%- template_path = File.join(File.dirname(__FILE__), location['format']) + '.erb' -%>
-<%- break unless File.exists?(template_path) -%>
- ##
- ## <%= name %> (<%= location['format'] %>)
- ##
-<%= scope.function_templatewlv([template_path, local_vars]) %>
-<%- end -%>
+<%= provider_json %>
+<%= custom_apache_config %>
+<%= locations %>
</VirtualHost>
diff --git a/puppet/modules/site_static/templates/rack.erb b/puppet/modules/site_static/templates/rack.erb
index 431778bb..1cbf84d2 100644
--- a/puppet/modules/site_static/templates/rack.erb
+++ b/puppet/modules/site_static/templates/rack.erb
@@ -10,10 +10,10 @@
<%- end -%>
<Directory "<%=@directory%>">
Options -MultiViews
-<% if scope.function_guess_apache_version([]) == '2.4' %>
+<%- if scope.function_guess_apache_version([]) == '2.4' -%>
Require all granted
-<% else %>
+<%- else -%>
Order deny,allow
Allow from all
-<% end %>
+<%- end -%>
</Directory>