Exemple #1
0
func newLdapService() {
	Service.LdapAuth = Cfg.MustBool("security", "LDAP_AUTH", false)
	if !Service.LdapAuth {
		return
	}

	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++
			log.Debug("%s added as LDAP source", ldapname)
		}
	}
	if nbsrc == 0 {
		log.Warn("No valide LDAP found, LDAP Authentication NOT enabled")
		Service.LdapAuth = false
		return
	}

	log.Info("LDAP Authentication Enabled")
}
Exemple #2
0
func NewConfigContext() {
	//var err error
	workDir, err := ExecDir()
	if err != nil {
		qlog.Fatalf("Fail to get work directory: %s\n", err)
	}

	cfgPath := filepath.Join(workDir, "conf/app.ini")
	Cfg, err = goconfig.LoadConfigFile(cfgPath)
	if err != nil {
		qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
	}
	Cfg.BlockMode = false

	cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
	if com.IsFile(cfgPath) {
		if err = Cfg.AppendFiles(cfgPath); err != nil {
			qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
		}
	}

	AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
	AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
	AppUrl = Cfg.MustValue("server", "ROOT_URL")
	Domain = Cfg.MustValue("server", "DOMAIN")
	SecretKey = Cfg.MustValue("security", "SECRET_KEY")

	InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)

	RunUser = Cfg.MustValue("", "RUN_USER")
	curUser := os.Getenv("USER")
	if len(curUser) == 0 {
		curUser = os.Getenv("USERNAME")
	}
	// Does not check run user when the install lock is off.
	if InstallLock && RunUser != curUser {
		qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
	}

	LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
	CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
	CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")

	// load LDAP authentication configuration if present
	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")

	// Determine and create root git reposiroty path.
	homeDir, err := com.HomeDir()
	if err != nil {
		qlog.Fatalf("Fail to get home directory): %v\n", err)
	}
	RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
	if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
		qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
	}
	ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
}