|
@@ -10,6 +10,7 @@ import (
|
|
|
"os/exec"
|
|
|
"path"
|
|
|
"path/filepath"
|
|
|
+ "regexp"
|
|
|
"strings"
|
|
|
|
|
|
"github.com/Unknwon/com"
|
|
@@ -19,6 +20,7 @@ import (
|
|
|
"github.com/gogits/cache"
|
|
|
"github.com/gogits/session"
|
|
|
|
|
|
+ "github.com/gogits/gogs/modules/auth/ldap"
|
|
|
"github.com/gogits/gogs/modules/log"
|
|
|
)
|
|
|
|
|
@@ -51,6 +53,7 @@ var (
|
|
|
Domain string
|
|
|
SecretKey string
|
|
|
RunUser string
|
|
|
+ LdapAuth bool
|
|
|
|
|
|
RepoRootPath string
|
|
|
ScriptType string
|
|
@@ -83,13 +86,13 @@ var (
|
|
|
)
|
|
|
|
|
|
var Service struct {
|
|
|
- RegisterEmailConfirm bool
|
|
|
- DisableRegistration bool
|
|
|
- RequireSignInView bool
|
|
|
- EnableCacheAvatar bool
|
|
|
- NotifyMail bool
|
|
|
- ActiveCodeLives int
|
|
|
- ResetPwdCodeLives int
|
|
|
+ RegisterEmailConfirm bool
|
|
|
+ DisableRegistration bool
|
|
|
+ RequireSignInView bool
|
|
|
+ EnableCacheAvatar bool
|
|
|
+ NotifyMail bool
|
|
|
+ ActiveCodeLives int
|
|
|
+ ResetPwdCodeLives int
|
|
|
}
|
|
|
|
|
|
func ExecDir() (string, error) {
|
|
@@ -310,6 +313,33 @@ func NewConfigContext() {
|
|
|
CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
|
|
|
CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")
|
|
|
|
|
|
+
|
|
|
+ LdapAuth = Cfg.MustBool("security", "LDAP_AUTH", false)
|
|
|
+ if LdapAuth {
|
|
|
+ log.Debug("LDAP AUTHENTICATION activated")
|
|
|
+ nbsrc := 0
|
|
|
+ for _, v := range Cfg.GetSectionList() {
|
|
|
+ if matched, _ := regexp.MatchString("(?i)^LDAPSOURCE.*", v); matched {
|
|
|
+ ldapname := Cfg.MustValue(v, "name", v)
|
|
|
+ ldaphost := Cfg.MustValue(v, "host")
|
|
|
+ ldapport := Cfg.MustInt(v, "port", 389)
|
|
|
+ ldapbasedn := Cfg.MustValue(v, "basedn", "dc=*,dc=*")
|
|
|
+ ldapattribute := Cfg.MustValue(v, "attribute", "mail")
|
|
|
+ ldapfilter := Cfg.MustValue(v, "filter", "(*)")
|
|
|
+ ldapmsadsaformat := Cfg.MustValue(v, "MSADSAFORMAT", "%s")
|
|
|
+ ldap.AddSource(ldapname, ldaphost, ldapport, ldapbasedn, ldapattribute, ldapfilter, ldapmsadsaformat)
|
|
|
+ nbsrc += 1
|
|
|
+ log.Debug("%s added as LDAP source", ldapname)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if nbsrc == 0 {
|
|
|
+ log.Debug("No valide LDAP found, LDAP AUTHENTICATION NOT activated")
|
|
|
+ LdapAuth = false
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.Debug("LDAP AUTHENTICATION NOT activated")
|
|
|
+ }
|
|
|
+
|
|
|
PictureService = Cfg.MustValue("picture", "SERVICE")
|
|
|
|
|
|
|