1
1
const _ = require ( 'lodash' ) ;
2
- const fs = require ( 'fs' ) ;
2
+ const fs = require ( 'node: fs' ) ;
3
3
const batchflow = require ( 'batchflow' ) ;
4
4
const logger = require ( '../logger' ) . access ;
5
5
const error = require ( '../lib/error' ) ;
@@ -38,7 +38,7 @@ const internalAccessList = {
38
38
. then ( ( row ) => {
39
39
data . id = row . id ;
40
40
41
- let promises = [ ] ;
41
+ const promises = [ ] ;
42
42
43
43
// Now add the items
44
44
data . items . map ( ( item ) => {
@@ -116,7 +116,7 @@ const internalAccessList = {
116
116
. then ( ( row ) => {
117
117
if ( row . id !== data . id ) {
118
118
// Sanity check that something crazy hasn't happened
119
- throw new error . InternalValidationError ( ' Access List could not be updated, IDs do not match: ' + row . id + ' !== ' + data . id ) ;
119
+ throw new error . InternalValidationError ( ` Access List could not be updated, IDs do not match: ${ row . id } !== ${ data . id } ` ) ;
120
120
}
121
121
} )
122
122
. then ( ( ) => {
@@ -135,10 +135,10 @@ const internalAccessList = {
135
135
. then ( ( ) => {
136
136
// Check for items and add/update/remove them
137
137
if ( typeof data . items !== 'undefined' && data . items ) {
138
- let promises = [ ] ;
139
- let items_to_keep = [ ] ;
138
+ const promises = [ ] ;
139
+ const items_to_keep = [ ] ;
140
140
141
- data . items . map ( function ( item ) {
141
+ data . items . map ( ( item ) => {
142
142
if ( item . password ) {
143
143
promises . push ( accessListAuthModel
144
144
. query ( )
@@ -154,7 +154,7 @@ const internalAccessList = {
154
154
}
155
155
} ) ;
156
156
157
- let query = accessListAuthModel
157
+ const query = accessListAuthModel
158
158
. query ( )
159
159
. delete ( )
160
160
. where ( 'access_list_id' , data . id ) ;
@@ -175,9 +175,9 @@ const internalAccessList = {
175
175
. then ( ( ) => {
176
176
// Check for clients and add/update/remove them
177
177
if ( typeof data . clients !== 'undefined' && data . clients ) {
178
- let promises = [ ] ;
178
+ const promises = [ ] ;
179
179
180
- data . clients . map ( function ( client ) {
180
+ data . clients . map ( ( client ) => {
181
181
if ( client . address ) {
182
182
promises . push ( accessListClientModel
183
183
. query ( )
@@ -190,7 +190,7 @@ const internalAccessList = {
190
190
}
191
191
} ) ;
192
192
193
- let query = accessListClientModel
193
+ const query = accessListClientModel
194
194
. query ( )
195
195
. delete ( )
196
196
. where ( 'access_list_id' , data . id ) ;
@@ -249,7 +249,7 @@ const internalAccessList = {
249
249
250
250
return access . can ( 'access_lists:get' , data . id )
251
251
. then ( ( access_data ) => {
252
- let query = accessListModel
252
+ const query = accessListModel
253
253
. query ( )
254
254
. select ( 'access_list.*' , accessListModel . raw ( 'COUNT(proxy_host.id) as proxy_host_count' ) )
255
255
. leftJoin ( 'proxy_host' , function ( ) {
@@ -267,7 +267,7 @@ const internalAccessList = {
267
267
}
268
268
269
269
if ( typeof data . expand !== 'undefined' && data . expand !== null ) {
270
- query . withGraphFetched ( '[' + data . expand . join ( ', ' ) + ']' ) ;
270
+ query . withGraphFetched ( `[ ${ data . expand . join ( ', ' ) } ]` ) ;
271
271
}
272
272
273
273
return query . then ( utils . omitRow ( omissions ( ) ) ) ;
@@ -327,7 +327,7 @@ const internalAccessList = {
327
327
// 3. reconfigure those hosts, then reload nginx
328
328
329
329
// set the access_list_id to zero for these items
330
- row . proxy_hosts . map ( function ( val , idx ) {
330
+ row . proxy_hosts . map ( ( _val , idx ) => {
331
331
row . proxy_hosts [ idx ] . access_list_id = 0 ;
332
332
} ) ;
333
333
@@ -340,11 +340,11 @@ const internalAccessList = {
340
340
} )
341
341
. then ( ( ) => {
342
342
// delete the htpasswd file
343
- let htpasswd_file = internalAccessList . getFilename ( row ) ;
343
+ const htpasswd_file = internalAccessList . getFilename ( row ) ;
344
344
345
345
try {
346
346
fs . unlinkSync ( htpasswd_file ) ;
347
- } catch ( err ) {
347
+ } catch ( _err ) {
348
348
// do nothing
349
349
}
350
350
} )
@@ -374,7 +374,7 @@ const internalAccessList = {
374
374
getAll : ( access , expand , search_query ) => {
375
375
return access . can ( 'access_lists:list' )
376
376
. then ( ( access_data ) => {
377
- let query = accessListModel
377
+ const query = accessListModel
378
378
. query ( )
379
379
. select ( 'access_list.*' , accessListModel . raw ( 'COUNT(proxy_host.id) as proxy_host_count' ) )
380
380
. leftJoin ( 'proxy_host' , function ( ) {
@@ -393,19 +393,19 @@ const internalAccessList = {
393
393
// Query is used for searching
394
394
if ( typeof search_query === 'string' ) {
395
395
query . where ( function ( ) {
396
- this . where ( 'name' , 'like' , '%' + search_query + '%' ) ;
396
+ this . where ( 'name' , 'like' , `% ${ search_query } %` ) ;
397
397
} ) ;
398
398
}
399
399
400
400
if ( typeof expand !== 'undefined' && expand !== null ) {
401
- query . withGraphFetched ( '[' + expand . join ( ', ' ) + ']' ) ;
401
+ query . withGraphFetched ( `[ ${ expand . join ( ', ' ) } ]` ) ;
402
402
}
403
403
404
404
return query . then ( utils . omitRows ( omissions ( ) ) ) ;
405
405
} )
406
406
. then ( ( rows ) => {
407
407
if ( rows ) {
408
- rows . map ( function ( row , idx ) {
408
+ rows . map ( ( row , idx ) => {
409
409
if ( typeof row . items !== 'undefined' && row . items ) {
410
410
rows [ idx ] = internalAccessList . maskItems ( row ) ;
411
411
}
@@ -424,7 +424,7 @@ const internalAccessList = {
424
424
* @returns {Promise }
425
425
*/
426
426
getCount : ( user_id , visibility ) => {
427
- let query = accessListModel
427
+ const query = accessListModel
428
428
. query ( )
429
429
. count ( 'id as count' )
430
430
. where ( 'is_deleted' , 0 ) ;
@@ -445,7 +445,7 @@ const internalAccessList = {
445
445
*/
446
446
maskItems : ( list ) => {
447
447
if ( list && typeof list . items !== 'undefined' ) {
448
- list . items . map ( function ( val , idx ) {
448
+ list . items . map ( ( val , idx ) => {
449
449
let repeat_for = 8 ;
450
450
let first_char = '*' ;
451
451
@@ -468,7 +468,7 @@ const internalAccessList = {
468
468
* @returns {String }
469
469
*/
470
470
getFilename : ( list ) => {
471
- return ' /data/access/' + list . id ;
471
+ return ` /data/access/${ list . id } ` ;
472
472
} ,
473
473
474
474
/**
@@ -479,15 +479,15 @@ const internalAccessList = {
479
479
* @returns {Promise }
480
480
*/
481
481
build : ( list ) => {
482
- logger . info ( ' Building Access file #' + list . id + ' for: ' + list . name ) ;
482
+ logger . info ( ` Building Access file #${ list . id } for: ${ list . name } ` ) ;
483
483
484
484
return new Promise ( ( resolve , reject ) => {
485
- let htpasswd_file = internalAccessList . getFilename ( list ) ;
485
+ const htpasswd_file = internalAccessList . getFilename ( list ) ;
486
486
487
487
// 1. remove any existing access file
488
488
try {
489
489
fs . unlinkSync ( htpasswd_file ) ;
490
- } catch ( err ) {
490
+ } catch ( _err ) {
491
491
// do nothing
492
492
}
493
493
@@ -504,14 +504,14 @@ const internalAccessList = {
504
504
if ( list . items . length ) {
505
505
return new Promise ( ( resolve , reject ) => {
506
506
batchflow ( list . items ) . sequential ( )
507
- . each ( ( i , item , next ) => {
507
+ . each ( ( _i , item , next ) => {
508
508
if ( typeof item . password !== 'undefined' && item . password . length ) {
509
- logger . info ( ' Adding: ' + item . username ) ;
509
+ logger . info ( ` Adding: ${ item . username } ` ) ;
510
510
511
511
utils . execFile ( 'openssl' , [ 'passwd' , '-apr1' , item . password ] )
512
512
. then ( ( res ) => {
513
513
try {
514
- fs . appendFileSync ( htpasswd_file , item . username + ':' + res + '\n' , { encoding : 'utf8' } ) ;
514
+ fs . appendFileSync ( htpasswd_file , ` ${ item . username } : ${ res } \n` , { encoding : 'utf8' } ) ;
515
515
} catch ( err ) {
516
516
reject ( err ) ;
517
517
}
@@ -528,7 +528,7 @@ const internalAccessList = {
528
528
reject ( err ) ;
529
529
} )
530
530
. end ( ( results ) => {
531
- logger . success ( ' Built Access file #' + list . id + ' for: ' + list . name ) ;
531
+ logger . success ( ` Built Access file #${ list . id } for: ${ list . name } ` ) ;
532
532
resolve ( results ) ;
533
533
} ) ;
534
534
} ) ;
0 commit comments