mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-05 20:10:33 +00:00
(feat) user rate-limiting support for all SOGo requests
This commit is contained in:
@@ -141,6 +141,15 @@
|
||||
forPath: (NSString *) thePath;
|
||||
- (NSMutableDictionary *) aclsForPath: (NSString *) thePath;
|
||||
|
||||
//
|
||||
// SOGo rate-limiting
|
||||
//
|
||||
- (void) setRequestCount: (int) theCount
|
||||
forLogin: (NSString *) theLogin
|
||||
interval: (unsigned int) theInterval;
|
||||
|
||||
- (NSDictionary *) requestCountForLogin: (NSString *) theLogin;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* SOGOCACHE_H */
|
||||
|
||||
@@ -727,5 +727,58 @@ static memcached_st *handle = NULL;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// SOGo request count for rate-limiting
|
||||
//
|
||||
- (void) setRequestCount: (int) theCount
|
||||
forLogin: (NSString *) theLogin
|
||||
interval: (unsigned int) theInterval
|
||||
{
|
||||
NSMutableDictionary *d;
|
||||
NSNumber *count;
|
||||
|
||||
if (theCount)
|
||||
{
|
||||
count = [NSNumber numberWithInt: theCount];
|
||||
|
||||
d = [NSMutableDictionary dictionaryWithDictionary: [self requestCountForLogin: theLogin]];
|
||||
|
||||
if (![d objectForKey: @"InitialDate"] || theInterval == 0)
|
||||
[d setObject: [NSNumber numberWithUnsignedInt: [[NSCalendarDate date] timeIntervalSince1970]] forKey: @"InitialDate"];
|
||||
else
|
||||
[d setObject: [NSNumber numberWithUnsignedInt: theInterval] forKey: @"InitialDate"];
|
||||
|
||||
[d setObject: count forKey: @"RequestCount"];
|
||||
[self _cacheValues: [d jsonRepresentation]
|
||||
ofType: @"requestcount"
|
||||
forKey: theLogin];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self removeValueForKey: [NSString stringWithFormat: @"%@+failedlogins", theLogin]];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Returns a dictionary with two keys/values
|
||||
//
|
||||
// RequestCount ->
|
||||
// InitialDate ->
|
||||
//
|
||||
- (NSDictionary *) requestCountForLogin: (NSString *) theLogin
|
||||
{
|
||||
NSDictionary *d;
|
||||
NSString *s;
|
||||
|
||||
s = [self _valuesOfType: @"requestcount" forKey: theLogin];
|
||||
d = nil;
|
||||
|
||||
if (s)
|
||||
{
|
||||
d = [s objectFromJSONString];
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -97,6 +97,11 @@
|
||||
- (int) maximumSubmissionInterval;
|
||||
- (int) messageSubmissionBlockInterval;
|
||||
|
||||
- (int) maximumRequestCount;
|
||||
- (int) maximumRequestInterval;
|
||||
- (int) requestBlockInterval;
|
||||
|
||||
|
||||
- (int) maximumPingInterval;
|
||||
- (int) maximumSyncInterval;
|
||||
- (int) internalSyncInterval;
|
||||
|
||||
@@ -598,6 +598,42 @@ _injectConfigurationFromFile (NSMutableDictionary *defaultsDict,
|
||||
return v;
|
||||
}
|
||||
|
||||
//
|
||||
// SOGo rate-limiting
|
||||
//
|
||||
- (int) maximumRequestCount
|
||||
{
|
||||
return [self integerForKey: @"SOGoMaximumRequestCount"];
|
||||
}
|
||||
|
||||
- (int) maximumRequestInterval
|
||||
{
|
||||
int v;
|
||||
|
||||
v = [self integerForKey: @"SOGoMaximumRequestInterval"];
|
||||
|
||||
if (!v)
|
||||
v = 30;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
- (int) requestBlockInterval
|
||||
{
|
||||
int v;
|
||||
|
||||
v = [self integerForKey: @"SOGoRequestBlockInterval"];
|
||||
|
||||
if (!v)
|
||||
v = 300;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// SOGo EAS settings
|
||||
//
|
||||
- (int) maximumPingInterval
|
||||
{
|
||||
int v;
|
||||
|
||||
Reference in New Issue
Block a user