|
|
@ -4,7 +4,6 @@ import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
@ -66,16 +65,12 @@ func runServ(*cli.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
f, _ := os.Create("test2.log") |
|
|
|
println(cmd) |
|
|
|
f.WriteString(cmd) |
|
|
|
|
|
|
|
f.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.Info("cmd is %s", cmd) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verb, args := parseCmd(cmd) |
|
|
|
verb, args := parseCmd(cmd) |
|
|
|
rr := strings.SplitN(strings.Trim(args, "'"), "/", 1) |
|
|
|
rr := strings.SplitN(strings.Trim(args, "'"), "/", 2) |
|
|
|
if len(rr) != 2 { |
|
|
|
if len(rr) != 2 { |
|
|
|
fmt.Printf("Unavilable repository") |
|
|
|
println("Unavilable repository", args) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
repoName := rr[1] |
|
|
|
repoName := rr[1] |
|
|
@ -84,6 +79,9 @@ func runServ(*cli.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
isWrite := In(verb, COMMANDS_WRITE) |
|
|
|
isWrite := In(verb, COMMANDS_WRITE) |
|
|
|
isRead := In(verb, COMMANDS_READONLY) |
|
|
|
isRead := In(verb, COMMANDS_READONLY) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println("repoPath:", models.RepoPath(user.Name, repoName)) |
|
|
|
|
|
|
|
|
|
|
|
switch { |
|
|
|
switch { |
|
|
|
case isWrite: |
|
|
|
case isWrite: |
|
|
|
has, err := models.HasAccess(user.Name, repoName, COMMANDS_WRITE[verb]) |
|
|
|
has, err := models.HasAccess(user.Name, repoName, COMMANDS_WRITE[verb]) |
|
|
@ -92,7 +90,7 @@ func runServ(*cli.Context) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
if !has { |
|
|
|
if !has { |
|
|
|
fmt.Println("You have no right to access this repository") |
|
|
|
println("You have no right to access this repository") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
case isRead: |
|
|
|
case isRead: |
|
|
@ -109,36 +107,36 @@ func runServ(*cli.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if !has { |
|
|
|
if !has { |
|
|
|
fmt.Println("You have no right to access this repository") |
|
|
|
println("You have no right to access this repository") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
fmt.Println("Unknown command") |
|
|
|
println("Unknown command") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isExist, err := models.IsRepositoryExist(user, repoName) |
|
|
|
isExist, err := models.IsRepositoryExist(user, repoName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println("Inernel error") |
|
|
|
println("Inernel error:", err.Error()) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !isExist { |
|
|
|
if !isExist { |
|
|
|
if isRead { |
|
|
|
if isRead { |
|
|
|
fmt.Println("Repository is not exist") |
|
|
|
println("Repository", user.Name+"/"+repoName, "is not exist") |
|
|
|
return |
|
|
|
return |
|
|
|
} else if isWrite { |
|
|
|
} else if isWrite { |
|
|
|
_, err := models.CreateRepository(user, repoName) |
|
|
|
_, err := models.CreateRepository(user, repoName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Println("Create repository failed") |
|
|
|
println("Create repository failed") |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fullPath := filepath.Join(models.RepoRootPath, user.Name, repoName+".git") |
|
|
|
fullPath := models.RepoPath(user.Name, repoName) |
|
|
|
newcmd := fmt.Sprintf("%s '%s'", verb, fullPath) |
|
|
|
newcmd := fmt.Sprintf("%s '%s'", verb, fullPath) |
|
|
|
fmt.Println(newcmd) |
|
|
|
println(newcmd) |
|
|
|
gitcmd := exec.Command("git", "shell", "-c", newcmd) |
|
|
|
gitcmd := exec.Command("git", "shell", "-c", newcmd) |
|
|
|
gitcmd.Stdout = os.Stdout |
|
|
|
gitcmd.Stdout = os.Stdout |
|
|
|
gitcmd.Stderr = os.Stderr |
|
|
|
gitcmd.Stderr = os.Stderr |
|
|
@ -150,13 +148,14 @@ func runServ(*cli.Context) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func parseCmd(cmd string) (string, string) { |
|
|
|
func parseCmd(cmd string) (string, string) { |
|
|
|
ss := strings.SplitN(cmd, " ", 1) |
|
|
|
ss := strings.SplitN(cmd, " ", 2) |
|
|
|
if len(ss) != 2 { |
|
|
|
if len(ss) != 2 { |
|
|
|
return "", "" |
|
|
|
return "", "" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
verb, args := ss[0], ss[1] |
|
|
|
verb, args := ss[0], ss[1] |
|
|
|
if verb == "git" { |
|
|
|
if verb == "git" { |
|
|
|
ss = strings.SplitN(args, " ", 1) |
|
|
|
ss = strings.SplitN(args, " ", 2) |
|
|
|
args = ss[1] |
|
|
|
args = ss[1] |
|
|
|
verb = fmt.Sprintf("%s %s", verb, ss[0]) |
|
|
|
verb = fmt.Sprintf("%s %s", verb, ss[0]) |
|
|
|
} |
|
|
|
} |
|
|
|