|
@ -9,13 +9,13 @@ import ( |
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli" |
|
|
"github.com/codegangsta/cli" |
|
|
"github.com/gogits/gogs/models" |
|
|
"github.com/gogits/gogs/models" |
|
|
"github.com/gogits/gogs/utils/log" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
|
COMMANDS_READONLY = map[string]int{ |
|
|
COMMANDS_READONLY = map[string]int{ |
|
|
"git-upload-pack": models.AU_WRITABLE, |
|
|
|
|
|
"git upload-pack": models.AU_WRITABLE, |
|
|
|
|
|
|
|
|
"git-upload-pack": models.AU_WRITABLE, |
|
|
|
|
|
"git upload-pack": models.AU_WRITABLE, |
|
|
|
|
|
"git-upload-archive": models.AU_WRITABLE, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
COMMANDS_WRITE = map[string]int{ |
|
|
COMMANDS_WRITE = map[string]int{ |
|
@ -26,9 +26,9 @@ var ( |
|
|
|
|
|
|
|
|
var CmdServ = cli.Command{ |
|
|
var CmdServ = cli.Command{ |
|
|
Name: "serv", |
|
|
Name: "serv", |
|
|
Usage: "just run", |
|
|
|
|
|
|
|
|
Usage: "This command just should be called by ssh shell", |
|
|
Description: ` |
|
|
Description: ` |
|
|
gogs serv`, |
|
|
|
|
|
|
|
|
gogs serv provide access auth for repositories`, |
|
|
Action: runServ, |
|
|
Action: runServ, |
|
|
Flags: []cli.Flag{ |
|
|
Flags: []cli.Flag{ |
|
|
//cli.BoolFlag{"update, u", "update pakcage(s) and dependencies if any"},
|
|
|
//cli.BoolFlag{"update, u", "update pakcage(s) and dependencies if any"},
|
|
@ -61,14 +61,13 @@ func runServ(*cli.Context) { |
|
|
|
|
|
|
|
|
cmd := os.Getenv("SSH_ORIGINAL_COMMAND") |
|
|
cmd := os.Getenv("SSH_ORIGINAL_COMMAND") |
|
|
if cmd == "" { |
|
|
if cmd == "" { |
|
|
fmt.Printf("Hi %s! You've successfully authenticated, but Gogits does not provide shell access.\n", user.Name) |
|
|
|
|
|
|
|
|
println("Hi %s! You've successfully authenticated, but Gogits does not provide shell access.\n", user.Name) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//println(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
verb, args := parseCmd(cmd) |
|
|
verb, args := parseCmd(cmd) |
|
|
rr := strings.SplitN(strings.Trim(args, "'"), "/", 2) |
|
|
|
|
|
|
|
|
rRepo := strings.Trim(args, "'") |
|
|
|
|
|
rr := strings.SplitN(rRepo, "/", 2) |
|
|
if len(rr) != 2 { |
|
|
if len(rr) != 2 { |
|
|
println("Unavilable repository", args) |
|
|
println("Unavilable repository", args) |
|
|
return |
|
|
return |
|
@ -80,13 +79,11 @@ 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]) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("Inernel error:", err) |
|
|
|
|
|
|
|
|
println("Inernel error:", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if !has { |
|
|
if !has { |
|
@ -96,13 +93,13 @@ func runServ(*cli.Context) { |
|
|
case isRead: |
|
|
case isRead: |
|
|
has, err := models.HasAccess(user.Name, repoName, COMMANDS_READONLY[verb]) |
|
|
has, err := models.HasAccess(user.Name, repoName, COMMANDS_READONLY[verb]) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("Inernel error") |
|
|
|
|
|
|
|
|
println("Inernel error") |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if !has { |
|
|
if !has { |
|
|
has, err = models.HasAccess(user.Name, repoName, COMMANDS_WRITE[verb]) |
|
|
has, err = models.HasAccess(user.Name, repoName, COMMANDS_WRITE[verb]) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("Inernel error") |
|
|
|
|
|
|
|
|
println("Inernel error") |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -134,16 +131,15 @@ func runServ(*cli.Context) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fullPath := models.RepoPath(user.Name, repoName) |
|
|
|
|
|
newcmd := fmt.Sprintf("%s '%s'", verb, fullPath) |
|
|
|
|
|
//println(newcmd)
|
|
|
|
|
|
gitcmd := exec.Command("git", "shell", "-c", newcmd) |
|
|
|
|
|
|
|
|
gitcmd := exec.Command(verb, rRepo) |
|
|
|
|
|
gitcmd.Dir = models.RepoRootPath |
|
|
gitcmd.Stdout = os.Stdout |
|
|
gitcmd.Stdout = os.Stdout |
|
|
|
|
|
gitcmd.Stdin = os.Stdin |
|
|
gitcmd.Stderr = os.Stderr |
|
|
gitcmd.Stderr = os.Stderr |
|
|
|
|
|
|
|
|
err = gitcmd.Run() |
|
|
err = gitcmd.Run() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
log.Error("execute command error: %s", err) |
|
|
|
|
|
|
|
|
println("execute command error:", err.Error()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|