From 0fd754bbe0dab966ad3070dc24f9583c67c84513 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 28 Mar 2014 07:26:22 -0400 Subject: [PATCH] Working on install page --- models/models.go | 4 +-- modules/base/conf.go | 4 +++ routers/install.go | 26 +++++++++++++++++--- serve.go | 2 +- templates/install.tmpl | 55 ++++++++++++++++++++---------------------- update.go | 2 +- 6 files changed, 56 insertions(+), 37 deletions(-) diff --git a/models/models.go b/models/models.go index 813725be4..04a361c59 100644 --- a/models/models.go +++ b/models/models.go @@ -34,7 +34,7 @@ func LoadModelsConfig() { DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") } -func setEngine() { +func SetEngine() { var err error switch DbCfg.Type { case "mysql": @@ -70,7 +70,7 @@ func setEngine() { } func NewEngine() { - setEngine() + SetEngine() if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), new(Action), new(Access), new(Issue), new(Comment)); err != nil { fmt.Printf("sync database struct error: %v\n", err) diff --git a/modules/base/conf.go b/modules/base/conf.go index 2e5688393..f905c3814 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -38,6 +38,8 @@ var ( RunUser string RepoRootPath string + InstallLock bool + EnableHttpsClone bool LogInRememberDays int @@ -282,6 +284,8 @@ func NewConfigContext() { os.Exit(2) } + InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false) + EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS") diff --git a/routers/install.go b/routers/install.go index d7d5159ef..b44b89034 100644 --- a/routers/install.go +++ b/routers/install.go @@ -4,10 +4,28 @@ package routers -import "github.com/gogits/gogs/modules/middleware" +import ( + "errors" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/middleware" +) + +func Install(ctx *middleware.Context) { + if base.InstallLock { + ctx.Handle(404, "install.Install", errors.New("Installation is prohibited")) + return + } -func Install(ctx *middleware.Context){ - ctx.Data["PageIsInstall"] = true ctx.Data["Title"] = "Install" - ctx.HTML(200,"install") + ctx.Data["DbCfg"] = models.DbCfg + ctx.Data["RepoRootPath"] = base.RepoRootPath + ctx.Data["RunUser"] = base.RunUser + ctx.Data["PageIsInstall"] = true + + if ctx.Req.Method == "GET" { + ctx.HTML(200, "install") + return + } } diff --git a/serve.go b/serve.go index 96f03e724..ad31260f0 100644 --- a/serve.go +++ b/serve.go @@ -78,7 +78,7 @@ func runServ(k *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() - models.NewEngine() + models.SetEngine() keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { diff --git a/templates/install.tmpl b/templates/install.tmpl index 4fbef3cba..99ac8421f 100644 --- a/templates/install.tmpl +++ b/templates/install.tmpl @@ -12,7 +12,7 @@ @@ -21,28 +21,21 @@
- -
- -
- - -
- +
- +
- +
@@ -50,7 +43,7 @@
- +

Recommend use INNODB engine with utf8_general_ci charset.

@@ -71,18 +64,12 @@
- -

The file path of SQLite database.

+ +

The file path of SQLite3 database.

- -

General Settings of Gogs

@@ -91,7 +78,7 @@
- +

The git copy of each repository is saved in this directory.

@@ -100,7 +87,7 @@
- +

The user has access to visit and run Gogs.

@@ -113,20 +100,30 @@
- +
+
- + +
+
+ +
+ + +
+

+
- +
- +

@@ -168,7 +165,7 @@
@@ -179,7 +176,7 @@
diff --git a/update.go b/update.go index 39729937e..23abd7b2e 100644 --- a/update.go +++ b/update.go @@ -32,7 +32,7 @@ gogs serv provide access auth for repositories`, func runUpdate(c *cli.Context) { base.NewConfigContext() models.LoadModelsConfig() - models.NewEngine() + models.SetEngine() w, _ := os.Create("update.log") defer w.Close()