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