diff --git a/README.md b/README.md index 3668ae899..e78ce8fe9 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ There are some very good products in this category such as [gitlab](http://gitla - Repository viewer. - Gravatar support. - Mail service(register). +- Administration panel. - Supports MySQL, PostgreSQL and SQLite3(binary release only). ## Installation diff --git a/models/models.go b/models/models.go index 8df230975..bb0015d3d 100644 --- a/models/models.go +++ b/models/models.go @@ -16,30 +16,39 @@ import ( "github.com/gogits/gogs/modules/base" ) -var orm *xorm.Engine +var ( + orm *xorm.Engine + + dbCfg struct { + Type, Host, Name, User, Pwd, Path, SslMode string + } +) + +func LoadModelsConfig() { + dbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE") + dbCfg.Host = base.Cfg.MustValue("database", "HOST") + dbCfg.Name = base.Cfg.MustValue("database", "NAME") + dbCfg.User = base.Cfg.MustValue("database", "USER") + dbCfg.Pwd = base.Cfg.MustValue("database", "PASSWD") + dbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") + dbCfg.SslMode = base.Cfg.MustValue("database", "SSL_MODE") +} func setEngine() { - dbType := base.Cfg.MustValue("database", "DB_TYPE") - dbHost := base.Cfg.MustValue("database", "HOST") - dbName := base.Cfg.MustValue("database", "NAME") - dbUser := base.Cfg.MustValue("database", "USER") - dbPwd := base.Cfg.MustValue("database", "PASSWD") - dbPath := base.Cfg.MustValue("database", "PATH", "data/gogs.db") - sslMode := base.Cfg.MustValue("database", "SSL_MODE") var err error - switch dbType { + switch dbCfg.Type { case "mysql": orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8", - dbUser, dbPwd, dbHost, dbName)) + dbCfg.User, dbCfg.Pwd, dbCfg.Host, dbCfg.Name)) case "postgres": orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", - dbUser, dbPwd, dbName, sslMode)) + dbCfg.User, dbCfg.Pwd, dbCfg.Name, dbCfg.SslMode)) case "sqlite3": - os.MkdirAll(path.Dir(dbPath), os.ModePerm) - orm, err = xorm.NewEngine("sqlite3", dbPath) + os.MkdirAll(path.Dir(dbCfg.Path), os.ModePerm) + orm, err = xorm.NewEngine("sqlite3", dbCfg.Path) default: - fmt.Printf("Unknown database type: %s\n", dbType) + fmt.Printf("Unknown database type: %s\n", dbCfg.Type) os.Exit(2) } if err != nil { @@ -61,7 +70,7 @@ func setEngine() { orm.ShowSQL = true } -func init() { +func NewEngine() { setEngine() if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), new(Action), new(Access)); err != nil { diff --git a/models/models_test.go b/models/models_test.go index c44ef476c..d0f734d67 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -13,6 +13,9 @@ import ( ) func init() { + LoadModelsConfig() + NewEngine() + var err error orm, err = xorm.NewEngine("sqlite3", "./test.db") if err != nil { diff --git a/models/repo.go b/models/repo.go index 93f68cedd..f25200478 100644 --- a/models/repo.go +++ b/models/repo.go @@ -41,10 +41,12 @@ var ( LanguageIgns, Licenses []string ) -func init() { +func LoadRepoConfig() { LanguageIgns = strings.Split(base.Cfg.MustValue("repository", "LANG_IGNS"), "|") Licenses = strings.Split(base.Cfg.MustValue("repository", "LICENSES"), "|") +} +func NewRepoContext() { zip.Verbose = false // Check if server has basic git setting. diff --git a/modules/base/conf.go b/modules/base/conf.go index 41b66b69f..42d50da4f 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -148,7 +148,7 @@ func newRegisterMailService() { log.Info("Register Mail Service Enabled") } -func init() { +func NewConfigContext() { var err error workDir, err := exeDir() if err != nil { diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 150607f8c..da63e01d2 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -40,7 +40,7 @@ func (m Message) Content() string { var mailQueue chan *Message -func init() { +func NewMailerContext() { mailQueue = make(chan *Message, base.Cfg.MustInt("mailer", "SEND_BUFFER_LEN", 10)) go processMailQueue() } diff --git a/routers/admin/admin.go b/routers/admin/admin.go index a37f1207c..1095a599b 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -11,12 +11,14 @@ import ( func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Admin Dashboard" + ctx.Data["PageIsDashboard"] = true ctx.Data["Stats"] = models.GetStatistic() ctx.HTML(200, "admin/dashboard") } func Users(ctx *middleware.Context) { ctx.Data["Title"] = "User Management" + ctx.Data["PageIsUsers"] = true var err error ctx.Data["Users"], err = models.GetUsers(100, 0) @@ -29,6 +31,8 @@ func Users(ctx *middleware.Context) { func Repositories(ctx *middleware.Context) { ctx.Data["Title"] = "Repository Management" + ctx.Data["PageIsRepos"] = true + var err error ctx.Data["Repos"], err = models.GetRepos(100, 0) if err != nil { @@ -37,3 +41,9 @@ func Repositories(ctx *middleware.Context) { } ctx.HTML(200, "admin/repos") } + +func Config(ctx *middleware.Context) { + ctx.Data["Title"] = "Server Configuration" + ctx.Data["PageIsConfig"] = true + ctx.HTML(200, "admin/config") +} diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl new file mode 100644 index 000000000..d209bcdfd --- /dev/null +++ b/templates/admin/config.tmpl @@ -0,0 +1,17 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +