added ms-autodiscover

This commit is contained in:
Paul Wilde 2021-08-11 09:33:06 +01:00
parent 1e27206820
commit 4411a0aaf1
6 changed files with 79 additions and 32 deletions

View file

@ -40,6 +40,9 @@ class Responder {
case "mail/config-v1.1.xml": case "mail/config-v1.1.xml":
$resp = $this->moz_auto_config(); $resp = $this->moz_auto_config();
break; break;
case "autodiscover":
$resp = $this->ms_autodiscover();
break;
case "none": case "none":
case "test": case "test":
case "home": case "home":
@ -70,6 +73,12 @@ class Responder {
$response->content = "public/autoconfig.php"; $response->content = "public/autoconfig.php";
return $response; return $response;
} }
private function ms_autodiscover(){
$response = new Response();
$response->content_type = "xml";
$response->content = "public/autodiscover.php";
return $response;
}
private function dummy_response(){ private function dummy_response(){
// Generate a dummy response for testing // Generate a dummy response for testing
$response = new Response(); $response = new Response();

View file

@ -2,29 +2,40 @@
$conf = Core::$Config["Services"]; $conf = Core::$Config["Services"];
$data = Core::get_get_data(); $data = Core::get_get_data();
$email_provided = false; $email_provided = false;
if ($data["path"]) { $display_name = false;
$query = parse_url($data["path"]); $emailaddress = false;
$email = explode("=",$query["query"]); if ($data["emailaddress"]) {
if ($email[0] == "emailaddress") { $email_address = $data["emailaddress"];
$email = $email[1]; $display_name = $email_address;
$email_provided = true; $email_provided = true;
if (Core::$Config["LogonDomain"]) { } else if ($data["path"]) {
$email = str_ireplace(Core::$Config["Domain"],Core::$Config["LogonDomain"],$email); $query = parse_url($data["path"]);
$email_address = explode("=",$query["query"]);
if ($email_address[0] == "emailaddress") {
$email_address = $email[1];
$email_provided = true;
$display_name = $email_address;
} }
}
if ($email_provided) {
if(!Core::$Config["RequireAuthDomain"]) {
$email_address = str_ireplace("@".Core::$Config["Domain"],"",$email_address);
} else if (Core::$Config["LogonDomain"]) {
$email_address = str_ireplace(Core::$Config["Domain"],Core::$Config["LogonDomain"],$email_address);
} }
} }
?> ?>
<clientConfig version="1.1"> <clientConfig version="1.1">
<emailProvider id="<?php echo Core::$Config["Domain"]?>"> <emailProvider id="<?php echo Core::$Config["Domain"]?>">
<domain><?php echo Core::$Config["Domain"]?></domain> <domain><?php echo Core::$Config["Domain"]?></domain>
<displayName><?php echo $email_provided ? $email : "%EMAILADDRESS%" ;?></displayName> <displayName><?php echo $email_provided ? $display_name : "%EMAILADDRESS%" ;?></displayName>
<?php if($conf["InMail"]){ <?php if($conf["InMail"]){
$in = $conf["InMail"]; ?> $in = $conf["InMail"]; ?>
<incomingServer type="<?php echo strtolower($in["Type"]);?>"> <incomingServer type="<?php echo strtolower($in["Type"]);?>">
<hostname><?php echo $in["Server"];?></hostname> <hostname><?php echo $in["Server"];?></hostname>
<port><?php echo $in["Port"];?></port> <port><?php echo $in["Port"];?></port>
<socketType><?php echo $in["SocketType"];?></socketType> <socketType><?php echo $in["SocketType"];?></socketType>
<username><?php echo $email_provided ? $email : "%EMAILADDRESS%";?></username> <username><?php echo $email_provided ? $email_address : "%EMAILADDRESS%";?></username>
<authentication><?php echo $in["Authentication"];?></authentication> <authentication><?php echo $in["Authentication"];?></authentication>
</incomingServer> </incomingServer>
<?php } ?> <?php } ?>
@ -34,7 +45,7 @@ if ($data["path"]) {
<hostname><?php echo $out["Server"];?></hostname> <hostname><?php echo $out["Server"];?></hostname>
<port><?php echo $out["Port"];?></port> <port><?php echo $out["Port"];?></port>
<socketType><?php echo $out["SocketType"];?></socketType> <socketType><?php echo $out["SocketType"];?></socketType>
<username><?php echo $email_provided ? $email : "%EMAILADDRESS%";?></username> <username><?php echo $email_provided ? $email_address : "%EMAILADDRESS%";?></username>
<authentication><?php echo $out["Authentication"];?></authentication> <authentication><?php echo $out["Authentication"];?></authentication>
</outgoingServer> </outgoingServer>
<?php } ?> <?php } ?>

View file

@ -1,30 +1,42 @@
<?php
$conf = Core::$Config["Services"];
//get raw POST data so we can extract the email address
$data = file_get_contents("php://input");
preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $data, $matches);
echo '<?xml version="1.0" encoding="utf-8" ?>'; ?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006"> <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a"> <Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<Account> <Account>
<AccountType>email</AccountType> <AccountType>email</AccountType>
<Action>settings</Action> <Action>settings</Action>
<?php if ($conf["InMail"]){
$in = $conf["InMail"];?>
<Protocol> <Protocol>
<Type>IMAP</Type> <Type><?php echo $in["Type"];?></Type>
<Server>server.hostname.com</Server> <Server><?php echo $in["Server"];?></Server>
<Port>993</Port> <Port><?php echo $in["Port"];?></Port>
<DomainRequired>off</DomainRequired> <DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName> <LoginName><?php echo $matches[1]; ?></LoginName>
<SPA>off</SPA> <SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
<SSL>on</SSL> <SSL><?php echo $in["SocketType"] == "SSL" ? "on" : "off";?></SSL>
<AuthRequired>on</AuthRequired> <AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>
</Protocol> </Protocol>
<?php }
if ($conf["OutMail"]) {
$out = $conf["OutMail"];?>
<Protocol> <Protocol>
<Type>SMTP</Type> <Type><?php echo $out["Type"];?></Type>
<Server>server.hostname.com</Server> <Server><?php echo $out["Server"];?></Server>
<Port>587</Port> <Port><?php echo $out["Port"];?></Port>
<DomainRequired>off</DomainRequired> <DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName> <LoginName><?php echo $matches[1]; ?></LoginName>
<SPA>off</SPA> <SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
<Encryption>TLS</Encryption> <Encryption><?php echo $in["SocketType"];?></Encryption>
<AuthRequired>on</AuthRequired> <AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>
<UsePOPAuth>off</UsePOPAuth> <UsePOPAuth><?php echo $in["POPAuth"] ? "on" : "off";?></UsePOPAuth>
<SMTPLast>off</SMTPLast> <SMTPLast><?php echo $in["SMTPLast"] ? "on" : "off";?></SMTPLast>
</Protocol> </Protocol>
<?php } ?>
</Account> </Account>
</Response> </Response>
</Autodiscover> </Autodiscover>

View file

@ -4,6 +4,7 @@
; Set the base domain for use with this service ; Set the base domain for use with this service
Domain = example.com Domain = example.com
LogonDomain = example.local LogonDomain = example.local
RequireAuthDomain = false
; Admin User configuration ; Admin User configuration
; not in use yet ; not in use yet

4
test-entry.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
a2enmod rewrite
service apache2 stop
exec apache2-foreground

10
test-server.sh Normal file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
podman run --name davdiscover-test \
--rm \
-p "8010:80" \
-v ./src:/var/www/html/ \
-v ./config:/var/www/html/config \
-v ./test-entry.sh:/test-entry.sh \
--entrypoint "/bin/bash" \
php:7.4-apache \
/test-entry.sh