added mozilla autoconfig file generation

This commit is contained in:
Paul Wilde 2021-08-10 21:14:47 +01:00
parent 7342c1ccda
commit a3bc938449
6 changed files with 101 additions and 20 deletions

View file

@ -19,9 +19,6 @@ class Loader {
break;
default:
$p = $this->get_page_name();
if (substr($p,0,6) != "/admin") {
header('Content-Type: application/json'); // <-- header declaration
}
if(substr($p,0,1) == "/") {
Core::$CurrentPage = substr($p,1);
} else {

View file

@ -1,5 +1,6 @@
<?php
class Responder {
private $Response;
public function show_response(){
// get the response detailed by the url requested
$response = $this->get_response();
@ -13,8 +14,19 @@ class Responder {
}
}
private function send_response($response){
// Send json encoded response
echo json_encode($response, true);
switch ($response->content_type){
case "json":
header('Content-Type: application/json');
// Send json encoded response
echo json_encode($response, true);
break;
case "xml":
header('Content-Type: application/xml');
include ($response->content);
break;
}
}
private function get_response(){
$resp = false;
@ -25,8 +37,8 @@ class Responder {
case "get/all":
$resp = $this->all_urls();
break;
case "get/select":
$resp = $this->selection();
case "mail/config-v1.1.xml":
$resp = $this->moz_auto_config();
break;
case "none":
case "test":
@ -40,8 +52,6 @@ class Responder {
return $resp;
}
private function all_urls(){
// This would be the default request from, say, an app.
$response = new Response();
// TODO:: Will work out a better message later
@ -49,23 +59,22 @@ class Responder {
// Cycle through each service and add to payload
foreach (Core::$Config["Services"] as $key => $service){
$response->payload[$key] = $service;
$response->content[$key] = $service;
}
return $response;
}
private function selection(){
private function moz_auto_config(){
$response = new Response();
$response->message = "Not Implemented";
$uri = Core::full_url();
$response->payload = parse_url($uri);
$response->content_type = "xml";
$response->content = "public/autoconfig.php";
return $response;
}
private function dummy_response(){
// Generate a dummy response for testing
$response = new Response();
$response->message = "OK, here's some scrumptious data! Enjoy!";
$response->payload = array("data" => array("some_data" => "Ohhhhhmmmm nom nom nom nom nom nom",
$response->content = array("data" => array("some_data" => "Ohhhhhmmmm nom nom nom nom nom nom",
"extra_data" => array("garnish" => "buuuuuuuuuuurp")),
"more_data" => "yuuuuuum yum yum yum");
return $response;
@ -79,8 +88,9 @@ class Responder {
}
class Response {
public $url;
public $content_type = "json";
public $message;
public $payload = array();
public $content = array();
public function __construct(){
// add requested page to response. I don't know why, but it could helpful for diagnostics at some point
$this->url = Core::$CurrentPage;

39
src/public/autoconfig.php Normal file
View file

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

View file

@ -0,0 +1,30 @@
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
<Response xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a">
<Account>
<AccountType>email</AccountType>
<Action>settings</Action>
<Protocol>
<Type>IMAP</Type>
<Server>server.hostname.com</Server>
<Port>993</Port>
<DomainRequired>off</DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName>
<SPA>off</SPA>
<SSL>on</SSL>
<AuthRequired>on</AuthRequired>
</Protocol>
<Protocol>
<Type>SMTP</Type>
<Server>server.hostname.com</Server>
<Port>587</Port>
<DomainRequired>off</DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName>
<SPA>off</SPA>
<Encryption>TLS</Encryption>
<AuthRequired>on</AuthRequired>
<UsePOPAuth>off</UsePOPAuth>
<SMTPLast>off</SMTPLast>
</Protocol>
</Account>
</Response>
</Autodiscover>

View file

@ -1,6 +1,9 @@
; Sample config.ini file.
; Copy this file to "config/config.ini" and adjust the settings to your requirements
; Set the base domain for use with this service
Domain = example.com
; Admin User configuration
; not in use yet
;[AdminUser]

View file

@ -1,14 +1,16 @@
[InMail]
Type = "IMAP"
Server = "imap.example.com"
Protocol = "IMAP"
Port = 993
TLS = true
SocketType = SSL
Authentication = password-cleartext
[OutMail]
Type = "SMTP"
Server = "smtp.example.com"
Protocol = "SMTP"
Port = 465
TLS = true
SocketType = SSL
Authentication = password-cleartext
[CalDav]
Server = "https://caldav.example.com/etc/etc/"