From 028025e07d68f5dc3902b6a740cfc492e3170570 Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 8 Jul 2005 10:54:44 +0000 Subject: [PATCH] use common way to detect internet access git-svn-id: http://svn.opengroupware.org/SOGo/trunk@701 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 5 ++ SOGo/SoObjects/Mailer/SOGoMailAccounts.m | 35 ++--------- SOGo/SoObjects/Mailer/Version | 2 +- SOGo/SoObjects/SOGo/ChangeLog | 5 ++ SOGo/SoObjects/SOGo/Version | 2 +- SOGo/SoObjects/SOGo/WOContext+Agenor.m | 77 ++++++++++++++++-------- 6 files changed, 69 insertions(+), 57 deletions(-) diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 498306a6..a3eb41a0 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,8 @@ +2005-07-08 Helge Hess + + * SOGoMailAccounts.m: use WOContext method from libSOGo to detect + Internet access (v0.9.94) + 2005-07-08 Helge Hess * SOGoMailAccounts.m: only deliver share-names as subobjects if the diff --git a/SOGo/SoObjects/Mailer/SOGoMailAccounts.m b/SOGo/SoObjects/Mailer/SOGoMailAccounts.m index 78a1b25a..0c420313 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailAccounts.m +++ b/SOGo/SoObjects/Mailer/SOGoMailAccounts.m @@ -23,44 +23,17 @@ #include "common.h" #include #include +#include @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)internetDetectQualifier - evaluateWithObject:[rq headers]]; + return [[(WOApplication *)[WOApplication application] context] + isAccessFromIntranet] ? NO : YES; } /* listing the available mailboxes */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 52b2edd8..c2722d2d 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=93 +SUBMINOR_VERSION:=94 # v0.9.91 requires libNGMime v4.5.222 # v0.9.69 requires libNGMime v4.5.210 diff --git a/SOGo/SoObjects/SOGo/ChangeLog b/SOGo/SoObjects/SOGo/ChangeLog index ed0dd7bf..0706bdcb 100644 --- a/SOGo/SoObjects/SOGo/ChangeLog +++ b/SOGo/SoObjects/SOGo/ChangeLog @@ -1,3 +1,8 @@ +2005-07-08 Helge Hess + + * WOContext+Agenor.m: use SOGoInternetDetectQualifier for detecting + Internet access level (v0.9.41) + 2005-07-08 Marcus Mueller * WOContext+Agenor.[hm]: new category for discovering if the current diff --git a/SOGo/SoObjects/SOGo/Version b/SOGo/SoObjects/SOGo/Version index b5f44a7a..a84cdcc5 100644 --- a/SOGo/SoObjects/SOGo/Version +++ b/SOGo/SoObjects/SOGo/Version @@ -1,6 +1,6 @@ # version file -SUBMINOR_VERSION:=40 +SUBMINOR_VERSION:=41 # v0.9.34 requires libGDLContentStore v4.5.26 # v0.9.26 requires libOGoContentStore v0.9.13 diff --git a/SOGo/SoObjects/SOGo/WOContext+Agenor.m b/SOGo/SoObjects/SOGo/WOContext+Agenor.m index 81bb3939..f8d246fd 100644 --- a/SOGo/SoObjects/SOGo/WOContext+Agenor.m +++ b/SOGo/SoObjects/SOGo/WOContext+Agenor.m @@ -22,32 +22,61 @@ #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 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) */ -- 2.39.5