|
@@ -1,6 +1,7 @@
|
|
|
package route
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "net/http"
|
|
|
"net/mail"
|
|
"net/mail"
|
|
|
"os"
|
|
"os"
|
|
|
"os/exec"
|
|
"os/exec"
|
|
@@ -194,13 +195,12 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
c.HasValue("Err_AdminEmail") {
|
|
c.HasValue("Err_AdminEmail") {
|
|
|
c.FormErr("Admin")
|
|
c.FormErr("Admin")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- c.Success(INSTALL)
|
|
|
|
|
|
|
+ c.HTML(http.StatusBadRequest, INSTALL)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
if _, err := exec.LookPath("git"); err != nil {
|
|
|
- c.RenderWithErr(c.Tr("install.test_git_failed", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.test_git_failed", err), http.StatusInternalServerError, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -222,7 +222,7 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
|
|
|
|
|
if conf.Database.Type == "sqlite3" && conf.Database.Path == "" {
|
|
if conf.Database.Type == "sqlite3" && conf.Database.Path == "" {
|
|
|
c.FormErr("DbPath")
|
|
c.FormErr("DbPath")
|
|
|
- c.RenderWithErr(c.Tr("install.err_empty_db_path"), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.err_empty_db_path"), http.StatusBadRequest, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -230,10 +230,10 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
if err := database.NewTestEngine(); err != nil {
|
|
if err := database.NewTestEngine(); err != nil {
|
|
|
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
|
|
if strings.Contains(err.Error(), `Unknown database type: sqlite3`) {
|
|
|
c.FormErr("DbType")
|
|
c.FormErr("DbType")
|
|
|
- c.RenderWithErr(c.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.sqlite3_not_available", "https://gogs.io/docs/installation/install_from_binary.html"), http.StatusInternalServerError, INSTALL, &f)
|
|
|
} else {
|
|
} else {
|
|
|
c.FormErr("DbSetting")
|
|
c.FormErr("DbSetting")
|
|
|
- c.RenderWithErr(c.Tr("install.invalid_db_setting", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.invalid_db_setting", err), http.StatusBadRequest, INSTALL, &f)
|
|
|
}
|
|
}
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -242,7 +242,7 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
f.RepoRootPath = strings.ReplaceAll(f.RepoRootPath, "\\", "/")
|
|
f.RepoRootPath = strings.ReplaceAll(f.RepoRootPath, "\\", "/")
|
|
|
if err := os.MkdirAll(f.RepoRootPath, os.ModePerm); err != nil {
|
|
if err := os.MkdirAll(f.RepoRootPath, os.ModePerm); err != nil {
|
|
|
c.FormErr("RepoRootPath")
|
|
c.FormErr("RepoRootPath")
|
|
|
- c.RenderWithErr(c.Tr("install.invalid_repo_path", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.invalid_repo_path", err), http.StatusBadRequest, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -250,21 +250,21 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
f.LogRootPath = strings.ReplaceAll(f.LogRootPath, "\\", "/")
|
|
f.LogRootPath = strings.ReplaceAll(f.LogRootPath, "\\", "/")
|
|
|
if err := os.MkdirAll(f.LogRootPath, os.ModePerm); err != nil {
|
|
if err := os.MkdirAll(f.LogRootPath, os.ModePerm); err != nil {
|
|
|
c.FormErr("LogRootPath")
|
|
c.FormErr("LogRootPath")
|
|
|
- c.RenderWithErr(c.Tr("install.invalid_log_root_path", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.invalid_log_root_path", err), http.StatusBadRequest, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
currentUser, match := conf.CheckRunUser(f.RunUser)
|
|
currentUser, match := conf.CheckRunUser(f.RunUser)
|
|
|
if !match {
|
|
if !match {
|
|
|
c.FormErr("RunUser")
|
|
c.FormErr("RunUser")
|
|
|
- c.RenderWithErr(c.Tr("install.run_user_not_match", f.RunUser, currentUser), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.run_user_not_match", f.RunUser, currentUser), http.StatusForbidden, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check host address and port
|
|
// Check host address and port
|
|
|
if len(f.SMTPHost) > 0 && !strings.Contains(f.SMTPHost, ":") {
|
|
if len(f.SMTPHost) > 0 && !strings.Contains(f.SMTPHost, ":") {
|
|
|
c.FormErr("SMTP", "SMTPHost")
|
|
c.FormErr("SMTP", "SMTPHost")
|
|
|
- c.RenderWithErr(c.Tr("install.smtp_host_missing_port"), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.smtp_host_missing_port"), http.StatusBadRequest, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -273,7 +273,7 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
_, err := mail.ParseAddress(f.SMTPFrom)
|
|
_, err := mail.ParseAddress(f.SMTPFrom)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
c.FormErr("SMTP", "SMTPFrom")
|
|
c.FormErr("SMTP", "SMTPFrom")
|
|
|
- c.RenderWithErr(c.Tr("install.invalid_smtp_from", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.invalid_smtp_from", err), http.StatusBadRequest, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -281,19 +281,19 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
// Check logic loophole between disable self-registration and no admin account.
|
|
// Check logic loophole between disable self-registration and no admin account.
|
|
|
if f.DisableRegistration && f.AdminName == "" {
|
|
if f.DisableRegistration && f.AdminName == "" {
|
|
|
c.FormErr("Services", "Admin")
|
|
c.FormErr("Services", "Admin")
|
|
|
- c.RenderWithErr(c.Tr("install.no_admin_and_disable_registration"), INSTALL, f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.no_admin_and_disable_registration"), http.StatusUnprocessableEntity, INSTALL, f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Check admin password.
|
|
// Check admin password.
|
|
|
if len(f.AdminName) > 0 && f.AdminPasswd == "" {
|
|
if len(f.AdminName) > 0 && f.AdminPasswd == "" {
|
|
|
c.FormErr("Admin", "AdminPasswd")
|
|
c.FormErr("Admin", "AdminPasswd")
|
|
|
- c.RenderWithErr(c.Tr("install.err_empty_admin_password"), INSTALL, f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.err_empty_admin_password"), http.StatusBadRequest, INSTALL, f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
if f.AdminPasswd != f.AdminConfirmPasswd {
|
|
if f.AdminPasswd != f.AdminConfirmPasswd {
|
|
|
c.FormErr("Admin", "AdminPasswd")
|
|
c.FormErr("Admin", "AdminPasswd")
|
|
|
- c.RenderWithErr(c.Tr("form.password_not_match"), INSTALL, f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("form.password_not_match"), http.StatusBadRequest, INSTALL, f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -367,21 +367,21 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
|
|
cfg.Section("security").Key("INSTALL_LOCK").SetValue("true")
|
|
|
secretKey, err := strutil.RandomChars(15)
|
|
secretKey, err := strutil.RandomChars(15)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- c.RenderWithErr(c.Tr("install.secret_key_failed", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.secret_key_failed", err), http.StatusInternalServerError, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
cfg.Section("security").Key("SECRET_KEY").SetValue(secretKey)
|
|
cfg.Section("security").Key("SECRET_KEY").SetValue(secretKey)
|
|
|
|
|
|
|
|
_ = os.MkdirAll(filepath.Dir(conf.CustomConf), os.ModePerm)
|
|
_ = os.MkdirAll(filepath.Dir(conf.CustomConf), os.ModePerm)
|
|
|
if err := cfg.SaveTo(conf.CustomConf); err != nil {
|
|
if err := cfg.SaveTo(conf.CustomConf); err != nil {
|
|
|
- c.RenderWithErr(c.Tr("install.save_config_failed", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.save_config_failed", err), http.StatusInternalServerError, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// NOTE: We reuse the current value because this handler does not have access to CLI flags.
|
|
// NOTE: We reuse the current value because this handler does not have access to CLI flags.
|
|
|
err = GlobalInit(conf.CustomConf)
|
|
err = GlobalInit(conf.CustomConf)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- c.RenderWithErr(c.Tr("install.init_failed", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.init_failed", err), http.StatusInternalServerError, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -401,7 +401,7 @@ func InstallPost(c *context.Context, f form.Install) {
|
|
|
if !database.IsErrUserAlreadyExist(err) {
|
|
if !database.IsErrUserAlreadyExist(err) {
|
|
|
conf.Security.InstallLock = false
|
|
conf.Security.InstallLock = false
|
|
|
c.FormErr("AdminName", "AdminEmail")
|
|
c.FormErr("AdminName", "AdminEmail")
|
|
|
- c.RenderWithErr(c.Tr("install.invalid_admin_setting", err), INSTALL, &f)
|
|
|
|
|
|
|
+ c.RenderWithErr(c.Tr("install.invalid_admin_setting", err), http.StatusBadRequest, INSTALL, &f)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|