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;
$emailaddress = false;
if ($data["emailaddress"]) {
$email_address = $data["emailaddress"];
$display_name = $email_address;
$email_provided = true;
} else if ($data["path"]) {
$query = parse_url($data["path"]); $query = parse_url($data["path"]);
$email = explode("=",$query["query"]); $email_address = explode("=",$query["query"]);
if ($email[0] == "emailaddress") { if ($email_address[0] == "emailaddress") {
$email = $email[1]; $email_address = $email[1];
$email_provided = true; $email_provided = true;
if (Core::$Config["LogonDomain"]) { $display_name = $email_address;
$email = str_ireplace(Core::$Config["Domain"],Core::$Config["LogonDomain"],$email); }
} }
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>
<Protocol> <?php if ($conf["InMail"]){
<Type>IMAP</Type> $in = $conf["InMail"];?>
<Server>server.hostname.com</Server> <Protocol>
<Port>993</Port> <Type><?php echo $in["Type"];?></Type>
<DomainRequired>off</DomainRequired> <Server><?php echo $in["Server"];?></Server>
<LoginName><?php echo $matches[1]; ?></LoginName> <Port><?php echo $in["Port"];?></Port>
<SPA>off</SPA> <DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<SSL>on</SSL> <LoginName><?php echo $matches[1]; ?></LoginName>
<AuthRequired>on</AuthRequired> <SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
</Protocol> <SSL><?php echo $in["SocketType"] == "SSL" ? "on" : "off";?></SSL>
<Protocol> <AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>
<Type>SMTP</Type> </Protocol>
<Server>server.hostname.com</Server> <?php }
<Port>587</Port> if ($conf["OutMail"]) {
<DomainRequired>off</DomainRequired> $out = $conf["OutMail"];?>
<LoginName><?php echo $matches[1]; ?></LoginName> <Protocol>
<SPA>off</SPA> <Type><?php echo $out["Type"];?></Type>
<Encryption>TLS</Encryption> <Server><?php echo $out["Server"];?></Server>
<AuthRequired>on</AuthRequired> <Port><?php echo $out["Port"];?></Port>
<UsePOPAuth>off</UsePOPAuth> <DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<SMTPLast>off</SMTPLast> <LoginName><?php echo $matches[1]; ?></LoginName>
</Protocol> <SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
<Encryption><?php echo $in["SocketType"];?></Encryption>
<AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>
<UsePOPAuth><?php echo $in["POPAuth"] ? "on" : "off";?></UsePOPAuth>
<SMTPLast><?php echo $in["SMTPLast"] ? "on" : "off";?></SMTPLast>
</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