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 ;
8
9
9
10
const internalNginx = {
10
11
@@ -44,12 +45,21 @@ const internalNginx = {
44
45
nginx_err : null
45
46
} ) ;
46
47
48
+ if ( host_type === 'ssl_passthrough_host' ) {
49
+ return passthroughHostModel
50
+ . query ( )
51
+ . patch ( {
52
+ meta : combined_meta
53
+ } ) ;
54
+ }
55
+
47
56
return model
48
57
. query ( )
49
58
. where ( 'id' , host . id )
50
59
. patch ( {
51
60
meta : combined_meta
52
61
} ) ;
62
+
53
63
} )
54
64
. catch ( ( err ) => {
55
65
// 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 = {
125
135
126
136
if ( host_type === 'default' ) {
127
137
return '/data/nginx/default_host/site.conf' ;
138
+ } else if ( host_type === 'ssl_passthrough_host' ) {
139
+ return '/data/nginx/ssl_passthrough_host/hosts.conf' ;
128
140
}
129
141
130
142
return '/data/nginx/' + host_type + '/' + host_id + '.conf' ;
@@ -199,7 +211,7 @@ const internalNginx = {
199
211
root : __dirname + '/../templates/'
200
212
} ) ;
201
213
202
- return new Promise ( ( resolve , reject ) => {
214
+ return new Promise ( async ( resolve , reject ) => {
203
215
let template = null ;
204
216
let filename = internalNginx . getConfigName ( host_type , host . id ) ;
205
217
@@ -214,7 +226,25 @@ const internalNginx = {
214
226
let origLocations ;
215
227
216
228
// 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' ) {
218
248
host . use_default_location = true ;
219
249
if ( typeof host . advanced_config !== 'undefined' && host . advanced_config ) {
220
250
host . use_default_location = ! internalNginx . advancedConfigHasDefaultLocation ( host . advanced_config ) ;
@@ -429,6 +459,33 @@ const internalNginx = {
429
459
}
430
460
431
461
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 - 9 a - f A - F ] { 1 , 4 } : ) { 7 , 7 } [ 0 - 9 a - f A - F ] { 1 , 4 } | ( [ 0 - 9 a - f A - F ] { 1 , 4 } : ) { 1 , 7 } : | ( [ 0 - 9 a - f A - F ] { 1 , 4 } : ) { 1 , 6 } : [ 0 - 9 a - f A - F ] { 1 , 4 } | ( [ 0 - 9 a - f A - F ] { 1 , 4 } : ) { 1 , 5 } ( : [ 0 - 9 a - f A - F ] { 1 , 4 } ) { 1 , 2 } | ( [ 0 - 9 a - f A - F ] { 1 , 4 } : ) { 1 , 4 } ( : [ 0 - 9 a - f A - F ] { 1 , 4 } ) { 1 , 3 } | ( [ 0 - 9 a - f A - F ] { 1 , 4 } : ) { 1 , 3 } ( : [ 0 - 9 a - f A - F ] { 1 , 4 } ) { 1 , 4 } | ( [ 0 - 9 a - f A - F ] { 1 , 4 } : ) { 1 , 2 } ( : [ 0 - 9 a - f A - F ] { 1 , 4 } ) { 1 , 5 } | [ 0 - 9 a - f A - F ] { 1 , 4 } : ( ( : [ 0 - 9 a - f A - F ] { 1 , 4 } ) { 1 , 6 } ) | : ( ( : [ 0 - 9 a - f A - F ] { 1 , 4 } ) { 1 , 7 } | : ) | f e 8 0 : ( : [ 0 - 9 a - f A - F ] { 0 , 4 } ) { 0 , 4 } % [ 0 - 9 a - z A - Z ] { 1 , } | : : ( f f f f ( : 0 { 1 , 4 } ) { 0 , 1 } : ) { 0 , 1 } ( ( 2 5 [ 0 - 5 ] | ( 2 [ 0 - 4 ] | 1 { 0 , 1 } [ 0 - 9 ] ) { 0 , 1 } [ 0 - 9 ] ) \. ) { 3 , 3 } ( 2 5 [ 0 - 5 ] | ( 2 [ 0 - 4 ] | 1 { 0 , 1 } [ 0 - 9 ] ) { 0 , 1 } [ 0 - 9 ] ) | ( [ 0 - 9 a - f A - F ] { 1 , 4 } : ) { 1 , 4 } : ( ( 2 5 [ 0 - 5 ] | ( 2 [ 0 - 4 ] | 1 { 0 , 1 } [ 0 - 9 ] ) { 0 , 1 } [ 0 - 9 ] ) \. ) { 3 , 3 } ( 2 5 [ 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 ;
432
489
}
433
490
} ;
434
491
0 commit comments