diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/auth.go | 2 | ||||
-rw-r--r-- | modules/base/conf.go | 79 | ||||
-rw-r--r-- | modules/base/template.go | 10 | ||||
-rw-r--r-- | modules/middleware/repo.go | 7 |
4 files changed, 53 insertions, 45 deletions
diff --git a/modules/auth/auth.go b/modules/auth/auth.go index 350ef4fc..e493faef 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -57,7 +57,7 @@ func (f *RegisterForm) Validate(errors *base.BindingErrors, req *http.Request, c } type LogInForm struct { - UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"` + UserName string `form:"username" binding:"Required;MaxSize(35)"` Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"` Remember string `form:"remember"` } diff --git a/modules/base/conf.go b/modules/base/conf.go index 04c12457..cfc85ff5 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -45,15 +45,15 @@ type Oauther struct { } var ( - AppVer string - AppName string - AppLogo string - AppUrl string - IsProdMode bool - Domain string - SecretKey string - RunUser string - LdapAuth bool + AppVer string + AppName string + AppLogo string + AppUrl string + OfflineMode bool + ProdMode bool + Domain string + SecretKey string + RunUser string RepoRootPath string ScriptType string @@ -93,6 +93,7 @@ var Service struct { NotifyMail bool ActiveCodeLives int ResetPwdCodeLives int + LdapAuth bool } func ExecDir() (string, error) { @@ -178,6 +179,36 @@ func newLogService() { log.Info("Log Mode: %s(%s)", strings.Title(LogMode), levelName) } +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") +} + func newCacheService() { CacheAdapter = Cfg.MustValue("cache", "ADAPTER", "memory") if EnableRedis { @@ -295,6 +326,7 @@ func NewConfigContext() { AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png") AppUrl = Cfg.MustValue("server", "ROOT_URL") Domain = Cfg.MustValue("server", "DOMAIN") + OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false) SecretKey = Cfg.MustValue("security", "SECRET_KEY") InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) @@ -312,34 +344,6 @@ func NewConfigContext() { 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 { - qlog.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 - qlog.Debug("%s added as LDAP source", ldapname) - } - } - if nbsrc == 0 { - qlog.Debug("No valide LDAP found, LDAP AUTHENTICATION NOT activated") - LdapAuth = false - } - } else { - qlog.Debug("LDAP AUTHENTICATION NOT activated") - } - PictureService = Cfg.MustValue("picture", "SERVICE") // Determine and create root git reposiroty path. @@ -357,6 +361,7 @@ func NewConfigContext() { func NewBaseServices() { newService() newLogService() + newLdapService() newCacheService() newSessionService() newMailService() diff --git a/modules/base/template.go b/modules/base/template.go index 79aeeb9d..dd98df75 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -56,8 +56,8 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "AppDomain": func() string { return Domain }, - "IsProdMode": func() bool { - return IsProdMode + "CdnMode": func() bool { + return ProdMode && !OfflineMode }, "LoadTimes": func(startTime time.Time) string { return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" @@ -124,11 +124,11 @@ func ActionIcon(opType int) string { const ( TPL_CREATE_REPO = `<a href="/user/%s">%s</a> created repository <a href="/%s">%s</a>` TPL_COMMIT_REPO = `<a href="/user/%s">%s</a> pushed to <a href="/%s/src/%s">%s</a> at <a href="/%s">%s</a>%s` - TPL_COMMIT_REPO_LI = `<div><img src="%s?s=16" alt="user-avatar"/> <a href="/%s/commit/%s">%s</a> %s</div>` + TPL_COMMIT_REPO_LI = `<div><img src="%s?s=16" alt="user-avatar"/> <a href="/%s/commit/%s" rel="nofollow">%s</a> %s</div>` TPL_CREATE_ISSUE = `<a href="/user/%s">%s</a> opened issue <a href="/%s/issues/%s">%s#%s</a> <div><img src="%s?s=16" alt="user-avatar"/> %s</div>` TPL_TRANSFER_REPO = `<a href="/user/%s">%s</a> transfered repository <code>%s</code> to <a href="/%s">%s</a>` - TPL_PUSH_TAG = `<a href="/user/%s">%s</a> pushed tag <a href="/%s/src/%s">%s</a> at <a href="/%s">%s</a>` + TPL_PUSH_TAG = `<a href="/user/%s">%s</a> pushed tag <a href="/%s/src/%s" rel="nofollow">%s</a> at <a href="/%s">%s</a>` ) type PushCommit struct { @@ -165,7 +165,7 @@ func ActionDesc(act Actioner) string { buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n") } if push.Len > 3 { - buf.WriteString(fmt.Sprintf(`<div><a href="/%s/%s/commits/%s">%d other commits >></a></div>`, actUserName, repoName, branch, push.Len)) + buf.WriteString(fmt.Sprintf(`<div><a href="/%s/%s/commits/%s" rel="nofollow">%d other commits >></a></div>`, actUserName, repoName, branch, push.Len)) } return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, buf.String()) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 34144fe3..2d2778cb 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -26,11 +26,14 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { var displayBare bool if len(args) >= 1 { - validBranch = args[0] + // Note: argument has wrong value in Go1.3 martini. + // validBranch = args[0] + validBranch = true } if len(args) >= 2 { - displayBare = args[1] + // displayBare = args[1] + displayBare = true } var ( |