Skip to content

Commit

Permalink
feat(core): Add mobile provisioning download for Apple's devices
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodySlum authored and QHivert committed Sep 27, 2023
1 parent 5b73a60 commit 6d16ee7
Show file tree
Hide file tree
Showing 15 changed files with 282 additions and 2 deletions.
8 changes: 6 additions & 2 deletions SoObjects/SOGo/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ SOGo_HEADER_FILES = \
\
JWT.h \
\
NGMimeBodyPart+SOGo.h
NGMimeBodyPart+SOGo.h \
\
SOGoMobileProvision.h

all::
@touch SOGoBuild.m
Expand Down Expand Up @@ -180,7 +182,9 @@ SOGo_OBJC_FILES = \
\
JWT.m \
\
NGMimeBodyPart+SOGo.m
NGMimeBodyPart+SOGo.m \
\
SOGoMobileProvision.m

SOGo_C_FILES += lmhash.c aes.c crypt_blowfish.c pkcs5_pbkdf2.c

Expand Down
39 changes: 39 additions & 0 deletions SoObjects/SOGo/SOGoMobileProvision.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* SOGoMobileProvision.h - this file is part of SOGo
*
* Copyright (C) 2023 Alinto
*
* 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.
*/

#ifndef SOGOMOBILEPROVISION_H
#define SOGOMOBILEPROVISION_H

#include <SOGo/SOGoObject.h>

@class SOGoMobileProvision;
@class NSString;

@interface SOGoMobileProvision : SOGoObject
{

}

+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path;
+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path;

@end

#endif /* SOGOMOBILEPROVISION_H */
125 changes: 125 additions & 0 deletions SoObjects/SOGo/SOGoMobileProvision.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

/* SOGoMobileProvision.m - this file is part of SOGo
*
* Copyright (C) 2023 Alinto
*
* 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 <Foundation/Foundation.h>

#import "SOGoMobileProvision.h"
#import "SOGoUser.h"

typedef NS_ENUM(NSInteger, ProvisioningType) {
ProvisioningTypeCalendar,
ProvisioningTypeContact
};

@implementation SOGoMobileProvision

+ (NSString *)_plistWithContext:(WOContext *)context andPath:(NSString *)path andType:(ProvisioningType) provisioningType
{
NSData *plistData;
SOGoUser *activeUser;
NSURL *serverURL;
NSDictionary *provisioning;
NSError *error;
NSString *payloadType, *prefix, *type;

activeUser = [context activeUser];
serverURL = [context serverURL];

if (!context || !path) {
[self errorWithFormat: @"Invalid provisioning profile - no parameters"];
return nil;
}

switch(provisioningType) {
case ProvisioningTypeCalendar:
payloadType = @"com.apple.caldav.account";
prefix = @"CalDAV";
type = @"Calendar";
break;
case ProvisioningTypeContact:
payloadType = @"com.apple.carddav.account";
prefix = @"CardDAV";
type = @"Contact";
break;
}

provisioning = [NSDictionary dictionaryWithObjectsAndKeys:
[NSArray arrayWithObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%@ %@", type, [activeUser login]], [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",
[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",
@"SOGo", @"PayloadOrganization",
[NSNumber numberWithBool: NO], @"PayloadRemovalDisallowed",
@"Configuration", @"PayloadType",
[SOGoObject globallyUniqueObjectId], @"PayloadUUID",
[NSNumber numberWithInt: 1], @"PayloadVersion",
nil];

return [NSPropertyListSerialization dataWithPropertyList: provisioning
format: NSPropertyListXMLFormat_v1_0
options: 0
error: &error];
}

+ (NSString *)plistForCalendarsWithContext:(WOContext *)context andPath:(NSString *)path
{
NSData *plistData;
SOGoUser *activeUser;

plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeCalendar];
if (nil != plistData) {
return [[[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding] autorelease];
} else {
[self errorWithFormat: @"Invalid provisioning profile plist for account : %@", [activeUser login]];
return nil;
}
}

+ (NSString *)plistForContactsWithContext:(WOContext *)context andPath:(NSString *)path
{
NSData *plistData;
SOGoUser *activeUser;

plistData = [self _plistWithContext: context andPath: path andType: ProvisioningTypeContact];
if (nil != plistData) {
return [[[NSString alloc] initWithData:plistData encoding:NSUTF8StringEncoding] autorelease];
} else {
[self errorWithFormat: @"Invalid provisioning profile plist for account : %@", [activeUser login]];
return nil;
}
}


@end
1 change: 1 addition & 0 deletions UI/Contacts/English.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"Work" = "Work";
"Mobile" = "Mobile";
"Pager" = "Pager";
"Download configuration profile" = "Download configuration profile";

/* categories */
"contacts_category_labels" = "Colleague, Competitor, Customer, Friend, Family, Business Partner, Provider, Press, VIP";
Expand Down
1 change: 1 addition & 0 deletions UI/Contacts/French.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
"Work" = "Travail";
"Mobile" = "Portable";
"Pager" = "Téléavertisseur";
"Download configuration profile" = "Télécharger le profil de configuration";

/* categories */
"contacts_category_labels" = "Ami, Client, Collègue, Concurrent, Famille, Fournisseur, Partenaire d'affaire, Presse, VIP";
Expand Down
27 changes: 27 additions & 0 deletions UI/Contacts/UIxContactView.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@
#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>
#import <Contacts/SOGoContactFolders.h>

#import "UIxContactView.h"

Expand Down Expand Up @@ -448,4 +450,29 @@ - (NSString *) photoURL
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 */
5 changes: 5 additions & 0 deletions UI/Contacts/product.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
pageName = "UIxContactFoldersView";
actionName = "saveDragHandleState";
};
mobileconfig = {
protectedBy = "Access Contents Information";
actionClass = "UIxContactView";
actionName = "mobileconfig";
};
};
};

Expand Down
1 change: 1 addition & 0 deletions UI/Scheduler/English.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"A total of %{0} events were imported in the calendar." = "A total of %{0} events were imported in the calendar.";
"Compose E-Mail to All Attendees" = "Compose E-Mail to All Attendees";
"Compose E-Mail to Undecided Attendees" = "Compose E-Mail to Undecided Attendees";
"Download configuration profile" = "Download configuration profile";

/* Relative dates */
"Yesterday" = "Yesterday";
Expand Down
1 change: 1 addition & 0 deletions UI/Scheduler/French.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"A total of %{0} events were imported in the calendar." = "Un total de %{0} événements ont été importés dans le calendrier.";
"Compose E-Mail to All Attendees" = "Rédiger un courriel pour tous les participants";
"Compose E-Mail to Undecided Attendees" = "Rédiger un courriel pour les participants indécis";
"Download configuration profile" = "Télécharger le profil de configuration";

/* Relative dates */
"Yesterday" = "Hier";
Expand Down
26 changes: 26 additions & 0 deletions UI/Scheduler/UIxCalView.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import <SOGo/SOGoUserSettings.h>
#import <SOGo/SOGoMobileProvision.h>

#import <SOGoUI/SOGoAptFormatter.h>

Expand Down Expand Up @@ -657,4 +658,29 @@ - (id) redirectForUIDsAction
return r;
}

- (WOResponse *) mobileconfigAction
{
SOGoAppointmentFolders *folders;
NSString *davURL, *plistContent, *disposition;
WOResponse *response;

folders = [self clientObject];
davURL = [[folders container] davURLAsString];
plistContent = [SOGoMobileProvision plistForCalendarsWithContext: 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=\"calendar.mobileconfig\""];
[response setHeader: disposition forKey: @"Content-Disposition"];
} else {
response = [self responseWithStatus: 500
andString: @"Error while generating profile"];
}

return response;
}

@end /* UIxCalView */
5 changes: 5 additions & 0 deletions UI/Scheduler/product.plist
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@
protectedBy = "View";
pageName = "UIxReminderEditor";
};
mobileconfig = {
protectedBy = "Access Contents Information";
actionClass = "UIxCalView";
actionName = "mobileconfig";
};
};
};

Expand Down
5 changes: 5 additions & 0 deletions UI/Templates/ContactsUI/UIxContactFoldersView.wox
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
</md-button>
</md-menu-item>
</var:if>
<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>
Expand Down
6 changes: 6 additions & 0 deletions UI/Templates/SchedulerUI/UIxCalMainView.wox
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@
</md-button>
</md-menu-item>
</var:if>
<md-divider><!-- divider --></md-divider>
<md-menu-item>
<md-button ng-click="$menuCtrl.calendar.downloadProvisioningProfile()">
 <var:string label:value="Download configuration profile"/>
</md-button>
</md-menu-item>
</md-menu-content>
</div>
</script>
Expand Down
17 changes: 17 additions & 0 deletions UI/WebServerResources/js/Contacts/AddressBook.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,23 @@
}
};

/**
* @function downloadProvisioningProfile
* @memberof Calendar.prototype
* @desc Download provisioning profile for Apple's devices
* @returns a promise of the HTTP operation
*/
AddressBook.prototype.downloadProvisioningProfile = function () {
var options;

options = {
type: 'application/octet-stream',
filename: 'addressbook.mobileconfig'
}

return AddressBook.$$resource.open('', 'mobileconfig', null, options);
};

/**
* @function $unwrap
* @memberof AddressBook.prototype
Expand Down
17 changes: 17 additions & 0 deletions UI/WebServerResources/js/Scheduler/Calendar.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,23 @@
return resource.open(path, 'export', null, options);
};

/**
* @function downloadProvisioningProfile
* @memberof Calendar.prototype
* @desc Download provisioning profile for Apple's devices
* @returns a promise of the HTTP operation
*/
Calendar.prototype.downloadProvisioningProfile = function () {
var options;

options = {
type: 'application/octet-stream',
filename: 'calendar.mobileconfig'
}

return Calendar.$$resource.open('', 'mobileconfig', null, options);
};

/**
* @function $setActivation
* @memberof Calendar.prototype
Expand Down

0 comments on commit 6d16ee7

Please sign in to comment.