1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00

opt serve

This commit is contained in:
shylinux 2021-01-07 05:09:15 +08:00
parent 5aec0cc544
commit cc644e6e1e
10 changed files with 139 additions and 237 deletions

View File

@ -288,7 +288,7 @@ func (f *Frame) Start(m *ice.Message, arg ...string) bool {
case STDIO: // 终端交互
r, f.stdout = os.Stdin, os.Stdout
m.Option("_option", ice.MSG_USERNAME)
m.Option(ice.MSG_USEROPT, ice.MSG_USERNAME)
m.Option(ice.MSG_USERNAME, ice.Info.UserName)
m.Option(ice.MSG_USERROLE, aaa.ROOT)
m.Option(ice.MSG_USERZONE, "boot")

View File

@ -6,6 +6,7 @@ import (
"github.com/shylinux/icebergs/base/gdb"
"github.com/shylinux/icebergs/base/mdb"
"github.com/shylinux/icebergs/base/nfs"
"github.com/shylinux/icebergs/base/tcp"
kit "github.com/shylinux/toolkits"
"io/ioutil"
@ -106,7 +107,7 @@ func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
DREAM: {Name: DREAM, Help: "梦想家", Value: kit.Data(kit.MDB_PATH, "usr/local/work",
"cmd", []interface{}{"ice.bin", SPACE, "connect"},
"cmd", []interface{}{"ice.bin", SPACE, tcp.DIAL},
"env", kit.Dict("ctx_log", "bin/boot.log"),
"miss", `#!/bin/bash
[ -f ~/.ish/plug.sh ] || [ -f ./.ish/plug.sh ] || git clone ${ISH_CONF_HUB_PROXY:="https://"}github.com/shylinux/intshell ./.ish

View File

@ -10,6 +10,7 @@ import (
"net/http"
"os"
"path"
"strings"
"time"
)
@ -43,10 +44,12 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
case ice.RENDER_DOWNLOAD:
msg.W.Header().Set("Content-Disposition", fmt.Sprintf("filename=%s", kit.Select(path.Base(arg[0]), arg, 2)))
msg.W.Header().Set("Content-Type", kit.Select("text/html", arg, 1))
if _, e := os.Stat(arg[0]); e != nil {
arg[0] = "/" + arg[0]
if !ice.DumpBinPack(msg.W, arg[0], func(name string) { RenderType(msg.W, name) }) {
if _, e := os.Stat(arg[0]); e == nil {
http.ServeFile(msg.W, msg.R, arg[0])
}
}
http.ServeFile(msg.W, msg.R, arg[0])
case ice.RENDER_RESULT:
if len(arg) > 0 {
@ -71,6 +74,11 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
}
msg.Append(ice.MSG_OUTPUT, ice.RENDER_OUTPUT)
}
func RenderType(w http.ResponseWriter, name string) {
if strings.HasSuffix(name, ".css") {
w.Header().Set("Content-Type", "text/css; charset=utf-8")
}
}
func RenderCookie(msg *ice.Message, value string, arg ...string) { // name path expire
expire := time.Now().Add(kit.Duration(kit.Select(msg.Conf(aaa.SESS, "meta.expire"), arg, 2)))

View File

@ -1,9 +1,6 @@
package web
import (
"io"
"os"
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/aaa"
"github.com/shylinux/icebergs/base/cli"
@ -19,57 +16,14 @@ import (
"strings"
)
func _serve_proxy(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
m.Option(SPIDE_CB, func(msg *ice.Message, req *http.Request, res *http.Response) {
p := path.Join("var/proxy", strings.ReplaceAll(r.URL.String(), "/", "_"))
size := 0
if s, e := os.Stat(p); os.IsNotExist(e) {
if f, p, e := kit.Create(p); m.Assert(e) {
defer f.Close()
if n, e := io.Copy(f, res.Body); m.Assert(e) {
m.Debug("proxy %s res: %v", p, n)
size = int(n)
}
}
} else {
size = int(s.Size())
}
h := w.Header()
for k, v := range res.Header {
for _, v := range v {
switch k {
case ContentLength:
h.Add(k, kit.Format(size))
m.Debug("proxy res: %v %v", k, size+1)
default:
m.Debug("proxy res: %v %v", k, v)
h.Add(k, v)
}
}
}
w.WriteHeader(res.StatusCode)
if f, e := os.Open(p); m.Assert(e) {
defer f.Close()
if n, e := io.Copy(w, f); e == nil {
m.Debug("proxy res: %v", n)
} else {
m.Debug("proxy res: %v %v", n, e)
}
}
})
m.Cmdx(SPIDE, r.URL.Host, SPIDE_PROXY, r.Method, r.URL.String())
return true
}
func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
if r.Header.Get("index.module") != "" {
if r.Header.Get("index.module") == "" {
r.Header.Set("index.module", m.Target().Name)
} else {
return true
}
// 解析地址
// 用户地址
if ip := r.Header.Get("X-Forwarded-For"); ip != "" {
r.Header.Set(ice.MSG_USERIP, ip)
} else if ip := r.Header.Get("X-Real-Ip"); ip != "" {
@ -81,18 +35,6 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
}
m.Info("").Info("%s %s %s", r.Header.Get(ice.MSG_USERIP), r.Method, r.URL)
if strings.HasPrefix(r.URL.String(), "http") {
if m == nil {
m = ice.Pulse.Spawn()
}
return _serve_proxy(m, w, r)
}
// 请求地址
r.Header.Set("index.module", m.Target().Name)
r.Header.Set("index.path", r.URL.Path)
r.Header.Set("index.url", r.URL.String())
// 输出日志
if m.Conf(SERVE, "meta.logheaders") == "true" {
for k, v := range r.Header {
@ -108,81 +50,40 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
}()
}
if r.URL.Path == "/" && r.FormValue(SHARE) != "" {
m.W = w
defer func() { m.W = nil }()
if s := m.Cmd(SHARE, mdb.SELECT, kit.MDB_HASH, r.FormValue(SHARE)); s.Append(kit.MDB_TYPE) == "login" {
defer func() { http.Redirect(w, r, kit.MergeURL(r.URL.String(), SHARE, ""), http.StatusTemporaryRedirect) }()
msg := m.Spawn()
if c, e := r.Cookie(ice.MSG_SESSID); e == nil && c.Value != "" {
if aaa.SessCheck(msg, c.Value); msg.Option(ice.MSG_USERNAME) != "" {
return false // 复用会话
}
}
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
Render(msg, COOKIE, aaa.SessCreate(msg, s.Append(aaa.USERNAME), s.Append(aaa.USERROLE)))
return false // 新建会话
}
return true
}
// 调试接口
if strings.HasPrefix(r.URL.Path, "/debug") {
r.URL.Path = strings.Replace(r.URL.Path, "/debug", "/code", -1)
return true
}
if b, ok := ice.BinPack[r.URL.Path]; ok {
if strings.HasSuffix(r.URL.Path, ".css") {
w.Header().Set("Content-Type", "text/css; charset=utf-8")
}
w.Write(b)
return false
}
if r.URL.Path == "/" && strings.Contains(r.Header.Get("User-Agent"), "curl") {
http.ServeFile(w, r, path.Join(m.Conf(SERVE, "meta.intshell.path"), m.Conf(SERVE, "meta.intshell.index")))
// 主页接口
if r.Method == "GET" && r.URL.Path == "/" {
msg := m.Spawn()
if msg.W, msg.R = w, r; strings.Contains(r.Header.Get("User-Agent"), "curl") {
Render(msg, ice.RENDER_DOWNLOAD, kit.Path(m.Conf(SERVE, "meta.intshell.path"), m.Conf(SERVE, "meta.intshell.index")))
} else {
Render(msg, ice.RENDER_DOWNLOAD, kit.Path(m.Conf(SERVE, "meta.volcanos.path"), m.Conf(SERVE, "meta.volcanos.index")))
}
return false
}
// 单点登录
if r.URL.Path == "/" && m.Conf(SERVE, "meta.sso") != "" {
sessid := r.FormValue(ice.MSG_SESSID)
if sessid == "" {
if c, e := r.Cookie(ice.MSG_SESSID); e == nil {
sessid = c.Value
}
}
ok := false
m.Richs(aaa.SESS, "", sessid, func(key string, value map[string]interface{}) {
ok = true
})
if !ok {
http.Redirect(w, r, m.Conf(SERVE, "meta.sso"), http.StatusTemporaryRedirect)
return false
}
}
return true
// 内置文件
return !ice.DumpBinPack(w, r.URL.Path, func(name string) { RenderType(w, name) })
}
func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
defer func() {
msg.Cost(kit.Format("%s %v %v", r.URL.Path, msg.Optionv(ice.MSG_CMDS), msg.Format(ice.MSG_APPEND)))
}()
// 请求变量
// 环境变量
msg.Option(mdb.CACHE_LIMIT, "10")
msg.Option(ice.MSG_OUTPUT, "")
msg.Option(ice.MSG_SESSID, "")
for _, v := range r.Cookies() {
msg.Option(v.Name, v.Value)
}
// 请求地址
// 请求变量
if u, e := url.Parse(r.Header.Get("Referer")); e == nil {
for k, v := range u.Query() {
msg.Logs("refer", k, v)
@ -190,27 +91,23 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
}
}
// 用户请求
msg.Option(mdb.CACHE_LIMIT, "10")
msg.Option(ice.MSG_OUTPUT, "")
msg.Option(ice.MSG_METHOD, r.Method)
// 请求地址
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SHARE, "meta.domain"), r.Header.Get("Referer")))
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
msg.Option(ice.MSG_USERURL, r.URL.Path)
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
if msg.R, msg.W = r, w; r.Header.Get("X-Real-Port") != "" {
msg.Option(ice.MSG_USERADDR, msg.Option(ice.MSG_USERIP)+":"+r.Header.Get("X-Real-Port"))
} else {
msg.Option(ice.MSG_USERADDR, r.RemoteAddr)
}
// 解析引擎
// 请求数据
switch r.Header.Get(ContentType) {
case ContentJSON:
var data interface{}
if e := json.NewDecoder(r.Body).Decode(&data); !msg.Warn(e != nil, e) {
msg.Log_IMPORT(kit.MDB_VALUE, kit.Format(data))
msg.Optionv(ice.MSG_USERDATA, data)
msg.Logs("json", "value", kit.Format(data))
}
switch d := data.(type) {
@ -239,19 +136,19 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
}
// 请求命令
if msg.Option(ice.MSG_USERPOD, msg.Option("pod")); msg.Optionv(ice.MSG_CMDS) == nil {
if p := strings.TrimPrefix(msg.Option(ice.MSG_USERURL), key); p != "" {
if msg.Option(ice.MSG_USERPOD, msg.Option(kit.SSH_POD)); msg.Optionv(ice.MSG_CMDS) == nil {
if p := strings.TrimPrefix(r.URL.Path, key); p != "" {
msg.Optionv(ice.MSG_CMDS, strings.Split(p, "/"))
}
}
// 执行命令
if cmds, ok := _serve_login(msg, kit.Simple(msg.Optionv(ice.MSG_CMDS)), w, r); ok {
msg.Option("_option", msg.Optionv(ice.MSG_OPTION))
msg.Target().Cmd(msg, key, msg.Option(ice.MSG_USERURL), cmds...)
msg.Option(ice.MSG_USEROPT, msg.Optionv(ice.MSG_OPTION))
msg.Target().Cmd(msg, key, r.URL.Path, cmds...)
}
// 渲染引擎
// 输出响应
_args, _ := msg.Optionv(ice.MSG_ARGS).([]interface{})
Render(msg, msg.Option(ice.MSG_OUTPUT), _args...)
}
@ -263,35 +160,33 @@ func _serve_login(msg *ice.Message, cmds []string, w http.ResponseWriter, r *htt
// 会话认证
aaa.SessCheck(msg, msg.Option(ice.MSG_SESSID))
}
if !msg.Options(ice.MSG_USERNAME) && tcp.IsLocalHost(msg, msg.Option(ice.MSG_USERIP)) && msg.Conf(SERVE, "meta.localhost") == "true" {
if !msg.Options(ice.MSG_USERNAME) && tcp.IsLocalHost(msg, msg.Option(ice.MSG_USERIP)) && msg.Conf(SERVE, kit.Keym(tcp.LOCALHOST)) == "true" {
// 自动认证
aaa.UserLogin(msg, ice.Info.UserName, ice.Info.PassWord)
}
if _, ok := msg.Target().Commands[LOGIN]; ok {
// 权限检查
msg.Target().Cmd(msg, LOGIN, msg.Option(ice.MSG_USERURL), cmds...)
cmds = kit.Simple(msg.Optionv(ice.MSG_CMDS))
} else if ls := strings.Split(msg.Option(ice.MSG_USERURL), "/"); msg.Conf(SERVE, kit.Keys("meta.black", ls[1])) == "true" {
return cmds, false // 白名单
} else if msg.Conf(SERVE, kit.Keys("meta.white", ls[1])) == "true" {
return cmds, true // 黑名单
} else {
if msg.Warn(!msg.Options(ice.MSG_USERNAME), ice.ErrNotLogin, msg.Option(ice.MSG_USERURL)) {
msg.Render(STATUS, 401, ice.ErrNotLogin)
return cmds, false // 未登录
}
if msg.Warn(!msg.Right(msg.Option(ice.MSG_USERURL))) {
msg.Render(STATUS, 403, ice.ErrNotAuth)
return cmds, false // 未授权
}
msg.Target().Cmd(msg, LOGIN, r.URL.Path, cmds...)
return cmds, msg.Result() != "false"
}
return cmds, msg.Option(ice.MSG_USERURL) != ""
if ls := strings.Split(r.URL.Path, "/"); msg.Conf(SERVE, kit.Keym(aaa.BLACK, ls[1])) == "true" {
return cmds, false // 黑名单
} else if msg.Conf(SERVE, kit.Keym(aaa.WHITE, ls[1])) == "true" {
return cmds, true // 白名单
}
if msg.Warn(!msg.Options(ice.MSG_USERNAME), ice.ErrNotLogin, r.URL.Path) {
msg.Render(STATUS, 401, ice.ErrNotLogin)
return cmds, false // 未登录
}
if msg.Warn(!msg.Right(r.URL.Path)) {
msg.Render(STATUS, 403, ice.ErrNotAuth)
return cmds, false // 未授权
}
return cmds, true
}
const (
@ -306,27 +201,20 @@ const SERVE = "serve"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
SERVE: {Name: SERVE, Help: "服务器", Value: kit.Data(
kit.MDB_SHORT, kit.MDB_NAME,
"logheaders", "false",
"localhost", "true",
"black", kit.Dict(), "white", kit.Dict(
"login", true, "space", true, "share", true, "plugin", true, "publish", true, "intshell", true,
),
SERVE: {Name: SERVE, Help: "服务器", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME,
tcp.LOCALHOST, true, aaa.BLACK, kit.Dict(), aaa.WHITE, kit.Dict(
"intshell", true, "volcanos", true, "publish", true, "plugin", true,
"login", true, "space", true, "share", true,
), "logheaders", false,
"static", kit.Dict("/gitrepos/", "usr/repos/", "/", "usr/volcanos/"),
"volcanos", kit.Dict("refresh", "5",
"share", "usr/volcanos/page/share.html",
"path", "usr/volcanos", "require", ".ish/pluged",
"static", kit.Dict("/", "usr/volcanos/"),
"volcanos", kit.Dict("path", "usr/volcanos", "index", "page/index.html",
"repos", "https://github.com/shylinux/volcanos", "branch", "master",
), "publish", "usr/publish/",
"intshell", kit.Dict(
"index", "index.sh",
"path", "usr/intshell", "require", ".ish/pluged",
"repos", "https://github.com/shylinux/volcanos", "branch", "master",
),
"intshell", kit.Dict("path", "usr/intshell", "index", "index.sh",
"repos", "https://github.com/shylinux/intshell", "branch", "master",
), "require", ".ish/pluged",
)},
},
Commands: map[string]*ice.Command{
@ -340,7 +228,7 @@ func init() {
m.Sleep("1s")
for _, k := range kit.Split(m.Option(SPIDE_DEV)) {
m.Cmd(SPACE, "connect", "dev", k, "name", ice.Info.NodeName)
m.Cmd(SPACE, tcp.DIAL, SPIDE_DEV, k, kit.MDB_NAME, ice.Info.NodeName)
}
}},
aaa.WHITE: {Name: "white", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
@ -361,5 +249,14 @@ func init() {
"/intshell/": {Name: "/intshell/", Help: "脚本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Render(ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, "meta.intshell.path"), path.Join(arg...)))
}},
"/volcanos/": {Name: "/volcanos/", Help: "脚本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Render(ice.RENDER_DOWNLOAD, path.Join(m.Conf(SERVE, "meta.volcanos.path"), path.Join(arg...)))
}},
"/publish/": {Name: "/publish/", Help: "源码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_local(m, m.Conf(SERVE, "meta.publish"), path.Join(arg...))
}},
"/plugin/github.com/": {Name: "/plugin/github.com/", Help: "源码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_repos(m, "github.com/"+arg[0]+"/"+arg[1], arg[2:]...)
}},
}})
}

View File

@ -21,64 +21,57 @@ func _share_cache(m *ice.Message, arg ...string) {
func _share_local(m *ice.Message, arg ...string) {
p := path.Join(arg...)
switch ls := strings.Split(p, "/"); ls[0] {
case "etc", "var":
// 私有文件
case "etc", "var": // 私有文件
if m.Option(ice.MSG_USERROLE) == aaa.VOID {
m.Render(STATUS, http.StatusUnauthorized, "not auth")
return
return // 没有权限
}
default:
if m.Warn(!m.Right(ls), ice.ErrNotAuth, m.Option(ice.MSG_USERROLE), " of ", p) {
m.Render(STATUS, http.StatusUnauthorized, "not auth")
return
return // 没有权限
}
}
if m.Option("pod") != "" {
// 远程文件
pp := path.Join("var/proxy", m.Option("pod"), p)
if m.Option(kit.SSH_POD) != "" { // 远程文件
pp := path.Join("var/proxy", m.Option(kit.SSH_POD), p)
cache := time.Now().Add(-time.Hour * 240000)
if s, e := os.Stat(pp); e == nil {
cache = s.ModTime()
}
m.Cmdy(SPACE, m.Option("pod"), SPIDE, "dev", "raw", kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/"),
"part", "pod", m.Option("pod"), "path", p, "cache", cache.Format(ice.MOD_TIME), "upload", "@"+p)
m.Render(ice.RENDER_DOWNLOAD, path.Join("var/proxy", m.Option("pod"), p))
return
m.Cmdy(SPACE, m.Option(kit.SSH_POD), SPIDE, SPIDE_DEV, SPIDE_RAW, kit.MergeURL2(m.Option(ice.MSG_USERWEB), "/share/proxy/"),
SPIDE_PART, kit.SSH_POD, m.Option(kit.SSH_POD), kit.MDB_PATH, p, "cache", cache.Format(ice.MOD_TIME), "upload", "@"+p)
p = path.Join("var/proxy", m.Option(kit.SSH_POD), p)
}
// 本地文件
m.Render(ice.RENDER_DOWNLOAD, p)
}
func _share_proxy(m *ice.Message, arg ...string) {
switch m.Option(ice.MSG_METHOD) {
switch m.R.Method {
case http.MethodGet:
m.Render(ice.RENDER_DOWNLOAD, path.Join("var/proxy", path.Join(m.Option("pod"), m.Option("path"), m.Option("name"))))
m.Render(ice.RENDER_DOWNLOAD, path.Join("var/proxy", path.Join(m.Option(kit.SSH_POD), m.Option(kit.MDB_PATH), m.Option(kit.MDB_NAME))))
case http.MethodPost:
m.Cmdy(CACHE, UPLOAD)
m.Cmdy(CACHE, WATCH, m.Option("data"), path.Join("var/proxy", m.Option("pod"), m.Option("path")))
m.Render(ice.RENDER_RESULT, m.Option("path"))
m.Cmdy(CACHE, WATCH, m.Option("data"), path.Join("var/proxy", m.Option(kit.SSH_POD), m.Option(kit.MDB_PATH)))
m.Render(ice.RENDER_RESULT, m.Option(kit.MDB_PATH))
}
}
func _share_repos(m *ice.Message, repos string, arg ...string) {
prefix := m.Conf(SERVE, "meta.volcanos.require")
prefix := kit.Path(m.Conf(SERVE, "meta.require"))
if _, e := os.Stat(path.Join(prefix, repos)); e != nil {
m.Cmd(cli.SYSTEM, "git", "clone", "https://"+repos, path.Join(prefix, repos))
}
m.Render(ice.RENDER_DOWNLOAD, path.Join(prefix, repos, path.Join(arg...)))
}
func _share_remote(m *ice.Message, pod string, arg ...string) {
m.Cmdy(SPACE, pod, "web./publish/", arg)
m.Render(ice.RENDER_RESULT)
}
const SHARE = "share"
func init() {
Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{
SHARE: {Name: SHARE, Help: "共享链", Value: kit.Data("expire", "72h")},
SHARE: {Name: SHARE, Help: "共享链", Value: kit.Data(kit.MDB_EXPIRE, "72h")},
},
Commands: map[string]*ice.Command{
SHARE: {Name: "share hash auto", Help: "共享链", Action: map[string]*ice.Action{
@ -147,32 +140,14 @@ func init() {
"/share/cache/": {Name: "/share/cache/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_cache(m, arg...)
}},
"/share/local/": {Name: "/share/local/", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
"/share/local/": {Name: "/share/local/", Help: "文件夹", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_local(m, arg...)
}},
"/share/proxy/": {Name: "/share/proxy/", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
"/share/proxy/": {Name: "/share/proxy/", Help: "文件流", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_proxy(m, arg...)
}},
"/plugin/github.com/": {Name: "/space/", Help: "空间站", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_repos(m, "github.com/"+arg[0]+"/"+arg[1], arg[2:]...)
}},
"/publish/": {Name: "/publish/", Help: "发布", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if arg[0] == "order.js" && len(ice.BinPack) > 0 {
m.Render(ice.RENDER_RESULT, "{}")
return
}
if p := m.Option("pod"); p != "" {
m.Option("pod", "")
_share_remote(m, p, arg...)
return
}
p := path.Join(kit.Simple(m.Conf(SERVE, "meta.publish"), arg)...)
if m.W == nil {
m.Cmdy("nfs.cat", p)
} else {
m.Render(ice.RENDER_DOWNLOAD, p)
}
"/share/repos/": {Name: "/share/repos/", Help: "代码库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_share_repos(m, path.Join(arg[0], arg[1], arg[2]), arg[3:]...)
}},
}})
}

View File

@ -75,14 +75,14 @@ func _space_send(m *ice.Message, space string, arg ...string) {
m.Warn(m.Richs(SPACE, nil, target[0], func(key string, value map[string]interface{}) {
if socket, ok := value["socket"].(*websocket.Conn); !m.Warn(!ok, "socket err") {
// 复制选项
for _, k := range kit.Simple(m.Optionv("_option")) {
for _, k := range kit.Simple(m.Optionv(ice.MSG_USEROPT)) {
switch k {
case "detail", "cmds", ice.MSG_SESSID:
default:
m.Optionv(k, m.Optionv(k))
}
}
m.Optionv("_option", m.Optionv("_option"))
m.Optionv(ice.MSG_USEROPT, m.Optionv(ice.MSG_USEROPT))
m.Optionv("option", nil)
// 构造路由
@ -106,6 +106,12 @@ func _space_send(m *ice.Message, space string, arg ...string) {
}
func _space_echo(msg *ice.Message, source, target []string, c *websocket.Conn, name string) {
_args, _ := msg.Optionv(ice.MSG_ARGS).([]interface{})
switch arg := kit.Simple(_args...); msg.Option(ice.MSG_OUTPUT) {
case ice.RENDER_DOWNLOAD:
msg.Cmdy("nfs.cat", arg[0])
}
msg.Optionv(ice.MSG_SOURCE, source)
msg.Optionv(ice.MSG_TARGET, target)
e := c.WriteMessage(1, []byte(msg.Format("meta")))
@ -117,7 +123,7 @@ func _space_exec(msg *ice.Message, source, target []string, c *websocket.Conn, n
if !msg.Warn(!msg.Right(msg.Detailv()), ice.ErrNotAuth) {
msg = msg.Cmd()
}
msg.Set("_option")
msg.Set(ice.MSG_USEROPT)
_space_echo(msg, []string{}, kit.Revert(source)[1:], c, name)
msg.Cost(kit.Format("%v->%v %v %v", source, target, msg.Detailv(), msg.Format(ice.MSG_APPEND)))
}
@ -204,7 +210,7 @@ func init() {
},
Commands: map[string]*ice.Command{
SPACE: {Name: "space name cmd auto", Help: "空间站", Action: map[string]*ice.Action{
"connect": {Name: "connect dev name", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
tcp.DIAL: {Name: "dial dev name", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
_space_dial(m, m.Option("dev"), kit.Select(ice.Info.NodeName, m.Option(kit.MDB_NAME)))
}},
mdb.SEARCH: {Name: "search type name text arg...", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {

27
conf.go
View File

@ -29,26 +29,27 @@ const ( // MSG
MSG_DISPLAY = "_display"
MSG_PROCESS = "_process"
MSG_CMDS = "cmds"
MSG_SESSID = "sessid"
MSG_DOMAIN = "domain"
MSG_USERIP = "user.ip"
MSG_USERUA = "user.ua"
MSG_USERURL = "user.url"
MSG_USERWEB = "user.web"
MSG_USERPOD = "user.pod"
MSG_CMDS = "cmds"
MSG_SESSID = "sessid"
MSG_DOMAIN = "domain"
MSG_USERIP = "user.ip"
MSG_USERUA = "user.ua"
MSG_USERWEB = "user.web"
MSG_USERPOD = "user.pod"
// MSG_USEROPT = "user.opt"
MSG_USEROPT = "_option"
MSG_USERNICK = "user.nick"
MSG_USERNAME = "user.name"
MSG_USERZONE = "user.zone"
MSG_USERROLE = "user.role"
MSG_USERDATA = "user.data"
MSG_USERADDR = "user.addr"
MSG_LOCAL = "sess.path"
MSG_RIVER = "sess.river"
MSG_STORM = "sess.storm"
MSG_ACTIVE = "sess.active"
MSG_METHOD = "sess.method"
MSG_RIVER = "sess.river"
MSG_STORM = "sess.storm"
MSG_LOCAL = "sess.local"
)
const (
CONTROL_PAGE = "_page"

View File

@ -29,6 +29,7 @@ func init() {
m.Echo(m.Option(ice.MSG_USERNAME))
}},
CHECK: {Name: "check", Help: "登录检查", Hand: func(m *ice.Message, arg ...string) {
m.Option("sso", m.Conf(web.SERVE, "meta.sso"))
m.Echo(m.Option(ice.MSG_USERNAME))
}},

13
init.go
View File

@ -3,6 +3,7 @@ package ice
import (
kit "github.com/shylinux/toolkits"
"io"
"os"
"strings"
"sync"
@ -189,6 +190,18 @@ func Run(arg ...string) string {
}
var BinPack = map[string][]byte{}
func DumpBinPack(w io.Writer, name string, cb func(string)) bool {
if b, ok := BinPack[name]; ok {
if cb != nil {
cb(name)
}
w.Write(b)
return true
}
return false
}
var names = map[string]interface{}{}
var ErrNameExists = "name already exists: "

View File

@ -170,7 +170,7 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message {
if i := kit.IndexOf(m.meta[MSG_OPTION], k); i > -1 && len(m.meta[k]) > 0 {
m.meta[k] = m.meta[k][:0]
}
if i := kit.IndexOf(m.meta["_option"], k); i > -1 && len(m.meta[k]) > 0 {
if i := kit.IndexOf(m.meta[MSG_USEROPT], k); i > -1 && len(m.meta[k]) > 0 {
m.meta[k] = m.meta[k][:0]
}
if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 {