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

View File

@ -17,6 +17,28 @@ $database_name = getenv('DBNAME');
// Other variables
$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
// Can be "form" or "previous"
// "form" will stay in the current form, "previous" will redirect to previous page

View File

@ -122,6 +122,14 @@ services:
- DBUSER=${DBUSER}
- DBPASS=${DBPASS}
- 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
logging:
options: