2009-11-29 05:19:32 +01:00
|
|
|
/* SOGoSystemDefaults.m - this file is part of SOGo
|
|
|
|
*
|
2011-06-24 21:19:50 +02:00
|
|
|
* Copyright (C) 2009-2011 Inverse inc.
|
2012-10-19 16:07:45 +02:00
|
|
|
* Copyright (C) 2012 Jeroen Dekkers <jeroen@dekkers.ch>
|
2009-11-29 05:19:32 +01:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
2011-06-24 21:19:50 +02:00
|
|
|
* Francis Lachapelle <flachapelle@inverse.ca>
|
2009-11-29 05:19:32 +01:00
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <dlfcn.h>
|
|
|
|
#import <unistd.h>
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <Foundation/NSBundle.h>
|
|
|
|
#import <Foundation/NSFileManager.h>
|
2011-06-24 21:19:50 +02:00
|
|
|
#import <Foundation/NSFileManager.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
#import "NSArray+Utilities.h"
|
2009-11-29 05:19:32 +01:00
|
|
|
#import "NSDictionary+Utilities.h"
|
|
|
|
#import "SOGoStartupLogger.h"
|
|
|
|
|
|
|
|
#import "SOGoSystemDefaults.h"
|
2010-03-18 13:58:39 +01:00
|
|
|
#import "SOGoConstants.h"
|
2009-11-29 05:19:32 +01:00
|
|
|
|
|
|
|
@implementation SOGoSystemDefaults
|
|
|
|
|
|
|
|
#if defined(LDAP_CONFIG)
|
|
|
|
#import <SOGo/SOGoLDAPUserDefaults.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void (*NSUserDefaultsInitFunction) ();
|
|
|
|
|
|
|
|
#define DIR_SEP "/"
|
|
|
|
|
|
|
|
static void
|
|
|
|
BootstrapNSUserDefaults ()
|
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
NSUserDefaultsInitFunction SOGoNSUserDefaultsBootstrap;
|
|
|
|
void *handle;
|
|
|
|
|
|
|
|
filename = SOGO_LIBDIR DIR_SEP "libSOGoNSUserDefaults.so.1";
|
|
|
|
handle = dlopen (filename, RTLD_NOW | RTLD_GLOBAL);
|
|
|
|
if (handle)
|
|
|
|
{
|
|
|
|
SOGoNSUserDefaultsBootstrap = dlsym (handle,
|
|
|
|
"SOGoNSUserDefaultsBootstrap");
|
|
|
|
if (SOGoNSUserDefaultsBootstrap)
|
|
|
|
SOGoNSUserDefaultsBootstrap ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 19:41:34 +02:00
|
|
|
static void
|
|
|
|
_migrateSOGo09Configuration (NSUserDefaults *ud, NSObject *logger)
|
2009-11-29 05:19:32 +01:00
|
|
|
{
|
2012-10-23 19:41:34 +02:00
|
|
|
NSDictionary *domain;
|
2009-11-29 05:19:32 +01:00
|
|
|
|
2012-10-23 19:41:34 +02:00
|
|
|
domain = [ud persistentDomainForName: @"sogod-0.9"];
|
|
|
|
if ([domain count])
|
2009-11-29 05:19:32 +01:00
|
|
|
{
|
2012-10-23 19:41:34 +02:00
|
|
|
[logger logWithFormat: @"migrating user defaults from sogod-0.9"];
|
|
|
|
[ud setPersistentDomain: domain forName: @"sogod"];
|
|
|
|
[ud removePersistentDomainForName: @"sogod-0.9"];
|
|
|
|
[ud synchronize];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_injectConfigurationFromFile (NSUserDefaults *ud,
|
|
|
|
NSString *filename, NSObject *logger)
|
|
|
|
{
|
|
|
|
NSFileManager *fm;
|
|
|
|
NSDictionary *newConfig;
|
|
|
|
|
|
|
|
fm = [NSFileManager defaultManager];
|
|
|
|
if ([fm fileExistsAtPath: filename])
|
|
|
|
{
|
|
|
|
newConfig = [NSDictionary dictionaryWithContentsOfFile: filename];
|
|
|
|
if (newConfig)
|
|
|
|
[ud registerDefaults: newConfig];
|
|
|
|
else
|
2009-11-29 05:19:32 +01:00
|
|
|
{
|
2012-10-23 19:41:34 +02:00
|
|
|
[logger errorWithFormat: @"Cannot read configuration from '%@'.",
|
|
|
|
filename];
|
|
|
|
exit (1);
|
2009-11-29 05:19:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) prepareUserDefaults
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
SOGoStartupLogger *logger;
|
2012-10-23 19:41:34 +02:00
|
|
|
NSBundle *bundle;
|
|
|
|
NSString *confFiles[] = {@"/etc/sogo/debconf.conf",
|
|
|
|
@"/etc/sogo/sogo.conf"};
|
|
|
|
NSString *filename, *redirectURL;
|
|
|
|
NSUInteger count;
|
2009-11-29 05:19:32 +01:00
|
|
|
|
|
|
|
logger = [SOGoStartupLogger sharedLogger];
|
|
|
|
|
2012-10-23 19:41:34 +02:00
|
|
|
/* we load the configuration from the standard user default files */
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
2012-10-23 19:41:34 +02:00
|
|
|
/* if "sogod" does not exist, maybe "sogod-0.9" still exists from an old
|
|
|
|
configuration */
|
|
|
|
if (![[ud persistentDomainForName: @"sogod"] count])
|
|
|
|
_migrateSOGo09Configuration (ud, logger);
|
|
|
|
|
|
|
|
/* reregister defaults from domain "sogod" into default domain, for
|
|
|
|
non-sogod processes */
|
|
|
|
[ud addSuiteNamed: @"sogod"];
|
|
|
|
|
|
|
|
/* we populate the configuration with the values from SOGoDefaults.plist */
|
|
|
|
bundle = [NSBundle bundleForClass: self];
|
|
|
|
filename = [bundle pathForResource: @"SOGoDefaults" ofType: @"plist"];
|
|
|
|
if (filename)
|
|
|
|
_injectConfigurationFromFile (ud, filename, logger);
|
|
|
|
|
|
|
|
/* fill the possibly missing values with the configuration stored
|
|
|
|
in "/etc" */
|
|
|
|
for (count = 0; count < sizeof(confFiles)/sizeof(confFiles[0]); count++)
|
|
|
|
_injectConfigurationFromFile (ud, confFiles[count], logger);
|
|
|
|
|
|
|
|
/* issue a warning if WOApplicationRedirectURL is used */
|
2009-11-29 05:19:32 +01:00
|
|
|
redirectURL = [ud stringForKey: @"WOApplicationRedirectURL"];
|
|
|
|
if (redirectURL)
|
|
|
|
{
|
|
|
|
[logger warnWithFormat:
|
|
|
|
@"Using obsolete 'WOApplicationRedirectURL' user default."];
|
|
|
|
[logger warnWithFormat:
|
|
|
|
@" Please configure the use of the x-webobjects-XXX headers"
|
|
|
|
@" with your webserver (see sample files)."];
|
|
|
|
if ([redirectURL hasSuffix: @"/"])
|
|
|
|
[ud setObject: [redirectURL substringToIndex: [redirectURL length] - 1]
|
|
|
|
forKey: @"WOApplicationRedirectURL"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
BootstrapNSUserDefaults ();
|
|
|
|
[self prepareUserDefaults];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (SOGoSystemDefaults *) sharedSystemDefaults
|
|
|
|
{
|
|
|
|
static SOGoSystemDefaults *sharedSystemDefaults = nil;
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
|
|
|
if (!sharedSystemDefaults)
|
|
|
|
{
|
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
|
|
|
sharedSystemDefaults = [self defaultsSourceWithSource: ud
|
|
|
|
andParentSource: nil];
|
|
|
|
[sharedSystemDefaults retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return sharedSystemDefaults;
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
loginDomains = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[loginDomains release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (BOOL) migrate
|
|
|
|
{
|
|
|
|
static NSDictionary *migratedKeys = nil;
|
|
|
|
|
|
|
|
if (!migratedKeys)
|
|
|
|
{
|
|
|
|
migratedKeys = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"SOGoProfileURL", @"AgenorProfileURL",
|
|
|
|
@"SOGoTimeZone", @"SOGoServerTimeZone",
|
|
|
|
nil];
|
|
|
|
[migratedKeys retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ([self migrateOldDefaultsWithDictionary: migratedKeys]
|
|
|
|
| [super migrate]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) domainIds
|
|
|
|
{
|
|
|
|
return [[self dictionaryForKey: @"domains"] allKeys];
|
|
|
|
}
|
|
|
|
|
2011-07-19 18:25:11 +02:00
|
|
|
- (BOOL) enableDomainBasedUID
|
2011-07-16 00:22:11 +02:00
|
|
|
{
|
2011-07-19 18:25:11 +02:00
|
|
|
return ([[self domainIds] count] > 0 && [self boolForKey: @"SOGoEnableDomainBasedUID"]);
|
2011-07-16 00:22:11 +02:00
|
|
|
}
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
- (NSArray *) loginDomains
|
|
|
|
{
|
|
|
|
NSMutableArray *filteredLoginDomains;
|
|
|
|
NSArray *domains;
|
|
|
|
NSEnumerator *objects;
|
|
|
|
id currentObject;
|
|
|
|
|
|
|
|
if (self->loginDomains == nil)
|
|
|
|
{
|
|
|
|
filteredLoginDomains = [NSMutableArray arrayWithArray: [self stringArrayForKey: @"SOGoLoginDomains"]];
|
|
|
|
domains = [self domainIds];
|
|
|
|
objects = [filteredLoginDomains objectEnumerator];
|
|
|
|
while ((currentObject = [objects nextObject]))
|
|
|
|
{
|
|
|
|
if (![domains containsObject: currentObject])
|
|
|
|
{
|
|
|
|
[filteredLoginDomains removeObject: currentObject];
|
|
|
|
[self warnWithFormat: @"SOGoLoginDomains contains an invalid domain : %@", currentObject];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSIGN (self->loginDomains, filteredLoginDomains);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self->loginDomains;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) visibleDomainsForDomain: (NSString *) domain
|
|
|
|
{
|
|
|
|
NSMutableArray *domains;
|
|
|
|
NSArray *definedDomains, *visibleDomains, *currentGroup;
|
|
|
|
NSEnumerator *groups;
|
|
|
|
NSString *currentDomain;
|
|
|
|
|
|
|
|
definedDomains = [self domainIds];
|
|
|
|
visibleDomains = [self arrayForKey: @"SOGoDomainsVisibility"];
|
|
|
|
domains = [NSMutableArray array];
|
|
|
|
groups = [visibleDomains objectEnumerator];
|
|
|
|
while ((currentGroup = (NSArray *)[groups nextObject]))
|
|
|
|
{
|
|
|
|
if ([currentGroup containsObject: domain])
|
|
|
|
[domains addObjectsFromArray: currentGroup];
|
|
|
|
}
|
|
|
|
|
2011-07-16 00:22:11 +02:00
|
|
|
// Remove lookup domain and invalid domains
|
2011-06-24 21:19:50 +02:00
|
|
|
groups = [domains objectEnumerator];
|
|
|
|
while ((currentDomain = [groups nextObject]))
|
|
|
|
{
|
2011-07-16 00:22:11 +02:00
|
|
|
if ([currentDomain isEqualToString: domain] || ![definedDomains containsObject: currentDomain])
|
2011-06-24 21:19:50 +02:00
|
|
|
[domains removeObject: currentDomain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return [domains uniqueObjects];
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
/* System-level only */
|
|
|
|
|
|
|
|
- (BOOL) crashOnSessionCreate
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoCrashOnSessionCreate"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) debugRequests
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoDebugRequests"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) debugLeaks;
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoDebugLeaks"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) vmemLimit
|
|
|
|
{
|
|
|
|
return [self integerForKey: @"SxVMemLimit"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) trustProxyAuthentication;
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoTrustProxyAuthentication"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) useRelativeURLs
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"WOUseRelativeURLs"];
|
|
|
|
}
|
|
|
|
|
2009-12-09 00:18:12 +01:00
|
|
|
- (BOOL) isWebAccessEnabled
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoWebAccessEnabled"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isCalendarDAVAccessEnabled
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoCalendarDAVAccessEnabled"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isAddressBookDAVAccessEnabled
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoAddressBookDAVAccessEnabled"];
|
|
|
|
}
|
|
|
|
|
2010-08-19 19:27:58 +02:00
|
|
|
- (BOOL) enableEMailAlarms
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoEnableEMailAlarms"];
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (NSString *) faviconRelativeURL
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"SOGoFaviconRelativeURL"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) zipPath
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"SOGoZipPath"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) port
|
|
|
|
{
|
|
|
|
return [self integerForKey: @"WOPort"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) workers
|
|
|
|
{
|
|
|
|
return [self integerForKey: @"WOWorkersCount"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) logFile
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"WOLogFile"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) pidFile
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"WOPidFile"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTimeInterval) cacheCleanupInterval
|
|
|
|
{
|
|
|
|
return [self floatForKey: @"SOGoCacheCleanupInterval"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) memcachedHost
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"SOGoMemcachedHost"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) uixDebugEnabled
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoUIxDebugEnabled"];
|
|
|
|
}
|
|
|
|
|
2011-03-30 17:21:27 +02:00
|
|
|
- (NSString *) pageTitle
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"SOGoPageTitle"];
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (NSArray *) supportedLanguages
|
|
|
|
{
|
|
|
|
return [self stringArrayForKey: @"SOGoSupportedLanguages"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) userCanChangePassword
|
|
|
|
{
|
2010-03-18 13:58:39 +01:00
|
|
|
return [self boolForKey: SOGoPasswordChangeEnabled];
|
2009-11-29 05:19:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) uixAdditionalPreferences
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoUIxAdditionalPreferences"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) loginSuffix
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"SOGoLoginSuffix"];
|
|
|
|
}
|
|
|
|
|
2010-01-28 22:42:03 +01:00
|
|
|
- (NSString *) authenticationType
|
|
|
|
{
|
|
|
|
return [[self stringForKey: @"SOGoAuthenticationType"] lowercaseString];
|
|
|
|
}
|
|
|
|
|
2010-06-10 23:32:23 +02:00
|
|
|
- (NSString *) davAuthenticationType
|
|
|
|
{
|
|
|
|
return [[self stringForKey: @"SOGoDAVAuthenticationType"] lowercaseString];
|
|
|
|
}
|
|
|
|
|
2010-01-28 22:42:03 +01:00
|
|
|
- (NSString *) CASServiceURL
|
|
|
|
{
|
|
|
|
return [self stringForKey: @"SOGoCASServiceURL"];
|
|
|
|
}
|
|
|
|
|
2010-06-10 20:40:57 +02:00
|
|
|
- (BOOL) CASLogoutEnabled
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoCASLogoutEnabled"];
|
|
|
|
}
|
|
|
|
|
2010-06-01 20:49:01 +02:00
|
|
|
- (BOOL) enablePublicAccess
|
|
|
|
{
|
|
|
|
return [self boolForKey: @"SOGoEnablePublicAccess"];
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
@end
|