mobileconfig.php 5.6 KB

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