[Web] Apple mobileconfig enhancements by @feldsam

master
andryyy 2019-01-02 21:28:22 +01:00
parent 4f278255a5
commit ca9c610460
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
2 changed files with 156 additions and 138 deletions

View File

@ -1452,4 +1452,17 @@ function get_logs($application, $lines = false) {
} }
return false; return false;
} }
function getGUID() {
if (function_exists('com_create_guid')) {
return com_create_guid();
}
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);// "-"
return substr($charid, 0, 8).$hyphen
.substr($charid, 8, 4).$hyphen
.substr($charid,12, 4).$hyphen
.substr($charid,16, 4).$hyphen
.substr($charid,20,12);
}
?> ?>

View File

@ -1,5 +1,5 @@
<?php <?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/prerequisites.inc.php'; require_once 'inc/prerequisites.inc.php';
if (empty($mailcow_hostname)) { if (empty($mailcow_hostname)) {
exit(); exit();
@ -12,105 +12,80 @@ if (!isset($_SESSION['mailcow_cc_role']) || $_SESSION['mailcow_cc_role'] != 'use
error_reporting(0); error_reporting(0);
header('Content-Type: application/x-apple-aspen-config'); header('Content-Type: application/x-apple-aspen-config');
header('Content-Disposition: attachment; filename="Mailcow.mobileconfig"'); header('Content-Disposition: attachment; filename="'.$UI_TEXTS['main_name'].'.mobileconfig"');
$email = $_SESSION['mailcow_cc_username']; $email = $_SESSION['mailcow_cc_username'];
$domain = explode('@', $_SESSION['mailcow_cc_username'])[1]; $domain = explode('@', $_SESSION['mailcow_cc_username'])[1];
$identifier = implode('.', array_reverse(explode('.', $domain))) . '.iphoneprofile.mailcow'; $identifier = implode('.', array_reverse(preg_split( '/(@|\.)/', $email))) . '.appleprofile.'.preg_replace('/[^a-zA-Z0-9]+/', '', $UI_TEXTS['main_name']);
try { try {
$stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username"); $stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username");
$stmt->execute(array(':username' => $email)); $stmt->execute(array(':username' => $email));
$MailboxData = $stmt->fetch(PDO::FETCH_ASSOC); $MailboxData = $stmt->fetch(PDO::FETCH_ASSOC);
$displayname = empty($MailboxData['name']) ? $email : $MailboxData['name'];
} }
catch(PDOException $e) { catch(PDOException $e) {
die("Failed to determine name from SQL");
}
if (!empty($MailboxData['name'])) {
$displayname = $MailboxData['name'];
}
else {
$displayname = $email; $displayname = $email;
} }
if (isset($_GET['only_email'])) {
$onlyEmailAccount = true;
$description = 'IMAP';
} else {
$onlyEmailAccount = false;
$description = 'IMAP, CalDAV, CardDAV';
}
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
?> ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>PayloadContent</key> <key>PayloadContent</key>
<array> <array>
<dict>
<key>CalDAVAccountDescription</key>
<string><?php echo $domain; ?></string>
<key>CalDAVHostName</key>
<string><?php echo $autodiscover_config['caldav']['server']; ?></string>
<key>CalDAVPort</key>
<real><?php echo $autodiscover_config['caldav']['port']; ?></real>
<key>CalDAVPrincipalURL</key>
<string>/SOGo/dav/<?php echo $email; ?></string>
<key>CalDAVUseSSL</key>
<true/>
<key>CalDAVUsername</key>
<string><?php echo $email; ?></string>
<key>PayloadDescription</key>
<string>Configures CalDAV account.</string>
<key>PayloadDisplayName</key>
<string>CalDAV (<?php echo $domain; ?>)</string>
<key>PayloadIdentifier</key>
<string><?php echo $identifier; ?>.CalDAV</string>
<key>PayloadOrganization</key>
<string></string>
<key>PayloadType</key>
<string>com.apple.caldav.account</string>
<key>PayloadUUID</key>
<string>FC898573-EBA8-48AF-93BD-BFA0C9778FA7</string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
<dict> <dict>
<key>EmailAccountDescription</key> <key>EmailAccountDescription</key>
<string><?php echo $domain; ?></string> <string><?=$email?></string>
<key>EmailAccountType</key> <key>EmailAccountType</key>
<string>EmailTypeIMAP</string> <string>EmailTypeIMAP</string>
<key>EmailAccountName</key> <key>EmailAccountName</key>
<string><?php echo $displayname; ?></string> <string><?=$displayname?></string>
<key>EmailAddress</key> <key>EmailAddress</key>
<string><?php echo $email; ?></string> <string><?=$email?></string>
<key>IncomingMailServerAuthentication</key> <key>IncomingMailServerAuthentication</key>
<string>EmailAuthPassword</string> <string>EmailAuthPassword</string>
<key>IncomingMailServerHostName</key> <key>IncomingMailServerHostName</key>
<string><?php echo $autodiscover_config['imap']['server']; ?></string> <string><?=$autodiscover_config['imap']['server']?></string>
<key>IncomingMailServerPortNumber</key> <key>IncomingMailServerPortNumber</key>
<integer><?php echo $autodiscover_config['imap']['port']; ?></integer> <integer><?=$autodiscover_config['imap']['port']?></integer>
<key>IncomingMailServerUseSSL</key> <key>IncomingMailServerUseSSL</key>
<true/> <true/>
<key>IncomingMailServerUsername</key> <key>IncomingMailServerUsername</key>
<string><?php echo $email; ?></string> <string><?=$email?></string>
<key>OutgoingMailServerAuthentication</key> <key>OutgoingMailServerAuthentication</key>
<string>EmailAuthPassword</string> <string>EmailAuthPassword</string>
<key>OutgoingMailServerHostName</key> <key>OutgoingMailServerHostName</key>
<string><?php echo $autodiscover_config['smtp']['server']; ?></string> <string><?=$autodiscover_config['smtp']['server']?></string>
<key>OutgoingMailServerPortNumber</key> <key>OutgoingMailServerPortNumber</key>
<integer><?php echo $autodiscover_config['smtp']['port']; ?></integer> <integer><?=$autodiscover_config['smtp']['port']?></integer>
<key>OutgoingMailServerUseSSL</key> <key>OutgoingMailServerUseSSL</key>
<true/> <true/>
<key>OutgoingMailServerUsername</key> <key>OutgoingMailServerUsername</key>
<string><?php echo $email; ?></string> <string><?=$email?></string>
<key>OutgoingPasswordSameAsIncomingPassword</key> <key>OutgoingPasswordSameAsIncomingPassword</key>
<true/> <true/>
<key>PayloadDescription</key> <key>PayloadDescription</key>
<string>Configures email account.</string> <string>Configures email account.</string>
<key>PayloadDisplayName</key> <key>PayloadDisplayName</key>
<string>IMAP Account (<?php echo $domain; ?>)</string> <string>IMAP Account (<?=$email?>)</string>
<key>PayloadIdentifier</key> <key>PayloadIdentifier</key>
<string><?php echo $identifier; ?>.email</string> <string><?=$identifier?>.email</string>
<key>PayloadOrganization</key> <key>PayloadOrganization</key>
<string></string> <string></string>
<key>PayloadType</key> <key>PayloadType</key>
<string>com.apple.mail.managed</string> <string>com.apple.mail.managed</string>
<key>PayloadUUID</key> <key>PayloadUUID</key>
<string>00294FBB-1016-413E-87B9-652D856D6875</string> <string><?=getGUID()?></string>
<key>PayloadVersion</key> <key>PayloadVersion</key>
<integer>1</integer> <integer>1</integer>
<key>PreventAppSheet</key> <key>PreventAppSheet</key>
@ -120,50 +95,80 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
<key>SMIMEEnabled</key> <key>SMIMEEnabled</key>
<false/> <false/>
</dict> </dict>
<?php if($onlyEmailAccount === false): ?>
<dict>
<key>CalDAVAccountDescription</key>
<string><?=$email?></string>
<key>CalDAVHostName</key>
<string><?=$autodiscover_config['caldav']['server']?></string>
<key>CalDAVPort</key>
<real><?=$autodiscover_config['caldav']['port']?></real>
<key>CalDAVPrincipalURL</key>
<string>/SOGo/dav/<?=$email?></string>
<key>CalDAVUseSSL</key>
<true/>
<key>CalDAVUsername</key>
<string><?=$email?></string>
<key>PayloadDescription</key>
<string>Configures CalDAV account.</string>
<key>PayloadDisplayName</key>
<string>CalDAV (<?=$email?>)</string>
<key>PayloadIdentifier</key>
<string><?=$identifier?>.CalDAV</string>
<key>PayloadOrganization</key>
<string></string>
<key>PayloadType</key>
<string>com.apple.caldav.account</string>
<key>PayloadUUID</key>
<string><?=getGUID()?></string>
<key>PayloadVersion</key>
<integer>1</integer>
</dict>
<dict> <dict>
<key>CardDAVAccountDescription</key> <key>CardDAVAccountDescription</key>
<string><?php echo $domain; ?></string> <string><?=$email?></string>
<key>CardDAVHostName</key> <key>CardDAVHostName</key>
<string><?php echo $autodiscover_config['carddav']['server']; ?></string> <string><?=$autodiscover_config['carddav']['server']?></string>
<key>CardDAVPort</key> <key>CardDAVPort</key>
<integer><?php echo $autodiscover_config['carddav']['port']; ?></integer> <integer><?=$autodiscover_config['carddav']['port']?></integer>
<key>CardDAVPrincipalURL</key> <key>CardDAVPrincipalURL</key>
<string>/SOGo/dav/<?php echo $email; ?></string> <string>/SOGo/dav/<?=$email?></string>
<key>CardDAVUseSSL</key> <key>CardDAVUseSSL</key>
<true/> <true/>
<key>CardDAVUsername</key> <key>CardDAVUsername</key>
<string><?php echo $email; ?></string> <string><?=$email?></string>
<key>PayloadDescription</key> <key>PayloadDescription</key>
<string>Configures CardDAV accounts</string> <string>Configures CardDAV accounts</string>
<key>PayloadDisplayName</key> <key>PayloadDisplayName</key>
<string>CardDAV (<?php echo $domain; ?>)</string> <string>CardDAV (<?=$email?>)</string>
<key>PayloadIdentifier</key> <key>PayloadIdentifier</key>
<string><?php echo $identifier; ?>.carddav</string> <string><?=$identifier?>.carddav</string>
<key>PayloadOrganization</key> <key>PayloadOrganization</key>
<string></string> <string></string>
<key>PayloadType</key> <key>PayloadType</key>
<string>com.apple.carddav.account</string> <string>com.apple.carddav.account</string>
<key>PayloadUUID</key> <key>PayloadUUID</key>
<string>0797EF2B-B1F1-4BC7-ABCD-4580862252B4</string> <string><?=getGUID()?></string>
<key>PayloadVersion</key> <key>PayloadVersion</key>
<integer>1</integer> <integer>1</integer>
</dict> </dict>
<?php endif; ?>
</array> </array>
<key>PayloadDescription</key> <key>PayloadDescription</key>
<string>IMAP, CalDAV, CardDAV</string> <string><?=$description?></string>
<key>PayloadDisplayName</key> <key>PayloadDisplayName</key>
<string><?php echo $domain; ?> Mailcow</string> <string><?=$email?></string>
<key>PayloadIdentifier</key> <key>PayloadIdentifier</key>
<string><?php echo $identifier; ?></string> <string><?=$identifier?></string>
<key>PayloadOrganization</key> <key>PayloadOrganization</key>
<string></string> <string><?=$UI_TEXTS['main_name']?></string>
<key>PayloadRemovalDisallowed</key> <key>PayloadRemovalDisallowed</key>
<false/> <false/>
<key>PayloadType</key> <key>PayloadType</key>
<string>Configuration</string> <string>Configuration</string>
<key>PayloadUUID</key> <key>PayloadUUID</key>
<string>5EE248C5-ACCB-42D8-9199-8F8ED08D5624</string> <string><?=getGUID()?></string>
<key>PayloadVersion</key> <key>PayloadVersion</key>
<integer>1</integer> <integer>1</integer>
</dict> </dict>
</plist> </plist>