@@ -39,6 +39,8 @@ var settings = require('./models/settings.json');
39
39
//--
40
40
var limiter = process . env . LIMITER_STRING || settings . limiter ;
41
41
42
+ var lockdown = process . env . FORCE_BUSY_UPDATEURL_CHECK === 'true' ;
43
+
42
44
// WATCHPOINT: ~60 second poll time in MongoDB
43
45
var fudgeMin = 60 ;
44
46
var fudgeSec = 6 ;
@@ -53,8 +55,49 @@ var installCapLimiter = rateLimit({
53
55
windowMs : waitInstallCapMin * 60 * 1000 , // n minutes for all stores
54
56
max : 50 , // limit each IP to n requests per windowMs for memory store or expireTimeMs for mongo store
55
57
handler : function ( aReq , aRes , aNext , aOptions ) {
56
- aRes . header ( 'Retry-After' , waitInstallCapMin * 60 + ( isDev ? fudgeSec : fudgeMin ) ) ;
57
- aRes . status ( 429 ) . send ( ) ;
58
+ if ( aReq . rateLimit . current < aReq . rateLimit . limit + 4 ) {
59
+ // Midddlware options
60
+ if ( ! aRes . oujsOptions ) {
61
+ aRes . oujsOptions = { } ;
62
+ }
63
+
64
+ aRes . oujsOptions . showReminderInstallLimit = 4 - ( aReq . rateLimit . current - aReq . rateLimit . limit ) ;
65
+
66
+ aNext ( ) ;
67
+ } else if ( aReq . rateLimit . current < aReq . rateLimit . limit + 10 ) {
68
+ aRes . header ( 'Retry-After' , waitInstallCapMin * 60 + ( isDev ? fudgeSec : fudgeMin ) ) ;
69
+ statusCodePage ( aReq , aRes , aNext , {
70
+ statusCode : 429 ,
71
+ statusMessage : 'Too many requests.' ,
72
+ suppressNavigation : true ,
73
+ isCustomView : true ,
74
+ statusData : {
75
+ isListView : true ,
76
+ retryAfter : waitInstallCapMin * 60 + ( isDev ? fudgeSec : fudgeMin )
77
+ }
78
+ } ) ;
79
+ } else if ( aReq . rateLimit . current < aReq . rateLimit . limit + 15 ) {
80
+ aRes . header ( 'Retry-After' , waitInstallCapMin * 60 + ( isDev ? fudgeSec : fudgeMin ) ) ;
81
+ aRes . status ( 429 ) . send ( 'Too many requests. Please try again later' ) ;
82
+ } else if ( aReq . rateLimit . current < aReq . rateLimit . limit + 20 ) {
83
+ aRes . header ( 'Retry-After' , waitInstallCapMin * 60 + ( isDev ? fudgeSec : fudgeMin ) ) ;
84
+ aRes . status ( 429 ) . send ( ) ;
85
+ } else {
86
+ cmd = ( isPro && process . env . AUTOBAN ? process . env . AUTOBAN : 'echo SIMULATING INSTALL AUTOBAN' ) +
87
+ ' ' + aReq . connection . remoteAddress ;
88
+
89
+ exec ( cmd , function ( aErr , aStdout , aStderr ) {
90
+ if ( aErr ) {
91
+ console . error ( 'FAIL INSTALL AUTOBAN' , cmd ) ;
92
+ // fallthrough
93
+ } else {
94
+ console . log ( 'INSTALL AUTOBAN' , aReq . connection . remoteAddress ) ;
95
+ // fallthrough
96
+ }
97
+
98
+ aRes . connection . destroy ( ) ;
99
+ } ) ;
100
+ }
58
101
} ,
59
102
skip : function ( aReq , aRes ) {
60
103
var authedUser = aReq . session . user ;
@@ -100,7 +143,7 @@ var installRateLimiter = rateLimit({
100
143
skip : function ( aReq , aRes ) {
101
144
var authedUser = aReq . session . user ;
102
145
103
- if ( aReq . params . type === 'libs' ) {
146
+ if ( aReq . params . type === 'libs' && ! lockdown ) {
104
147
return true ;
105
148
}
106
149
@@ -277,15 +320,15 @@ var listCapLimiter = rateLimit({
277
320
aRes . header ( 'Retry-After' , waitListCapMin * 60 + ( isDev ? fudgeSec : fudgeMin ) ) ;
278
321
aRes . status ( 429 ) . send ( ) ;
279
322
} else {
280
- cmd = ( isPro && process . env . AUTOBAN ? process . env . AUTOBAN : 'echo SIMULATING AUTOBAN' ) +
323
+ cmd = ( isPro && process . env . AUTOBAN ? process . env . AUTOBAN : 'echo SIMULATING LIST AUTOBAN' ) +
281
324
' ' + aReq . connection . remoteAddress ;
282
325
283
326
exec ( cmd , function ( aErr , aStdout , aStderr ) {
284
327
if ( aErr ) {
285
- console . error ( 'FAIL AUTOBAN' , cmd ) ;
328
+ console . error ( 'FAIL LIST AUTOBAN' , cmd ) ;
286
329
// fallthrough
287
330
} else {
288
- console . log ( 'AUTOBAN' , aReq . connection . remoteAddress ) ;
331
+ console . log ( 'LIST AUTOBAN' , aReq . connection . remoteAddress ) ;
289
332
// fallthrough
290
333
}
291
334
0 commit comments