56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
|
|
|
$url = parse_url($_SERVER['REQUEST_URI']);
|
|
|
|
function parseMail($email) {
|
|
global $user, $domain;
|
|
$parts = explode('@', $email);
|
|
|
|
if (isset($parts[0]))
|
|
$user = $parts[0];
|
|
if (isset($parts[0]))
|
|
$domain = $parts[1];
|
|
}
|
|
|
|
switch ($url['path']) {
|
|
case '/autodiscover/autodiscover.xml':
|
|
$raw = file_get_contents('php://input');
|
|
$matches = [];
|
|
|
|
if (preg_match('/<EMailAddress>(.*)<\/EMailAddress>/', $raw, $matches) === 1) {
|
|
parseMail($matches[1]);
|
|
} else {
|
|
$domainPart = array_slice(explode('.', $_SERVER['HTTP_HOST']), -2);
|
|
$domain = implode('.', $domainPart);
|
|
}
|
|
|
|
$template = 'autodiscover.xml';
|
|
break;
|
|
case '/mail/config-v1.1.xml':
|
|
case '/.well-known/autoconfig/mail/config-v1.1.xml':
|
|
$user = '%EMAILLOCALPART%';
|
|
$domain = '%EMAILDOMAIN%';
|
|
$template = 'autoconfig.xml';
|
|
|
|
if (isset($_GET['emailaddress']))
|
|
parseMail($_GET['emailaddress']);
|
|
break;
|
|
default:
|
|
header('HTTP/1.0 404 Not Found');
|
|
exit;
|
|
}
|
|
|
|
$config = require('/etc/vn-autoconfig/config.php');
|
|
extract($config);
|
|
|
|
$finalDefaults = [
|
|
'imapServer' => "imap.$domain",
|
|
'imapPort' => 993,
|
|
'smtpServer' => "smtp.$domain",
|
|
'smtpPort' => 465
|
|
];
|
|
extract($finalDefaults, EXTR_SKIP);
|
|
|
|
header('Content-type: application/xml');
|
|
include($template);
|