#include "common.h"
#include <NGObjWeb/SoObject+SoDAV.h>
#include <SOGo/AgenorUserManager.h>
+#include <SOGo/WOContext+Agenor.h>
@implementation SOGoMailAccounts
-static EOQualifier *internetDetectQualifier = nil;
-static NSString *AgenorShareLoginMarker = @".-.";
-
-+ (void)initialize {
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
- NSString *s;
-
- if ((s = [ud stringForKey:@"SOGoInternetDetectQualifier"]) != nil) {
- internetDetectQualifier =
- [[EOQualifier qualifierWithQualifierFormat:s] retain];
- if (internetDetectQualifier == nil)
- NSLog(@"ERROR: could not parse qualifier: '%@'", s);
- }
- if (internetDetectQualifier == nil)
- NSLog(@"SOGoMailAccounts: no 'SOGoInternetDetectQualifier' configured.");
- else {
- NSLog(@"SOGoMailAccounts: detect Internet access using: %@",
- internetDetectQualifier);
- }
-}
+static NSString *AgenorShareLoginMarker = @".-.";
/* detect webmail being accessed from the outside */
- (BOOL)isInternetRequest {
- WORequest *rq;
-
- rq = [[(WOApplication *)[WOApplication application] context] request];
- if (rq == nil) {
- [self logWithFormat:
- @"ERROR: got no WORequest for checking Internet headers!"];
- return NO;
- }
-
- return [(id<EOQualifierEvaluation>)internetDetectQualifier
- evaluateWithObject:[rq headers]];
+ return [[(WOApplication *)[WOApplication application] context]
+ isAccessFromIntranet] ? NO : YES;
}
/* listing the available mailboxes */
#include "WOContext+Agenor.h"
#include "common.h"
-@implementation WOContext (Agenor)
+@implementation WOContext(Agenor)
+
+static EOQualifier *internetDetectQualifier = nil;
+
+static EOQualifier *getInternetDetectQualifier(void) {
+ static BOOL didCheck = NO;
+ NSUserDefaults *ud;
+ NSString *s;
+
+ if (didCheck) return internetDetectQualifier;
+
+ ud = [NSUserDefaults standardUserDefaults];
+
+ if ((s = [ud stringForKey:@"SOGoInternetDetectQualifier"]) != nil) {
+ internetDetectQualifier =
+ [[EOQualifier qualifierWithQualifierFormat:s] retain];
+ if (internetDetectQualifier == nil)
+ NSLog(@"ERROR: could not parse qualifier: '%@'", s);
+ }
+ if (internetDetectQualifier == nil)
+ NSLog(@"Note: no 'SOGoInternetDetectQualifier' configured.");
+ else {
+ NSLog(@"Note: detect Internet access using: %@",
+ internetDetectQualifier);
+ }
+
+ didCheck = YES;
+ return internetDetectQualifier;
+}
- (BOOL)isAccessFromIntranet {
- NSNumber *bv;
-
- bv = [self valueForKey:@"_agenorUnrestricedAccess"];
- if (!bv) {
- NSString *mineqProvenance;
-
- /* See Agenor technical specification, Section 2 */
- mineqProvenance = [[self request] formValueForKey:@"X-mineqProvenance"];
- if ([mineqProvenance hasPrefix:@"intranet"]) {
- bv = [NSNumber numberWithBool:YES];
- }
- else {
- /* fallback for testing */
- NSUserDefaults *ud;
- BOOL allowed;
-
- ud = [NSUserDefaults standardUserDefaults];
- allowed = [ud boolForKey:@"SOGoAllowsUnrestrictedAccess"];
- bv = [NSNumber numberWithBool:allowed];
- }
- [self takeValue:bv forKey:@"_agenorUnrestricedAccess"];
+ id<EOQualifierEvaluation> q;
+ NSNumber *bv;
+ WORequest *rq;
+ BOOL ok;
+
+ if ((bv = [self objectForKey:@"_agenorUnrestricedAccess"]) != nil)
+ return [bv boolValue];
+
+ if ((rq = [self request]) == nil) {
+ [self logWithFormat:@"ERROR: got no request for context!"];
+ return NO;
}
- return [bv boolValue];
+
+
+ if ((q = (id)getInternetDetectQualifier()) == nil)
+ /* if no qualifier is set, allow access */
+ ok = YES;
+ else
+ /* is Internet request? */
+ ok = [q evaluateWithObject:[rq headers]] ? NO : YES;
+
+ bv = [NSNumber numberWithBool:ok];
+ [self setObject:bv forKey:@"_agenorUnrestricedAccess"];
+ return ok;
}
-@end
+@end /* WOContext(Agenor) */