mobileconfig.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. header('Content-Type: application/x-apple-aspen-config');
  11. header('Content-Disposition: attachment; filename="Mailcow.mobileconfig"');
  12. $email = $_SESSION['mailcow_cc_username'];
  13. $domain = explode('@', $_SESSION['mailcow_cc_username'])[1];
  14. $identifier = implode('.', array_reverse(explode('.', $domain))) . '.iphoneprofile.mailcow';
  15. try {
  16. $stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username");
  17. $stmt->execute(array(':username' => $email));
  18. $MailboxData = $stmt->fetch(PDO::FETCH_ASSOC);
  19. }
  20. catch(PDOException $e) {
  21. die("Failed to determine name from SQL");
  22. }
  23. if (!empty($MailboxData['name'])) {
  24. $displayname = utf8_encode($MailboxData['name']);
  25. }
  26. else {
  27. $displayname = $email;
  28. }
  29. echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  30. ?>
  31. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  32. <plist version="1.0">
  33. <dict>
  34. <key>PayloadContent</key>
  35. <array>
  36. <dict>
  37. <key>CalDAVAccountDescription</key>
  38. <string><?php echo $domain; ?></string>
  39. <key>CalDAVHostName</key>
  40. <string><?php echo $autodiscover_config['caldav']['server']; ?></string>
  41. <key>CalDAVPort</key>
  42. <real><?php echo $autodiscover_config['caldav']['port']; ?></real>
  43. <key>CalDAVPrincipalURL</key>
  44. <string>/SOGo/dav/<?php echo $email; ?></string>
  45. <key>CalDAVUseSSL</key>
  46. <true/>
  47. <key>CalDAVUsername</key>
  48. <string><?php echo $email; ?></string>
  49. <key>PayloadDescription</key>
  50. <string>Configures CalDAV account.</string>
  51. <key>PayloadDisplayName</key>
  52. <string>CalDAV (<?php echo $domain; ?>)</string>
  53. <key>PayloadIdentifier</key>
  54. <string><?php echo $identifier; ?>.CalDAV</string>
  55. <key>PayloadOrganization</key>
  56. <string></string>
  57. <key>PayloadType</key>
  58. <string>com.apple.caldav.account</string>
  59. <key>PayloadUUID</key>
  60. <string>FC898573-EBA8-48AF-93BD-BFA0C9778FA7</string>
  61. <key>PayloadVersion</key>
  62. <integer>1</integer>
  63. </dict>
  64. <dict>
  65. <key>EmailAccountDescription</key>
  66. <string><?php echo $domain; ?></string>
  67. <key>EmailAccountType</key>
  68. <string>EmailTypeIMAP</string>
  69. <key>EmailAccountName</key>
  70. <string><?php echo $displayname; ?></string>
  71. <key>EmailAddress</key>
  72. <string><?php echo $email; ?></string>
  73. <key>IncomingMailServerAuthentication</key>
  74. <string>EmailAuthPassword</string>
  75. <key>IncomingMailServerHostName</key>
  76. <string><?php echo $autodiscover_config['imap']['server']; ?></string>
  77. <key>IncomingMailServerPortNumber</key>
  78. <integer><?php echo $autodiscover_config['imap']['port']; ?></integer>
  79. <key>IncomingMailServerUseSSL</key>
  80. <true/>
  81. <key>IncomingMailServerUsername</key>
  82. <string><?php echo $email; ?></string>
  83. <key>OutgoingMailServerAuthentication</key>
  84. <string>EmailAuthPassword</string>
  85. <key>OutgoingMailServerHostName</key>
  86. <string><?php echo $autodiscover_config['smtp']['server']; ?></string>
  87. <key>OutgoingMailServerPortNumber</key>
  88. <integer><?php echo $autodiscover_config['smtp']['port']; ?></integer>
  89. <key>OutgoingMailServerUseSSL</key>
  90. <true/>
  91. <key>OutgoingMailServerUsername</key>
  92. <string><?php echo $email; ?></string>
  93. <key>OutgoingPasswordSameAsIncomingPassword</key>
  94. <true/>
  95. <key>PayloadDescription</key>
  96. <string>Configures email account.</string>
  97. <key>PayloadDisplayName</key>
  98. <string>IMAP Account (<?php echo $domain; ?>)</string>
  99. <key>PayloadIdentifier</key>
  100. <string><?php echo $identifier; ?>.email</string>
  101. <key>PayloadOrganization</key>
  102. <string></string>
  103. <key>PayloadType</key>
  104. <string>com.apple.mail.managed</string>
  105. <key>PayloadUUID</key>
  106. <string>00294FBB-1016-413E-87B9-652D856D6875</string>
  107. <key>PayloadVersion</key>
  108. <integer>1</integer>
  109. <key>PreventAppSheet</key>
  110. <false/>
  111. <key>PreventMove</key>
  112. <false/>
  113. <key>SMIMEEnabled</key>
  114. <false/>
  115. </dict>
  116. <dict>
  117. <key>CardDAVAccountDescription</key>
  118. <string><?php echo $domain; ?></string>
  119. <key>CardDAVHostName</key>
  120. <string><?php echo $autodiscover_config['carddav']['server']; ?></string>
  121. <key>CardDAVPort</key>
  122. <integer><?php echo $autodiscover_config['carddav']['port']; ?></integer>
  123. <key>CardDAVPrincipalURL</key>
  124. <string>/SOGo/dav/<?php echo $email; ?></string>
  125. <key>CardDAVUseSSL</key>
  126. <true/>
  127. <key>CardDAVUsername</key>
  128. <string><?php echo $email; ?></string>
  129. <key>PayloadDescription</key>
  130. <string>Configures CardDAV accounts</string>
  131. <key>PayloadDisplayName</key>
  132. <string>CardDAV (<?php echo $domain; ?>)</string>
  133. <key>PayloadIdentifier</key>
  134. <string><?php echo $identifier; ?>.carddav</string>
  135. <key>PayloadOrganization</key>
  136. <string></string>
  137. <key>PayloadType</key>
  138. <string>com.apple.carddav.account</string>
  139. <key>PayloadUUID</key>
  140. <string>0797EF2B-B1F1-4BC7-ABCD-4580862252B4</string>
  141. <key>PayloadVersion</key>
  142. <integer>1</integer>
  143. </dict>
  144. </array>
  145. <key>PayloadDescription</key>
  146. <string>IMAP, CalDAV, CardDAV</string>
  147. <key>PayloadDisplayName</key>
  148. <string><?php echo $domain; ?> Mailcow</string>
  149. <key>PayloadIdentifier</key>
  150. <string><?php echo $identifier; ?></string>
  151. <key>PayloadOrganization</key>
  152. <string></string>
  153. <key>PayloadRemovalDisallowed</key>
  154. <false/>
  155. <key>PayloadType</key>
  156. <string>Configuration</string>
  157. <key>PayloadUUID</key>
  158. <string>5EE248C5-ACCB-42D8-9199-8F8ED08D5624</string>
  159. <key>PayloadVersion</key>
  160. <integer>1</integer>
  161. </dict>
  162. </plist>