mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt git.server
This commit is contained in:
parent
c201d925ca
commit
3c49f7f667
@ -64,6 +64,9 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
||||
fmt.Fprint(msg.W, msg.Formats(kit.MDB_META))
|
||||
}
|
||||
}
|
||||
func RenderHeader(msg *ice.Message, key, value string) {
|
||||
msg.W.Header().Set(key, value)
|
||||
}
|
||||
func RenderStatus(msg *ice.Message, code int, text string) {
|
||||
msg.W.WriteHeader(code)
|
||||
msg.W.Write([]byte(text))
|
||||
@ -72,6 +75,10 @@ func RenderCookie(msg *ice.Message, value string, arg ...string) { // name path
|
||||
expire := time.Now().Add(kit.Duration(kit.Select(msg.Conf(aaa.SESS, "meta.expire"), arg, 2)))
|
||||
http.SetCookie(msg.W, &http.Cookie{Value: value, Name: kit.Select(ice.MSG_SESSID, arg, 0), Path: kit.Select("/", arg, 1), Expires: expire})
|
||||
}
|
||||
func RenderMeta(msg *ice.Message, name, content string) {
|
||||
msg.W.Write([]byte(kit.Format(`<meta name="%s" content="%s">`, name, content)))
|
||||
msg.W.Write([]byte(ice.NL))
|
||||
}
|
||||
func RenderType(w http.ResponseWriter, name, mime string) {
|
||||
if mime != "" {
|
||||
w.Header().Set(ContentType, mime)
|
||||
@ -83,9 +90,6 @@ func RenderType(w http.ResponseWriter, name, mime string) {
|
||||
w.Header().Set(ContentType, "text/css; charset=utf-8")
|
||||
case "pdf":
|
||||
w.Header().Set(ContentType, "application/pdf")
|
||||
|
||||
default:
|
||||
break
|
||||
w.Header().Set(ContentType, ContentHTML)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
@ -65,7 +64,7 @@ func _server_login(m *ice.Message) error {
|
||||
return fmt.Errorf("username or password error")
|
||||
}
|
||||
if aaa.UserRole(m, username) == aaa.VOID {
|
||||
return fmt.Errorf("userrole error")
|
||||
return fmt.Errorf("userrole has no right")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -82,15 +81,10 @@ func _server_param(m *ice.Message, arg ...string) (string, string) {
|
||||
func _server_repos(m *ice.Message, arg ...string) error {
|
||||
repos, service := _server_param(m, arg...)
|
||||
|
||||
m.Option(cli.CMD_DIR, repos)
|
||||
if strings.HasSuffix(path.Join(arg...), "info/refs") {
|
||||
// m.W.Header().Set("Pragma", "no-cache")
|
||||
// m.W.Header().Set("Expires", "Fri, 01 Jan 1980 00:00:00 GMT")
|
||||
// m.W.Header().Set("Cache-Control", "no-cache, max-age=0, must-revalidate")
|
||||
m.W.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-advertisement", service))
|
||||
if m.Option(cli.CMD_DIR, repos); strings.HasSuffix(path.Join(arg...), "info/refs") {
|
||||
web.RenderType(m.W, "", kit.Format("application/x-git-%s-advertisement", service))
|
||||
msg := m.Cmd(cli.SYSTEM, GIT, service, "--stateless-rpc", "--advertise-refs", ".")
|
||||
packetWrite(m, "# service=git-"+service+"\n", msg.Result())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -102,7 +96,7 @@ func _server_repos(m *ice.Message, arg ...string) error {
|
||||
|
||||
m.Option(cli.CMD_OUTPUT, m.W)
|
||||
m.Option(cli.CMD_INPUT, reader)
|
||||
m.W.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", service))
|
||||
web.RenderType(m.W, "", kit.Format("application/x-git-%s-result", service))
|
||||
m.Cmd(cli.SYSTEM, GIT, service, "--stateless-rpc", ".")
|
||||
return nil
|
||||
}
|
||||
@ -121,35 +115,31 @@ func init() {
|
||||
"/repos/": {Name: "/repos/", Help: "代码库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Option("go-get") == "1" { // 下载地址
|
||||
p := m.Conf(web.SHARE, kit.Keym(kit.MDB_DOMAIN)) + "/x/" + path.Join(arg...)
|
||||
m.RenderResult(`<meta name="go-import" content="%s git %s">`, strings.TrimPrefix(p, "https://"), p)
|
||||
web.RenderMeta(m, "go-import", kit.Format(`%s git %s`, strings.TrimPrefix(p, "https://"), p))
|
||||
return
|
||||
}
|
||||
|
||||
switch repos, service := _server_param(m, arg...); service {
|
||||
case "receive-pack": // 上传代码
|
||||
if err := _server_login(m); err != nil {
|
||||
m.W.Header().Set("WWW-Authenticate", `Basic realm="git server"`)
|
||||
http.Error(m.W, err.Error(), 401)
|
||||
return // 认证失败
|
||||
web.RenderHeader(m, "WWW-Authenticate", `Basic realm="git server"`)
|
||||
web.RenderStatus(m, 401, err.Error())
|
||||
return
|
||||
}
|
||||
if _, e := os.Stat(path.Join(repos)); os.IsNotExist(e) {
|
||||
m.Cmd(cli.SYSTEM, GIT, INIT, "--bare", repos) // 创建仓库
|
||||
}
|
||||
|
||||
case "upload-pack": // 下载代码
|
||||
|
||||
}
|
||||
|
||||
if err := _server_repos(m, arg...); err != nil {
|
||||
http.Error(m.W, err.Error(), 500)
|
||||
return // 未知错误
|
||||
web.RenderStatus(m, 500, err.Error())
|
||||
}
|
||||
// githttp.New(kit.Path(m.Conf(SERVER, kit.META_PATH))).ServeHTTP(m.W, m.R)
|
||||
}},
|
||||
SERVER: {Name: "server path auto create", Help: "服务器", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create name", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(cli.CMD_DIR, path.Join(m.Conf(SERVER, kit.META_PATH), REPOS))
|
||||
m.Cmd(cli.SYSTEM, GIT, INIT, "--bare", m.Option(kit.MDB_NAME))
|
||||
m.Cmdy(cli.SYSTEM, GIT, INIT, "--bare", m.Option(kit.MDB_NAME))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Option(nfs.DIR_ROOT, path.Join(m.Conf(SERVER, kit.META_PATH), REPOS)); len(arg) == 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user