mobileconfig.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. require_once 'inc/prerequisites.inc.php';
  3. if (empty($mailcow_hostname)) {
  4. exit();
  5. }
  6. if (!isset($_SESSION['mailcow_cc_role']) || $_SESSION['mailcow_cc_role'] != 'user') {
  7. header("Location: index.php");
  8. die("This page is only available to logged-in users, not admins.");
  9. }
  10. error_reporting(0);
  11. header('Content-Type: application/x-apple-aspen-config');
  12. header('Content-Disposition: attachment; filename="'.$UI_TEXTS['main_name'].'.mobileconfig"');
  13. $email = $_SESSION['mailcow_cc_username'];
  14. $domain = explode('@', $_SESSION['mailcow_cc_username'])[1];
  15. $identifier = implode('.', array_reverse(preg_split( '/(@|\.)/', $email))) . '.appleprofile.'.preg_replace('/[^a-zA-Z0-9]+/', '', $UI_TEXTS['main_name']);
  16. try {
  17. $stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username");
  18. $stmt->execute(array(':username' => $email));
  19. $MailboxData = $stmt->fetch(PDO::FETCH_ASSOC);
  20. $displayname = htmlspecialchars(empty($MailboxData['name']) ? $email : $MailboxData['name'], ENT_NOQUOTES);
  21. }
  22. catch(PDOException $e) {
  23. $displayname = $email;
  24. }
  25. if (isset($_GET['only_email'])) {
  26. $onlyEmailAccount = true;
  27. $description = 'IMAP';
  28. } else {
  29. $onlyEmailAccount = false;
  30. $description = 'IMAP, CalDAV, CardDAV';
  31. }
  32. echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  33. ?>
  34. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  35. <plist version="1.0">
  36. <dict>
  37. <key>PayloadContent</key>
  38. <array>
  39. <dict>
  40. <key>EmailAccountDescription</key>
  41. <string><?=$email?></string>
  42. <key>EmailAccountType</key>
  43. <string>EmailTypeIMAP</string>
  44. <key>EmailAccountName</key>
  45. <string><?=$displayname?></string>
  46. <key>EmailAddress</key>
  47. <string><?=$email?></string>
  48. <key>IncomingMailServerAuthentication</key>
  49. <string>EmailAuthPassword</string>
  50. <key>IncomingMailServerHostName</key>
  51. <string><?=$autodiscover_config['imap']['server']?></string>
  52. <key>IncomingMailServerPortNumber</key>
  53. <integer><?=$autodiscover_config['imap']['port']?></integer>
  54. <key>IncomingMailServerUseSSL</key>
  55. <true/>
  56. <key>IncomingMailServerUsername</key>
  57. <string><?=$email?></string>
  58. <key>OutgoingMailServerAuthentication</key>
  59. <string>EmailAuthPassword</string>
  60. <key>OutgoingMailServerHostName</key>
  61. <string><?=$autodiscover_config['smtp']['server']?></string>
  62. <key>OutgoingMailServerPortNumber</key>
  63. <integer><?=$autodiscover_config['smtp']['port']?></integer>
  64. <key>OutgoingMailServerUseSSL</key>
  65. <true/>
  66. <key>OutgoingMailServerUsername</key>
  67. <string><?=$email?></string>
  68. <key>OutgoingPasswordSameAsIncomingPassword</key>
  69. <true/>
  70. <key>PayloadDescription</key>
  71. <string>Configures email account.</string>
  72. <key>PayloadDisplayName</key>
  73. <string>IMAP Account (<?=$email?>)</string>
  74. <key>PayloadIdentifier</key>
  75. <string><?=$identifier?>.email</string>
  76. <key>PayloadOrganization</key>
  77. <string></string>
  78. <key>PayloadType</key>
  79. <string>com.apple.mail.managed</string>
  80. <key>PayloadUUID</key>
  81. <string><?=getGUID()?></string>
  82. <key>PayloadVersion</key>
  83. <integer>1</integer>
  84. <key>PreventAppSheet</key>
  85. <false/>
  86. <key>PreventMove</key>
  87. <false/>
  88. <key>SMIMEEnabled</key>
  89. <false/>
  90. </dict>
  91. <?php if($onlyEmailAccount === false): ?>
  92. <dict>
  93. <key>CalDAVAccountDescription</key>
  94. <string><?=$email?></string>
  95. <key>CalDAVHostName</key>
  96. <string><?=$autodiscover_config['caldav']['server']?></string>
  97. <key>CalDAVPort</key>
  98. <real><?=$autodiscover_config['caldav']['port']?></real>
  99. <key>CalDAVPrincipalURL</key>
  100. <string>/SOGo/dav/<?=$email?></string>
  101. <key>CalDAVUseSSL</key>
  102. <true/>
  103. <key>CalDAVUsername</key>
  104. <string><?=$email?></string>
  105. <key>PayloadDescription</key>
  106. <string>Configures CalDAV account.</string>
  107. <key>PayloadDisplayName</key>
  108. <string>CalDAV (<?=$email?>)</string>
  109. <key>PayloadIdentifier</key>
  110. <string><?=$identifier?>.CalDAV</string>
  111. <key>PayloadOrganization</key>
  112. <string></string>
  113. <key>PayloadType</key>
  114. <string>com.apple.caldav.account</string>
  115. <key>PayloadUUID</key>
  116. <string><?=getGUID()?></string>
  117. <key>PayloadVersion</key>
  118. <integer>1</integer>
  119. </dict>
  120. <dict>
  121. <key>CardDAVAccountDescription</key>
  122. <string><?=$email?></string>
  123. <key>CardDAVHostName</key>
  124. <string><?=$autodiscover_config['carddav']['server']?></string>
  125. <key>CardDAVPort</key>
  126. <integer><?=$autodiscover_config['carddav']['port']?></integer>
  127. <key>CardDAVPrincipalURL</key>
  128. <string>/SOGo/dav/<?=$email?></string>
  129. <key>CardDAVUseSSL</key>
  130. <true/>
  131. <key>CardDAVUsername</key>
  132. <string><?=$email?></string>
  133. <key>PayloadDescription</key>
  134. <string>Configures CardDAV accounts</string>
  135. <key>PayloadDisplayName</key>
  136. <string>CardDAV (<?=$email?>)</string>
  137. <key>PayloadIdentifier</key>
  138. <string><?=$identifier?>.carddav</string>
  139. <key>PayloadOrganization</key>
  140. <string></string>
  141. <key>PayloadType</key>
  142. <string>com.apple.carddav.account</string>
  143. <key>PayloadUUID</key>
  144. <string><?=getGUID()?></string>
  145. <key>PayloadVersion</key>
  146. <integer>1</integer>
  147. </dict>
  148. <?php endif; ?>
  149. </array>
  150. <key>PayloadDescription</key>
  151. <string><?=$description?></string>
  152. <key>PayloadDisplayName</key>
  153. <string><?=$email?></string>
  154. <key>PayloadIdentifier</key>
  155. <string><?=$identifier?></string>
  156. <key>PayloadOrganization</key>
  157. <string><?=$UI_TEXTS['main_name']?></string>
  158. <key>PayloadRemovalDisallowed</key>
  159. <false/>
  160. <key>PayloadType</key>
  161. <string>Configuration</string>
  162. <key>PayloadUUID</key>
  163. <string><?=getGUID()?></string>
  164. <key>PayloadVersion</key>
  165. <integer>1</integer>
  166. </dict>
  167. </plist>