diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/authentication.go | 2 | ||||
-rw-r--r-- | modules/auth/issue.go | 35 | ||||
-rw-r--r-- | modules/auth/publickey.go (renamed from modules/auth/setting.go) | 0 | ||||
-rw-r--r-- | modules/auth/release.go | 36 | ||||
-rw-r--r-- | modules/auth/repo.go | 96 | ||||
-rw-r--r-- | modules/base/conf.go | 103 | ||||
-rw-r--r-- | modules/base/markdown.go | 29 | ||||
-rw-r--r-- | modules/log/log.go | 41 | ||||
-rw-r--r-- | modules/middleware/repo.go | 7 |
9 files changed, 212 insertions, 137 deletions
diff --git a/modules/auth/authentication.go b/modules/auth/authentication.go index 74d5e11b..e9b21510 100644 --- a/modules/auth/authentication.go +++ b/modules/auth/authentication.go @@ -28,6 +28,8 @@ type AuthenticationForm struct { MsAdSA string `form:"ms_ad_sa"` IsActived bool `form:"is_actived"` SmtpAuth string `form:"smtpauth"` + SmtpHost string `form:"smtphost"` + SmtpPort int `form:"smtpport"` Tls bool `form:"tls"` AllowAutoRegister bool `form:"allowautoregister"` } diff --git a/modules/auth/issue.go b/modules/auth/issue.go deleted file mode 100644 index f3cad520..00000000 --- a/modules/auth/issue.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package auth - -import ( - "net/http" - "reflect" - - "github.com/go-martini/martini" - - "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/middleware/binding" -) - -type CreateIssueForm struct { - IssueName string `form:"title" binding:"Required;MaxSize(50)"` - MilestoneId int64 `form:"milestoneid"` - AssigneeId int64 `form:"assigneeid"` - Labels string `form:"labels"` - Content string `form:"content"` -} - -func (f *CreateIssueForm) Name(field string) string { - names := map[string]string{ - "IssueName": "Issue name", - } - return names[field] -} - -func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { - data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) - validate(errors, data, f) -} diff --git a/modules/auth/setting.go b/modules/auth/publickey.go index b828c92b..b828c92b 100644 --- a/modules/auth/setting.go +++ b/modules/auth/publickey.go diff --git a/modules/auth/release.go b/modules/auth/release.go deleted file mode 100644 index 7fadb3c0..00000000 --- a/modules/auth/release.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package auth - -import ( - "net/http" - "reflect" - - "github.com/go-martini/martini" - - "github.com/gogits/gogs/modules/base" - "github.com/gogits/gogs/modules/middleware/binding" -) - -type NewReleaseForm struct { - TagName string `form:"tag_name" binding:"Required"` - Title string `form:"title" binding:"Required"` - Content string `form:"content" binding:"Required"` - Prerelease bool `form:"prerelease"` -} - -func (f *NewReleaseForm) Name(field string) string { - names := map[string]string{ - "TagName": "Tag name", - "Title": "Release title", - "Content": "Release content", - } - return names[field] -} - -func (f *NewReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { - data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) - validate(errors, data, f) -} diff --git a/modules/auth/repo.go b/modules/auth/repo.go index f880cdf5..92ca839f 100644 --- a/modules/auth/repo.go +++ b/modules/auth/repo.go @@ -14,6 +14,13 @@ import ( "github.com/gogits/gogs/modules/middleware/binding" ) +// __________ .__ __ +// \______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. +// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | +// | | \ ___/| |_> > <_> )___ \| || | ( <_> ) | \/\___ | +// |____|_ /\___ > __/ \____/____ >__||__| \____/|__| / ____| +// \/ \/|__| \/ \/ + type CreateRepoForm struct { RepoName string `form:"repo" binding:"Required;AlphaDash;MaxSize(100)"` Private bool `form:"private"` @@ -63,7 +70,7 @@ func (f *MigrateRepoForm) Validate(errors *binding.Errors, req *http.Request, co type RepoSettingForm struct { RepoName string `form:"name" binding:"Required;AlphaDash;MaxSize(100)"` Description string `form:"desc" binding:"MaxSize(100)"` - Website string `form:"url" binding:"Url;MaxSize(100)"` + Website string `form:"site" binding:"Url;MaxSize(100)"` Branch string `form:"branch"` Interval int `form:"interval"` Private bool `form:"private"` @@ -84,6 +91,13 @@ func (f *RepoSettingForm) Validate(errors *binding.Errors, req *http.Request, co validate(errors, data, f) } +// __ __ ___. .__ .__ __ +// / \ / \ ____\_ |__ | |__ | |__ ____ | | __ +// \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ / +// \ /\ ___/| \_\ \ Y \ Y ( <_> ) < +// \__/\ / \___ >___ /___| /___| /\____/|__|_ \ +// \/ \/ \/ \/ \/ \/ + type NewWebhookForm struct { Url string `form:"url" binding:"Required;Url"` ContentType string `form:"content_type" binding:"Required"` @@ -104,3 +118,83 @@ func (f *NewWebhookForm) Validate(errors *binding.Errors, req *http.Request, con data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) validate(errors, data, f) } + +// .___ +// | | ______ ________ __ ____ +// | |/ ___// ___/ | \_/ __ \ +// | |\___ \ \___ \| | /\ ___/ +// |___/____ >____ >____/ \___ > +// \/ \/ \/ + +type CreateIssueForm struct { + IssueName string `form:"title" binding:"Required;MaxSize(50)"` + MilestoneId int64 `form:"milestoneid"` + AssigneeId int64 `form:"assigneeid"` + Labels string `form:"labels"` + Content string `form:"content"` +} + +func (f *CreateIssueForm) Name(field string) string { + names := map[string]string{ + "IssueName": "Issue name", + } + return names[field] +} + +func (f *CreateIssueForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + validate(errors, data, f) +} + +// _____ .__.__ __ +// / \ |__| | ____ _______/ |_ ____ ____ ____ +// / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \ +// / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/ +// \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ > +// \/ \/ \/ \/ \/ + +type CreateMilestoneForm struct { + Title string `form:"title" binding:"Required;MaxSize(50)"` + Content string `form:"content"` + Deadline string `form:"due_date"` +} + +func (f *CreateMilestoneForm) Name(field string) string { + names := map[string]string{ + "Title": "Milestone name", + } + return names[field] +} + +func (f *CreateMilestoneForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + validate(errors, data, f) +} + +// __________ .__ +// \______ \ ____ | | ____ _____ ______ ____ +// | _// __ \| | _/ __ \\__ \ / ___// __ \ +// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/ +// |____|_ /\___ >____/\___ >____ /____ >\___ > +// \/ \/ \/ \/ \/ \/ + +type NewReleaseForm struct { + TagName string `form:"tag_name" binding:"Required"` + Title string `form:"title" binding:"Required"` + Content string `form:"content" binding:"Required"` + Prerelease bool `form:"prerelease"` +} + +func (f *NewReleaseForm) Name(field string) string { + names := map[string]string{ + "TagName": "Tag name", + "Title": "Release title", + "Content": "Release content", + } + return names[field] +} + +func (f *NewReleaseForm) Validate(errors *binding.Errors, req *http.Request, context martini.Context) { + data := context.Get(reflect.TypeOf(base.TmplData{})).Interface().(base.TmplData) + validate(errors, data, f) +} diff --git a/modules/base/conf.go b/modules/base/conf.go index 7d26623a..03e453e6 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -70,8 +70,8 @@ var ( MailService *Mailer OauthService *Oauther - LogMode string - LogConfig string + LogModes []string + LogConfigs []string Cache cache.Cache CacheAdapter string @@ -130,57 +130,62 @@ func newService() { } func newLogService() { + log.Info("%s %s", AppName, AppVer) + // Get and check log mode. - LogMode = Cfg.MustValue("log", "MODE", "console") - modeSec := "log." + LogMode - if _, err := Cfg.GetSection(modeSec); err != nil { - qlog.Fatalf("Unknown log mode: %s\n", LogMode) - } + LogModes = strings.Split(Cfg.MustValue("log", "MODE", "console"), ",") + LogConfigs = make([]string, len(LogModes)) + for i, mode := range LogModes { + mode = strings.TrimSpace(mode) + modeSec := "log." + mode + if _, err := Cfg.GetSection(modeSec); err != nil { + qlog.Fatalf("Unknown log mode: %s\n", mode) + } - // Log level. - levelName := Cfg.MustValue("log."+LogMode, "LEVEL", "Trace") - level, ok := logLevels[levelName] - if !ok { - qlog.Fatalf("Unknown log level: %s\n", levelName) - } + // Log level. + levelName := Cfg.MustValue("log."+mode, "LEVEL", "Trace") + level, ok := logLevels[levelName] + if !ok { + qlog.Fatalf("Unknown log level: %s\n", levelName) + } - // Generate log configuration. - switch LogMode { - case "console": - LogConfig = fmt.Sprintf(`{"level":%s}`, level) - case "file": - logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") - os.MkdirAll(path.Dir(logPath), os.ModePerm) - LogConfig = fmt.Sprintf( - `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level, - logPath, - Cfg.MustBool(modeSec, "LOG_ROTATE", true), - Cfg.MustInt(modeSec, "MAX_LINES", 1000000), - 1<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)), - Cfg.MustBool(modeSec, "DAILY_ROTATE", true), - Cfg.MustInt(modeSec, "MAX_DAYS", 7)) - case "conn": - LogConfig = fmt.Sprintf(`{"level":"%s","reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level, - Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false), - Cfg.MustBool(modeSec, "RECONNECT", false), - Cfg.MustValue(modeSec, "PROTOCOL", "tcp"), - Cfg.MustValue(modeSec, "ADDR", ":7020")) - case "smtp": - LogConfig = fmt.Sprintf(`{"level":"%s","username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level, - Cfg.MustValue(modeSec, "USER", "example@example.com"), - Cfg.MustValue(modeSec, "PASSWD", "******"), - Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"), - Cfg.MustValue(modeSec, "RECEIVERS", "[]"), - Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve")) - case "database": - LogConfig = fmt.Sprintf(`{"level":"%s","driver":"%s","conn":"%s"}`, level, - Cfg.MustValue(modeSec, "Driver"), - Cfg.MustValue(modeSec, "CONN")) - } + // Generate log configuration. + switch mode { + case "console": + LogConfigs[i] = fmt.Sprintf(`{"level":%s}`, level) + case "file": + logPath := Cfg.MustValue(modeSec, "FILE_NAME", "log/gogs.log") + os.MkdirAll(path.Dir(logPath), os.ModePerm) + LogConfigs[i] = fmt.Sprintf( + `{"level":%s,"filename":"%s","rotate":%v,"maxlines":%d,"maxsize":%d,"daily":%v,"maxdays":%d}`, level, + logPath, + Cfg.MustBool(modeSec, "LOG_ROTATE", true), + Cfg.MustInt(modeSec, "MAX_LINES", 1000000), + 1<<uint(Cfg.MustInt(modeSec, "MAX_SIZE_SHIFT", 28)), + Cfg.MustBool(modeSec, "DAILY_ROTATE", true), + Cfg.MustInt(modeSec, "MAX_DAYS", 7)) + case "conn": + LogConfigs[i] = fmt.Sprintf(`{"level":"%s","reconnectOnMsg":%v,"reconnect":%v,"net":"%s","addr":"%s"}`, level, + Cfg.MustBool(modeSec, "RECONNECT_ON_MSG", false), + Cfg.MustBool(modeSec, "RECONNECT", false), + Cfg.MustValue(modeSec, "PROTOCOL", "tcp"), + Cfg.MustValue(modeSec, "ADDR", ":7020")) + case "smtp": + LogConfigs[i] = fmt.Sprintf(`{"level":"%s","username":"%s","password":"%s","host":"%s","sendTos":"%s","subject":"%s"}`, level, + Cfg.MustValue(modeSec, "USER", "example@example.com"), + Cfg.MustValue(modeSec, "PASSWD", "******"), + Cfg.MustValue(modeSec, "HOST", "127.0.0.1:25"), + Cfg.MustValue(modeSec, "RECEIVERS", "[]"), + Cfg.MustValue(modeSec, "SUBJECT", "Diagnostic message from serve")) + case "database": + LogConfigs[i] = fmt.Sprintf(`{"level":"%s","driver":"%s","conn":"%s"}`, level, + Cfg.MustValue(modeSec, "Driver"), + Cfg.MustValue(modeSec, "CONN")) + } - log.Info("%s %s", AppName, AppVer) - log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), LogMode, LogConfig) - log.Info("Log Mode: %s(%s)", strings.Title(LogMode), levelName) + log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, LogConfigs[i]) + log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName) + } } func newLdapService() { diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 057e1b04..0825decb 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -97,12 +97,31 @@ var ( ) func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { - ms := MentionPattern.FindAll(rawBytes, -1) - for _, m := range ms { - rawBytes = bytes.Replace(rawBytes, m, - []byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1) + buf := bytes.NewBufferString("") + inCodeBlock := false + codeBlockPrefix := []byte("```") + lineBreak := []byte("\n") + tab := []byte("\t") + lines := bytes.Split(rawBytes, lineBreak) + for _, line := range lines { + if bytes.HasPrefix(line, codeBlockPrefix) { + inCodeBlock = !inCodeBlock + } + + if !inCodeBlock && !bytes.HasPrefix(line, tab) { + ms := MentionPattern.FindAll(line, -1) + for _, m := range ms { + line = bytes.Replace(line, m, + []byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1) + } + } + + buf.Write(line) + buf.Write(lineBreak) } - ms = commitPattern.FindAll(rawBytes, -1) + + rawBytes = buf.Bytes() + ms := commitPattern.FindAll(rawBytes, -1) for _, m := range ms { m = bytes.TrimSpace(m) i := strings.Index(string(m), "commit/") diff --git a/modules/log/log.go b/modules/log/log.go index 636ea787..eea3c8ad 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -10,8 +10,7 @@ import ( ) var ( - logger *logs.BeeLogger - Mode, Config string + loggers []*logs.BeeLogger ) func init() { @@ -19,32 +18,54 @@ func init() { } func NewLogger(bufLen int64, mode, config string) { - Mode, Config = mode, config - logger = logs.NewLogger(bufLen) + logger := logs.NewLogger(bufLen) + + isExist := false + for _, l := range loggers { + if l.Adapter == mode { + isExist = true + l = logger + } + } + if !isExist { + loggers = append(loggers, logger) + } logger.SetLogFuncCallDepth(3) logger.SetLogger(mode, config) } func Trace(format string, v ...interface{}) { - logger.Trace(format, v...) + for _, logger := range loggers { + logger.Trace(format, v...) + } } func Debug(format string, v ...interface{}) { - logger.Debug(format, v...) + for _, logger := range loggers { + logger.Debug(format, v...) + } } func Info(format string, v ...interface{}) { - logger.Info(format, v...) + for _, logger := range loggers { + logger.Info(format, v...) + } } func Error(format string, v ...interface{}) { - logger.Error(format, v...) + for _, logger := range loggers { + logger.Error(format, v...) + } } func Warn(format string, v ...interface{}) { - logger.Warn(format, v...) + for _, logger := range loggers { + logger.Warn(format, v...) + } } func Critical(format string, v ...interface{}) { - logger.Critical(format, v...) + for _, logger := range loggers { + logger.Critical(format, v...) + } } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index ff99f828..863860e7 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -99,6 +99,11 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { return } + // Check if the mirror repository owner(mirror repository doesn't have access). + if ctx.IsSigned && !ctx.Repo.IsOwner && repo.OwnerId == ctx.User.Id { + ctx.Repo.IsOwner = true + } + // Check access. if repo.IsPrivate && !ctx.Repo.IsOwner { if ctx.User == nil { @@ -128,6 +133,7 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { } repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues + repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones ctx.Repo.Repository = repo ctx.Data["IsBareRepo"] = ctx.Repo.Repository.IsBare @@ -225,7 +231,6 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler { ctx.Data["IsBranch"] = ctx.Repo.IsBranch ctx.Data["IsCommit"] = ctx.Repo.IsCommit - log.Debug("Repo.Commit: %v", ctx.Repo.Commit) } log.Debug("displayBare: %v; IsBare: %v", displayBare, ctx.Repo.Repository.IsBare) |