feat(core): Add mobile provisioning download for Apple's devices. Fix shared calendar and contacts

This commit is contained in:
smizrahi
2023-10-18 11:43:11 +02:00
parent c67ad819ab
commit 65f8336255
11 changed files with 84 additions and 49 deletions

View File

@@ -37,8 +37,8 @@ typedef enum
}
+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path;
+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path;
+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path andName:(NSString *)name;
+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path andName:(NSString *)name;
@end

View File

@@ -23,10 +23,11 @@
#import "SOGoMobileProvision.h"
#import "SOGoUser.h"
#import "NSString+Crypto.h"
@implementation SOGoMobileProvision
+ (NSString *)_plistWithContext:(WOContext *)context andPath:(NSString *)path andType:(ProvisioningType) provisioningType
+ (NSString *)_plistWithContext:(WOContext *)context andPath:(NSString *)path andType:(ProvisioningType) provisioningType andName:(NSString *)name
{
NSData *plistData;
SOGoUser *activeUser;
@@ -58,23 +59,23 @@
provisioning = [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%@ %@", type, [activeUser login]], [NSString stringWithFormat:@"%@%@", prefix, @"AccountDescription"],
[NSString stringWithFormat:@"%@ %@", type, name], [NSString stringWithFormat:@"%@%@", prefix, @"AccountDescription"],
[serverURL host], [NSString stringWithFormat:@"%@%@", prefix, @"HostName"],
[serverURL port], [NSString stringWithFormat:@"%@%@", prefix, @"Port"],
path, [NSString stringWithFormat:@"%@%@", prefix, @"PrincipalURL"],
[NSNumber numberWithBool:[[serverURL scheme] isEqualToString:@"https"]], [NSString stringWithFormat:@"%@%@", prefix, @"UseSSL"],
[activeUser login], [NSString stringWithFormat:@"%@%@", prefix, @"Username"],
[NSString stringWithFormat: @"SOGo %@ provisioning", prefix], @"PayloadDescription",
[NSString stringWithFormat:@"%@ %@", type, [activeUser login]], @"PayloadDisplayName",
[NSString stringWithFormat:@"%@.apple.%@", [serverURL host], [prefix lowercaseString]], @"PayloadIdentifier",
[NSString stringWithFormat:@"%@ %@", type, name], @"PayloadDisplayName",
[NSString stringWithFormat:@"%@.%@.apple.%@", [serverURL host], [name asMD5String], [prefix lowercaseString]], @"PayloadIdentifier",
[serverURL host], @"PayloadOrganization",
payloadType, @"PayloadType",
[SOGoObject globallyUniqueObjectId], @"PayloadUUID",
[NSNumber numberWithInt: 1], @"PayloadVersion",
nil]], @"PayloadContent",
[NSString stringWithFormat:@"SOGo %@ provisioning", prefix], @"PayloadDescription",
[NSString stringWithFormat: @"%@ (%@)", [activeUser login], type], @"PayloadDisplayName",
[NSString stringWithFormat:@"%@.%@.apple", [prefix lowercaseString], [serverURL host]], @"PayloadIdentifier",
[NSString stringWithFormat: @"%@ (%@)", name, type], @"PayloadDisplayName",
[NSString stringWithFormat:@"%@.%@.%@.apple", [prefix lowercaseString], [serverURL host], [name asMD5String]], @"PayloadIdentifier",
@"SOGo", @"PayloadOrganization",
[NSNumber numberWithBool: NO], @"PayloadRemovalDisallowed",
@"Configuration", @"PayloadType",
@@ -88,12 +89,12 @@
error: &error];
}
+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path
+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path andName:(NSString *)name
{
NSData *plistData;
SOGoUser *activeUser;
plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeCalendar];
plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeCalendar andName: name];
if (nil != plistData) {
return [[[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding] autorelease];
} else {
@@ -102,12 +103,12 @@
}
}
+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path
+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path andName:(NSString *)name
{
NSData *plistData;
SOGoUser *activeUser;
plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeContact];
plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeContact andName: name];
if (nil != plistData) {
return [[[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding] autorelease];
} else {

View File

@@ -103,7 +103,8 @@
/* ownership */
- (void) setOwner: (NSString *) newOwner;
- (NSString *)owner;
- (void)setOwner:(NSString *)newOwner;
- (NSString *) ownerInContext: (id) _ctx;
/* a helper that determines whether access rights can be ignored on

View File

@@ -211,6 +211,11 @@
/* ownership */
- (NSString *) owner
{
return owner;
}
- (void) setOwner: (NSString *) newOwner
{
NSString *uid;

View File

@@ -51,6 +51,7 @@
#import <SoObjects/Contacts/SOGoContactGCSFolder.h>
#import <SOGo/NSString+Utilities.h>
#import <SOGo/SOGoMobileProvision.h>
#import "UIxContactFolderActions.h"
@@ -463,4 +464,29 @@ static NSArray *photoTags = nil;
return rc;
}
- (WOResponse *) mobileconfigAction
{
SOGoContactGCSFolder *folder;
NSString *davURL, *plistContent, *disposition;
WOResponse *response;
folder = [self clientObject];
davURL = [folder davURLAsString];
plistContent = [SOGoMobileProvision plistForContactsWithContext: context andPath: davURL andName: [NSString stringWithFormat: @"%@ - %@", [folder owner], [folder realNameInContainer]]];
if (nil != plistContent) {
response = [self responseWithStatus: 200
andString: plistContent];
[response setHeader: @"application/x-plist; charset=utf-8"
forKey: @"content-type"];
disposition = [NSString stringWithString: @"attachment; filename=\"contacts.mobileconfig\""];
[response setHeader: disposition forKey: @"Content-Disposition"];
} else {
response = [self responseWithStatus: 500
andString: @"Error while generating profile"];
}
return response;
}
@end /* UIxContactFolderActions */

View File

@@ -35,7 +35,6 @@
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserManager.h>
#import <SOGo/SOGoMobileProvision.h>
#import <Contacts/NGVCard+SOGo.h>
#import <Contacts/SOGoContactObject.h>
@@ -450,29 +449,4 @@
return [NSString stringWithFormat: @"%@/photo", [soURL absoluteString]];
}
- (WOResponse *) mobileconfigAction
{
SOGoContactFolders *folders;
NSString *davURL, *plistContent, *disposition;
WOResponse *response;
folders = [self clientObject];
davURL = [[folders container] davURLAsString];
plistContent = [SOGoMobileProvision plistForContactsWithContext: context andPath: davURL];
if (nil != plistContent) {
response = [self responseWithStatus: 200
andString: plistContent];
[response setHeader: @"application/x-plist; charset=utf-8"
forKey: @"content-type"];
disposition = [NSString stringWithString: @"attachment; filename=\"contacts.mobileconfig\""];
[response setHeader: disposition forKey: @"Content-Disposition"];
} else {
response = [self responseWithStatus: 500
andString: @"Error while generating profile"];
}
return response;
}
@end /* UIxContactView */

View File

@@ -50,11 +50,6 @@
pageName = "UIxContactFoldersView";
actionName = "saveDragHandleState";
};
mobileconfig = {
protectedBy = "Access Contents Information";
actionClass = "UIxContactView";
actionName = "mobileconfig";
};
};
};
@@ -115,6 +110,11 @@
pageName = "UIxContactFolderProperties";
actionName = "saveProperties";
};
mobileconfig = {
protectedBy = "Access Contents Information";
actionClass = "UIxContactFolderActions";
actionName = "mobileconfig";
};
};
};

View File

@@ -666,7 +666,7 @@
folders = [self clientObject];
davURL = [[folders container] davURLAsString];
plistContent = [SOGoMobileProvision plistForCalendarsWithContext: context andPath: davURL];
plistContent = [SOGoMobileProvision plistForCalendarsWithContext: context andPath: davURL andName: [folders owner]];
if (nil != plistContent) {
response = [self responseWithStatus: 200

View File

@@ -205,6 +205,12 @@
<var:string label:value="Export"/>
</md-button>
</md-menu-item>
<md-menu-divider><!-- divider --></md-menu-divider>
<md-menu-item>
<md-button ng-click="folder.downloadProvisioningProfile()">
 <var:string label:value="Download configuration profile"/>
</md-button>
</md-menu-item>
</md-menu-content>
</md-menu>
</md-list-item>

View File

@@ -756,14 +756,25 @@
* @returns a promise of the HTTP operation
*/
AddressBook.prototype.downloadProvisioningProfile = function () {
var options;
var options, resource, index, ownerPaths, realOwnerId, path;
options = {
type: 'application/octet-stream',
filename: 'addressbook.mobileconfig'
}
return AddressBook.$$resource.open('', 'mobileconfig', null, options);
if (this.isSubscription) {
index = this.urls.cardDavURL.indexOf('/dav/');
ownerPaths = this.urls.cardDavURL.substring(index + 5).split(/\//);
realOwnerId = ownerPaths[0];
resource = AddressBook.$$resource.userResource(realOwnerId);
path = ownerPaths[1] + '/' + ownerPaths[2];
} else {
resource = AddressBook.$$resource;
path = this.id;
}
return resource.open(path, 'mobileconfig', null, options);
};
/**

View File

@@ -583,14 +583,25 @@
* @returns a promise of the HTTP operation
*/
Calendar.prototype.downloadProvisioningProfile = function () {
var options;
var options, resource, index, ownerPaths, realOwnerId, path;
options = {
type: 'application/octet-stream',
filename: 'calendar.mobileconfig'
}
return Calendar.$$resource.open('', 'mobileconfig', null, options);
if (this.isSubscription) {
index = this.urls.webDavICSURL.indexOf('/dav/');
ownerPaths = this.urls.webDavICSURL.substring(index + 5).split(/\//);
realOwnerId = ownerPaths[0];
resource = Calendar.$$resource.userResource(realOwnerId);
path = 'Calendar';
} else {
resource = Calendar.$$resource;
path = '';
}
return resource.open(path, 'mobileconfig', null, options);
};
/**