Skip to content

Commit 5a3d32d

Browse files
lopugitJamie Curnow
authored andcommitted
Frontend form and marionette modifications to allow static hosts and locations
1 parent 8de118d commit 5a3d32d

File tree

8 files changed

+107
-26
lines changed

8 files changed

+107
-26
lines changed

frontend/js/app/nginx/proxy/form.ejs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</div>
3636
<div class="col-sm-3 col-md-3">
3737
<div class="form-group">
38-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %><span class="form-required">*</span></label>
38+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %></label>
3939
<select name="forward_scheme" class="form-control custom-select" placeholder="http">
4040
<option value="http" <%- forward_scheme === 'http' ? 'selected' : '' %>>http</option>
4141
<option value="https" <%- forward_scheme === 'https' ? 'selected' : '' %>>https</option>
@@ -44,14 +44,26 @@
4444
</div>
4545
<div class="col-sm-5 col-md-5">
4646
<div class="form-group">
47-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><span class="form-required">*</span></label>
48-
<input type="text" name="forward_host" class="form-control text-monospace" placeholder="" value="<%- forward_host %>" autocomplete="off" maxlength="255" required>
47+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><% if (!static) { %> <span class="form-required">*</span><% } %></label>
48+
<input type="text" name="forward_host" class="form-control text-monospace" placeholder="" value="<%- forward_host %>" <%- !static ? 'required' : '' %> autocomplete="off" maxlength="255">
4949
</div>
5050
</div>
5151
<div class="col-sm-4 col-md-4">
5252
<div class="form-group">
53-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %> <span class="form-required">*</span></label>
54-
<input name="forward_port" type="number" class="form-control text-monospace" placeholder="80" value="<%- forward_port %>" required>
53+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %><% if (!static) { %> <span class="form-required">*</span><% } %> </label>
54+
<input name="forward_port" type="number" class="form-control text-monospace" placeholder="80" value="<%- forward_port %>" <%- !static ? 'required' : '' %>>
55+
</div>
56+
</div>
57+
<div class="col-sm-5 col-md-5">
58+
<div class="form-group">
59+
<label class="form-label"><%- i18n('proxy-hosts', 'root-dir') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
60+
<input type="text" name="root_dir" class="form-control text-monospace" placeholder="" value="<%- root_dir %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="255">
61+
</div>
62+
</div>
63+
<div class="col-sm-5 col-md-5">
64+
<div class="form-group">
65+
<label class="form-label"><%- i18n('proxy-hosts', 'index-file') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
66+
<input type="text" name="index_file" class="form-control text-monospace" placeholder="" value="<%- index_file %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="255">
5567
</div>
5668
</div>
5769
<div class="col-sm-6 col-md-6">
@@ -81,6 +93,15 @@
8193
</label>
8294
</div>
8395
</div>
96+
<div class="col-sm-12 col-md-12">
97+
<div class="form-group">
98+
<label class="custom-switch">
99+
<input type="checkbox" class="custom-switch-input static-checkbox" name="static" value="1"<%- static ? ' checked' : '' %>>
100+
<span class="custom-switch-indicator"></span>
101+
<span class="custom-switch-description"><%- i18n('proxy-hosts', 'static') %></span>
102+
</label>
103+
</div>
104+
</div>
84105

85106
<div class="col-sm-12 col-md-12">
86107
<div class="form-group">

frontend/js/app/nginx/proxy/form.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ module.exports = Mn.View.extend({
4343
dns_provider_credentials: 'textarea[name="meta[dns_provider_credentials]"]',
4444
propagation_seconds: 'input[name="meta[propagation_seconds]"]',
4545
forward_scheme: 'select[name="forward_scheme"]',
46-
letsencrypt: '.letsencrypt'
46+
letsencrypt: '.letsencrypt',
47+
root_dir: 'input[name="root_dir"]',
48+
index_file: 'input[name="index_file"]',
49+
static: 'input[type="checkbox"].static-checkbox',
4750
},
4851

4952
regions: {
@@ -113,7 +116,7 @@ module.exports = Mn.View.extend({
113116
} else {
114117
this.ui.dns_provider.prop('required', false);
115118
this.ui.dns_provider_credentials.prop('required', false);
116-
this.ui.dns_challenge_content.hide();
119+
this.ui.dns_challenge_content.hide();
117120
}
118121
},
119122

@@ -125,17 +128,26 @@ module.exports = Mn.View.extend({
125128
this.ui.credentials_file_content.show();
126129
} else {
127130
this.ui.dns_provider_credentials.prop('required', false);
128-
this.ui.credentials_file_content.hide();
131+
this.ui.credentials_file_content.hide();
129132
}
130133
},
131134

132135
'click @ui.add_location_btn': function (e) {
133136
e.preventDefault();
134-
137+
135138
const model = new ProxyLocationModel.Model();
136139
this.locationsCollection.add(model);
137140
},
138141

142+
'click @ui.static': function(e){
143+
const map = {};
144+
let value = e.target.value
145+
if(e.target.type == 'checkbox') value = e.target.checked;
146+
map[e.target.name] = value;
147+
this.model.set(map);
148+
setTimeout(this.render.bind(this), 300)
149+
},
150+
139151
'click @ui.save': function (e) {
140152
e.preventDefault();
141153
this.ui.le_error_info.hide();
@@ -167,25 +179,26 @@ module.exports = Mn.View.extend({
167179
data.hsts_enabled = !!data.hsts_enabled;
168180
data.hsts_subdomains = !!data.hsts_subdomains;
169181
data.ssl_forced = !!data.ssl_forced;
170-
182+
data.static = !!data.static;
183+
171184
if (typeof data.meta === 'undefined') data.meta = {};
172185
data.meta.letsencrypt_agree = data.meta.letsencrypt_agree == 1;
173186
data.meta.dns_challenge = data.meta.dns_challenge == 1;
174-
187+
175188
if(!data.meta.dns_challenge){
176189
data.meta.dns_provider = undefined;
177190
data.meta.dns_provider_credentials = undefined;
178191
data.meta.propagation_seconds = undefined;
179192
} else {
180-
if(data.meta.propagation_seconds === '') data.meta.propagation_seconds = undefined;
193+
if(data.meta.propagation_seconds === '') data.meta.propagation_seconds = undefined;
181194
}
182195

183196
if (typeof data.domain_names === 'string' && data.domain_names) {
184197
data.domain_names = data.domain_names.split(',');
185198
}
186199

187200
// Check for any domain names containing wildcards, which are not allowed with letsencrypt
188-
if (data.certificate_id === 'new') {
201+
if (data.certificate_id === 'new') {
189202
let domain_err = false;
190203
if (!data.meta.dns_challenge) {
191204
data.domain_names.map(function (name) {

frontend/js/app/nginx/proxy/list/item.ejs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@
2323
</div>
2424
</td>
2525
<td>
26-
<div class="text-monospace"><%- forward_scheme %>://<%- forward_host %>:<%- forward_port %></div>
26+
<!-- <div> <%- static %> </div> -->
27+
<% if (!static) { %>
28+
<div class="text-monospace"><%- forward_scheme %>://<%- forward_host %>:<%- forward_port %></div>
29+
<% } else { %>
30+
<div class="text-monospace"><%- root_dir %></div>
31+
<div class="text-monospace"><%- index_file %></div>
32+
<% } %>
2733
</td>
2834
<td>
2935
<div><%- certificate && certificate_id ? i18n('ssl', certificate.provider) : i18n('ssl', 'none') %></div>

frontend/js/app/nginx/proxy/location-item.ejs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<div class="col-auto">
1717
<div class="selectgroup">
1818
<label class="selectgroup-item">
19-
<input type="checkbox" class="selectgroup-input">
19+
<input type="checkbox" class="selectgroup-input settings-checkbox">
2020
<span class="selectgroup-button">
2121
<i class="fe fe-settings"></i>
2222
</span>
@@ -28,7 +28,7 @@
2828
</div>
2929
<div class="col-sm-3 col-md-3">
3030
<div class="form-group">
31-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %><span class="form-required">*</span></label>
31+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-scheme') %></label>
3232
<select name="forward_scheme" class="form-control custom-select model" placeholder="http">
3333
<option value="http" <%- forward_scheme === 'http' ? 'selected' : '' %>>http</option>
3434
<option value="https" <%- forward_scheme === 'https' ? 'selected' : '' %>>https</option>
@@ -37,17 +37,38 @@
3737
</div>
3838
<div class="col-sm-5 col-md-5">
3939
<div class="form-group">
40-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %><span class="form-required">*</span></label>
41-
<input type="text" name="forward_host" class="form-control text-monospace model" placeholder="" value="<%- forward_host %>" autocomplete="off" maxlength="200" required>
40+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-host') %> <% if (!static) { %> <span class="form-required">*</span> <% } %> </label>
41+
<input type="text" name="forward_host" class="form-control text-monospace model" placeholder="" value="<%- forward_host %>" <%- !static ? 'checked' : '' %> autocomplete="off" maxlength="200">
4242
<span style="font-size: 9px;"><%- i18n('proxy-hosts', 'custom-forward-host-help') %></span>
4343
</div>
4444
</div>
4545
<div class="col-sm-4 col-md-4">
4646
<div class="form-group">
47-
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %> <span class="form-required">*</span></label>
48-
<input name="forward_port" type="number" class="form-control text-monospace model" placeholder="80" value="<%- forward_port %>" required>
47+
<label class="form-label"><%- i18n('proxy-hosts', 'forward-port') %> <% if (!static) { %> <span class="form-required">*</span><% } %> </label>
48+
<input name="forward_port" type="number" class="form-control text-monospace model" placeholder="80" value="<%- forward_port %>" <%- !static ? 'checked' : '' %> >
4949
</div>
5050
</div>
51+
<div class="col-sm-5 col-md-5">
52+
<div class="form-group">
53+
<label class="form-label"><%- i18n('proxy-hosts', 'root-dir') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
54+
<input type="text" name="root_dir" class="form-control text-monospace model" placeholder="" value="<%- root_dir %>" <%- static ? 'required' : '' %> autocomplete="off" maxlength="200">
55+
</div>
56+
</div>
57+
<div class="col-sm-5 col-md-5">
58+
<div class="form-group">
59+
<label class="form-label"><%- i18n('proxy-hosts', 'index-file') %><% if (static) { %> <span class="form-required">*</span><% } %></label>
60+
<input type="text" name="index_file" class="form-control text-monospace model" placeholder="" value="<%- index_file %>" <%- static ? 'required' : false %> autocomplete="off" maxlength="200">
61+
</div>
62+
</div>
63+
<div class="col-sm-12 col-md-12">
64+
<div class="form-group">
65+
<label class="custom-switch">
66+
<input type="checkbox" class="custom-switch-input location-static-checkbox model" name="static" value="1"<%- static ? ' checked' : '' %> >
67+
<span class="custom-switch-indicator"></span>
68+
<span class="custom-switch-description"><%- i18n('proxy-hosts', 'static') %></span>
69+
</label>
70+
</div>
71+
</div>
5172
</div>
5273
<div class="row config">
5374
<div class="col-md-12">

frontend/js/app/nginx/proxy/location.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ const LocationView = Mn.View.extend({
77
className: 'location_block',
88

99
ui: {
10-
toggle: 'input[type="checkbox"]',
10+
settings: 'input[type="checkbox"].settings-checkbox',
11+
static: 'input[type="checkbox"].location-static-checkbox',
1112
config: '.config',
1213
delete: '.location-delete'
1314
},
1415

1516
events: {
16-
'change @ui.toggle': function(el) {
17+
18+
'change @ui.settings': function(el) {
1719
if (el.target.checked) {
1820
this.ui.config.show();
1921
} else {
@@ -22,11 +24,20 @@ const LocationView = Mn.View.extend({
2224
},
2325

2426
'change .model': function (e) {
27+
2528
const map = {};
26-
map[e.target.name] = e.target.value;
29+
30+
let value = e.target.value
31+
if(e.target.type == 'checkbox') value = e.target.checked ? 1 : 0
32+
map[e.target.name] = value
2733
this.model.set(map);
34+
35+
setTimeout(this.render.bind(this), 300)
36+
2837
},
2938

39+
// 'click @ui.static': 'render',
40+
3041
'click @ui.delete': function () {
3142
this.model.destroy();
3243
}

frontend/js/i18n/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
"forward-scheme": "Scheme",
124124
"forward-host": "Forward Hostname / IP",
125125
"forward-port": "Forward Port",
126+
"root-dir": "Root Directory",
127+
"static": "Static File Proxy",
128+
"index-file": "Index File",
126129
"delete": "Delete Proxy Host",
127130
"delete-confirm": "Are you sure you want to delete the Proxy host for: <strong>{domains}</strong>?",
128131
"help-title": "What is a Proxy Host?",

frontend/js/models/proxy-host-location.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ const model = Backbone.Model.extend({
99
path: '',
1010
advanced_config: '',
1111
forward_scheme: 'http',
12-
forward_host: '',
13-
forward_port: '80'
12+
forward_host: null,
13+
forward_port: '80',
14+
root_dir: null,
15+
static: false,
16+
index_file: 'index.html',
1417
}
1518
},
1619

frontend/js/models/proxy-host.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ const model = Backbone.Model.extend({
1010
modified_on: null,
1111
domain_names: [],
1212
forward_scheme: 'http',
13-
forward_host: '',
13+
forward_host: null,
1414
forward_port: null,
15+
root_dir: null,
16+
static: false,
17+
index_file: 'index.html',
1518
access_list_id: 0,
1619
certificate_id: 0,
1720
ssl_forced: false,

0 commit comments

Comments
 (0)