From 8dd07c0ddd99ae626a1ec8c06f75f27fed51269f Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 26 Jul 2014 00:24:27 -0400 Subject: New UI merge in progress --- modules/ssh/ssh.go | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 modules/ssh/ssh.go (limited to 'modules/ssh/ssh.go') diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go new file mode 100644 index 0000000000..78ad678dc5 --- /dev/null +++ b/modules/ssh/ssh.go @@ -0,0 +1,119 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +// Prototype, git client looks like do not recognize req.Reply. +package ssh + +import ( + "fmt" + "io/ioutil" + "net" + "os" + "os/exec" + "strings" + + "code.google.com/p/go.crypto/ssh" + + "github.com/Unknwon/com" + + "github.com/gogits/gogs-ng/modules/log" +) + +func handleServerConn(keyId string, chans <-chan ssh.NewChannel) { + for newChan := range chans { + if newChan.ChannelType() != "session" { + newChan.Reject(ssh.UnknownChannelType, "unknown channel type") + continue + } + channel, requests, err := newChan.Accept() + if err != nil { + log.Error(3, "Could not accept channel: %v", err) + continue + } + + go func(in <-chan *ssh.Request) { + defer channel.Close() + for req := range in { + ok, payload := false, strings.TrimLeft(string(req.Payload), "\x00") + fmt.Println("Request:", req.Type, req.WantReply, payload) + switch req.Type { + case "env": + args := strings.Split(strings.Replace(payload, "\x00", "", -1), "\v") + if len(args) != 2 { + break + } + args[0] = strings.TrimLeft(args[0], "\x04") + _, _, err := com.ExecCmdBytes("env", args[0]+"="+args[1]) + if err != nil { + log.Error(3, "env: %v", err) + channel.Stderr().Write([]byte(err.Error())) + break + } + ok = true + case "exec": + os.Setenv("SSH_ORIGINAL_COMMAND", 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.Stdout = channel + cmd.Stdin = channel + cmd.Stderr = channel.Stderr() + if err := cmd.Run(); err != nil { + log.Error(3, "exec: %v", err) + } else { + ok = true + } + } + fmt.Println("Done:", ok) + req.Reply(ok, nil) // BUG: Git on Mac seems not know this reply and hang? + } + fmt.Println("Done!!!") + }(requests) + } +} + +func listen(config *ssh.ServerConfig, port string) { + listener, err := net.Listen("tcp", "0.0.0.0:"+port) + if err != nil { + panic(err) + } + for { + // Once a ServerConfig has been configured, connections can be accepted. + conn, err := listener.Accept() + if err != nil { + log.Error(3, "Fail to accept incoming connection: %v", err) + continue + } + // Before use, a handshake must be performed on the incoming net.Conn. + sConn, chans, reqs, err := ssh.NewServerConn(conn, config) + if err != nil { + log.Error(3, "Fail to handshake: %v", err) + continue + } + // The incoming Request channel must be serviced. + go ssh.DiscardRequests(reqs) + go handleServerConn(sConn.Permissions.Extensions["key-id"], chans) + } +} + +// Listen starts a SSH server listens on given port. +func Listen(port string) { + config := &ssh.ServerConfig{ + PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) { + // keyCache[string(ssh.MarshalAuthorizedKey(key))] = 2 + return &ssh.Permissions{Extensions: map[string]string{"key-id": "2"}}, nil + }, + } + + privateBytes, err := ioutil.ReadFile("/Users/jiahuachen/.ssh/id_rsa") + if err != nil { + panic("failed to load private key") + } + private, err := ssh.ParsePrivateKey(privateBytes) + if err != nil { + panic("failed to parse private key") + } + config.AddHostKey(private) + + go listen(config, port) +} -- cgit v1.2.3 From 545d320648a5ce93e394a3cbc1317f73553b0d75 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sat, 26 Jul 2014 03:02:46 -0400 Subject: Docs fix --- .gobuild.yml | 7 ++++--- .gopmfile | 37 +++++++++++++++++++------------------ README.md | 8 +++----- README_ZH.md | 8 +++----- modules/ssh/ssh.go | 2 +- modules/workers/worker.go | 10 ---------- 6 files changed, 30 insertions(+), 42 deletions(-) delete mode 100644 modules/workers/worker.go (limited to 'modules/ssh/ssh.go') diff --git a/.gobuild.yml b/.gobuild.yml index 2570717edb..c3fa262efc 100644 --- a/.gobuild.yml +++ b/.gobuild.yml @@ -1,11 +1,12 @@ filesets: includes: - - templates + - conf + - etc - public + - scripts + - templates - LICENSE - README.md - README_ZH.md - - start.bat - - start.sh excludes: - \.git diff --git a/.gopmfile b/.gopmfile index b8aa02372a..235a8a436f 100644 --- a/.gopmfile +++ b/.gopmfile @@ -2,24 +2,25 @@ path = github.com/gogits/gogs [deps] -github.com/Unknwon/cae = `commit:a1fa53b` -github.com/Unknwon/com = `commit:019c36f` -github.com/Unknwon/goconfig = `commit:c4e325f` -github.com/codegangsta/cli = `commit:bb91895` -github.com/go-martini/martini = `commit:49411a5` -github.com/go-sql-driver/mysql = `commit:b44cac6` -github.com/go-xorm/core = `commit:267e375` -github.com/go-xorm/xorm = `commit:bd1487b` -github.com/gogits/cache = `commit:f9bb61f` -github.com/gogits/gfm = `commit:40f747a` -github.com/gogits/git = `commit:3d9e771` -github.com/gogits/logs = `commit:0a97a46` -github.com/gogits/oauth2 = `commit:99cbec8` -github.com/gogits/session = `commit:7ab78d4` -github.com/juju2013/goldap = `commit:f4a7f67` -github.com/lib/pq = `commit:529edd9` -github.com/nfnt/resize = `commit:8aee0d9` +github.com/Unknwon/cae = +github.com/Unknwon/com = +github.com/Unknwon/goconfig = +github.com/Unknwon/i18n = +github.com/Unknwon/macaron = +github.com/codegangsta/cli = +github.com/go-sql-driver/mysql = +github.com/go-xorm/core = +github.com/go-xorm/xorm = +github.com/gogits/cache = +github.com/gogits/gfm = +github.com/gogits/git = +github.com/gogits/oauth2 = +github.com/juju2013/goldap = +github.com/lib/pq = +github.com/macaron-contrib/i18n = +github.com/macaron-contrib/session = +github.com/nfnt/resize = [res] -include = templates|public +include = conf|etc|public|scripts|templates diff --git a/README.md b/README.md index af33b0e8eb..c1fd499e0d 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ Gogs - Go Git Service [![wercker status](https://app.wercker.com/status/ad0bdb0bc450ac6f09bc56b9640a50aa/s/ "wercker status")](https://app.wercker.com/project/bykey/ad0bdb0bc450ac6f09bc56b9640a50aa) [![Build Status](https://drone.io/github.com/gogits/gogs/status.png)](https://drone.io/github.com/gogits/gogs/latest) ===================== -Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language. +Gogs(Go Git Service) is a painless self-hosted Git Service written in Go. ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.4.5 Alpha +##### Current version: 0.4.7 Alpha ### NOTICES @@ -18,9 +18,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ## Purpose -Since we choose to use pure Go implementation of Git manipulation, Gogs certainly supports **ALL platforms** that Go supports, including Linux, Mac OS X, and Windows with **ZERO** dependency. - -More importantly, Gogs only needs one binary to setup your own project hosting on the fly! +The goal of this project is to make the easiest, fastest and most painless way to set up a self-hosted Git service. With Go, this can be done in independent binary distribution across **ALL platforms** that Go supports, including Linux, Mac OS X, and Windows. ## Overview diff --git a/README_ZH.md b/README_ZH.md index 26746ccbe8..24836208da 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -1,17 +1,15 @@ Gogs - Go Git Service [![wercker status](https://app.wercker.com/status/ad0bdb0bc450ac6f09bc56b9640a50aa/s/ "wercker status")](https://app.wercker.com/project/bykey/ad0bdb0bc450ac6f09bc56b9640a50aa) [![Build Status](https://drone.io/github.com/gogits/gogs/status.png)](https://drone.io/github.com/gogits/gogs/latest) ===================== -Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。 +Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。 ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.4.5 Alpha +##### 当前版本:0.4.7 Alpha ## 开发目的 -Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依赖,并且支持 Go 语言所支持的 **所有平台**,包括 Linux、Mac OS X 以及 Windows。 - -更重要的是,您只需要一个可执行文件就能借助 Gogs 快速搭建属于您自己的代码托管服务! +Gogs 的目标是打造一个最简单、最快速和最轻松的方式搭建自助 Git 服务。使用 Go 语言开发使得 Gogs 能够通过独立的二进制分发,并且支持 Go 语言支持的 **所有平台**,包括 Linux、Mac OS X 以及 Windows。 ## 项目概览 diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 78ad678dc5..814a3dd1f4 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -17,7 +17,7 @@ import ( "github.com/Unknwon/com" - "github.com/gogits/gogs-ng/modules/log" + "github.com/gogits/gogs/modules/log" ) func handleServerConn(keyId string, chans <-chan ssh.NewChannel) { diff --git a/modules/workers/worker.go b/modules/workers/worker.go deleted file mode 100644 index 97535b2b4d..0000000000 --- a/modules/workers/worker.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2014 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package workers - -// Work represents a background work interface of any kind. -type Work interface { - Do() error -} -- cgit v1.2.3