Skip to content

Commit 5b1f0ce

Browse files
committed
WIP: started adding new host type ssl passthrough
1 parent 85128f0 commit 5b1f0ce

35 files changed

+1743
-49
lines changed

backend/internal/host.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const _ = require('lodash');
2-
const proxyHostModel = require('../models/proxy_host');
3-
const redirectionHostModel = require('../models/redirection_host');
4-
const deadHostModel = require('../models/dead_host');
1+
const _ = require('lodash');
2+
const proxyHostModel = require('../models/proxy_host');
3+
const redirectionHostModel = require('../models/redirection_host');
4+
const deadHostModel = require('../models/dead_host');
5+
const sslPassthroughHostModel = require('../models/ssl_passthrough_host');
56

67
const internalHost = {
78

@@ -81,6 +82,9 @@ const internalHost = {
8182
.query()
8283
.where('is_deleted', 0),
8384
deadHostModel
85+
.query()
86+
.where('is_deleted', 0),
87+
sslPassthroughHostModel
8488
.query()
8589
.where('is_deleted', 0)
8690
];
@@ -112,6 +116,12 @@ const internalHost = {
112116
response_object.total_count += response_object.dead_hosts.length;
113117
}
114118

119+
if (promises_results[3]) {
120+
// 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;
123+
}
124+
115125
return response_object;
116126
});
117127
},
@@ -137,7 +147,11 @@ const internalHost = {
137147
deadHostModel
138148
.query()
139149
.where('is_deleted', 0)
140-
.andWhere('domain_names', 'like', '%' + hostname + '%')
150+
.andWhere('domain_names', 'like', '%' + hostname + '%'),
151+
sslPassthroughHostModel
152+
.query()
153+
.where('is_deleted', 0)
154+
.andWhere('domain_name', '=', hostname),
141155
];
142156

143157
return Promise.all(promises)
@@ -165,6 +179,13 @@ const internalHost = {
165179
}
166180
}
167181

182+
if (promises_results[3]) {
183+
// SSL Passthrough Hosts
184+
if (internalHost._checkHostnameRecordsTaken(hostname, promises_results[3], ignore_type === 'ssl_passthrough' && ignore_id ? ignore_id : 0)) {
185+
is_taken = true;
186+
}
187+
}
188+
168189
return {
169190
hostname: hostname,
170191
is_taken: is_taken

backend/internal/nginx.js

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +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 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;
89

910
const internalNginx = {
1011

@@ -44,12 +45,21 @@ const internalNginx = {
4445
nginx_err: null
4546
});
4647

48+
if(host_type === 'ssl_passthrough_host'){
49+
return passthroughHostModel
50+
.query()
51+
.patch({
52+
meta: combined_meta
53+
});
54+
}
55+
4756
return model
4857
.query()
4958
.where('id', host.id)
5059
.patch({
5160
meta: combined_meta
5261
});
62+
5363
})
5464
.catch((err) => {
5565
// Remove the error_log line because it's a docker-ism false positive that doesn't need to be reported.
@@ -125,6 +135,8 @@ const internalNginx = {
125135

126136
if (host_type === 'default') {
127137
return '/data/nginx/default_host/site.conf';
138+
} else if (host_type === 'ssl_passthrough_host') {
139+
return '/data/nginx/ssl_passthrough_host/hosts.conf';
128140
}
129141

130142
return '/data/nginx/' + host_type + '/' + host_id + '.conf';
@@ -199,7 +211,7 @@ const internalNginx = {
199211
root: __dirname + '/../templates/'
200212
});
201213

202-
return new Promise((resolve, reject) => {
214+
return new Promise(async (resolve, reject) => {
203215
let template = null;
204216
let filename = internalNginx.getConfigName(host_type, host.id);
205217

@@ -214,7 +226,25 @@ const internalNginx = {
214226
let origLocations;
215227

216228
// Manipulate the data a bit before sending it to the template
217-
if (host_type !== 'default') {
229+
if (host_type === 'ssl_passthrough_host') {
230+
if(internalNginx.sslPassthroughEnabled()){
231+
const allHosts = await passthroughHostModel
232+
.query()
233+
.where('is_deleted', 0)
234+
.groupBy('id')
235+
.omit(['is_deleted']);
236+
host = {
237+
all_passthrough_hosts: allHosts.map((host) => {
238+
// Replace dots in ___domain
239+
host.escaped_name = host.domain_name.replace(/\./, '_');
240+
host.forwarding_host = internalNginx.addIpv6Brackets(host.forwarding_host);
241+
}),
242+
}
243+
} else {
244+
internalNginx.deleteConfig(host_type, host)
245+
}
246+
247+
} else if (host_type !== 'default') {
218248
host.use_default_location = true;
219249
if (typeof host.advanced_config !== 'undefined' && host.advanced_config) {
220250
host.use_default_location = !internalNginx.advancedConfigHasDefaultLocation(host.advanced_config);
@@ -429,6 +459,33 @@ const internalNginx = {
429459
}
430460

431461
return true;
462+
},
463+
464+
/**
465+
* @returns {boolean}
466+
*/
467+
sslPassthroughEnabled: function () {
468+
if (typeof process.env.ENABLE_SSL_PASSTHROUGH !== 'undefined') {
469+
const enabled = process.env.ENABLE_SSL_PASSTHROUGH.toLowerCase();
470+
return (enabled === 'on' || enabled === 'true' || enabled === '1' || enabled === 'yes');
471+
}
472+
473+
return true;
474+
},
475+
476+
/**
477+
* Helper function to add brackets to an IP if it is IPv6
478+
* @returns {string}
479+
*/
480+
addIpv6Brackets: function (ip) {
481+
// Only run check if ipv6 is enabled
482+
if (internalNginx.ipv6Enabled()) {
483+
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;
484+
if(ipv6Regex.test(ip)){
485+
return `[${ip}]`
486+
}
487+
}
488+
return ip;
432489
}
433490
};
434491

0 commit comments

Comments
 (0)