|
|
@ -13,9 +13,8 @@ import ( |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"code.google.com/p/go.crypto/ssh" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
"github.com/Unknwon/com" |
|
|
|
|
|
|
|
"golang.org/x/crypto/ssh" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
) |
|
|
|
) |
|
|
@ -35,8 +34,11 @@ func handleServerConn(keyId string, chans <-chan ssh.NewChannel) { |
|
|
|
go func(in <-chan *ssh.Request) { |
|
|
|
go func(in <-chan *ssh.Request) { |
|
|
|
defer channel.Close() |
|
|
|
defer channel.Close() |
|
|
|
for req := range in { |
|
|
|
for req := range in { |
|
|
|
ok, payload := false, strings.TrimLeft(string(req.Payload), "\x00") |
|
|
|
ok, payload := false, strings.TrimLeft(string(req.Payload), "\x00&") |
|
|
|
fmt.Println("Request:", req.Type, req.WantReply, payload) |
|
|
|
fmt.Println("Request:", req.Type, req.WantReply, payload) |
|
|
|
|
|
|
|
if req.WantReply { |
|
|
|
|
|
|
|
fmt.Println(req.Reply(true, nil)) |
|
|
|
|
|
|
|
} |
|
|
|
switch req.Type { |
|
|
|
switch req.Type { |
|
|
|
case "env": |
|
|
|
case "env": |
|
|
|
args := strings.Split(strings.Replace(payload, "\x00", "", -1), "\v") |
|
|
|
args := strings.Split(strings.Replace(payload, "\x00", "", -1), "\v") |
|
|
@ -54,7 +56,7 @@ func handleServerConn(keyId string, chans <-chan ssh.NewChannel) { |
|
|
|
case "exec": |
|
|
|
case "exec": |
|
|
|
os.Setenv("SSH_ORIGINAL_COMMAND", strings.TrimLeft(payload, "'(")) |
|
|
|
os.Setenv("SSH_ORIGINAL_COMMAND", strings.TrimLeft(payload, "'(")) |
|
|
|
log.Info("Payload: %v", strings.TrimLeft(payload, "'(")) |
|
|
|
log.Info("Payload: %v", strings.TrimLeft(payload, "'(")) |
|
|
|
cmd := exec.Command("/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs-ng/gogs-ng", "serv", "key-"+keyId) |
|
|
|
cmd := exec.Command("/Users/jiahuachen/Applications/Go/src/github.com/gogits/gogs/gogs", "serv", "key-"+keyId) |
|
|
|
cmd.Stdout = channel |
|
|
|
cmd.Stdout = channel |
|
|
|
cmd.Stdin = channel |
|
|
|
cmd.Stdin = channel |
|
|
|
cmd.Stderr = channel.Stderr() |
|
|
|
cmd.Stderr = channel.Stderr() |
|
|
@ -65,7 +67,6 @@ func handleServerConn(keyId string, chans <-chan ssh.NewChannel) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println("Done:", ok) |
|
|
|
fmt.Println("Done:", ok) |
|
|
|
req.Reply(ok, nil) // BUG: Git on Mac seems not know this reply and hang?
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Println("Done!!!") |
|
|
|
fmt.Println("Done!!!") |
|
|
|
}(requests) |
|
|
|
}(requests) |
|
|
@ -101,7 +102,7 @@ func Listen(port string) { |
|
|
|
config := &ssh.ServerConfig{ |
|
|
|
config := &ssh.ServerConfig{ |
|
|
|
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) { |
|
|
|
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) { |
|
|
|
// keyCache[string(ssh.MarshalAuthorizedKey(key))] = 2
|
|
|
|
// keyCache[string(ssh.MarshalAuthorizedKey(key))] = 2
|
|
|
|
return &ssh.Permissions{Extensions: map[string]string{"key-id": "2"}}, nil |
|
|
|
return &ssh.Permissions{Extensions: map[string]string{"key-id": "1"}}, nil |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|