config and services files changes and handling thereof

This commit is contained in:
Paul Wilde 2021-08-12 13:41:58 +01:00
parent 48692b4765
commit 30302dfb84
8 changed files with 117 additions and 65 deletions

View file

@ -1,3 +1,8 @@
#!/usr/bin/env bash
cp /var/www/html/sample-config/* /var/www/html/config/
echo Removing old sample config files…
rm /var/www/html/config/*.sample.ini
echo Copying new sample config files…
cp /var/www/html/default-config/config.default.ini /var/www/html/config/config.sample.ini
cp /var/www/html/default-config/services.default.ini /var/www/html/config/services.sample.ini
echo Running HTTPD…
exec apache2-foreground

View file

@ -22,30 +22,33 @@ class Init {
$loader->request_page();
}
private function get_config(){
// define the config file location
$config = Core::root_dir()."/config/config.ini";
// parse the default config file for default values
$default_config = parse_ini_file(Core::root_dir()."/default-config/config.default.ini", true);
// define the custom config file location
$config_file = Core::root_dir()."/config/config.ini";
$config = array();
if (file_exists($config_file)) {
// if a custom config file exists then parse that file too
$config = parse_ini_file($config_file, true);
}
// merge the default config with the custom config
Core::$Config = array_merge($default_config,$config);
// if it doesn't exist, use the sample file
// YOU REALLY SHOULD HAVE YOUR OWN CONFIG FILE!!!
// parse the default services file for default values
$default_services = parse_ini_file(Core::root_dir()."/default-config/services.default.ini", true);
if (!file_exists($config)) {
$config = Core::root_dir()."/sample-config/config.sample.ini";
// define the custom services file location
$services_file = Core::root_dir()."/config/services.ini";
$services = array();
if (file_exists($services_file)) {
// if a custom config file exists then parse that file too
$services = parse_ini_file($services_file, true);
}
// define services file location
$services = Core::root_dir()."/config/services.ini";
// merge the default config with the custom config
Core::$Config["Services"] = array_merge($default_services,$services);
// if it doesn't exist, use the sample file
// YOU REALLY SHOULD HAVE YOUR OWN SERVICES FILE!!!
if (!file_exists($services)) {
$services = Core::root_dir()."/sample-config/services.sample.ini";
}
// Store the config settings in the Core::Config variable
// the "true" means it's going to parse the headers as well.
Core::$Config = parse_ini_file($config, true);
Core::$Config["Services"] = parse_ini_file($services, true);
// get the current git commit, if it exists. For testing
Core::$Config["CommitID"] = Core::get_current_git_commit();
}
}

View file

@ -1,6 +1,6 @@
<?php class Core {
public static $Config;
public const VERSION = "0.0.3";
public const VERSION = "0.0.4";
public static $CurrentPage;
public static function root_dir(){
return $_SERVER['DOCUMENT_ROOT'];

View file

@ -73,6 +73,9 @@ class Responder {
// Cycle through each service and add to payload
foreach (Core::$Config["Services"] as $key => $service){
if (!$service["Enabled"]) {
continue;
}
$response->content[$key] = $service;
}
@ -130,7 +133,7 @@ class Response {
public $url;
public $content_type = "json";
public $message;
public $headers_set = false;
// public $headers_set = false;
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

View file

@ -4,13 +4,10 @@
; The URL of this application
BaseURL = "https://autoconfig.example.com"
; Set the base email domain for use with this service
Domain = example.com
; Set the email domains for use with this service. The first one is primary.
; each will need their own DNS A record for autoconfig.domain.name
Domain[] = example.com
Domain[] = example2.com
; If you use a different domain to authenticate with, enter it here
LogonDomain = example.local
; Change to true if you need the domain/logondomain to form part of the username
RequireAuthDomain = false

View file

@ -1,6 +1,9 @@
; The Incoming mail Server Config
[InMail]
; Enable this service
Enabled = true
; Mail Type, i.e. IMAP, POP3
Type = "IMAP"
@ -13,6 +16,15 @@ Port = 993
; The socket type : SSL, STARTTLS, or NONE
SocketType = SSL
; Use Secure Password Authentication
SPA = false
; Change to true if you need the domain/logondomain to form part of the username
UsernameIsFQDN = false
; Do you need to authenticate to your mail server? You should! so this should be false!
NoAuthRequired = false
; Authentication type,
;"password-cleartext" : Send password in the clear
; (dangerous, if SSL isn't used either).
@ -23,9 +35,14 @@ SocketType = SSL
; the Windows login mechanism.
Authentication = password-cleartext
; The Outgoing mail server config
[OutMail]
; Enable this service
Enabled = true
; Mail type, likely to only be SMTP
Type = "SMTP"
@ -41,30 +58,53 @@ SocketType = SSL
; See InMail > Authentication
Authentication = password-cleartext
; Use Secure Password Authentication
SPA = false
; Change to true if you need the domain/logondomain to form part of the username
UsernameIsFQDN = false
; Do you need to authenticate to your mail server? You should! so this should be false!
NoAuthRequired = false
; Use POP Authentication? You probably shouldn't be.
POPAuth = false
; This setting is here to limit errors, I'm not sure what it does yet.
SMTPLast = false
; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
;[Calendar]
;Server = "https://example.com/remote.php/dav/"
;Port = 443
;Type = CalDAV
;Authentication = http-basic
[Calendar]
; Disable this service
Enabled = false
Server = "https://example.com/remote.php/dav/"
Port = 443
Type = CalDAV
Authentication = http-basic
UsernameIsFQDN = false
; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
;[AddressBook]
;Server = "https://example.com/remote.php/dav/"
;Port = 443
;Type = CardDAV
;Authentication = http-basic
[AddressBook]
; Disable this service
Enabled = false
Server = "https://example.com/remote.php/dav/"
Port = 443
Type = CardDAV
Authentication = http-basic
UsernameIsFQDN = false
; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
;[WebMail]
;Server = https://mail.example.com
;UsernameDivID = "username"
;UsernameDivName = "username"
;PasswordDivName = "password"
;SubmitButtonID = "submit"
;SubmitButtonName = "submit"
[WebMail]
; Disable this service
Enabled = false
Server = https://mail.example.com
UsernameDivID = "username"
UsernameDivName = "username"
PasswordDivName = "password"
SubmitButtonID = "submit"
SubmitButtonName = "submit"
UsernameIsFQDN = false
; In theory, additional custom services can be configured and will be displayed with

View file

@ -13,18 +13,20 @@ $data = Core::get_get_data();
$email_provided = false;
$display_name = false;
$emailaddress = false;
if ($data["emailaddress"]) {
if (isset($data["emailaddress"])) {
$email_address = $data["emailaddress"];
$display_name = $email_address;
$email_provided = true;
} else if ($data["path"]) {
$query = parse_url($data["path"]);
if (isset($query["query"])){
$email_address = explode("=",$query["query"]);
if ($email_address[0] == "emailaddress") {
$email_address = $email[1];
$email_address = $email_address[1];
$email_provided = true;
$display_name = $email_address;
}
}
}
if ($email_provided) {
if(!Core::$Config["RequireAuthDomain"]) {
@ -38,10 +40,12 @@ if ($email_provided) {
// https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
?>
<clientConfig version="1.1">
<emailProvider id="<?php echo Core::$Config["Domain"]?>">
<domain><?php echo Core::$Config["Domain"]?></domain>
<emailProvider id="<?php echo Core::$Config["Domain"][0]?>">
<?php foreach (Core::$Config["Domain"] as $domain){ ?>
<domain><?php echo $domain; ?></domain>
<?php } ?>
<displayName><?php echo $email_provided ? $display_name : "%EMAILADDRESS%" ;?></displayName>
<?php if($conf["InMail"]){
<?php if($conf["InMail"]&& $conf["InMail"]["Enabled"]){
$in = $conf["InMail"]; ?>
<incomingServer type="<?php echo strtolower($in["Type"]);?>">
<hostname><?php echo $in["Server"];?></hostname>
@ -51,7 +55,7 @@ if ($email_provided) {
<authentication><?php echo $in["Authentication"];?></authentication>
</incomingServer>
<?php }
if($conf["OutMail"]){
if($conf["OutMail"]&& $conf["OutMail"]["Enabled"]){
$out = $conf["OutMail"]; ?>
<outgoingServer type="<?php echo strtolower($out["Type"]);?>">
<hostname><?php echo $out["Server"];?></hostname>
@ -61,7 +65,7 @@ if ($email_provided) {
<authentication><?php echo $out["Authentication"];?></authentication>
</outgoingServer>
<?php }
if ($conf["AddressBook"]) {
if ($conf["AddressBook"] && $conf["AddressBook"]["Enabled"]) {
$card = $conf["AddressBook"]; ?>
<addressBook type="<?php echo strtolower($card["Type"]); ?>">
<username><?php echo $email_provided ? $email_address : "%EMAILADDRESS%";?></username>
@ -69,7 +73,7 @@ if ($email_provided) {
<serverURL><?php echo $card["Server"];?></serverURL>
</addressBook>
<?php }
if ($conf["Calendar"]){
if ($conf["Calendar"] && $conf["Calendar"]["Enabled"]){
$cal = $conf["Calendar"] ;?>
<calendar type="<?php echo strtolower($cal["Type"]);?>">
<username><?php echo $email_provided ? $email_address : "%EMAILADDRESS%";?></username>
@ -77,7 +81,7 @@ if ($email_provided) {
<serverURL><?php echo $card["Server"];?></serverURL>
</calendar>
<?php }
if ($conf["WebMail"]) {
if ($conf["WebMail"] && $conf["WebMail"]["Enabled"]) {
$wm = $conf["WebMail"]; ?>
<webMail>
<loginPage url="<?php echo $wm["Server"];?>" />

View file

@ -8,38 +8,38 @@ preg_match("/\<EMailAddress\>(.*?)\<\/EMailAddress\>/", $data, $matches);
// <?xml version="1.0" \?\>
// <Autodiscover xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
// <Request>
// <EMailAddress>psw@wilde.cloud</EMailAddress>
// <EMailAddress>your@email.address</EMailAddress>
// <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
// </Request>
// </Autodiscover>
echo '<?xml version="1.0" encoding="utf-8" ?>';?>
<Autodiscover xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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">
<Account>
<AccountType>email</AccountType>
<Action>settings</Action>
<?php if ($conf["InMail"]){
<?php if ($conf["InMail"] && $conf["InMail"]["Enabled"]){
$in = $conf["InMail"];?>
<Protocol>
<Type><?php echo $in["Type"];?></Type>
<Server><?php echo $in["Server"];?></Server>
<Port><?php echo $in["Port"];?></Port>
<DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName>
<LoginName><?php echo isset($matches[1]) ? $matches[1] : false ; ?></LoginName>
<SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
<SSL><?php echo $in["SocketType"] == "SSL" ? "on" : "off";?></SSL>
<AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>
</Protocol>
<?php }
if ($conf["OutMail"]) {
if ($conf["OutMail"]&& $conf["OutMail"]["Enabled"]) {
$out = $conf["OutMail"];?>
<Protocol>
<Type><?php echo $out["Type"];?></Type>
<Server><?php echo $out["Server"];?></Server>
<Port><?php echo $out["Port"];?></Port>
<DomainRequired><?php echo Core::$Config["RequireAuthDomain"] ? "on" : "off";?></DomainRequired>
<LoginName><?php echo $matches[1]; ?></LoginName>
<LoginName><?php echo isset($matches[1]) ? $matches[1] : false ; ?></LoginName>
<SPA><?php echo $in["SPA"] ? "on" : "off";?></SPA>
<Encryption><?php echo $in["SocketType"];?></Encryption>
<AuthRequired><?php echo $in["NoAuthRequired"] ? "off" : "on";?></AuthRequired>