2017-06-29 00:59:15 +08:00
|
|
|
<?php
|
2018-10-11 17:59:23 +08:00
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/vars.inc.php';
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/functions.inc.php';
|
2017-06-29 05:22:51 +08:00
|
|
|
$default_autodiscover_config = $autodiscover_config;
|
2017-06-29 00:59:15 +08:00
|
|
|
if(file_exists('inc/vars.local.inc.php')) {
|
|
|
|
include_once 'inc/vars.local.inc.php';
|
|
|
|
}
|
2017-09-16 19:33:27 +08:00
|
|
|
$autodiscover_config = array_merge($default_autodiscover_config, $autodiscover_config);
|
2017-06-29 00:59:15 +08:00
|
|
|
|
2017-07-23 21:27:18 +08:00
|
|
|
// Redis
|
|
|
|
$redis = new Redis();
|
2020-02-05 18:04:14 +08:00
|
|
|
try {
|
|
|
|
if (!empty(getenv('REDIS_SLAVEOF_IP'))) {
|
|
|
|
$redis->connect(getenv('REDIS_SLAVEOF_IP'), getenv('REDIS_SLAVEOF_PORT'));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$redis->connect('redis-mailcow', 6379);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception $e) {
|
|
|
|
exit;
|
|
|
|
}
|
2017-07-23 21:27:18 +08:00
|
|
|
|
2017-06-29 00:59:15 +08:00
|
|
|
error_reporting(0);
|
|
|
|
|
|
|
|
$data = trim(file_get_contents("php://input"));
|
|
|
|
|
2017-10-03 22:48:33 +08:00
|
|
|
if (strpos($data, 'autodiscover/outlook/responseschema') !== false) {
|
|
|
|
$autodiscover_config['autodiscoverType'] = 'imap';
|
|
|
|
if ($autodiscover_config['useEASforOutlook'] == 'yes' &&
|
|
|
|
// Office for macOS does not support EAS
|
|
|
|
strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') === false &&
|
|
|
|
// Outlook 2013 (version 15) or higher
|
2018-02-20 08:42:23 +08:00
|
|
|
preg_match('/(Outlook|Office).+1[5-9]\./', $_SERVER['HTTP_USER_AGENT'])
|
2017-10-03 22:48:33 +08:00
|
|
|
) {
|
|
|
|
$autodiscover_config['autodiscoverType'] = 'activesync';
|
2017-06-29 00:59:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 23:27:47 +08:00
|
|
|
if (getenv('SKIP_SOGO') == "y") {
|
|
|
|
$autodiscover_config['autodiscoverType'] = 'imap';
|
|
|
|
}
|
|
|
|
|
[Docker API] Use TLS encryption for communication with "on-the-fly" created key paris (non-exposed)
[Docker API] Create pipe to pass Rspamd UI worker password
[Dovecot] Pull Spamassassin ruleset to be read by Rspamd (MANY THANKS to Peer Heinlein!)
[Dovecot] Garbage collector for deleted maildirs (set keep time via MAILDIR_GC_TIME which defaults to 1440 minutes)
[Web] Flush memcached after mailbox item changes, fixes #1808
[Web] Fix duplicate IDs, fixes #1792
[Compose] Use SQL sockets
[PHP-FPM] Update APCu and Redis libs
[Dovecot] Encrypt maildir with global key pair in crypt-vol-1 (BACKUP!), also fixes #1791
[Web] Fix deletion of spam aliases
[Helper] Add "crypt" to backup script
[Helper] Override file for external SQL socket (not supported!)
[Compose] New images for Rspamd, PHP-FPM, SOGo, Dovecot, Docker API, Watchdog, ACME, Postfix
2018-09-30 04:01:23 +08:00
|
|
|
//$dsn = $database_type . ":host=" . $database_host . ";dbname=" . $database_name;
|
|
|
|
$dsn = $database_type . ":unix_socket=" . $database_sock . ";dbname=" . $database_name;
|
2017-06-29 00:59:15 +08:00
|
|
|
$opt = [
|
|
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
|
|
];
|
|
|
|
$pdo = new PDO($dsn, $database_user, $database_pass, $opt);
|
|
|
|
$login_user = strtolower(trim($_SERVER['PHP_AUTH_USER']));
|
2017-11-04 03:37:24 +08:00
|
|
|
$login_pass = trim(htmlspecialchars_decode($_SERVER['PHP_AUTH_PW']));
|
2017-06-29 00:59:15 +08:00
|
|
|
|
2018-02-22 16:16:16 +08:00
|
|
|
if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW'])) {
|
2018-08-04 02:31:33 +08:00
|
|
|
$json = json_encode(
|
|
|
|
array(
|
|
|
|
"time" => time(),
|
|
|
|
"ua" => $_SERVER['HTTP_USER_AGENT'],
|
|
|
|
"user" => "none",
|
2021-10-24 18:53:20 +08:00
|
|
|
"ip" => $_SERVER['REMOTE_ADDR'],
|
2018-08-04 02:31:33 +08:00
|
|
|
"service" => "Error: must be authenticated"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$redis->lPush('AUTODISCOVER_LOG', $json);
|
2017-10-03 04:19:20 +08:00
|
|
|
header('WWW-Authenticate: Basic realm="' . $_SERVER['HTTP_HOST'] . '"');
|
2017-06-29 00:59:15 +08:00
|
|
|
header('HTTP/1.0 401 Unauthorized');
|
|
|
|
exit(0);
|
|
|
|
}
|
2018-02-22 16:16:16 +08:00
|
|
|
|
|
|
|
$login_role = check_login($login_user, $login_pass);
|
|
|
|
|
|
|
|
if ($login_role === "user") {
|
|
|
|
header("Content-Type: application/xml");
|
|
|
|
echo '<?xml version="1.0" encoding="utf-8" ?>' . PHP_EOL;
|
2017-06-29 00:59:15 +08:00
|
|
|
?>
|
|
|
|
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
|
|
|
|
<?php
|
2018-02-22 16:16:16 +08:00
|
|
|
if(!$data) {
|
|
|
|
try {
|
|
|
|
$json = json_encode(
|
|
|
|
array(
|
|
|
|
"time" => time(),
|
|
|
|
"ua" => $_SERVER['HTTP_USER_AGENT'],
|
|
|
|
"user" => $_SERVER['PHP_AUTH_USER'],
|
2021-10-24 18:53:20 +08:00
|
|
|
"ip" => $_SERVER['REMOTE_ADDR'],
|
2018-02-22 16:16:16 +08:00
|
|
|
"service" => "Error: invalid or missing request data"
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$redis->lPush('AUTODISCOVER_LOG', $json);
|
|
|
|
$redis->lTrim('AUTODISCOVER_LOG', 0, 100);
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2018-02-22 16:16:16 +08:00
|
|
|
'type' => 'danger',
|
|
|
|
'msg' => 'Redis: '.$e
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
list($usec, $sec) = explode(' ', microtime());
|
2017-06-29 00:59:15 +08:00
|
|
|
?>
|
|
|
|
<Response>
|
|
|
|
<Error Time="<?=date('H:i:s', $sec) . substr($usec, 0, strlen($usec) - 2);?>" Id="2477272013">
|
|
|
|
<ErrorCode>600</ErrorCode>
|
|
|
|
<Message>Invalid Request</Message>
|
|
|
|
<DebugData />
|
|
|
|
</Error>
|
|
|
|
</Response>
|
|
|
|
</Autodiscover>
|
|
|
|
<?php
|
2018-02-22 16:16:16 +08:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$discover = new SimpleXMLElement($data);
|
|
|
|
$email = $discover->Request->EMailAddress;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$email = $_SERVER['PHP_AUTH_USER'];
|
|
|
|
}
|
2017-07-11 02:52:51 +08:00
|
|
|
|
2018-02-22 16:16:16 +08:00
|
|
|
$username = trim($email);
|
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare("SELECT `name` FROM `mailbox` WHERE `username`= :username");
|
|
|
|
$stmt->execute(array(':username' => $username));
|
|
|
|
$MailboxData = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
}
|
|
|
|
catch(PDOException $e) {
|
|
|
|
die("Failed to determine name from SQL");
|
|
|
|
}
|
|
|
|
if (!empty($MailboxData['name'])) {
|
|
|
|
$displayname = $MailboxData['name'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$displayname = $email;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$json = json_encode(
|
|
|
|
array(
|
|
|
|
"time" => time(),
|
|
|
|
"ua" => $_SERVER['HTTP_USER_AGENT'],
|
|
|
|
"user" => $_SERVER['PHP_AUTH_USER'],
|
2021-10-24 18:53:20 +08:00
|
|
|
"ip" => $_SERVER['REMOTE_ADDR'],
|
2018-02-22 16:16:16 +08:00
|
|
|
"service" => $autodiscover_config['autodiscoverType']
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$redis->lPush('AUTODISCOVER_LOG', $json);
|
|
|
|
$redis->lTrim('AUTODISCOVER_LOG', 0, 100);
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-14 05:20:40 +08:00
|
|
|
$_SESSION['return'][] = array(
|
2018-02-22 16:16:16 +08:00
|
|
|
'type' => 'danger',
|
|
|
|
'msg' => 'Redis: '.$e
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($autodiscover_config['autodiscoverType'] == 'imap') {
|
2017-06-29 00:59:15 +08:00
|
|
|
?>
|
|
|
|
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
|
|
|
|
<User>
|
2018-02-10 06:03:08 +08:00
|
|
|
<DisplayName><?=htmlspecialchars($displayname, ENT_XML1 | ENT_QUOTES, 'UTF-8');?></DisplayName>
|
2017-06-29 00:59:15 +08:00
|
|
|
</User>
|
|
|
|
<Account>
|
|
|
|
<AccountType>email</AccountType>
|
|
|
|
<Action>settings</Action>
|
|
|
|
<Protocol>
|
|
|
|
<Type>IMAP</Type>
|
2017-09-16 19:33:27 +08:00
|
|
|
<Server><?=$autodiscover_config['imap']['server'];?></Server>
|
|
|
|
<Port><?=$autodiscover_config['imap']['port'];?></Port>
|
2017-06-29 00:59:15 +08:00
|
|
|
<DomainRequired>off</DomainRequired>
|
|
|
|
<LoginName><?=$email;?></LoginName>
|
|
|
|
<SPA>off</SPA>
|
2017-06-29 05:22:51 +08:00
|
|
|
<SSL>on</SSL>
|
2017-06-29 00:59:15 +08:00
|
|
|
<AuthRequired>on</AuthRequired>
|
|
|
|
</Protocol>
|
|
|
|
<Protocol>
|
|
|
|
<Type>SMTP</Type>
|
2017-09-16 19:33:27 +08:00
|
|
|
<Server><?=$autodiscover_config['smtp']['server'];?></Server>
|
|
|
|
<Port><?=$autodiscover_config['smtp']['port'];?></Port>
|
2017-06-29 00:59:15 +08:00
|
|
|
<DomainRequired>off</DomainRequired>
|
|
|
|
<LoginName><?=$email;?></LoginName>
|
|
|
|
<SPA>off</SPA>
|
2017-06-29 05:22:51 +08:00
|
|
|
<SSL>on</SSL>
|
2017-06-29 00:59:15 +08:00
|
|
|
<AuthRequired>on</AuthRequired>
|
|
|
|
<UsePOPAuth>on</UsePOPAuth>
|
|
|
|
<SMTPLast>off</SMTPLast>
|
|
|
|
</Protocol>
|
2020-04-27 23:27:47 +08:00
|
|
|
<?php
|
|
|
|
if (getenv('SKIP_SOGO') != "y") {
|
|
|
|
?>
|
2017-06-29 00:59:15 +08:00
|
|
|
<Protocol>
|
|
|
|
<Type>CalDAV</Type>
|
2017-10-03 04:46:55 +08:00
|
|
|
<Server>https://<?=$autodiscover_config['caldav']['server'];?><?php if ($autodiscover_config['caldav']['port'] != 443) echo ':'.$autodiscover_config['caldav']['port']; ?>/SOGo/dav/<?=$email;?>/</Server>
|
2017-06-29 00:59:15 +08:00
|
|
|
<DomainRequired>off</DomainRequired>
|
|
|
|
<LoginName><?=$email;?></LoginName>
|
|
|
|
</Protocol>
|
|
|
|
<Protocol>
|
|
|
|
<Type>CardDAV</Type>
|
2017-10-03 04:46:55 +08:00
|
|
|
<Server>https://<?=$autodiscover_config['carddav']['server'];?><?php if ($autodiscover_config['caldav']['port'] != 443) echo ':'.$autodiscover_config['carddav']['port']; ?>/SOGo/dav/<?=$email;?>/</Server>
|
2017-06-29 00:59:15 +08:00
|
|
|
<DomainRequired>off</DomainRequired>
|
|
|
|
<LoginName><?=$email;?></LoginName>
|
|
|
|
</Protocol>
|
2020-04-27 23:27:47 +08:00
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|
2017-06-29 00:59:15 +08:00
|
|
|
</Account>
|
|
|
|
</Response>
|
|
|
|
<?php
|
2018-02-22 16:16:16 +08:00
|
|
|
}
|
|
|
|
else if ($autodiscover_config['autodiscoverType'] == 'activesync') {
|
2017-06-29 00:59:15 +08:00
|
|
|
?>
|
|
|
|
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006">
|
|
|
|
<Culture>en:en</Culture>
|
|
|
|
<User>
|
2018-02-10 06:03:08 +08:00
|
|
|
<DisplayName><?=htmlspecialchars($displayname, ENT_XML1 | ENT_QUOTES, 'UTF-8');?></DisplayName>
|
2017-06-29 00:59:15 +08:00
|
|
|
<EMailAddress><?=$email;?></EMailAddress>
|
|
|
|
</User>
|
|
|
|
<Action>
|
|
|
|
<Settings>
|
|
|
|
<Server>
|
|
|
|
<Type>MobileSync</Type>
|
2017-09-16 19:33:27 +08:00
|
|
|
<Url><?=$autodiscover_config['activesync']['url'];?></Url>
|
|
|
|
<Name><?=$autodiscover_config['activesync']['url'];?></Name>
|
2017-06-29 00:59:15 +08:00
|
|
|
</Server>
|
|
|
|
</Settings>
|
|
|
|
</Action>
|
|
|
|
</Response>
|
|
|
|
<?php
|
2018-02-22 16:16:16 +08:00
|
|
|
}
|
2017-06-29 00:59:15 +08:00
|
|
|
?>
|
|
|
|
</Autodiscover>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
?>
|