1
0
forked from x/icebergs
This commit is contained in:
shaoying 2020-06-03 08:12:58 +08:00
parent 0f4cd57c21
commit 7b87b62fbc
6 changed files with 46 additions and 11 deletions

View File

@ -91,6 +91,12 @@ func _config_make(m *ice.Message, chain string, arg ...string) {
m.Echo(kit.Formats(msg.Confv(chain))) m.Echo(kit.Formats(msg.Confv(chain)))
} }
} }
func _config_rich(m *ice.Message, name string, key string, arg ...string) {
m.Rich(name, key, kit.Dict(arg))
}
func _config_grow(m *ice.Message, name string, key string, arg ...string) {
m.Grow(name, key, kit.Dict(arg))
}
func _command_list(m *ice.Message, all bool) { func _command_list(m *ice.Message, all bool) {
p := m.Spawn(m.Source()) p := m.Spawn(m.Source())
@ -252,6 +258,10 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块",
_config_save(m, arg[1], arg[2:]...) _config_save(m, arg[1], arg[2:]...)
case "load": case "load":
_config_load(m, arg[1], arg[2:]...) _config_load(m, arg[1], arg[2:]...)
case "grow":
_config_grow(m, arg[1], arg[2], arg[3:]...)
case "rich":
_config_rich(m, arg[1], arg[2], arg[3:]...)
default: default:
_config_make(m, arg[0], arg[1:]...) _config_make(m, arg[0], arg[1:]...)
} }

View File

@ -264,10 +264,10 @@ func _story_catch(m *ice.Message, arg ...string) {
_story_add(m, arg...) _story_add(m, arg...)
} }
func _story_add(m *ice.Message, arg ...string) { func _story_add(m *ice.Message, arg ...string) {
if len(arg) > 3 && (arg[3] == "" || m.Richs(ice.WEB_CACHE, nil, arg[3], func(key string, value map[string]interface{}) { if len(arg) < 4 || arg[3] == "" || m.Richs(ice.WEB_CACHE, nil, arg[3], func(key string, value map[string]interface{}) {
// 复用缓存 // 复用缓存
arg[3] = key arg[3] = key
}) == nil) { }) == nil {
// 添加缓存 // 添加缓存
m.Cmdy(ice.WEB_CACHE, arg) m.Cmdy(ice.WEB_CACHE, arg)
arg = []string{arg[0], m.Append("type"), m.Append("name"), m.Append("data")} arg = []string{arg[0], m.Append("type"), m.Append("name"), m.Append("data")}
@ -305,11 +305,15 @@ func _story_add(m *ice.Message, arg ...string) {
} }
// 分发数据 // 分发数据
if p := kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), m.Option("you")); p != "" { for _, k := range []string{"you", "pod"} {
m.Option("you", "") if p := m.Option(k); p != "" {
m.Option(k, "")
m.Cmd(ice.WEB_PROXY, p, ice.WEB_STORY, ice.STORY_PULL, arg[2], "dev", arg[2]) m.Cmd(ice.WEB_PROXY, p, ice.WEB_STORY, ice.STORY_PULL, arg[2], "dev", arg[2])
return
} }
}
m.Cmd(ice.WEB_PROXY, m.Conf(ice.WEB_FAVOR, "meta.proxy"),
ice.WEB_STORY, ice.STORY_PULL, arg[2], "dev", arg[2])
} }
func _story_index(m *ice.Message, name string) { func _story_index(m *ice.Message, name string) {

View File

@ -24,6 +24,8 @@ import (
"time" "time"
) )
var SERVE = ice.Name("serve", Index)
type Frame struct { type Frame struct {
*http.Client *http.Client
*http.Server *http.Server
@ -99,6 +101,13 @@ func IsLocalIP(msg *ice.Message, ip string) (ok bool) {
if ip == "::1" || strings.HasPrefix(ip, "127.") { if ip == "::1" || strings.HasPrefix(ip, "127.") {
return true return true
} }
msg.Log_AUTH("ip", ip)
if msg.Richs(SERVE, kit.Keys("meta.white"), ip, nil) != nil {
msg.Log_AUTH("ip", ip)
return true
}
msg.Cmd("tcp.ifconfig").Table(func(index int, value map[string]string, head []string) { msg.Cmd("tcp.ifconfig").Table(func(index int, value map[string]string, head []string) {
if value["ip"] == ip { if value["ip"] == ip {
ok = true ok = true
@ -159,7 +168,7 @@ func (web *Frame) HandleWSS(m *ice.Message, safe bool, c *websocket.Conn, name s
socket, msg := c, m.Spawns(b) socket, msg := c, m.Spawns(b)
target := kit.Simple(msg.Optionv(ice.MSG_TARGET)) target := kit.Simple(msg.Optionv(ice.MSG_TARGET))
source := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name) source := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name)
msg.Info("recv %v<-%v %s %v", target, source, msg.Detailv(), msg.Format("meta")) msg.Info("recv %v<-%v %s %v", target, source, msg.Detailv(), msg.Formats("meta"))
if len(target) == 0 { if len(target) == 0 {
msg.Option(ice.MSG_USERROLE, msg.Cmdx(ice.AAA_ROLE, "check", msg.Option(ice.MSG_USERNAME))) msg.Option(ice.MSG_USERROLE, msg.Cmdx(ice.AAA_ROLE, "check", msg.Option(ice.MSG_USERNAME)))
@ -205,7 +214,7 @@ func (web *Frame) HandleWSS(m *ice.Message, safe bool, c *websocket.Conn, name s
msg.Optionv(ice.MSG_TARGET, target) msg.Optionv(ice.MSG_TARGET, target)
socket.WriteMessage(t, []byte(msg.Format("meta"))) socket.WriteMessage(t, []byte(msg.Format("meta")))
target = append([]string{name}, target...) target = append([]string{name}, target...)
msg.Info("send %v %v->%v %v", t, source, target, msg.Format("meta")) msg.Info("send %v %v->%v %v %v", t, source, target, msg.Detailv(), msg.Formats("meta"))
msg.Cost("%v->%v %v %v", source, target, msg.Detailv(), msg.Format("append")) msg.Cost("%v->%v %v %v", source, target, msg.Detailv(), msg.Format("append"))
} }
} }
@ -470,6 +479,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
`{{define "raw"}}{{.Result}}{{end}}`, `{{define "raw"}}{{.Result}}{{end}}`,
}), }),
"logheaders", "false", "init", "false", "logheaders", "false", "init", "false",
"black", kit.Dict(),
)}, )},
ice.WEB_SPACE: {Name: "space", Help: "空间站", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME, ice.WEB_SPACE: {Name: "space", Help: "空间站", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME,
"redial.a", 3000, "redial.b", 1000, "redial.c", 1000, "redial.a", 3000, "redial.b", 1000, "redial.c", 1000,
@ -948,7 +958,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
m.Set(ice.MSG_DETAIL, arg[1:]...) m.Set(ice.MSG_DETAIL, arg[1:]...)
m.Optionv(ice.MSG_TARGET, target[1:]) m.Optionv(ice.MSG_TARGET, target[1:])
m.Optionv(ice.MSG_SOURCE, []string{id}) m.Optionv(ice.MSG_SOURCE, []string{id})
m.Info("send [%s]->%v %s", id, target, m.Format("meta")) m.Info("send [%s]->%v %v %s", id, target, m.Detailv(), m.Formats("meta"))
// 下发命令 // 下发命令
m.Target().Server().(*Frame).send[id] = m m.Target().Server().(*Frame).send[id] = m

View File

@ -75,6 +75,8 @@ func _action_action(m *ice.Message, action string, arg ...string) bool {
msg := m.Cmd(ice.WEB_STORY, "upload") msg := m.Cmd(ice.WEB_STORY, "upload")
m.Option("name", msg.Append("name")) m.Option("name", msg.Append("name"))
m.Option("data", msg.Append("data")) m.Option("data", msg.Append("data"))
m.Debug("what", m.Option("name"))
m.Debug("what", m.Option("data"))
} }
return false return false
} }
@ -89,6 +91,7 @@ func _action_order(m *ice.Message, arg ...string) {
m.Render("status", 403, "not auth") m.Render("status", 403, "not auth")
return return
} }
m.Add("option", "_option", "data", "name")
m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds) m.Cmdy(_action_proxy(m), cmds).Option("cmds", cmds)
} }

View File

@ -167,7 +167,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
default: default:
// 群组检查 // 群组检查
m.Richs(ice.CHAT_RIVER, nil, arg[0], func(key string, value map[string]interface{}) { if m.Richs(ice.CHAT_RIVER, nil, arg[0], func(key string, value map[string]interface{}) {
m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, arg[0], "user"), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) { m.Richs(ice.CHAT_RIVER, kit.Keys(kit.MDB_HASH, arg[0], "user"), m.Option(ice.MSG_USERNAME), func(key string, value map[string]interface{}) {
if m.Option(ice.MSG_RIVER, arg[0]); len(arg) > 1 { if m.Option(ice.MSG_RIVER, arg[0]); len(arg) > 1 {
// 应用检查 // 应用检查
@ -177,7 +177,11 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
} }
m.Logs(ice.LOG_AUTH, "river", m.Option(ice.MSG_RIVER), "storm", m.Option(ice.MSG_STORM)) m.Logs(ice.LOG_AUTH, "river", m.Option(ice.MSG_RIVER), "storm", m.Option(ice.MSG_STORM))
}) })
}) }) == nil {
// 前端应用
// m.Option(ice.MSG_RIVER, arg[0])
// m.Option(ice.MSG_STORM, arg[1])
}
} }
} }
switch m.Option(ice.MSG_USERURL) { switch m.Option(ice.MSG_USERURL) {

View File

@ -118,3 +118,7 @@ func (m *Message) Log_REMOVE(arg ...interface{}) *Message {
func (m *Message) Log_CREATE(arg ...interface{}) *Message { func (m *Message) Log_CREATE(arg ...interface{}) *Message {
return m.log(LOG_CREATE, log_fields(arg...)) return m.log(LOG_CREATE, log_fields(arg...))
} }
func (m *Message) Log_AUTH(arg ...interface{}) *Message {
return m.log(LOG_AUTH, log_fields(arg...))
}