From b0327c0a4ea6c229a59894443ddcc9353d80211c Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Thu, 12 Aug 2021 14:55:54 +0100 Subject: [PATCH] tidied up some code, i.e. new autoconf function --- src/core/init.php | 3 +- src/core/init/responder.php | 13 +++++ src/public/autoconfig.php | 111 +++++++++++++----------------------- 3 files changed, 55 insertions(+), 72 deletions(-) diff --git a/src/core/init.php b/src/core/init.php index b35a251..a94124c 100644 --- a/src/core/init.php +++ b/src/core/init.php @@ -33,7 +33,8 @@ class Init { } // merge the default config with the custom config Core::$Config = array_merge($default_config,$config); - + Core::$Config["PrimaryDomain"] = Core::$Config["Domain"][0]; + // parse the default services file for default values $default_services = parse_ini_file(Core::root_dir()."/default-config/services.default.ini", true); diff --git a/src/core/init/responder.php b/src/core/init/responder.php index eb06e49..e3c394f 100644 --- a/src/core/init/responder.php +++ b/src/core/init/responder.php @@ -65,6 +65,19 @@ class Responder { } return $resp; } + private function get_username($service,$email_address) { + $username = "%EMAILADDRESS%"; + if(!$service["UsernameIsFQDN"]) { + + preg_match("/^[^@]+/",$email_address,$matches); + if (count($matches) > 0){ + $username = $matches[0]; + } + } else if ($service["RequireLogonDomain"]) { + $username = preg_replace("/[^@]+$/",Core::$Config["LogonDomain"],$email_address,1); + } + return $username; + } private function all_urls(){ $response = new Response(); // Not really useful, unless some lovely app developers want to parse it for their app :) diff --git a/src/public/autoconfig.php b/src/public/autoconfig.php index 3d91f35..767abb2 100644 --- a/src/public/autoconfig.php +++ b/src/public/autoconfig.php @@ -1,95 +1,64 @@ - "> + "> - - - "> - - - - - + %EMAILADDRESS% + + "> + + + + get_username($service,$email_address); ?> + - "> - - - - - + if($services["OutMail"]&& $services["OutMail"]["Enabled"]){ + $service = $services["OutMail"]; ?> + "> + + + + get_username($service,$email_address);?> + - "> - - - + if ($services["AddressBook"] && $services["AddressBook"]["Enabled"]) { + $service = $services["AddressBook"]; ?> + "> + get_username($service,$email_address);?> + + - "> - - - + if ($services["Calendar"] && $services["Calendar"]["Enabled"]){ + $service = $services["Calendar"] ;?> + "> + get_username($service,$email_address);?> + + + if ($services["WebMail"] && $services["WebMail"]["Enabled"]) { + $service = $services["WebMail"]; ?> - " /> - "> - - " name="" /> - " /> - " name=""/> + " /> + "> + get_username($service,$email_address);?> + " name="" /> + " /> + " name=""/>