Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | <?php |
| 2 | require_once 'inc/prerequisites.inc.php'; |
| 3 | |
| 4 | if (empty($mailcow_hostname)) { |
| 5 | exit(); |
| 6 | } |
| 7 | if (!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' : ''; |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 11 | $append_get .= (isset($_GET['app_password'])) ? '&app_password' : ''; |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 12 | header('Location: index.php?mobileconfig' . $append_get); |
| 13 | die(); |
| 14 | } |
| 15 | |
| 16 | error_reporting(0); |
| 17 | |
| 18 | header('Content-Type: application/x-apple-aspen-config'); |
| 19 | header('Content-Disposition: attachment; filename="'.$UI_TEXTS['main_name'].'.mobileconfig"'); |
| 20 | |
| 21 | $email = $_SESSION['mailcow_cc_username']; |
| 22 | $domain = explode('@', $_SESSION['mailcow_cc_username'])[1]; |
| 23 | $identifier = implode('.', array_reverse(preg_split( '/(@|\.)/', $email))) . '.appleprofile.'.preg_replace('/[^a-zA-Z0-9]+/', '', $UI_TEXTS['main_name']); |
| 24 | |
| 25 | try { |
| 26 | $stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username"); |
| 27 | $stmt->execute(array(':username' => $email)); |
| 28 | $MailboxData = $stmt->fetch(PDO::FETCH_ASSOC); |
| 29 | $displayname = htmlspecialchars(empty($MailboxData['name']) ? $email : $MailboxData['name'], ENT_NOQUOTES); |
| 30 | } |
| 31 | catch(PDOException $e) { |
| 32 | $displayname = $email; |
| 33 | } |
| 34 | |
| 35 | if (isset($_GET['only_email'])) { |
| 36 | $onlyEmailAccount = true; |
| 37 | $description = 'IMAP'; |
| 38 | } else { |
| 39 | $onlyEmailAccount = false; |
| 40 | $description = 'IMAP, CalDAV, CardDAV'; |
| 41 | } |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 42 | if (isset($_GET['app_password'])) { |
| 43 | $app_password = true; |
| 44 | $description .= ' with application password'; |
| 45 | |
| 46 | if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== FALSE) |
| 47 | $platform = 'iPad'; |
| 48 | elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE) |
| 49 | $platform = 'iPhone'; |
| 50 | elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Macintosh') !== FALSE) |
| 51 | $platform = 'Mac'; |
| 52 | else |
| 53 | $platform = $_SERVER['HTTP_USER_AGENT']; |
| 54 | |
| 55 | $password = bin2hex(openssl_random_pseudo_bytes(16)); |
| 56 | $attr = array( |
| 57 | 'app_name' => $platform, |
| 58 | 'app_passwd' => $password, |
| 59 | 'app_passwd2' => $password, |
| 60 | 'active' => 1, |
| 61 | 'protocols' => array('imap_access', 'smtp_access'), |
| 62 | ); |
| 63 | if (!$onlyEmailAccount) { |
| 64 | $attr['protocols'][] = 'dav_access'; |
| 65 | } |
| 66 | app_passwd("add", $attr); |
| 67 | } else { |
| 68 | $app_password = false; |
| 69 | } |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 70 | |
| 71 | echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; |
| 72 | ?> |
| 73 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 74 | <plist version="1.0"> |
| 75 | <dict> |
| 76 | <key>PayloadContent</key> |
| 77 | <array> |
| 78 | <dict> |
| 79 | <key>EmailAccountDescription</key> |
| 80 | <string><?=$email?></string> |
| 81 | <key>EmailAccountType</key> |
| 82 | <string>EmailTypeIMAP</string> |
| 83 | <key>EmailAccountName</key> |
| 84 | <string><?=$displayname?></string> |
| 85 | <key>EmailAddress</key> |
| 86 | <string><?=$email?></string> |
| 87 | <key>IncomingMailServerAuthentication</key> |
| 88 | <string>EmailAuthPassword</string> |
| 89 | <key>IncomingMailServerHostName</key> |
| 90 | <string><?=$autodiscover_config['imap']['server']?></string> |
| 91 | <key>IncomingMailServerPortNumber</key> |
| 92 | <integer><?=$autodiscover_config['imap']['port']?></integer> |
| 93 | <key>IncomingMailServerUseSSL</key> |
| 94 | <true/> |
| 95 | <key>IncomingMailServerUsername</key> |
| 96 | <string><?=$email?></string> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 97 | <?php if($app_password === true): ?> |
| 98 | <key>IncomingPassword</key> |
| 99 | <string><?=$password?></string> |
| 100 | <?php endif; ?> |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 101 | <key>OutgoingMailServerAuthentication</key> |
| 102 | <string>EmailAuthPassword</string> |
| 103 | <key>OutgoingMailServerHostName</key> |
| 104 | <string><?=$autodiscover_config['smtp']['server']?></string> |
| 105 | <key>OutgoingMailServerPortNumber</key> |
| 106 | <integer><?=$autodiscover_config['smtp']['port']?></integer> |
| 107 | <key>OutgoingMailServerUseSSL</key> |
| 108 | <true/> |
| 109 | <key>OutgoingMailServerUsername</key> |
| 110 | <string><?=$email?></string> |
| 111 | <key>OutgoingPasswordSameAsIncomingPassword</key> |
| 112 | <true/> |
| 113 | <key>PayloadDescription</key> |
| 114 | <string>Configures email account.</string> |
| 115 | <key>PayloadDisplayName</key> |
| 116 | <string>IMAP Account (<?=$email?>)</string> |
| 117 | <key>PayloadIdentifier</key> |
| 118 | <string><?=$identifier?>.email</string> |
| 119 | <key>PayloadOrganization</key> |
| 120 | <string></string> |
| 121 | <key>PayloadType</key> |
| 122 | <string>com.apple.mail.managed</string> |
| 123 | <key>PayloadUUID</key> |
| 124 | <string><?=getGUID()?></string> |
| 125 | <key>PayloadVersion</key> |
| 126 | <integer>1</integer> |
| 127 | <key>PreventAppSheet</key> |
| 128 | <false/> |
| 129 | <key>PreventMove</key> |
| 130 | <false/> |
| 131 | <key>SMIMESigningUserOverrideable</key> |
| 132 | <true/> |
| 133 | <key>SMIMESigningCertificateUUIDUserOverrideable</key> |
| 134 | <true/> |
| 135 | <key>SMIMEEncryptByDefaultUserOverrideable</key> |
| 136 | <true/> |
| 137 | <key>SMIMEEncryptionCertificateUUIDUserOverrideable</key> |
| 138 | <true/> |
| 139 | <key>SMIMEEnableEncryptionPerMessageSwitch</key> |
| 140 | <true/> |
| 141 | </dict> |
| 142 | <?php if($onlyEmailAccount === false): ?> |
| 143 | <dict> |
| 144 | <key>CalDAVAccountDescription</key> |
| 145 | <string><?=$email?></string> |
| 146 | <key>CalDAVHostName</key> |
| 147 | <string><?=$autodiscover_config['caldav']['server']?></string> |
| 148 | <key>CalDAVPort</key> |
| 149 | <real><?=$autodiscover_config['caldav']['port']?></real> |
| 150 | <key>CalDAVPrincipalURL</key> |
| 151 | <string>/SOGo/dav/<?=$email?></string> |
| 152 | <key>CalDAVUseSSL</key> |
| 153 | <true/> |
| 154 | <key>CalDAVUsername</key> |
| 155 | <string><?=$email?></string> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 156 | <?php if($app_password === true): ?> |
| 157 | <key>CalDAVPassword</key> |
| 158 | <string><?=$password?></string> |
| 159 | <?php endif; ?> |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 160 | <key>PayloadDescription</key> |
| 161 | <string>Configures CalDAV account.</string> |
| 162 | <key>PayloadDisplayName</key> |
| 163 | <string>CalDAV (<?=$email?>)</string> |
| 164 | <key>PayloadIdentifier</key> |
| 165 | <string><?=$identifier?>.CalDAV</string> |
| 166 | <key>PayloadOrganization</key> |
| 167 | <string></string> |
| 168 | <key>PayloadType</key> |
| 169 | <string>com.apple.caldav.account</string> |
| 170 | <key>PayloadUUID</key> |
| 171 | <string><?=getGUID()?></string> |
| 172 | <key>PayloadVersion</key> |
| 173 | <integer>1</integer> |
| 174 | </dict> |
| 175 | <dict> |
| 176 | <key>CardDAVAccountDescription</key> |
| 177 | <string><?=$email?></string> |
| 178 | <key>CardDAVHostName</key> |
| 179 | <string><?=$autodiscover_config['carddav']['server']?></string> |
| 180 | <key>CardDAVPort</key> |
| 181 | <integer><?=$autodiscover_config['carddav']['port']?></integer> |
| 182 | <key>CardDAVPrincipalURL</key> |
| 183 | <string>/SOGo/dav/<?=$email?></string> |
| 184 | <key>CardDAVUseSSL</key> |
| 185 | <true/> |
| 186 | <key>CardDAVUsername</key> |
| 187 | <string><?=$email?></string> |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 188 | <?php if($app_password === true): ?> |
| 189 | <key>CardDAVPassword</key> |
| 190 | <string><?=$password?></string> |
| 191 | <?php endif; ?> |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 192 | <key>PayloadDescription</key> |
| 193 | <string>Configures CardDAV accounts</string> |
| 194 | <key>PayloadDisplayName</key> |
| 195 | <string>CardDAV (<?=$email?>)</string> |
| 196 | <key>PayloadIdentifier</key> |
| 197 | <string><?=$identifier?>.carddav</string> |
| 198 | <key>PayloadOrganization</key> |
| 199 | <string></string> |
| 200 | <key>PayloadType</key> |
| 201 | <string>com.apple.carddav.account</string> |
| 202 | <key>PayloadUUID</key> |
| 203 | <string><?=getGUID()?></string> |
| 204 | <key>PayloadVersion</key> |
| 205 | <integer>1</integer> |
| 206 | </dict> |
| 207 | <?php endif; ?> |
| 208 | </array> |
| 209 | <key>PayloadDescription</key> |
| 210 | <string><?=$description?></string> |
| 211 | <key>PayloadDisplayName</key> |
| 212 | <string><?=$email?></string> |
| 213 | <key>PayloadIdentifier</key> |
| 214 | <string><?=$identifier?></string> |
| 215 | <key>PayloadOrganization</key> |
| 216 | <string><?=$UI_TEXTS['main_name']?></string> |
| 217 | <key>PayloadRemovalDisallowed</key> |
| 218 | <false/> |
| 219 | <key>PayloadType</key> |
| 220 | <string>Configuration</string> |
| 221 | <key>PayloadUUID</key> |
| 222 | <string><?=getGUID()?></string> |
| 223 | <key>PayloadVersion</key> |
| 224 | <integer>1</integer> |
| 225 | </dict> |
| 226 | </plist> |