Fix autodiscover, pass ports to phpfpm-mailcow for further features and autodiscover

master
andryyy 2017-06-25 18:09:42 +02:00
parent bb77ba41c0
commit b6bc1eaf0a
3 changed files with 52 additions and 25 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
require_once 'inc/vars.inc.php'; require_once 'inc/vars.inc.php';
require_once 'inc/functions.inc.php'; require_once 'inc/functions.inc.php';
$config = array( $autodiscover_config = array(
'useEASforOutlook' => 'yes', 'useEASforOutlook' => 'yes',
'autodiscoverType' => 'activesync', 'autodiscoverType' => 'activesync',
'imap' => array( 'imap' => array(
@ -19,7 +19,7 @@ $config = array(
) )
); );
if(file_exists('inc/vars.local.inc.php')) { if (file_exists('inc/vars.local.inc.php')) {
include_once 'inc/vars.local.inc.php'; include_once 'inc/vars.local.inc.php';
} }
@ -29,17 +29,13 @@ error_reporting(0);
$data = trim(file_get_contents("php://input")); $data = trim(file_get_contents("php://input"));
// Desktop client needs IMAP, unless it's Outlook 2013 or higher on Windows if ($autodiscover_config['useEASforOutlook'] == 'yes' &&
if (strpos($data, 'autodiscover/outlook/responseschema')) { // desktop client preg_match('/(Outlook|Office).+(1[5-9]\.)/', $_SERVER['HTTP_USER_AGENT']) &&
$config['autodiscoverType'] = 'imap'; strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') === false) {
if ($config['useEASforOutlook'] == 'yes' && $autodiscover_config['autodiscoverType'] = 'activesync';
strpos($_SERVER['HTTP_USER_AGENT'], 'Outlook') !== FALSE && // Outlook }
strpos($_SERVER['HTTP_USER_AGENT'], 'Windows NT') !== FALSE && // Windows else {
preg_match('/Outlook (1[5-9]\.|[2-9]|1[0-9][0-9])/', $_SERVER['HTTP_USER_AGENT']) && // Outlook 2013 (version 15) or higher $autodiscover_config['autodiscoverType'] = 'imap';
strpos($_SERVER['HTTP_USER_AGENT'], 'MS Connectivity Analyzer') === FALSE // https://testconnectivity.microsoft.com doesn't support EAS for Outlook
) {
$config['autodiscoverType'] = 'activesync';
}
} }
$dsn = "$database_type:host=$database_host;dbname=$database_name"; $dsn = "$database_type:host=$database_host;dbname=$database_name";
@ -56,13 +52,14 @@ if (!isset($_SERVER['PHP_AUTH_USER']) OR $as !== "user") {
header('WWW-Authenticate: Basic realm=""'); header('WWW-Authenticate: Basic realm=""');
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
exit; exit;
} else { }
else {
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
if ($as === "user") { if ($as === "user") {
header("Content-Type: application/xml"); header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="utf-8" ?><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">'; echo '<?xml version="1.0" encoding="utf-8" ?><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">';
if(!$data) { if (!$data) {
list($usec, $sec) = explode(' ', microtime()); list($usec, $sec) = explode(' ', microtime());
echo '<Response>'; echo '<Response>';
echo '<Error Time="' . date('H:i:s', $sec) . substr($usec, 0, strlen($usec) - 2) . '" Id="2477272013">'; echo '<Error Time="' . date('H:i:s', $sec) . substr($usec, 0, strlen($usec) - 2) . '" Id="2477272013">';
@ -74,7 +71,7 @@ if (!isset($_SERVER['PHP_AUTH_USER']) OR $as !== "user") {
$discover = new SimpleXMLElement($data); $discover = new SimpleXMLElement($data);
$email = $discover->Request->EMailAddress; $email = $discover->Request->EMailAddress;
if ($config['autodiscoverType'] == 'imap') { if ($autodiscover_config['autodiscoverType'] == 'imap') {
?> ?>
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"> <Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<User> <User>
@ -85,22 +82,22 @@ if (!isset($_SERVER['PHP_AUTH_USER']) OR $as !== "user") {
<Action>settings</Action> <Action>settings</Action>
<Protocol> <Protocol>
<Type>IMAP</Type> <Type>IMAP</Type>
<Server><?php echo $config['imap']['server']; ?></Server> <Server><?php echo $autodiscover_config['imap']['server']; ?></Server>
<Port><?php echo $config['imap']['port']; ?></Port> <Port><?php echo $autodiscover_config['imap']['port']; ?></Port>
<DomainRequired>off</DomainRequired> <DomainRequired>off</DomainRequired>
<LoginName><?php echo $email; ?></LoginName> <LoginName><?php echo $email; ?></LoginName>
<SPA>off</SPA> <SPA>off</SPA>
<SSL><?php echo $config['imap']['ssl']; ?></SSL> <SSL><?php echo $autodiscover_config['imap']['ssl']; ?></SSL>
<AuthRequired>on</AuthRequired> <AuthRequired>on</AuthRequired>
</Protocol> </Protocol>
<Protocol> <Protocol>
<Type>SMTP</Type> <Type>SMTP</Type>
<Server><?php echo $config['smtp']['server']; ?></Server> <Server><?php echo $autodiscover_config['smtp']['server']; ?></Server>
<Port><?php echo $config['smtp']['port']; ?></Port> <Port><?php echo $autodiscover_config['smtp']['port']; ?></Port>
<DomainRequired>off</DomainRequired> <DomainRequired>off</DomainRequired>
<LoginName><?php echo $email; ?></LoginName> <LoginName><?php echo $email; ?></LoginName>
<SPA>off</SPA> <SPA>off</SPA>
<SSL><?php echo $config['smtp']['ssl']; ?></SSL> <SSL><?php echo $autodiscover_config['smtp']['ssl']; ?></SSL>
<AuthRequired>on</AuthRequired> <AuthRequired>on</AuthRequired>
<UsePOPAuth>on</UsePOPAuth> <UsePOPAuth>on</UsePOPAuth>
<SMTPLast>off</SMTPLast> <SMTPLast>off</SMTPLast>
@ -121,7 +118,7 @@ if (!isset($_SERVER['PHP_AUTH_USER']) OR $as !== "user") {
</Response> </Response>
<?php <?php
} }
else if ($config['autodiscoverType'] == 'activesync') { else if ($autodiscover_config['autodiscoverType'] == 'activesync') {
$username = trim($email); $username = trim($email);
try { try {
$stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username"); $stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username");
@ -148,8 +145,8 @@ if (!isset($_SERVER['PHP_AUTH_USER']) OR $as !== "user") {
<Settings> <Settings>
<Server> <Server>
<Type>MobileSync</Type> <Type>MobileSync</Type>
<Url><?php echo $config['activesync']['url']; ?></Url> <Url><?php echo $autodiscover_config['activesync']['url']; ?></Url>
<Name><?php echo $config['activesync']['url']; ?></Name> <Name><?php echo $autodiscover_config['activesync']['url']; ?></Name>
</Server> </Server>
</Settings> </Settings>
</Action> </Action>

View File

@ -17,6 +17,28 @@ $database_name = getenv('DBNAME');
// Other variables // Other variables
$mailcow_hostname = getenv('MAILCOW_HOSTNAME'); $mailcow_hostname = getenv('MAILCOW_HOSTNAME');
// Autodiscover settings
$autodiscover_config = array(
// Enable the autodiscover service for Outlook desktop clients
'useEASforOutlook' => 'yes',
// General autodiscover service type: "activesync" or "imap"
'autodiscoverType' => 'activesync',
'imap' => array(
'server' => $mailcow_hostname,
'port' => getenv('IMAPS_PORT'),
'ssl' => 'on',
),
'smtp' => array(
'server' => $mailcow_hostname,
'port' => getenv('SMTPS_PORT'),
'ssl' => 'on'
),
'activesync' => array(
'url' => 'https://'.$mailcow_hostname.'/Microsoft-Server-ActiveSync'
)
);
// Where to go after adding and editing objects // Where to go after adding and editing objects
// Can be "form" or "previous" // Can be "form" or "previous"
// "form" will stay in the current form, "previous" will redirect to previous page // "form" will stay in the current form, "previous" will redirect to previous page

View File

@ -122,6 +122,14 @@ services:
- DBUSER=${DBUSER} - DBUSER=${DBUSER}
- DBPASS=${DBPASS} - DBPASS=${DBPASS}
- MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME} - MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
- IMAP_PORT=${IMAP_PORT:-143}
- IMAPS_PORT=${IMAPS_PORT:-993}
- POP_PORT=${POP_PORT:-110}
- POPS_PORT=${POPS_PORT:-995}
- SIEVE_PORT=${SIEVE_PORT:-4190}
- SUBMISSION_PORT=${SUBMISSION_PORT:-587}
- SMTPS_PORT=${SMTPS_PORT:-465}
- SMTP_PORT=${SMTP_PORT:-25}
restart: always restart: always
logging: logging:
options: options: