Skip to content

Commit f650137

Browse files
committed
Fixes eslint errors
1 parent 02d3093 commit f650137

File tree

5 files changed

+107
-110
lines changed

5 files changed

+107
-110
lines changed

backend/internal/host.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ const internalHost = {
118118

119119
if (promises_results[3]) {
120120
// SSL Passthrough Hosts
121-
response_object.ssl_passthrough_hosts = internalHost._getHostsWithDomains(promises_results[3], domain_names);
122-
response_object.total_count += response_object.ssl_passthrough_hosts.length;
121+
response_object.ssl_passthrough_hosts = internalHost._getHostsWithDomains(promises_results[3], domain_names);
122+
response_object.total_count += response_object.ssl_passthrough_hosts.length;
123123
}
124124

125125
return response_object;

backend/internal/nginx.js

Lines changed: 85 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const _ = require('lodash');
2-
const fs = require('fs');
3-
const logger = require('../logger').nginx;
4-
const utils = require('../lib/utils');
5-
const error = require('../lib/error');
6-
const { Liquid } = require('liquidjs');
7-
const passthroughHostModel = require('../models/ssl_passthrough_host');
8-
const debug_mode = process.env.NODE_ENV !== 'production' || !!process.env.DEBUG;
1+
const _ = require('lodash');
2+
const fs = require('fs');
3+
const logger = require('../logger').nginx;
4+
const utils = require('../lib/utils');
5+
const error = require('../lib/error');
6+
const { Liquid } = require('liquidjs');
7+
const passthroughHostModel = require('../models/ssl_passthrough_host');
8+
const debug_mode = process.env.NODE_ENV !== 'production' || !!process.env.DEBUG;
99

1010
const internalNginx = {
1111

@@ -24,7 +24,7 @@ const internalNginx = {
2424
* @returns {Promise}
2525
*/
2626
configure: (model, host_type, host) => {
27-
let combined_meta = {};
27+
let combined_meta = {};
2828
const sslPassthroughEnabled = internalNginx.sslPassthroughEnabled();
2929

3030
return internalNginx.test()
@@ -34,7 +34,7 @@ const internalNginx = {
3434
return internalNginx.deleteConfig(host_type, host); // Don't throw errors, as the file may not exist at all
3535
})
3636
.then(() => {
37-
if(host_type === 'ssl_passthrough_host' && !sslPassthroughEnabled){
37+
if (host_type === 'ssl_passthrough_host' && !sslPassthroughEnabled){
3838
// ssl passthrough is disabled
3939
const meta = {
4040
nginx_online: false,
@@ -64,7 +64,7 @@ const internalNginx = {
6464
nginx_err: null
6565
});
6666

67-
if(host_type === 'ssl_passthrough_host'){
67+
if (host_type === 'ssl_passthrough_host'){
6868
// If passthrough is disabled we have already marked the hosts as offline
6969
if (sslPassthroughEnabled) {
7070
return passthroughHostModel
@@ -109,7 +109,7 @@ const internalNginx = {
109109
nginx_err: valid_lines.join('\n')
110110
});
111111

112-
if(host_type === 'ssl_passthrough_host'){
112+
if (host_type === 'ssl_passthrough_host'){
113113
return passthroughHostModel
114114
.query()
115115
.where('is_deleted', 0)
@@ -235,7 +235,7 @@ const internalNginx = {
235235
* @param {Object} host
236236
* @returns {Promise}
237237
*/
238-
generateConfig: (host_type, host) => {
238+
generateConfig: async (host_type, host) => {
239239
host_type = host_type.replace(new RegExp('-', 'g'), '_');
240240

241241
if (debug_mode) {
@@ -248,90 +248,87 @@ const internalNginx = {
248248
root: __dirname + '/../templates/'
249249
});
250250

251-
return new Promise(async (resolve, reject) => {
252-
let template = null;
253-
let filename = internalNginx.getConfigName(host_type, host.id);
254-
255-
try {
256-
template = fs.readFileSync(__dirname + '/../templates/' + host_type + '.conf', {encoding: 'utf8'});
257-
} catch (err) {
258-
reject(new error.ConfigurationError(err.message));
259-
return;
260-
}
251+
let template = null;
252+
let filename = internalNginx.getConfigName(host_type, host.id);
261253

262-
let locationsPromise;
263-
let origLocations;
254+
try {
255+
template = fs.readFileSync(__dirname + '/../templates/' + host_type + '.conf', {encoding: 'utf8'});
256+
} catch (err) {
257+
throw new error.ConfigurationError(err.message);
258+
}
264259

265-
// Manipulate the data a bit before sending it to the template
266-
if (host_type === 'ssl_passthrough_host') {
267-
if(internalNginx.sslPassthroughEnabled()){
268-
const allHosts = await passthroughHostModel
269-
.query()
270-
.where('is_deleted', 0)
271-
.groupBy('id')
272-
.omit(['is_deleted']);
273-
host = {
274-
all_passthrough_hosts: allHosts.map((host) => {
275-
// Replace dots in ___domain
276-
host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host);
277-
return host;
278-
}),
279-
}
280-
} else {
281-
internalNginx.deleteConfig(host_type, host, false)
282-
}
283-
284-
} else if (host_type !== 'default') {
285-
host.use_default_location = true;
286-
if (typeof host.advanced_config !== 'undefined' && host.advanced_config) {
287-
host.use_default_location = !internalNginx.advancedConfigHasDefaultLocation(host.advanced_config);
288-
}
260+
let locationsPromise;
261+
let origLocations;
262+
263+
// Manipulate the data a bit before sending it to the template
264+
if (host_type === 'ssl_passthrough_host') {
265+
if (internalNginx.sslPassthroughEnabled()){
266+
const allHosts = await passthroughHostModel
267+
.query()
268+
.where('is_deleted', 0)
269+
.groupBy('id')
270+
.omit(['is_deleted']);
271+
host = {
272+
all_passthrough_hosts: allHosts.map((host) => {
273+
// Replace dots in ___domain
274+
host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host);
275+
return host;
276+
}),
277+
};
278+
} else {
279+
internalNginx.deleteConfig(host_type, host, false);
289280
}
281+
282+
} else if (host_type !== 'default') {
283+
host.use_default_location = true;
284+
if (typeof host.advanced_config !== 'undefined' && host.advanced_config) {
285+
host.use_default_location = !internalNginx.advancedConfigHasDefaultLocation(host.advanced_config);
286+
}
287+
}
290288

291-
if (host.locations) {
292-
//logger.info ('host.locations = ' + JSON.stringify(host.locations, null, 2));
293-
origLocations = [].concat(host.locations);
294-
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
295-
host.locations = renderedLocations;
296-
});
289+
if (host.locations) {
290+
//logger.info ('host.locations = ' + JSON.stringify(host.locations, null, 2));
291+
origLocations = [].concat(host.locations);
292+
locationsPromise = internalNginx.renderLocations(host).then((renderedLocations) => {
293+
host.locations = renderedLocations;
294+
});
297295

298-
// Allow someone who is using / custom ___location path to use it, and skip the default / ___location
299-
_.map(host.locations, (___location) => {
300-
if (___location.path === '/') {
301-
host.use_default_location = false;
302-
}
303-
});
296+
// Allow someone who is using / custom ___location path to use it, and skip the default / ___location
297+
_.map(host.locations, (___location) => {
298+
if (___location.path === '/') {
299+
host.use_default_location = false;
300+
}
301+
});
304302

305-
} else {
306-
locationsPromise = Promise.resolve();
307-
}
303+
} else {
304+
locationsPromise = Promise.resolve();
305+
}
308306

309-
// Set the IPv6 setting for the host
310-
host.ipv6 = internalNginx.ipv6Enabled();
307+
// Set the IPv6 setting for the host
308+
host.ipv6 = internalNginx.ipv6Enabled();
311309

312-
locationsPromise.then(() => {
313-
renderEngine
314-
.parseAndRender(template, host)
315-
.then((config_text) => {
316-
fs.writeFileSync(filename, config_text, {encoding: 'utf8'});
310+
return locationsPromise.then(() => {
311+
renderEngine
312+
.parseAndRender(template, host)
313+
.then((config_text) => {
314+
fs.writeFileSync(filename, config_text, {encoding: 'utf8'});
317315

318-
if (debug_mode) {
319-
logger.success('Wrote config:', filename, config_text);
320-
}
316+
if (debug_mode) {
317+
logger.success('Wrote config:', filename, config_text);
318+
}
321319

322-
// Restore locations array
323-
host.locations = origLocations;
320+
// Restore locations array
321+
host.locations = origLocations;
324322

325-
resolve(true);
326-
})
327-
.catch((err) => {
328-
if (debug_mode) {
329-
logger.warn('Could not write ' + filename + ':', err.message);
330-
}
323+
return true;
324+
})
325+
.catch((err) => {
326+
if (debug_mode) {
327+
logger.warn('Could not write ' + filename + ':', err.message);
328+
}
331329

332-
reject(new error.ConfigurationError(err.message));
333-
});
334-
});
330+
throw new error.ConfigurationError(err.message);
331+
});
335332
});
336333
},
337334

@@ -514,12 +511,12 @@ const internalNginx = {
514511
* Helper function to add brackets to an IP if it is IPv6
515512
* @returns {string}
516513
*/
517-
addIpv6Brackets: function (ip) {
514+
addIpv6Brackets: function (ip) {
518515
// Only run check if ipv6 is enabled
519516
if (internalNginx.ipv6Enabled()) {
520517
const ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/gi;
521-
if(ipv6Regex.test(ip)){
522-
return `[${ip}]`
518+
if (ipv6Regex.test(ip)){
519+
return `[${ip}]`;
523520
}
524521
}
525522
return ip;

backend/migrations/20211010141200_ssl_passthrough_host.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ exports.up = function (knex/*, Promise*/) {
2727
}).then(() => {
2828
logger.info('[' + migrate_name + '] Table created');
2929
})
30-
.then(() => {
31-
return knex.schema.table('user_permission', (table) => {
32-
table.string('ssl_passthrough_hosts').notNull();
33-
})
34-
.then(() => {
35-
return knex('user_permission').update('ssl_passthrough_hosts', knex.ref('streams'));
36-
})
37-
.then(() => {
38-
return knex.schema.alterTable('user_permission', (table) => {
39-
table.string('ssl_passthrough_hosts').notNullable().alter();
40-
});
41-
})
42-
.then(() => {
43-
logger.info('[' + migrate_name + '] permissions updated');
44-
});
45-
})
46-
;
30+
.then(() => {
31+
return knex.schema.table('user_permission', (table) => {
32+
table.string('ssl_passthrough_hosts').notNull();
33+
})
34+
.then(() => {
35+
return knex('user_permission').update('ssl_passthrough_hosts', knex.ref('streams'));
36+
})
37+
.then(() => {
38+
return knex.schema.alterTable('user_permission', (table) => {
39+
table.string('ssl_passthrough_hosts').notNullable().alter();
40+
});
41+
})
42+
.then(() => {
43+
logger.info('[' + migrate_name + '] permissions updated');
44+
});
45+
})
46+
;
4747
};
4848

4949
/**
@@ -59,7 +59,7 @@ exports.down = function (knex/*, Promise*/) {
5959
return knex.schema.dropTable('stream').then(() => {
6060
return knex.schema.table('user_permission', (table) => {
6161
table.dropColumn('ssl_passthrough_hosts');
62-
})
62+
});
6363
})
6464
.then(function () {
6565
logger.info('[' + migrate_name + '] Table altered and permissions updated');

backend/routes/api/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ router.use('/nginx/certificates', require('./nginx/certificates'));
4242

4343
router.get('/ssl-passthrough-enabled', (req, res/*, next*/) => {
4444
res.status(200).send({
45-
status: 'OK',
45+
status: 'OK',
4646
ssl_passthrough_enabled: internalNginx.sslPassthroughEnabled()
4747
});
4848
});

backend/routes/api/nginx/ssl_passthrough_hosts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ router
9898
}
9999
}, {
100100
host_id: req.params.host_id,
101-
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
101+
expand: (typeof req.query.expand === 'string' ? req.query.expand.split(',') : null)
102102
})
103103
.then((data) => {
104104
return internalSslPassthrough.get(res.locals.access, {

0 commit comments

Comments
 (0)