re-enabled enabling/disabled services

This commit is contained in:
Paul Wilde 2021-08-16 21:40:13 +01:00
parent 50c8d3baf2
commit 7f78103ce5
4 changed files with 107 additions and 67 deletions

View file

@ -12,6 +12,7 @@ import (
// Global variables // Global variables
var ThisSession Session var ThisSession Session
var MainConfig Config var MainConfig Config
const defaultConfigDir string = "default-config/" const defaultConfigDir string = "default-config/"
const configDir string = "config/" const configDir string = "config/"
@ -33,6 +34,7 @@ func loadConfig() Config {
fmt.Println("Loading Custom Services…") fmt.Println("Loading Custom Services…")
customsvcfile := configDir + "services.yaml" customsvcfile := configDir + "services.yaml"
unmarshalConfig(customsvcfile, &cfg) unmarshalConfig(customsvcfile, &cfg)
removeDisabledItems(&cfg)
return cfg return cfg
} }
@ -44,12 +46,36 @@ func unmarshalConfig(file string, cfg *Config) {
} }
err2 := yaml.Unmarshal(content, &cfg) err2 := yaml.Unmarshal(content, &cfg)
if err2 != nil { if err2 != nil {
fmt.Println("Error unmarshalling config :", file, " : ", err2) fmt.Println("Error unmarshaling config :", file, " : ", err2)
} }
} }
} }
func removeDisabledItems(cfg *Config) {
// Rework this, not pretty
if !cfg.InMail.Enabled {
cfg.InMail = Service{}
}
if !cfg.OutMail.Enabled {
cfg.OutMail = Service{}
}
if !cfg.Calendar.Enabled {
cfg.Calendar = Service{}
}
if !cfg.AddressBook.Enabled {
cfg.AddressBook = Service{}
}
if !cfg.WebMail.Enabled {
cfg.WebMail = Service{}
}
new_svcs := []Service{}
for _,svc := range cfg.OtherServices {
if svc.Enabled {
new_svcs = append(new_svcs,svc)
}
}
cfg.OtherServices = new_svcs
}
func FileExists(file string) bool { func FileExists(file string) bool {
exists := false exists := false
if _, err := os.Stat(file); err == nil { if _, err := os.Stat(file); err == nil {

View file

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

View file

@ -5,30 +5,34 @@
<AccountType>email</AccountType> <AccountType>email</AccountType>
<Action>settings</Action> <Action>settings</Action>
{{ with .Config.InMail }} {{ with .Config.InMail }}
<Protocol> {{ if .Enabled }}
<Type>{{ .Type }}</Type> <Protocol>
<Server>{{ .Server }}</Server> <Type>{{ .Type }}</Type>
<Port>{{ .Port }}</Port> <Server>{{ .Server }}</Server>
<DomainRequired>{{ .UsernameIsFQDN | onoff }}</DomainRequired> <Port>{{ .Port }}</Port>
<LoginName>{{ . | parseUsername }}</LoginName> <DomainRequired>{{ .UsernameIsFQDN | onoff }}</DomainRequired>
<SPA>{{ .SPA | onoff }}</SPA> <LoginName>{{ . | parseUsername }}</LoginName>
<SSL>{{ if eq .SocketType "SSL" }}on{{ else }}off{{ end }}</SSL> <SPA>{{ .SPA | onoff }}</SPA>
<AuthRequired>{{ not .NoAuthRequired | onoff }}</AuthRequired> <SSL>{{ if eq .SocketType "SSL" }}on{{ else }}off{{ end }}</SSL>
</Protocol> <AuthRequired>{{ not .NoAuthRequired | onoff }}</AuthRequired>
</Protocol>
{{ end }}
{{ end }} {{ end }}
{{ with .Config.OutMail }} {{ with .Config.OutMail }}
<Protocol> {{ if .Enabled }}
<Type>{{ .Type }}</Type> <Protocol>
<Server>{{ .Server }}</Server> <Type>{{ .Type }}</Type>
<Port>{{ .Port }}</Port> <Server>{{ .Server }}</Server>
<DomainRequired>{{ .UsernameIsFQDN | onoff }}</DomainRequired> <Port>{{ .Port }}</Port>
<LoginName>{{ . | parseUsername }}</LoginName> <DomainRequired>{{ .UsernameIsFQDN | onoff }}</DomainRequired>
<SPA>{{ .SPA | onoff }}</SPA> <LoginName>{{ . | parseUsername }}</LoginName>
<Encryption>{{ .SocketType }}</Encryption> <SPA>{{ .SPA | onoff }}</SPA>
<AuthRequired>{{ not .NoAuthRequired | onoff }}</AuthRequired> <Encryption>{{ .SocketType }}</Encryption>
<UsePOPAuth>{{ .POPAuth | onoff }}</UsePOPAuth> <AuthRequired>{{ not .NoAuthRequired | onoff }}</AuthRequired>
<SMTPLast>{{ .SMTPLast | onoff }}</SMTPLast> <UsePOPAuth>{{ .POPAuth | onoff }}</UsePOPAuth>
</Protocol> <SMTPLast>{{ .SMTPLast | onoff }}</SMTPLast>
</Protocol>
{{ end }}
{{ end }} {{ end }}
</Account> </Account>
</Response> </Response>

View file

@ -81,7 +81,7 @@ func OurConfig() string {
} }
func parseUsername(svc Service) string { func parseUsername(svc Service) string {
if email == "" { if email == "" {
return "<!-- not provided -->" return "not-provided"
} }
if svc.UsernameIsFQDN && !svc.RequireLocalDomain{ if svc.UsernameIsFQDN && !svc.RequireLocalDomain{
return email return email