Explorar o código

Add LDAP configuration

Andrea Fazzi %!s(int64=6) %!d(string=hai) anos
pai
achega
46545d1079
Modificáronse 1 ficheiros con 41 adicións e 0 borrados
  1. 41 0
      config/config.go

+ 41 - 0
config/config.go

@@ -1,7 +1,9 @@
 package config
 
 import (
+	"fmt"
 	"io/ioutil"
+	"strings"
 
 	yaml "gopkg.in/yaml.v2"
 )
@@ -16,6 +18,7 @@ type ConfigT struct {
 
 	// Domain
 
+	Url    string
 	Domain string
 
 	// Logging
@@ -45,6 +48,33 @@ type ConfigT struct {
 		AutoMigrate bool
 		Regenerate  bool
 	}
+
+	Ldap struct {
+		Host   string
+		Domain string
+
+		AdminCN       string `yaml:"admin_cn"`
+		AdminPassword string `yaml:"admin_password"`
+
+		TeachersDN string `yaml:"teachers_dn"`
+		PeopleDN   string `yaml:"people_dn"`
+		GroupsDN   string `yaml:"groups_dn"`
+
+		MailGIDNumber  string `yaml:"mail_gid_number"`
+		FirstUIDNumber string `yaml:"first_uid_number"`
+
+		MailDirBasePath string `yaml:"maildir_base_path"`
+		MailQuota       string `yaml:"mail_quota"`
+	}
+
+	Smtp struct {
+		Host     string
+		Port     int
+		Username string
+		Password string
+		From     string
+		Cc       string
+	}
 }
 
 var Config *ConfigT
@@ -72,3 +102,14 @@ func Read(data []byte, config *ConfigT) error {
 	}
 	return nil
 }
+
+func (conf *ConfigT) DomainDN() (out string) {
+	for _, dc := range strings.Split(conf.Domain, ".") {
+		out += "dc=" + dc + ","
+	}
+	return strings.TrimRight(out, ",")
+}
+
+func (conf *ConfigT) AdminCN() string {
+	return fmt.Sprintf("cn=%s,%s", conf.Ldap.AdminCN, conf.DomainDN())
+}