summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/middleware/context.go16
-rw-r--r--modules/setting/setting.go18
2 files changed, 27 insertions, 7 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index c641449a87..cf849802d9 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -139,10 +139,6 @@ func (ctx *Context) Handle(status int, title string, err error) {
ctx.HTML(status, base.TplName(fmt.Sprintf("status/%d", status)))
}
-func (ctx *Context) Debug(msg string, args ...interface{}) {
- log.Debug(msg, args...)
-}
-
func (ctx *Context) GetCookie(name string) string {
cookie, err := ctx.Req.Cookie(name)
if err != nil {
@@ -323,7 +319,6 @@ func (f *Flash) Success(msg string) {
// InitContext initializes a classic context for a request.
func InitContext() martini.Handler {
return func(res http.ResponseWriter, r *http.Request, c martini.Context, rd *Render) {
-
ctx := &Context{
c: c,
// p: p,
@@ -332,7 +327,6 @@ func InitContext() martini.Handler {
Cache: setting.Cache,
Render: rd,
}
-
ctx.Data["PageStartTime"] = time.Now()
// start session
@@ -356,7 +350,7 @@ func InitContext() martini.Handler {
ctx.Session.SessionRelease(res)
if flash := ctx.Flash.Encode(); len(flash) > 0 {
- ctx.SetCookie("gogs_flash", ctx.Flash.Encode(), 0)
+ ctx.SetCookie("gogs_flash", flash, 0)
}
})
@@ -374,6 +368,14 @@ func InitContext() martini.Handler {
ctx.Data["IsAdmin"] = ctx.User.IsAdmin
}
+ // If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid.
+ if strings.Contains(r.Header.Get("Content-Type"), "multipart/form-data") {
+ if err = ctx.Req.ParseMultipartForm(setting.AttachmentMaxSize << 20); err != nil { // 32MB max size
+ ctx.Handle(500, "issue.Comment(ctx.Req.ParseMultipartForm)", err)
+ return
+ }
+ }
+
// get or create csrf token
ctx.Data["CsrfToken"] = ctx.CsrfToken()
ctx.Data["CsrfTokenHtml"] = template.HTML(`<input type="hidden" name="_csrf" value="` + ctx.csrfToken + `">`)
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index f03aa8aeae..48b17f95cf 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -71,6 +71,13 @@ var (
LogModes []string
LogConfigs []string
+ // Attachment settings.
+ AttachmentPath string
+ AttachmentAllowedTypes string
+ AttachmentMaxSize int64
+ AttachmentMaxFiles int
+ AttachmentEnabled bool
+
// Cache settings.
Cache cache.Cache
CacheAdapter string
@@ -166,6 +173,16 @@ func NewConfigContext() {
CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")
ReverseProxyAuthUser = Cfg.MustValue("security", "REVERSE_PROXY_AUTHENTICATION_USER", "X-WEBAUTH-USER")
+ AttachmentPath = Cfg.MustValue("attachment", "PATH", "files/attachments")
+ AttachmentAllowedTypes = Cfg.MustValue("attachment", "ALLOWED_TYPES", "*/*")
+ AttachmentMaxSize = Cfg.MustInt64("attachment", "MAX_SIZE", 32)
+ AttachmentMaxFiles = Cfg.MustInt("attachment", "MAX_FILES", 10)
+ AttachmentEnabled = Cfg.MustBool("attachment", "ENABLE", true)
+
+ if err = os.MkdirAll(AttachmentPath, os.ModePerm); err != nil {
+ log.Fatal("Could not create directory %s: %s", AttachmentPath, err)
+ }
+
RunUser = Cfg.MustValue("", "RUN_USER")
curUser := os.Getenv("USER")
if len(curUser) == 0 {
@@ -341,6 +358,7 @@ func newSessionService() {
log.Fatal("Init session system failed, provider: %s, %v",
SessionProvider, err)
}
+ go SessionManager.GC()
log.Info("Session Service Enabled")
}