@ -6,6 +6,7 @@ package routes
import (
import (
"net/mail"
"net/mail"
"net/http"
"os"
"os"
"os/exec"
"os/exec"
"path/filepath"
"path/filepath"
@ -186,7 +187,7 @@ func InstallPost(c *context.Context, f form.Install) {
}
}
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 ) , INSTALL , & f , http . StatusOK )
return
return
}
}
@ -203,7 +204,7 @@ func InstallPost(c *context.Context, f form.Install) {
if models . DbCfg . Type == "sqlite3" && len ( models . DbCfg . Path ) == 0 {
if models . DbCfg . Type == "sqlite3" && len ( models . DbCfg . Path ) == 0 {
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" ) , INSTALL , & f , http . StatusBadRequest )
return
return
}
}
@ -212,10 +213,10 @@ func InstallPost(c *context.Context, f form.Install) {
if err := models . NewTestEngine ( x ) ; err != nil {
if err := models . NewTestEngine ( x ) ; 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" ) , INSTALL , & f , http . StatusOK )
} 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 ) , INSTALL , & f , http . StatusOK )
}
}
return
return
}
}
@ -224,7 +225,7 @@ func InstallPost(c *context.Context, f form.Install) {
f . RepoRootPath = strings . Replace ( f . RepoRootPath , "\\" , "/" , - 1 )
f . RepoRootPath = strings . Replace ( f . RepoRootPath , "\\" , "/" , - 1 )
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 ) , INSTALL , & f , http . StatusOK )
return
return
}
}
@ -232,21 +233,21 @@ func InstallPost(c *context.Context, f form.Install) {
f . LogRootPath = strings . Replace ( f . LogRootPath , "\\" , "/" , - 1 )
f . LogRootPath = strings . Replace ( f . LogRootPath , "\\" , "/" , - 1 )
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 ) , INSTALL , & f , http . StatusOK )
return
return
}
}
currentUser , match := setting . IsRunUserMatchCurrentUser ( f . RunUser )
currentUser , match := setting . IsRunUserMatchCurrentUser ( 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 ) , INSTALL , & f , http . StatusOK )
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" ) , INSTALL , & f , http . StatusOK )
return
return
}
}
@ -255,7 +256,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 ) , INSTALL , & f , http . StatusOK )
return
return
}
}
}
}
@ -263,19 +264,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 && len ( f . AdminName ) == 0 {
if f . DisableRegistration && len ( f . AdminName ) == 0 {
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" ) , INSTALL , f , http . StatusOK )
return
return
}
}
// Check admin password.
// Check admin password.
if len ( f . AdminName ) > 0 && len ( f . AdminPasswd ) == 0 {
if len ( f . AdminName ) > 0 && len ( f . AdminPasswd ) == 0 {
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" ) , INSTALL , f , http . StatusOK )
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" ) , INSTALL , f , http . StatusOK )
return
return
}
}
@ -348,14 +349,14 @@ 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 := tool . RandomString ( 15 )
secretKey , err := tool . RandomString ( 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 ) , INSTALL , & f , http . StatusInternalServerError )
return
return
}
}
cfg . Section ( "security" ) . Key ( "SECRET_KEY" ) . SetValue ( secretKey )
cfg . Section ( "security" ) . Key ( "SECRET_KEY" ) . SetValue ( secretKey )
os . MkdirAll ( filepath . Dir ( setting . CustomConf ) , os . ModePerm )
os . MkdirAll ( filepath . Dir ( setting . CustomConf ) , os . ModePerm )
if err := cfg . SaveTo ( setting . CustomConf ) ; err != nil {
if err := cfg . SaveTo ( setting . CustomConf ) ; err != nil {
c . RenderWithErr ( c . Tr ( "install.save_config_failed" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.save_config_failed" , err ) , INSTALL , & f , http . StatusInternalServerError )
return
return
}
}
@ -374,7 +375,7 @@ func InstallPost(c *context.Context, f form.Install) {
if ! models . IsErrUserAlreadyExist ( err ) {
if ! models . IsErrUserAlreadyExist ( err ) {
setting . InstallLock = false
setting . 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 ) , INSTALL , & f , http . StatusBadRequest )
return
return
}
}
log . Info ( "Admin account already exist" )
log . Info ( "Admin account already exist" )