goversion conversion completed

This commit is contained in:
Paul Wilde 2021-08-16 20:15:27 +01:00
parent c3831ed8dd
commit b435c1bf96
13 changed files with 244 additions and 154 deletions

View file

@ -1,15 +1,22 @@
FROM php:7.4-apache FROM golang:1-alpine3.14 AS builder
COPY src/ /var/www/html/ COPY src/ /mailautoconf
WORKDIR /mailautoconf
RUN go build -o /mailautoconf/mailautoconf
FROM alpine:3.14
ENV UID=1426 \
GID=1426
RUN apk add --no-cache bash
COPY --from=builder /mailautoconf/mailautoconf /mailautoconf/mailautoconf
COPY --from=builder /mailautoconf/default-config /mailautoconf/default-config
COPY --from=builder /mailautoconf/templates /mailautoconf/templates
COPY ./entrypoint.sh / COPY ./entrypoint.sh /
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
# Use the default production configuration EXPOSE 8010
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
RUN a2enmod rewrite
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View file

@ -1,29 +1,29 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo Removing old sample files… echo Removing old sample files…
rm /var/www/html/config/*.sample.ini rm /mailautoconf/config/*.sample.yaml
function write_file() { function write_file() {
while read line; while read line;
do do
first_char=${line:0:1} first_char=${line:0:1}
if [[ $first_char != ";" ]]; then if [[ $first_char != "#" ]]; then
line="; "$line line="#"$line
fi fi
echo $line >> $2 echo $line >> $2
done < $1 done < $1
} }
echo Setting up new sample config files… echo Setting up new sample config files…
def_conf="/var/www/html/default-config/config.default.ini" def_conf="/mailautoconf/default-config/config.default.yaml"
new_conf="/var/www/html/config/config.sample.ini" new_conf="/mailautoconf/config/config.sample.yaml"
write_file $def_conf $new_conf write_file $def_conf $new_conf
def_serv="/var/www/html/default-config/services.default.ini" def_serv="/mailautoconf/default-config/services.default.yaml"
new_serv="/var/www/html/config/services.sample.ini" new_serv="/mailautoconf/config/services.sample.yaml"
write_file $def_serv $new_serv write_file $def_serv $new_serv
echo New sample files copied
cd /mailautoconf
echo Running HTTPD… exec /mailautoconf/mailautoconf
exec apache2-foreground

View file

@ -14,4 +14,4 @@ Domains :
- "example2,com" - "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" LocalDomain : "example.local"

View file

@ -28,6 +28,9 @@ InMail:
# Change to true if you need the domain/logondomain to form part of the username # Change to true if you need the domain/logondomain to form part of the username
UsernameIsFQDN: false UsernameIsFQDN: false
# Use the LogonDomain instead of the Email Domain
RequireLocalDomain : false
# Do you need to authenticate to your mail server? You should! so this should be false! # Do you need to authenticate to your mail server? You should! so this should be false!
NoAuthRequired: false NoAuthRequired: false
@ -67,6 +70,9 @@ OutMail:
# Change to true if you need the domain/logondomain to form part of the username # Change to true if you need the domain/logondomain to form part of the username
UsernameIsFQDN: false UsernameIsFQDN: false
# Use the LogonDomain instead of the Email Domain
RequireLocalDomain : false
# Do you need to authenticate to your mail server? You should! so this should be false! # Do you need to authenticate to your mail server? You should! so this should be false!
NoAuthRequired: false NoAuthRequired: false
@ -87,6 +93,7 @@ Calendar:
Type: "CalDAV" Type: "CalDAV"
Authentication: "http-basic" Authentication: "http-basic"
UsernameIsFQDN: false UsernameIsFQDN: false
RequireLocalDomain : 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:
@ -98,6 +105,7 @@ AddressBook:
Type: "CardDAV" Type: "CardDAV"
Authentication: "http-basic" Authentication: "http-basic"
UsernameIsFQDN: false UsernameIsFQDN: false
RequireLocalDomain : 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:
@ -111,6 +119,7 @@ WebMail:
SubmitButtonID: "submit" SubmitButtonID: "submit"
SubmitButtonName: "submit" SubmitButtonName: "submit"
UsernameIsFQDN: false UsernameIsFQDN: false
RequireLocalDomain : 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

@ -3,5 +3,13 @@ module mailautoconf
go 1.16 go 1.16
require ( require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
) )

View file

@ -1,3 +1,28 @@
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e h1:VvfwVmMH40bpMeizC9/K7ipM5Qjucuu16RWfneFPyhQ=
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

View file

@ -14,11 +14,12 @@ type Config struct {
Version string `yaml:"Version"` Version string `yaml:"Version"`
BaseURL string `yaml:"BaseURL"` BaseURL string `yaml:"BaseURL"`
Domains []string `yaml:"Domains"` Domains []string `yaml:"Domains"`
LogonDomain string `yaml:"LogonDomain"` LocalDomain string `yaml:"LocalDomain"`
InMail Service `yaml:"InMail"` InMail Service `yaml:"InMail"`
OutMail Service `yaml:"OutMail"` OutMail Service `yaml:"OutMail"`
Calendar Service `yaml:"Calendar"` Calendar Service `yaml:"Calendar"`
AddressBook Service `yaml:"AddressBook"` AddressBook Service `yaml:"AddressBook"`
WebMail Service `yaml:"WebMail"`
OtherServices []Service `yaml:"OtherServices"` OtherServices []Service `yaml:"OtherServices"`
} }
@ -31,6 +32,7 @@ type Service struct {
SocketType string `yaml:"SocketType"` SocketType string `yaml:"SocketType"`
SPA bool `yaml:"SPA"` SPA bool `yaml:"SPA"`
UsernameIsFQDN bool `yaml:"UsernameIsFQDN"` UsernameIsFQDN bool `yaml:"UsernameIsFQDN"`
RequireLocalDomain bool `yaml:"RequireLocalDomain"`
NoAuthRequired bool `yaml:"NoAuthRequired"` NoAuthRequired bool `yaml:"NoAuthRequired"`
Authentication string `yaml:"Authentication"` Authentication string `yaml:"Authentication"`
// For Outgoing Mail // For Outgoing Mail
@ -47,7 +49,9 @@ type Response struct {
Url string `json:"url"` Url string `json:"url"`
ContentType string `json:"content_type"` ContentType string `json:"content_type"`
Message string `json:"message"` Message string `json:"message"`
Content []interface{} `json:"content"` Content map[string]interface{} `json:"content"`
Config Config
Email string
} }
type MSAutodiscoverJSONResponse struct { type MSAutodiscoverJSONResponse struct {
// More work to do - handling of MS Autodiscover.json requests // More work to do - handling of MS Autodiscover.json requests

View file

@ -1,64 +0,0 @@
<h1>Go templates</h1>
<p>The user is {{ .Name }}</p>
<h2>Skills:</h2>
{{ range .Skills }}
<p>{{ . }}</p>
{{ end }}
<clientConfig version="1.1">
<emailProvider id="<?php echo Core::$Config["PrimaryDomain"]?>">{{ . }}
<?php foreach (Core::$Config["Domain"] as $domain){ ?>
<domain><?php echo $domain; ?></domain>
<?php } ?>
<displayName>%EMAILADDRESS%</displayName>
<?php if($services["InMail"]&& $services["InMail"]["Enabled"]){
$service = $services["InMail"]; ?>
<incomingServer type="<?php echo strtolower($service["Type"]);?>">
<hostname><?php echo $service["Server"];?></hostname>
<port><?php echo $service["Port"];?></port>
<socketType><?php echo $service["SocketType"];?></socketType>
<username><?php echo $this->get_username($service,$email_address); ?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
</incomingServer>
<?php }
if($services["OutMail"]&& $services["OutMail"]["Enabled"]){
$service = $services["OutMail"]; ?>
<outgoingServer type="<?php echo strtolower($service["Type"]);?>">
<hostname><?php echo $service["Server"];?></hostname>
<port><?php echo $service["Port"];?></port>
<socketType><?php echo $service["SocketType"];?></socketType>
<username><?php echo $this->get_username($service,$email_address);?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
</outgoingServer>
<?php }
if ($services["AddressBook"] && $services["AddressBook"]["Enabled"]) {
$service = $services["AddressBook"]; ?>
<addressBook type="<?php echo strtolower($service["Type"]); ?>">
<username><?php echo $this->get_username($service,$email_address);?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
<serverURL><?php echo $service["Server"];?></serverURL>
</addressBook>
<?php }
if ($services["Calendar"] && $services["Calendar"]["Enabled"]){
$service = $services["Calendar"] ;?>
<calendar type="<?php echo strtolower($service["Type"]);?>">
<username><?php echo $this->get_username($service,$email_address);?></username>
<authentication><?php echo $service["Authentication"];?></authentication>
<serverURL><?php echo $service["Server"];?></serverURL>
</calendar>
<?php }
if ($services["WebMail"] && $services["WebMail"]["Enabled"]) {
$service = $services["WebMail"]; ?>
<webMail>
<loginPage url="<?php echo $service["Server"];?>" />
<loginPageInfo url="<?php echo $service["Server"];?>">
<username><?php echo $this->get_username($service,$email_address);?></username>
<usernameField id="<?php echo $service["UsernameDivID"];?>" name="<?php echo $service["UsernameDivName"];?>" />
<passwordField name="<?php echo $service["PasswordDivName"];?>" />
<loginButton id="<?php echo $service["SubmitButtonID"];?>" name="<?php echo $service["SubmitButtonName"];?>"/>
</loginPageInfo>
</webMail>
<?php } ?>
</emailProvider>
</clientConfig>

View file

@ -0,0 +1,50 @@
<clientConfig version="1.1">
<emailProvider id="{{ index .Config.Domains 0 }}">
{{ range .Config.Domains }}<domain>{{ . }}</domain>
{{ end }}
<displayName>{{ .Email }}</displayName>
{{ with .Config.InMail }}
<incomingServer type="{{ .Type | lower }}">
<hostname>{{ .Server }}</hostname>
<port>{{ .Port }}</port>
<socketType>{{ .SocketType }}</socketType>
<username>{{ . | parseUsername }}</username>
<authentication>{{ .Authentication }}</authentication>
</incomingServer>
{{ end }}
{{ with .Config.OutMail }}
<outgoingServer type="{{ .Type | lower }}">
<hostname>{{ .Server }}</hostname>
<port>{{ .Port }}></port>
<socketType>{{ .SocketType }}</socketType>
<username>{{ . | parseUsername }}</username>
<authentication>{{ .Authentication }}</authentication>
</outgoingServer>
{{ end }}
{{ with .Config.AddressBook }}
<addressBook type="{{ .Type | lower }}">
<username>{{ . | parseUsername }}</username>
<authentication>{{ .Authentication }}</authentication>
<serverURL>{{ .Server }}</serverURL>
</addressBook>
{{ end }}
{{ with .Config.Calendar }}
<calendar type="{{ .Type | lower }}">
<username>{{ . | parseUsername }}</username>
<authentication>{{ .Authentication }}</authentication>
<serverURL>{{ .Server }}</serverURL>
</calendar>
{{ end }}
{{ with .Config.WebMail }}
<webMail>
<loginPage url="{{ .Server }}" />
<loginPageInfo url="{{ .Server }}">
<username>{{ . | parseUsername }}</username>
<usernameField id="{{ .UsernameDivID }}" name="{{ .UsernameDivID }}" />
<passwordField name="{{ .PasswordDivName }}" />
<loginButton id="{{ .SubmitButtonID }}" name="{{ .SubmitButtonName }}"/>
</loginPageInfo>
</webMail>
{{ end }}
</emailProvider>
</clientConfig>

View file

@ -1,45 +0,0 @@
<!-- Example POST Request (sent from client) :
<?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>your@email.address</EMailAddress>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
</Request>
</Autodiscover> -->
<?xml version="1.0" encoding="utf-8" ?>
<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"] && $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 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"]&& $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 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>
<UsePOPAuth><?php echo $in["POPAuth"] ? "on" : "off";?></UsePOPAuth>
<SMTPLast><?php echo $in["SMTPLast"] ? "on" : "off";?></SMTPLast>
</Protocol>
<?php } ?>
</Account>
</Response>
</Autodiscover>

View file

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<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>
{{ with .Config.InMail }}
<Protocol>
<Type>{{ .Type }}</Type>
<Server>{{ .Server }}</Server>
<Port>{{ .Port }}</Port>
<DomainRequired>{{ .UsernameIsFQDN | onoff }}</DomainRequired>
<LoginName>{{ . | parseUsername }}</LoginName>
<SPA>{{ .SPA | onoff }}</SPA>
<SSL>{{ if eq .SocketType "SSL" }}on{{ else }}off{{ end }}</SSL>
<AuthRequired>{{ not .NoAuthRequired | onoff }}</AuthRequired>
</Protocol>
{{ end }}
{{ with .Config.OutMail }}
<Protocol>
<Type>{{ .Type }}</Type>
<Server>{{ .Server }}</Server>
<Port>{{ .Port }}</Port>
<DomainRequired>{{ .UsernameIsFQDN | onoff }}</DomainRequired>
<LoginName>{{ . | parseUsername }}</LoginName>
<SPA>{{ .SPA | onoff }}</SPA>
<Encryption>{{ .SocketType }}</Encryption>
<AuthRequired>{{ not .NoAuthRequired | onoff }}</AuthRequired>
<UsePOPAuth>{{ .POPAuth | onoff }}</UsePOPAuth>
<SMTPLast>{{ .SMTPLast | onoff }}</SMTPLast>
</Protocol>
{{ end }}
</Account>
</Response>
</Autodiscover>

View file

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
) )
func WebHandler(w http.ResponseWriter, r *http.Request) { func WebHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Request For :",r.URL)
ThisSession = Session{} ThisSession = Session{}
ThisSession.ResponseWriter = w ThisSession.ResponseWriter = w
ThisSession.Request = r ThisSession.Request = r
@ -15,9 +16,9 @@ func WebHandler(w http.ResponseWriter, r *http.Request) {
if ThisSession.Path == "" { if ThisSession.Path == "" {
ThisSession.Path = "none" ThisSession.Path = "none"
} }
switch ThisSession.Path { switch ThisSession.Path {
case "mail/config-v1.1.xml": case "mail/config-v1.1.xml",
"mail/autoconfig.xml":
ThisSession.WebContent = responses.MozAutoconfig() ThisSession.WebContent = responses.MozAutoconfig()
case "autodiscover/autodiscover.xml": case "autodiscover/autodiscover.xml":
ThisSession.WebContent = responses.MsAutoDiscoverXML() ThisSession.WebContent = responses.MsAutoDiscoverXML()

View file

@ -2,30 +2,65 @@ package responses
import ( import (
"mailautoconf/global" "mailautoconf/global"
. "mailautoconf/structs" . "mailautoconf/structs"
"html/template" "text/template"
// "fmt" "fmt"
"path"
"strings"
"bytes"
"regexp"
) )
var email string
var fmap = template.FuncMap{
"lower": strings.ToLower,
"parseUsername": parseUsername,
"onoff": chooseOnOff,
}
func MozAutoconfig() string { func MozAutoconfig() string {
// The below link has config-v1.1.xml information // The below link has config-v1.1.xml information
// https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat // https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat
tmpl := "templates/autoconfig.html" tmpl := "templates/autoconfig.xml"
t := template.Must(template.ParseFiles(tmpl)) response := Response{}
data := struct { response.Email = global.ThisSession.Request.FormValue("emailaddress")
Name string response.Config = global.MainConfig
Skills []string
}{ name := path.Base(tmpl)
Name: "John Doe", t, err1 := template.New(name).Funcs(fmap).ParseFiles(tmpl)
Skills: []string{ if err1 != nil {
"C++", panic (err1)
"Java",
"Python",
},
} }
t.Execute(global.ThisSession.ResponseWriter, data) global.ThisSession.ContentType = "application/xml"
return "" var result bytes.Buffer
err := t.Execute(&result, response)
if err != nil {
fmt.Println(err)
}
return result.String()
} }
func MsAutoDiscoverXML() string { func MsAutoDiscoverXML() string {
return "" // Example POST Request (sent from client) :
// <?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>your@email.address</EMailAddress>
// <AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
// </Request>
// </Autodiscover>
tmpl := "templates/autodiscover.xml"
email = global.ThisSession.Request.FormValue("EMailAddress")
response := Response{}
response.Config = global.MainConfig
name := path.Base(tmpl)
t, err1 := template.New(name).Funcs(fmap).ParseFiles(tmpl)
if err1 != nil {
panic (err1)
}
global.ThisSession.ContentType = "application/xml"
var result bytes.Buffer
err := t.Execute(&result, response)
if err != nil {
fmt.Println(err)
}
return result.String()
} }
func MsAutoDiscoverJSON() string { func MsAutoDiscoverJSON() string {
return "" return ""
@ -43,3 +78,28 @@ func OurConfig() string {
content := global.JSONify(global.MainConfig) content := global.JSONify(global.MainConfig)
return content return content
} }
func parseUsername(svc Service) string {
if email == "" {
return "<!-- not provided -->"
}
if svc.UsernameIsFQDN && !svc.RequireLocalDomain{
return email
} else if svc.UsernameIsFQDN && svc.RequireLocalDomain {
re := regexp.MustCompile(`[^@]+$`)
domain := re.FindString(email)
localemail := strings.Replace(email, domain,
global.MainConfig.LocalDomain,1)
return localemail
} else {
re := regexp.MustCompile(`^[^@]+`)
username := re.FindString(email)
return username
}
}
func chooseOnOff(value bool) string {
if value {
return "on"
} else {
return "off"
}
}