Skip to content

Commit 2ab715a

Browse files
committed
Enables nginx autoindex
1 parent aae84e1 commit 2ab715a

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

archive/puphpet/puppet/nodes/Nginx.pp

+18-5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
'locations' => [
139139
{
140140
'location' => '/',
141+
'autoindex' => 'off',
141142
'try_files' => ['$uri', '$uri/', 'index.php',],
142143
'fastcgi' => '',
143144
'fastcgi_index' => '',
@@ -147,6 +148,7 @@
147148
},
148149
{
149150
'location' => '~ \.php$',
151+
'autoindex' => 'off',
150152
'try_files' => [
151153
'$uri', '$uri/', 'index.php', '/index.php$is_args$args'
152154
],
@@ -214,9 +216,9 @@
214216
true => $vhost['ssl_port'],
215217
default => '443',
216218
}
217-
$rewrite_to_https = array_true($vhost, 'rewrite_to_https') ? {
219+
$rewrite_to_https = $ssl and array_true($vhost, 'rewrite_to_https') ? {
218220
true => true,
219-
default => false,
221+
default => undef,
220222
}
221223

222224
$vhost_cfg_append = deep_merge(
@@ -244,26 +246,37 @@
244246
}
245247

246248
each( $nginx_locations ) |$lkey, $location| {
249+
if $location['autoindex'] or $location['autoindex'] == 'on' {
250+
$autoindex = 'on'
251+
} else {
252+
$autoindex = 'off'
253+
}
254+
247255
# remove empty values
248256
$location_trimmed = merge({
249257
'fast_cgi_params_extra' => [],
250258
}, delete_values($location, ''))
251259

260+
# transforms user-data to expected
261+
$location_custom_data = merge($location_trimmed, {
262+
'autoindex' => $autoindex,
263+
})
264+
252265
# Takes gui ENV vars: fastcgi_param {ENV_NAME} {VALUE}
253266
$location_custom_cfg_append = prefix(
254-
$location_trimmed['fast_cgi_params_extra'],
267+
$location_custom_data['fast_cgi_params_extra'],
255268
'fastcgi_param '
256269
)
257270

258-
# separate from $location_trimmed because some values
271+
# separate from $location_custom_data because some values
259272
# really need to be set to a default.
260273
# Removes fast_cgi_params_extra because it only exists in gui
261274
# not puppet-nginx
262275
$location_no_root = delete(merge({
263276
'vhost' => $key,
264277
'ssl' => $ssl,
265278
'location_custom_cfg_append' => $location_custom_cfg_append,
266-
}, $location_trimmed), 'fast_cgi_params_extra')
279+
}, $location_custom_data), 'fast_cgi_params_extra')
267280

268281
# If www_root was removed with all the trimmings,
269282
# add it back it

src/Puphpet/MainBundle/Resources/config/nginx/available.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ empty_vhost:
3030

3131
empty_location:
3232
location: '/'
33+
autoindex: 0
3334
try_files: []
3435
fastcgi: ~
3536
fastcgi_index: ~

src/Puphpet/MainBundle/Resources/config/nginx/defaults.yml

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ vhosts:
3030
locations:
3131
-
3232
location: '/'
33+
autoindex: 0
3334
try_files:
3435
- '$uri'
3536
- '$uri/'
@@ -40,6 +41,7 @@ vhosts:
4041
fast_cgi_params_extra: []
4142
-
4243
location: '~ \.php$'
44+
autoindex: 0
4345
try_files:
4446
- '$uri'
4547
- '$uri/'

src/Puphpet/MainBundle/Resources/views/nginx/sections/location.html.twig

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% set uniqid = uniqid('nxvl_', true) %}
2+
{% set autoindex = (location.autoindex is defined and location.autoindex is sameas('on')) ? true : false %}
23
{% set try_files = (location.try_files is defined) ? location.try_files : [] %}
34
{% set fast_cgi_params_extras = (location.fast_cgi_params_extra is defined) ? location.fast_cgi_params_extra : [] %}
45

@@ -8,7 +9,7 @@
89
<fieldset>
910
<legend>Location</legend>
1011

11-
<div class="form-group col-xs-12">
12+
<div class="form-group col-xs-6">
1213
<div class="help-text">
1314
<a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#location"
1415
target="_blank">More information</a>.
@@ -20,6 +21,25 @@
2021
value="{{ location.location }}"/>
2122
</div>
2223

24+
<div class="form-group col-xs-6">
25+
<div class="clearfix"><label>autoindex</label></div>
26+
27+
<label class="radio-tile mini set-width">
28+
<span class="help-text">
29+
Enables directory listings.
30+
</span>
31+
<input type="hidden" name="nginx[vhosts][{{ vhostId }}][locations][{{ uniqid }}][autoindex]" value="off" />
32+
<input type="checkbox" name="nginx[vhosts][{{ vhostId }}][locations][{{ uniqid }}][autoindex]"
33+
class="invisible" {% if autoindex %}checked{% endif %} value="on" />
34+
<span class="content">
35+
<span class="header">
36+
<i class="icon"></i>
37+
<span class="title">Enable autoindex</span>
38+
</span>
39+
</span>
40+
</label>
41+
</div>
42+
2343
<div class="clearfix"></div>
2444

2545
<div class="form-group col-xs-12">

0 commit comments

Comments
 (0)