aboutsummaryrefslogtreecommitdiff
path: root/modules/setting
diff options
context:
space:
mode:
Diffstat (limited to 'modules/setting')
-rw-r--r--modules/setting/setting.go134
1 files changed, 85 insertions, 49 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index f03aa8ae..ebc1020a 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -11,15 +11,14 @@ import (
"path"
"path/filepath"
"strings"
+ "time"
"github.com/Unknwon/com"
"github.com/Unknwon/goconfig"
+ "github.com/macaron-contrib/session"
- "github.com/gogits/cache"
- "github.com/gogits/session"
-
- "github.com/gogits/gogs/modules/bin"
"github.com/gogits/gogs/modules/log"
+ // "github.com/gogits/gogs-ng/modules/ssh"
)
type Scheme string
@@ -45,6 +44,7 @@ var (
DisableRouterLog bool
CertFile, KeyFile string
StaticRootPath string
+ EnableGzip bool
// Security settings.
InstallLock bool
@@ -71,10 +71,20 @@ var (
LogModes []string
LogConfigs []string
+ // Attachment settings.
+ AttachmentPath string
+ AttachmentAllowedTypes string
+ AttachmentMaxSize int64
+ AttachmentMaxFiles int
+ AttachmentEnabled bool
+
+ // Time settings.
+ TimeFormat string
+
// Cache settings.
- Cache cache.Cache
- CacheAdapter string
- CacheConfig string
+ CacheAdapter string
+ CacheInternal int
+ CacheConn string
EnableRedis bool
EnableMemcache bool
@@ -82,15 +92,22 @@ var (
// Session settings.
SessionProvider string
SessionConfig *session.Config
- SessionManager *session.Manager
// Global setting objects.
- Cfg *goconfig.ConfigFile
- CustomPath string // Custom directory path.
- ProdMode bool
- RunUser string
+ Cfg *goconfig.ConfigFile
+ ConfRootPath string
+ CustomPath string // Custom directory path.
+ ProdMode bool
+ RunUser string
+
+ // I18n settings.
+ Langs, Names []string
)
+func init() {
+ log.NewLogger(0, "console", `{"level": 0}`)
+}
+
func ExecPath() (string, error) {
file, err := exec.LookPath(os.Args[0])
if err != nil {
@@ -114,16 +131,13 @@ func WorkDir() (string, error) {
func NewConfigContext() {
workDir, err := WorkDir()
if err != nil {
- log.Fatal("Fail to get work directory: %v", err)
+ log.Fatal(4, "Fail to get work directory: %v", err)
}
+ ConfRootPath = path.Join(workDir, "conf")
- data, err := bin.Asset("conf/app.ini")
+ Cfg, err = goconfig.LoadConfigFile(path.Join(workDir, "conf/app.ini"))
if err != nil {
- log.Fatal("Fail to read 'conf/app.ini': %v", err)
- }
- Cfg, err = goconfig.LoadFromData(data)
- if err != nil {
- log.Fatal("Fail to parse 'conf/app.ini': %v", err)
+ log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err)
}
CustomPath = os.Getenv("GOGS_CUSTOM")
@@ -134,15 +148,18 @@ func NewConfigContext() {
cfgPath := path.Join(CustomPath, "conf/app.ini")
if com.IsFile(cfgPath) {
if err = Cfg.AppendFiles(cfgPath); err != nil {
- log.Fatal("Fail to load custom 'conf/app.ini': %v", err)
+ log.Fatal(4, "Fail to load custom 'conf/app.ini': %v", err)
}
} else {
- log.Warn("No custom 'conf/app.ini' found")
+ log.Warn("No custom 'conf/app.ini' found, please go to '/install'")
}
AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
- AppUrl = Cfg.MustValue("server", "ROOT_URL", "http://localhost:3000")
+ AppUrl = Cfg.MustValue("server", "ROOT_URL", "http://localhost:3000/")
+ if AppUrl[len(AppUrl)-1] != '/' {
+ AppUrl += "/"
+ }
Protocol = HTTP
if Cfg.MustValue("server", "PROTOCOL") == "https" {
@@ -158,6 +175,7 @@ func NewConfigContext() {
DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG")
StaticRootPath = Cfg.MustValue("server", "STATIC_ROOT_PATH", workDir)
LogRootPath = Cfg.MustValue("log", "ROOT_PATH", path.Join(workDir, "log"))
+ EnableGzip = Cfg.MustBool("server", "ENABLE_GZIP")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK")
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
@@ -166,6 +184,34 @@ 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", "data/attachments")
+ AttachmentAllowedTypes = Cfg.MustValue("attachment", "ALLOWED_TYPES", "image/jpeg|image/png")
+ AttachmentMaxSize = Cfg.MustInt64("attachment", "MAX_SIZE", 32)
+ AttachmentMaxFiles = Cfg.MustInt("attachment", "MAX_FILES", 10)
+ AttachmentEnabled = Cfg.MustBool("attachment", "ENABLE", true)
+
+ TimeFormat = map[string]string{
+ "ANSIC": time.ANSIC,
+ "UnixDate": time.UnixDate,
+ "RubyDate": time.RubyDate,
+ "RFC822": time.RFC822,
+ "RFC822Z": time.RFC822Z,
+ "RFC850": time.RFC850,
+ "RFC1123": time.RFC1123,
+ "RFC1123Z": time.RFC1123Z,
+ "RFC3339": time.RFC3339,
+ "RFC3339Nano": time.RFC3339Nano,
+ "Kitchen": time.Kitchen,
+ "Stamp": time.Stamp,
+ "StampMilli": time.StampMilli,
+ "StampMicro": time.StampMicro,
+ "StampNano": time.StampNano,
+ }[Cfg.MustValue("time", "FORMAT", "RFC1123")]
+
+ if err = os.MkdirAll(AttachmentPath, os.ModePerm); err != nil {
+ log.Fatal(4, "Could not create directory %s: %s", AttachmentPath, err)
+ }
+
RunUser = Cfg.MustValue("", "RUN_USER")
curUser := os.Getenv("USER")
if len(curUser) == 0 {
@@ -173,13 +219,13 @@ func NewConfigContext() {
}
// Does not check run user when the install lock is off.
if InstallLock && RunUser != curUser {
- log.Fatal("Expect user(%s) but current user is: %s", RunUser, curUser)
+ log.Fatal(4, "Expect user(%s) but current user is: %s", RunUser, curUser)
}
// Determine and create root git reposiroty path.
homeDir, err := com.HomeDir()
if err != nil {
- log.Fatal("Fail to get home directory: %v", err)
+ log.Fatal(4, "Fail to get home directory: %v", err)
}
RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
if !filepath.IsAbs(RepoRootPath) {
@@ -189,13 +235,16 @@ func NewConfigContext() {
}
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
- log.Fatal("Fail to create repository root path(%s): %v", RepoRootPath, err)
+ log.Fatal(4, "Fail to create repository root path(%s): %v", RepoRootPath, err)
}
ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
PictureService = Cfg.MustValueRange("picture", "SERVICE", "server",
[]string{"server"})
DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR")
+
+ Langs = Cfg.MustValueArray("i18n", "LANGS", ",")
+ Names = Cfg.MustValueArray("i18n", "NAMES", ",")
}
var Service struct {
@@ -238,7 +287,7 @@ func newLogService() {
mode = strings.TrimSpace(mode)
modeSec := "log." + mode
if _, err := Cfg.GetSection(modeSec); err != nil {
- log.Fatal("Unknown log mode: %s", mode)
+ log.Fatal(4, "Unknown log mode: %s", mode)
}
// Log level.
@@ -246,7 +295,7 @@ func newLogService() {
[]string{"Trace", "Debug", "Info", "Warn", "Error", "Critical"})
level, ok := logLevels[levelName]
if !ok {
- log.Fatal("Unknown log level: %s", levelName)
+ log.Fatal(4, "Unknown log level: %s", levelName)
}
// Generate log configuration.
@@ -299,18 +348,11 @@ func newCacheService() {
switch CacheAdapter {
case "memory":
- CacheConfig = fmt.Sprintf(`{"interval":%d}`, Cfg.MustInt("cache", "INTERVAL", 60))
+ CacheInternal = Cfg.MustInt("cache", "INTERVAL", 60)
case "redis", "memcache":
- CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST"))
+ CacheConn = strings.Trim(Cfg.MustValue("cache", "HOST"), "\" ")
default:
- log.Fatal("Unknown cache adapter: %s", CacheAdapter)
- }
-
- var err error
- Cache, err = cache.NewCache(CacheAdapter, CacheConfig)
- if err != nil {
- log.Fatal("Init cache system failed, adapter: %s, config: %s, %v\n",
- CacheAdapter, CacheConfig, err)
+ log.Fatal(4, "Unknown cache adapter: %s", CacheAdapter)
}
log.Info("Cache Service Enabled")
@@ -321,27 +363,20 @@ func newSessionService() {
[]string{"memory", "file", "redis", "mysql"})
SessionConfig = new(session.Config)
- SessionConfig.ProviderConfig = Cfg.MustValue("session", "PROVIDER_CONFIG")
+ SessionConfig.ProviderConfig = strings.Trim(Cfg.MustValue("session", "PROVIDER_CONFIG"), "\" ")
SessionConfig.CookieName = Cfg.MustValue("session", "COOKIE_NAME", "i_like_gogits")
- SessionConfig.CookieSecure = Cfg.MustBool("session", "COOKIE_SECURE")
+ SessionConfig.Secure = Cfg.MustBool("session", "COOKIE_SECURE")
SessionConfig.EnableSetCookie = Cfg.MustBool("session", "ENABLE_SET_COOKIE", true)
- SessionConfig.GcIntervalTime = Cfg.MustInt64("session", "GC_INTERVAL_TIME", 86400)
- SessionConfig.SessionLifeTime = Cfg.MustInt64("session", "SESSION_LIFE_TIME", 86400)
+ SessionConfig.Gclifetime = Cfg.MustInt64("session", "GC_INTERVAL_TIME", 86400)
+ SessionConfig.Maxlifetime = Cfg.MustInt64("session", "SESSION_LIFE_TIME", 86400)
SessionConfig.SessionIDHashFunc = Cfg.MustValueRange("session", "SESSION_ID_HASHFUNC",
"sha1", []string{"sha1", "sha256", "md5"})
- SessionConfig.SessionIDHashKey = Cfg.MustValue("session", "SESSION_ID_HASHKEY")
+ SessionConfig.SessionIDHashKey = Cfg.MustValue("session", "SESSION_ID_HASHKEY", string(com.RandomCreateBytes(16)))
if SessionProvider == "file" {
os.MkdirAll(path.Dir(SessionConfig.ProviderConfig), os.ModePerm)
}
- var err error
- SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
- if err != nil {
- log.Fatal("Init session system failed, provider: %s, %v",
- SessionProvider, err)
- }
-
log.Info("Session Service Enabled")
}
@@ -423,4 +458,5 @@ func NewServices() {
newRegisterMailService()
newNotifyMailService()
newWebhookService()
+ // ssh.Listen("2022")
}