|
|
@ -74,29 +74,33 @@ func In(b string, sl map[string]int) bool { |
|
|
|
func runServ(k *cli.Context) { |
|
|
|
func runServ(k *cli.Context) { |
|
|
|
execDir, _ := base.ExecDir() |
|
|
|
execDir, _ := base.ExecDir() |
|
|
|
newLogger(execDir) |
|
|
|
newLogger(execDir) |
|
|
|
log.Trace("new serv request " + log.Mode + ":" + log.Config) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base.NewConfigContext() |
|
|
|
base.NewConfigContext() |
|
|
|
models.LoadModelsConfig() |
|
|
|
models.LoadModelsConfig() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if models.UseSQLite3 { |
|
|
|
|
|
|
|
os.Chdir(execDir) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
models.SetEngine() |
|
|
|
models.SetEngine() |
|
|
|
|
|
|
|
|
|
|
|
keys := strings.Split(os.Args[2], "-") |
|
|
|
keys := strings.Split(os.Args[2], "-") |
|
|
|
if len(keys) != 2 { |
|
|
|
if len(keys) != 2 { |
|
|
|
fmt.Println("auth file format error") |
|
|
|
println("auth file format error") |
|
|
|
log.Error("auth file format error") |
|
|
|
log.Error("auth file format error") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
keyId, err := strconv.ParseInt(keys[1], 10, 64) |
|
|
|
keyId, err := strconv.ParseInt(keys[1], 10, 64) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println("auth file format error") |
|
|
|
println("auth file format error") |
|
|
|
log.Error("auth file format error", err) |
|
|
|
log.Error("auth file format error", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
user, err := models.GetUserByKeyId(keyId) |
|
|
|
user, err := models.GetUserByKeyId(keyId) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println("You have no right to access") |
|
|
|
println("You have no right to access") |
|
|
|
log.Error("SSH visit error", err) |
|
|
|
log.Error("SSH visit error: %v", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -133,13 +137,12 @@ func runServ(k *cli.Context) { |
|
|
|
// access check
|
|
|
|
// access check
|
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case isWrite: |
|
|
|
case isWrite: |
|
|
|
has, err := models.HasAccess(user.Name, strings.ToLower(path.Join(repoUserName, repoName)), models.AU_WRITABLE) |
|
|
|
has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
println("Inernel error:", err) |
|
|
|
println("Inernel error:", err) |
|
|
|
log.Error(err.Error()) |
|
|
|
log.Error(err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} else if !has { |
|
|
|
if !has { |
|
|
|
|
|
|
|
println("You have no right to write this repository") |
|
|
|
println("You have no right to write this repository") |
|
|
|
log.Error("User %s has no right to write repository %s", user.Name, repoPath) |
|
|
|
log.Error("User %s has no right to write repository %s", user.Name, repoPath) |
|
|
|
return |
|
|
|
return |
|
|
|