Fixes eslint errors

This commit is contained in:
chaptergy 2021-10-12 15:42:22 +02:00
parent 02d3093d88
commit f650137c84
5 changed files with 112 additions and 115 deletions

View File

@ -34,7 +34,7 @@ const internalNginx = {
return internalNginx.deleteConfig(host_type, host); // Don't throw errors, as the file may not exist at all return internalNginx.deleteConfig(host_type, host); // Don't throw errors, as the file may not exist at all
}) })
.then(() => { .then(() => {
if(host_type === 'ssl_passthrough_host' && !sslPassthroughEnabled){ if (host_type === 'ssl_passthrough_host' && !sslPassthroughEnabled){
// ssl passthrough is disabled // ssl passthrough is disabled
const meta = { const meta = {
nginx_online: false, nginx_online: false,
@ -64,7 +64,7 @@ const internalNginx = {
nginx_err: null nginx_err: null
}); });
if(host_type === 'ssl_passthrough_host'){ if (host_type === 'ssl_passthrough_host'){
// If passthrough is disabled we have already marked the hosts as offline // If passthrough is disabled we have already marked the hosts as offline
if (sslPassthroughEnabled) { if (sslPassthroughEnabled) {
return passthroughHostModel return passthroughHostModel
@ -109,7 +109,7 @@ const internalNginx = {
nginx_err: valid_lines.join('\n') nginx_err: valid_lines.join('\n')
}); });
if(host_type === 'ssl_passthrough_host'){ if (host_type === 'ssl_passthrough_host'){
return passthroughHostModel return passthroughHostModel
.query() .query()
.where('is_deleted', 0) .where('is_deleted', 0)
@ -235,7 +235,7 @@ const internalNginx = {
* @param {Object} host * @param {Object} host
* @returns {Promise} * @returns {Promise}
*/ */
generateConfig: (host_type, host) => { generateConfig: async (host_type, host) => {
host_type = host_type.replace(new RegExp('-', 'g'), '_'); host_type = host_type.replace(new RegExp('-', 'g'), '_');
if (debug_mode) { if (debug_mode) {
@ -248,15 +248,13 @@ const internalNginx = {
root: __dirname + '/../templates/' root: __dirname + '/../templates/'
}); });
return new Promise(async (resolve, reject) => {
let template = null; let template = null;
let filename = internalNginx.getConfigName(host_type, host.id); let filename = internalNginx.getConfigName(host_type, host.id);
try { try {
template = fs.readFileSync(__dirname + '/../templates/' + host_type + '.conf', {encoding: 'utf8'}); template = fs.readFileSync(__dirname + '/../templates/' + host_type + '.conf', {encoding: 'utf8'});
} catch (err) { } catch (err) {
reject(new error.ConfigurationError(err.message)); throw new error.ConfigurationError(err.message);
return;
} }
let locationsPromise; let locationsPromise;
@ -264,7 +262,7 @@ const internalNginx = {
// Manipulate the data a bit before sending it to the template // Manipulate the data a bit before sending it to the template
if (host_type === 'ssl_passthrough_host') { if (host_type === 'ssl_passthrough_host') {
if(internalNginx.sslPassthroughEnabled()){ if (internalNginx.sslPassthroughEnabled()){
const allHosts = await passthroughHostModel const allHosts = await passthroughHostModel
.query() .query()
.where('is_deleted', 0) .where('is_deleted', 0)
@ -276,9 +274,9 @@ const internalNginx = {
host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host); host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host);
return host; return host;
}), }),
} };
} else { } else {
internalNginx.deleteConfig(host_type, host, false) internalNginx.deleteConfig(host_type, host, false);
} }
} else if (host_type !== 'default') { } else if (host_type !== 'default') {
@ -309,7 +307,7 @@ const internalNginx = {
// Set the IPv6 setting for the host // Set the IPv6 setting for the host
host.ipv6 = internalNginx.ipv6Enabled(); host.ipv6 = internalNginx.ipv6Enabled();
locationsPromise.then(() => { return locationsPromise.then(() => {
renderEngine renderEngine
.parseAndRender(template, host) .parseAndRender(template, host)
.then((config_text) => { .then((config_text) => {
@ -322,15 +320,14 @@ const internalNginx = {
// Restore locations array // Restore locations array
host.locations = origLocations; host.locations = origLocations;
resolve(true); return true;
}) })
.catch((err) => { .catch((err) => {
if (debug_mode) { if (debug_mode) {
logger.warn('Could not write ' + filename + ':', err.message); logger.warn('Could not write ' + filename + ':', err.message);
} }
reject(new error.ConfigurationError(err.message)); throw new error.ConfigurationError(err.message);
});
}); });
}); });
}, },
@ -518,8 +515,8 @@ const internalNginx = {
// Only run check if ipv6 is enabled // Only run check if ipv6 is enabled
if (internalNginx.ipv6Enabled()) { if (internalNginx.ipv6Enabled()) {
const ipv6Regex = /^(([0-9a-fA-F]{1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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;
if(ipv6Regex.test(ip)){ if (ipv6Regex.test(ip)){
return `[${ip}]` return `[${ip}]`;
} }
} }
return ip; return ip;

View File

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