]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/WOContext+Agenor.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1051 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / WOContext+Agenor.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "WOContext+Agenor.h"
23 #include "common.h"
24
25 @implementation WOContext(Agenor)
26
27 static EOQualifier *internetDetectQualifier = nil;
28
29 static EOQualifier *getInternetDetectQualifier(void) {
30   static BOOL didCheck = NO;
31   NSUserDefaults *ud;
32   NSString *s;
33   
34   if (didCheck) return internetDetectQualifier;
35   
36   ud = [NSUserDefaults standardUserDefaults];
37   
38   if ((s = [ud stringForKey:@"SOGoInternetDetectQualifier"]) != nil) {
39     internetDetectQualifier = 
40       [[EOQualifier qualifierWithQualifierFormat:s] retain];
41     if (internetDetectQualifier == nil)
42       NSLog(@"ERROR: could not parse qualifier: '%@'", s);
43   }
44   if (internetDetectQualifier == nil)
45     NSLog(@"Note: no 'SOGoInternetDetectQualifier' configured.");
46   else {
47     NSLog(@"Note: detect Internet access using: %@", 
48           internetDetectQualifier);
49   }
50
51   didCheck = YES;
52   return internetDetectQualifier;
53 }
54
55 - (BOOL)isAccessFromIntranet {
56   id<EOQualifierEvaluation> q;
57   NSNumber  *bv;
58   WORequest *rq;
59   BOOL ok;
60   
61   if ((bv = [self objectForKey:@"_agenorUnrestricedAccess"]) != nil)
62     return [bv boolValue];
63
64   if ((rq = [self request]) == nil) {
65     [self logWithFormat:@"ERROR: got no request for context!"];
66     return NO;
67   }
68   
69
70   if ((q = (id)getInternetDetectQualifier()) == nil)
71     /* if no qualifier is set, allow access */
72     ok = YES;
73   else
74     /* is Internet request? */
75     ok = [q evaluateWithObject:[rq headers]] ? NO : YES;
76   
77   bv = [NSNumber numberWithBool:ok];
78   [self setObject:bv forKey:@"_agenorUnrestricedAccess"];
79   return ok;
80 }
81
82 @end /*  WOContext(Agenor) */