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 #!/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 exec apache2-foreground

View file

@ -22,30 +22,33 @@ class Init {
$loader->request_page(); $loader->request_page();
} }
private function get_config(){ private function get_config(){
// define the config file location // parse the default config file for default values
$config = Core::root_dir()."/config/config.ini"; $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 // parse the default services file for default values
// YOU REALLY SHOULD HAVE YOUR OWN CONFIG FILE!!! $default_services = parse_ini_file(Core::root_dir()."/default-config/services.default.ini", true);
if (!file_exists($config)) { // define the custom services file location
$config = Core::root_dir()."/sample-config/config.sample.ini"; $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 // merge the default config with the custom config
$services = Core::root_dir()."/config/services.ini"; Core::$Config["Services"] = array_merge($default_services,$services);
// if it doesn't exist, use the sample file // get the current git commit, if it exists. For testing
// 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);
Core::$Config["CommitID"] = Core::get_current_git_commit(); Core::$Config["CommitID"] = Core::get_current_git_commit();
} }
} }

View file

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

View file

@ -73,6 +73,9 @@ class Responder {
// Cycle through each service and add to payload // Cycle through each service and add to payload
foreach (Core::$Config["Services"] as $key => $service){ foreach (Core::$Config["Services"] as $key => $service){
if (!$service["Enabled"]) {
continue;
}
$response->content[$key] = $service; $response->content[$key] = $service;
} }
@ -130,7 +133,7 @@ class Response {
public $url; public $url;
public $content_type = "json"; public $content_type = "json";
public $message; public $message;
public $headers_set = false; // public $headers_set = false;
public $content = array(); public $content = array();
public function __construct(){ public function __construct(){
// add requested page to response. I don't know why, but it could helpful for diagnostics at some point // 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 ; The URL of this application
BaseURL = "https://autoconfig.example.com" BaseURL = "https://autoconfig.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
; Set the base email domain for use with this service Domain[] = example.com
Domain = example.com Domain[] = example2.com
; If you use a different domain to authenticate with, enter it here ; If you use a different domain to authenticate with, enter it here
LogonDomain = example.local 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 ; The Incoming mail Server Config
[InMail] [InMail]
; Enable this service
Enabled = true
; Mail Type, i.e. IMAP, POP3 ; Mail Type, i.e. IMAP, POP3
Type = "IMAP" Type = "IMAP"
@ -13,6 +16,15 @@ Port = 993
; The socket type : SSL, STARTTLS, or NONE ; The socket type : SSL, STARTTLS, or NONE
SocketType = SSL 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, ; Authentication type,
;"password-cleartext" : Send password in the clear ;"password-cleartext" : Send password in the clear
; (dangerous, if SSL isn't used either). ; (dangerous, if SSL isn't used either).
@ -23,9 +35,14 @@ SocketType = SSL
; the Windows login mechanism. ; the Windows login mechanism.
Authentication = password-cleartext Authentication = password-cleartext
; The Outgoing mail server config ; The Outgoing mail server config
[OutMail] [OutMail]
; Enable this service
Enabled = true
; Mail type, likely to only be SMTP ; Mail type, likely to only be SMTP
Type = "SMTP" Type = "SMTP"
@ -41,30 +58,53 @@ SocketType = SSL
; See InMail > Authentication ; See InMail > Authentication
Authentication = password-cleartext 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 ; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
;[Calendar] [Calendar]
;Server = "https://example.com/remote.php/dav/" ; Disable this service
;Port = 443 Enabled = false
;Type = CalDAV Server = "https://example.com/remote.php/dav/"
;Authentication = http-basic Port = 443
Type = CalDAV
Authentication = http-basic
UsernameIsFQDN = false
; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat ; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
;[AddressBook] [AddressBook]
;Server = "https://example.com/remote.php/dav/" ; Disable this service
;Port = 443 Enabled = false
;Type = CardDAV Server = "https://example.com/remote.php/dav/"
;Authentication = http-basic Port = 443
Type = CardDAV
Authentication = http-basic
UsernameIsFQDN = false
; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat ; Currently not implemented, see https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
;[WebMail] [WebMail]
;Server = https://mail.example.com ; Disable this service
;UsernameDivID = "username" Enabled = false
;UsernameDivName = "username" Server = https://mail.example.com
;PasswordDivName = "password" UsernameDivID = "username"
;SubmitButtonID = "submit" UsernameDivName = "username"
;SubmitButtonName = "submit" PasswordDivName = "password"
SubmitButtonID = "submit"
SubmitButtonName = "submit"
UsernameIsFQDN = false
; In theory, additional custom services can be configured and will be displayed with ; In theory, additional custom services can be configured and will be displayed with

View file

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

View file

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