From eeb793524f2da4afdca017b585d9cfb6e9628e85 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 06:52:56 -0400 Subject: Check run user --- modules/base/conf.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'modules/base/conf.go') diff --git a/modules/base/conf.go b/modules/base/conf.go index d3122a53..c692ddc2 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -259,16 +259,11 @@ func NewConfigContext() { Cfg.BlockMode = false cfgPath = filepath.Join(workDir, "custom/conf/app.ini") - if !com.IsFile(cfgPath) { - fmt.Println("Custom configuration not found(custom/conf/app.ini)\n" + - "Please create it and make your own configuration!") - os.Exit(2) - - } - - if err = Cfg.AppendFiles(cfgPath); err != nil { - fmt.Printf("Cannot load config file '%s'\n", cfgPath) - os.Exit(2) + if com.IsFile(cfgPath) { + if err = Cfg.AppendFiles(cfgPath); err != nil { + fmt.Printf("Cannot load config file '%s'\n", cfgPath) + os.Exit(2) + } } AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service") @@ -276,7 +271,13 @@ func NewConfigContext() { AppUrl = Cfg.MustValue("server", "ROOT_URL") Domain = Cfg.MustValue("server", "DOMAIN") SecretKey = Cfg.MustValue("security", "SECRET_KEY") + RunUser = Cfg.MustValue("", "RUN_USER") + curUser := os.Getenv("USERNAME") + if RunUser != curUser { + fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) + os.Exit(2) + } EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) -- cgit v1.2.3 From be69e74bc05b62deb6a5f9ae360af220cd5d5226 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:06:56 -0400 Subject: Mirror fix --- modules/base/conf.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/base/conf.go') diff --git a/modules/base/conf.go b/modules/base/conf.go index d0f8ae2c..3eb01bdd 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -274,6 +274,9 @@ func NewConfigContext() { RunUser = Cfg.MustValue("", "RUN_USER") curUser := os.Getenv("USERNAME") + if len(curUser) == 0 { + curUser = os.Getenv("whoami") + } if RunUser != curUser { fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) os.Exit(2) -- cgit v1.2.3 From 7aa0a97d10a6810ab0b6fb482c7f8f179431104f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:10:23 -0400 Subject: Mirror fix --- modules/base/conf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/base/conf.go') diff --git a/modules/base/conf.go b/modules/base/conf.go index 3eb01bdd..1661681e 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -275,7 +275,7 @@ func NewConfigContext() { RunUser = Cfg.MustValue("", "RUN_USER") curUser := os.Getenv("USERNAME") if len(curUser) == 0 { - curUser = os.Getenv("whoami") + curUser = os.Getenv("USER") } if RunUser != curUser { fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) -- cgit v1.2.3 From 197c4d4a5ba8a9540c49879324194f5f6be4689c Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 08:53:11 -0400 Subject: Fix wrong serve command log location and commit repo action --- models/action.go | 6 ++++-- modules/base/conf.go | 4 ++-- modules/middleware/repo.go | 2 +- serve.go | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'modules/base/conf.go') diff --git a/models/action.go b/models/action.go index 44d7aea8..dffc0e53 100644 --- a/models/action.go +++ b/models/action.go @@ -59,7 +59,7 @@ func (a Action) GetContent() string { // CommitRepoAction records action for commit repository. func CommitRepoAction(userId int64, userName string, repoId int64, repoName string, refName string, commits *base.PushCommits) error { - log.Trace("action.CommitRepoAction: %d/%s", userId, repoName) + log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) bs, err := json.Marshal(commits) if err != nil { @@ -92,8 +92,8 @@ func CommitRepoAction(userId int64, userName string, }) if err != nil { log.Error("action.CommitRepoAction(notify watches): %d/%s", userId, repoName) + return err } - return err } // Update repository last update time. @@ -107,6 +107,8 @@ func CommitRepoAction(userId int64, userName string, log.Error("action.CommitRepoAction(UpdateRepository): %d/%s", userId, repoName) return err } + + log.Trace("action.CommitRepoAction(end): %d/%s", userId, repoName) return nil } diff --git a/modules/base/conf.go b/modules/base/conf.go index 1661681e..0fb1ccdc 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -71,7 +71,7 @@ var Service struct { ResetPwdCodeLives int } -func exeDir() (string, error) { +func ExecDir() (string, error) { file, err := exec.LookPath(os.Args[0]) if err != nil { return "", err @@ -244,7 +244,7 @@ func newNotifyMailService() { func NewConfigContext() { //var err error - workDir, err := exeDir() + workDir, err := ExecDir() if err != nil { fmt.Printf("Fail to get work directory: %s\n", err) os.Exit(2) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index eea2570c..b23bccb1 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -73,7 +73,7 @@ func RepoAssignment(redirect bool) martini.Handler { if base.EnableHttpsClone { scheme = "https" } - ctx.Repo.CloneLink.SSH = fmt.Sprintf("git@%s:%s/%s.git", base.Domain, user.LowerName, repo.LowerName) + ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName) ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s://%s/%s/%s.git", scheme, base.Domain, user.LowerName, repo.LowerName) ctx.Data["IsRepositoryValid"] = true diff --git a/serve.go b/serve.go index 89ef0d84..7e21fcae 100644 --- a/serve.go +++ b/serve.go @@ -45,10 +45,10 @@ gogs serv provide access auth for repositories`, Flags: []cli.Flag{}, } -func init() { +func newLogger(execDir string) { level := "0" os.MkdirAll("log", os.ModePerm) - log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log")) + log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, execDir+"/log/serv.log")) log.Trace("start logging...") } @@ -73,6 +73,8 @@ func In(b string, sl map[string]int) bool { } func runServ(k *cli.Context) { + execDir, _ := base.ExecDir() + newLogger(execDir) log.Trace("new serv request " + log.Mode + ":" + log.Config) base.NewConfigContext() -- cgit v1.2.3