From eeb793524f2da4afdca017b585d9cfb6e9628e85 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 06:52:56 -0400 Subject: [PATCH 1/5] Check run user --- conf/app.ini | 4 ++-- gogs.go | 15 --------------- modules/base/conf.go | 21 +++++++++++---------- templates/user/delete.tmpl | 4 ++-- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/conf/app.ini b/conf/app.ini index 809ea61c07..4c2398dd68 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -1,8 +1,8 @@ ; App name that shows on every page title APP_NAME = Gogs: Go Git Service APP_LOGO = img/favicon.png -; !!MUST CHANGE TO YOUR USER NAME!! -RUN_USER = lunny +; Check it if you run locally +RUN_USER = git ; Either "dev", "prod" or "test", default is "dev" RUN_MODE = dev diff --git a/gogs.go b/gogs.go index 93b7231b77..7ac699cc69 100644 --- a/gogs.go +++ b/gogs.go @@ -7,7 +7,6 @@ package main import ( "os" - // "os/user" "runtime" "github.com/codegangsta/cli" @@ -27,21 +26,7 @@ func init() { runtime.GOMAXPROCS(runtime.NumCPU()) } -// func checkRunUser() bool { -// u, err := user.Current() -// if err != nil { -// // TODO: log -// return false -// } -// return u.Username == base.Cfg.MustValue("", "RUN_USER") -// } - func main() { - /*if !checkRunUser() { - println("The command should be run as", base.Cfg.MustValue("", "RUN_USER")) - return - }*/ - app := cli.NewApp() app.Name = "Gogs" app.Usage = "Go Git Service" diff --git a/modules/base/conf.go b/modules/base/conf.go index d3122a5339..c692ddc23f 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) diff --git a/templates/user/delete.tmpl b/templates/user/delete.tmpl index 46376672d4..04c713eb65 100644 --- a/templates/user/delete.tmpl +++ b/templates/user/delete.tmpl @@ -6,9 +6,9 @@ From be69e74bc05b62deb6a5f9ae360af220cd5d5226 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:06:56 -0400 Subject: [PATCH 2/5] Mirror fix --- modules/base/conf.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/base/conf.go b/modules/base/conf.go index d0f8ae2cc8..3eb01bdd56 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) From 7aa0a97d10a6810ab0b6fb482c7f8f179431104f Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:10:23 -0400 Subject: [PATCH 3/5] Mirror fix --- modules/base/conf.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/base/conf.go b/modules/base/conf.go index 3eb01bdd56..1661681e7e 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) From c3953a62fd874f035adf3c16a59dfd97f655c078 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:30:18 -0400 Subject: [PATCH 4/5] Add more log to locate issue --- serve.go | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/serve.go b/serve.go index acdcb877ff..962f877745 100644 --- a/serve.go +++ b/serve.go @@ -49,7 +49,7 @@ func init() { level := "0" os.MkdirAll("log", os.ModePerm) log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log")) - log.Info("start logging...") + log.Trace("start logging...") } func parseCmd(cmd string) (string, string) { @@ -80,17 +80,20 @@ func runServ(k *cli.Context) { keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { fmt.Println("auth file format error") + log.Error("auth file format error") return } keyId, err := strconv.ParseInt(keys[1], 10, 64) if err != nil { fmt.Println("auth file format error") + log.Error("auth file format error") return } user, err := models.GetUserByKeyId(keyId) if err != nil { fmt.Println("You have no right to access") + log.Error("You have no right to access") return } @@ -105,6 +108,7 @@ func runServ(k *cli.Context) { rr := strings.SplitN(rRepo, "/", 2) if len(rr) != 2 { println("Unavilable repository", args) + log.Error("Unavilable repository %v", args) return } repoName := rr[1] @@ -122,11 +126,12 @@ func runServ(k *cli.Context) { isExist = false if isRead { println("Repository", user.Name+"/"+repoName, "is not exist") + log.Error("Repository " + user.Name + "/" + repoName + " is not exist") return } } else { println("Get repository error:", err) - log.Error(err.Error()) + log.Error("Get repository error: " + err.Error()) return } } @@ -142,6 +147,7 @@ func runServ(k *cli.Context) { } if !has { println("You have no right to write this repository") + log.Error("You have no right to access this repository") return } case isRead: @@ -161,10 +167,12 @@ func runServ(k *cli.Context) { } if !has { println("You have no right to access this repository") + log.Error("You have no right to access this repository") return } default: println("Unknown command") + log.Error("Unknown command") return } @@ -175,23 +183,23 @@ func runServ(k *cli.Context) { _, err = models.CreateRepository(user, repoName, "", "", "", false, true) if err != nil { println("Create repository failed") - log.Error(err.Error()) + log.Error("Create repository failed: " + err.Error()) return } } } - rep, err = git.OpenRepository(repoPath) - if err != nil { - println("OpenRepository failed:", err.Error()) - log.Error(err.Error()) - return - } + rep, err = git.OpenRepository(repoPath) + if err != nil { + println("OpenRepository failed:", err.Error()) + log.Error("OpenRepository failed: " + err.Error()) + return + } refs, err := rep.AllReferencesMap() if err != nil { println("Get All References failed:", err.Error()) - log.Error(err.Error()) + log.Error("Get All References failed: " + err.Error()) return } @@ -208,7 +216,7 @@ func runServ(k *cli.Context) { if err = gitcmd.Run(); err != nil { println("execute command error:", err.Error()) - log.Error(err.Error()) + log.Error("execute command error: " + err.Error()) return } @@ -236,6 +244,7 @@ func runServ(k *cli.Context) { } if refname == "" { println("No find any reference name:", b.String()) + log.Error("No find any reference name: " + b.String()) return } @@ -248,17 +257,18 @@ func runServ(k *cli.Context) { refs, err = rep.AllReferencesMap() if err != nil { println("Get All References failed:", err.Error()) - log.Error(err.Error()) + log.Error("Get All References failed: " + err.Error()) return } if ref, ok = refs[refname]; !ok { + log.Error("unknow reference name -", refname, "-", b.String()) log.Error("unknow reference name -", refname, "-", b.String()) return } l, err = ref.AllCommits() if err != nil { println("Get All Commits failed:", err.Error()) - log.Error(err.Error()) + log.Error("Get All Commits failed: " + err.Error()) return } } else { @@ -268,14 +278,14 @@ func runServ(k *cli.Context) { last, err = ref.LastCommit() if err != nil { println("Get last commit failed:", err.Error()) - log.Error(err.Error()) + log.Error("Get last commit failed: " + err.Error()) return } ref2, err := rep.LookupReference(ref.Name) if err != nil { println("look up reference failed:", err.Error()) - log.Error(err.Error()) + log.Error("look up reference failed: " + err.Error()) return } @@ -283,7 +293,7 @@ func runServ(k *cli.Context) { before, err := ref2.LastCommit() if err != nil { println("Get last commit failed:", err.Error()) - log.Error(err.Error()) + log.Error("Get last commit failed: " + err.Error()) return } //log.Info("----", before.Id(), "-----", last.Id()) From ca49acfe67cee4b5d4be40519b83d9107833e60d Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Mar 2014 07:38:48 -0400 Subject: [PATCH 5/5] Add more log to locate issue --- serve.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/serve.go b/serve.go index 962f877745..a4d5a727d8 100644 --- a/serve.go +++ b/serve.go @@ -73,6 +73,8 @@ func In(b string, sl map[string]int) bool { } func runServ(k *cli.Context) { + log.Trace("new serv request") + base.NewConfigContext() models.LoadModelsConfig() models.NewEngine()