mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
opt web
This commit is contained in:
parent
e3c74fa4ac
commit
114a75b45f
@ -1,8 +1,6 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const AAA = "aaa"
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -10,38 +8,38 @@ import (
|
||||
|
||||
func _role_list(m *ice.Message, userrole string) {
|
||||
m.Richs(ROLE, nil, kit.Select(mdb.FOREACH, userrole), func(key string, value map[string]interface{}) {
|
||||
kit.Fetch(value[WHITE], func(k string, v interface{}) {
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME))
|
||||
m.Push(mdb.ZONE, WHITE)
|
||||
m.Push(mdb.KEY, k)
|
||||
})
|
||||
kit.Fetch(value[BLACK], func(k string, v interface{}) {
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME))
|
||||
m.Push(mdb.ZONE, BLACK)
|
||||
m.Push(mdb.KEY, k)
|
||||
})
|
||||
kit.Fetch(value[WHITE], func(k string, v interface{}) {
|
||||
m.Push(ROLE, kit.Value(value, mdb.NAME))
|
||||
m.Push(mdb.ZONE, WHITE)
|
||||
m.Push(mdb.KEY, k)
|
||||
})
|
||||
})
|
||||
}
|
||||
func _role_chain(arg ...string) string {
|
||||
return strings.ReplaceAll(kit.Keys(arg), ice.PS, ice.PT)
|
||||
return kit.ReplaceAll(kit.Keys(arg), ice.PS, ice.PT)
|
||||
}
|
||||
func _role_black(m *ice.Message, userrole, chain string, status bool) {
|
||||
func _role_black(m *ice.Message, userrole, chain string) {
|
||||
m.Richs(ROLE, nil, userrole, func(key string, value map[string]interface{}) {
|
||||
list := value[BLACK].(map[string]interface{})
|
||||
m.Log_CREATE(ROLE, userrole, BLACK, chain)
|
||||
list[chain] = status
|
||||
list[chain] = true
|
||||
})
|
||||
}
|
||||
func _role_white(m *ice.Message, userrole, chain string, status bool) {
|
||||
func _role_white(m *ice.Message, userrole, chain string) {
|
||||
m.Richs(ROLE, nil, userrole, func(key string, value map[string]interface{}) {
|
||||
list := value[WHITE].(map[string]interface{})
|
||||
m.Log_CREATE(ROLE, userrole, WHITE, chain)
|
||||
list[chain] = status
|
||||
list[chain] = true
|
||||
})
|
||||
}
|
||||
func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
if userrole == ROOT {
|
||||
return true // 超级用户
|
||||
return true // 超级权限
|
||||
}
|
||||
|
||||
m.Richs(ROLE, nil, kit.Select(VOID, userrole), func(key string, value map[string]interface{}) {
|
||||
@ -49,29 +47,29 @@ func _role_right(m *ice.Message, userrole string, keys ...string) (ok bool) {
|
||||
list := value[BLACK].(map[string]interface{})
|
||||
for i := 0; i < len(keys); i++ {
|
||||
if v, o := list[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
|
||||
ok = false
|
||||
ok = false // 在黑名单
|
||||
}
|
||||
}
|
||||
|
||||
if m.Warn(!ok, ice.ErrNotRight, keys, USERROLE, userrole) {
|
||||
return
|
||||
return // 没有权限
|
||||
}
|
||||
if userrole == TECH {
|
||||
return // 管理用户
|
||||
return // 管理权限
|
||||
}
|
||||
|
||||
ok = false
|
||||
list = value[WHITE].(map[string]interface{})
|
||||
for i := 0; i < len(keys); i++ {
|
||||
if v, o := list[kit.Join(keys[:i+1], ice.PT)]; o && v == true {
|
||||
ok = true
|
||||
ok = true // 在白名单
|
||||
}
|
||||
}
|
||||
|
||||
if m.Warn(!ok, ice.ErrNotRight, keys, USERROLE, userrole) {
|
||||
return
|
||||
return // 没有权限
|
||||
}
|
||||
if userrole == VOID {
|
||||
return // 用户权限
|
||||
}
|
||||
// 普通用户
|
||||
})
|
||||
return ok
|
||||
}
|
||||
@ -98,8 +96,8 @@ func init() {
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ROLE: {Name: "role role auto insert", Help: "角色", Action: map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Rich(ROLE, nil, kit.Dict(mdb.NAME, VOID, WHITE, kit.Dict(), BLACK, kit.Dict()))
|
||||
m.Rich(ROLE, nil, kit.Dict(mdb.NAME, TECH, BLACK, kit.Dict(), WHITE, kit.Dict()))
|
||||
m.Rich(ROLE, nil, kit.Dict(mdb.NAME, VOID, WHITE, kit.Dict(), BLACK, kit.Dict()))
|
||||
m.Cmd(ROLE, WHITE, VOID, ice.SRC)
|
||||
m.Cmd(ROLE, WHITE, VOID, ice.BIN)
|
||||
m.Cmd(ROLE, WHITE, VOID, ice.USR)
|
||||
@ -108,24 +106,24 @@ func init() {
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert role=void,tech zone=white,black key=", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(ROLE, nil, m.Option(ROLE), func(key string, value map[string]interface{}) {
|
||||
m.Log_CREATE(ROLE, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY))
|
||||
list := value[m.Option(mdb.ZONE)].(map[string]interface{})
|
||||
m.Log_CREATE(ROLE, m.Option(ROLE), m.Option(mdb.KEY))
|
||||
list[m.Option(mdb.KEY)] = true
|
||||
})
|
||||
}},
|
||||
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(ROLE, nil, m.Option(ROLE), func(key string, value map[string]interface{}) {
|
||||
m.Log_REMOVE(ROLE, m.Option(ROLE), m.Option(mdb.ZONE), m.Option(mdb.KEY))
|
||||
list := value[m.Option(mdb.ZONE)].(map[string]interface{})
|
||||
m.Log_REMOVE(ROLE, m.Option(ROLE), m.Option(mdb.KEY))
|
||||
delete(list, m.Option(mdb.KEY))
|
||||
})
|
||||
}},
|
||||
|
||||
BLACK: {Name: "black role chain", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_black(m, arg[0], _role_chain(arg[1:]...), true)
|
||||
_role_black(m, arg[0], _role_chain(arg[1:]...))
|
||||
}},
|
||||
WHITE: {Name: "white role chain", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
_role_white(m, arg[0], _role_chain(arg[1:]...), true)
|
||||
_role_white(m, arg[0], _role_chain(arg[1:]...))
|
||||
}},
|
||||
RIGHT: {Name: "right role chain", Help: "查看权限", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _role_right(m, arg[0], kit.Split(_role_chain(arg[1:]...), ice.PT)...) {
|
||||
|
@ -6,32 +6,42 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _sess_check(m *ice.Message, sessid string) {
|
||||
m.Richs(SESS, nil, sessid, func(value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
m.Richs(USER, nil, value[USERNAME], func(value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
func _sess_check(m *ice.Message, sessid string) bool {
|
||||
m.Option(ice.MSG_USERROLE, VOID)
|
||||
m.Option(ice.MSG_USERNAME, "")
|
||||
m.Option(ice.MSG_USERNICK, "")
|
||||
if sessid == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
m.Richs(SESS, nil, sessid, func(value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); m.Warn(kit.Time(kit.Format(value[mdb.TIME])) < kit.Time(m.Time()), ice.ErrExpire) {
|
||||
return // 会话超时
|
||||
}
|
||||
if m.Richs(USER, nil, value[USERNAME], func(value map[string]interface{}) {
|
||||
m.Log_AUTH(
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]),
|
||||
)
|
||||
})
|
||||
}) == nil {
|
||||
m.Log_AUTH(
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]),
|
||||
)
|
||||
}
|
||||
})
|
||||
return m.Option(ice.MSG_USERNAME) != ""
|
||||
}
|
||||
func _sess_create(m *ice.Message, username string) string {
|
||||
if username == "" {
|
||||
return ""
|
||||
}
|
||||
if !_user_exists(m, username) {
|
||||
_user_create(m, kit.Select(TECH, VOID, m.Option(ice.MSG_USERROLE) == VOID), username, kit.Hashs())
|
||||
}
|
||||
|
||||
h := m.Cmdx(mdb.INSERT, SESS, "", mdb.HASH,
|
||||
USERROLE, UserRole(m, username), USERNAME, username,
|
||||
h := m.Cmdx(mdb.INSERT, SESS, "", mdb.HASH, mdb.TIME, m.Time(m.Conf(SESS, kit.Keym(mdb.EXPIRE))),
|
||||
USERROLE, UserRole(m, username), USERNAME, username, USERNICK, UserNick(m, username),
|
||||
IP, m.Option(ice.MSG_USERIP), UA, m.Option(ice.MSG_USERUA),
|
||||
mdb.TIME, m.Time(m.Conf(SESS, kit.Keym(mdb.EXPIRE))),
|
||||
)
|
||||
m.Event(SESS_CREATE, SESS, h, USERNAME, username)
|
||||
return h
|
||||
@ -40,8 +50,8 @@ func _sess_create(m *ice.Message, username string) string {
|
||||
func SessCreate(m *ice.Message, username string) string {
|
||||
return m.Option(ice.MSG_SESSID, _sess_create(m, username))
|
||||
}
|
||||
func SessCheck(m *ice.Message, sessid string) {
|
||||
_sess_check(m, sessid)
|
||||
func SessCheck(m *ice.Message, sessid string) bool {
|
||||
return _sess_check(m, sessid)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -49,6 +59,7 @@ const (
|
||||
UA = "ua"
|
||||
)
|
||||
const (
|
||||
GRANT = "grant"
|
||||
LOGIN = "login"
|
||||
LOGOUT = "logout"
|
||||
)
|
||||
|
@ -54,12 +54,11 @@ const TOTP = "totp"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
TOTP: {Name: TOTP, Help: "动态令牌", Value: kit.Data(
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,secret,period,number",
|
||||
mdb.LINK, "otpauth://totp/%s?secret=%s",
|
||||
TOTP: {Name: TOTP, Help: "令牌", Value: kit.Data(
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,name,secret,period,number", mdb.LINK, "otpauth://totp/%s?secret=%s",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
TOTP: {Name: "totp name auto create", Help: "动态令牌", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
TOTP: {Name: "totp name auto create", Help: "令牌", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create name secret period=30 number=6", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(SECRET) == "" { // 创建密钥
|
||||
m.Option(SECRET, _totp_gen(kit.Int64(m.Option(PERIOD))))
|
||||
|
@ -15,7 +15,13 @@ func _user_login(m *ice.Message, name, word string) (ok bool) {
|
||||
}
|
||||
|
||||
m.Richs(USER, nil, name, func(key string, value map[string]interface{}) {
|
||||
ok = word == value[PASSWORD]
|
||||
if ok = !m.Warn(word != "" && word != value[PASSWORD], ice.ErrNotRight); ok {
|
||||
m.Log_AUTH(
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, value[USERROLE]),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, value[USERNAME]),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, value[USERNICK]),
|
||||
)
|
||||
}
|
||||
})
|
||||
return ok
|
||||
}
|
||||
@ -23,19 +29,14 @@ func _user_create(m *ice.Message, role, name, word string) {
|
||||
if word == "" {
|
||||
word = kit.Hashs()
|
||||
}
|
||||
m.Rich(USER, nil, kit.Dict(
|
||||
USERROLE, role, USERNAME, name, PASSWORD, word,
|
||||
USERNICK, name, USERZONE, m.Option(ice.MSG_USERZONE),
|
||||
))
|
||||
m.Rich(USER, nil, kit.Dict(USERROLE, role, USERNAME, name, PASSWORD, word))
|
||||
m.Event(USER_CREATE, USER, name)
|
||||
}
|
||||
func _user_search(m *ice.Message, name, text string) {
|
||||
m.Richs(USER, nil, mdb.FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); name != "" && name != value[USERNAME] {
|
||||
return
|
||||
if value = kit.GetMeta(value); name == "" || name == value[USERNAME] {
|
||||
m.PushSearch(kit.SimpleKV("", kit.Format(value[USERROLE]), kit.Format(value[USERNAME]), kit.Format(value[USERNICK])), value)
|
||||
}
|
||||
m.PushSearch(kit.SimpleKV("type,name,text",
|
||||
kit.Format(value[USERROLE]), kit.Format(value[USERNAME]), kit.Format(value[USERNICK])), value)
|
||||
})
|
||||
}
|
||||
|
||||
@ -69,15 +70,7 @@ func UserZone(m *ice.Message, username interface{}) (zone string) {
|
||||
return
|
||||
}
|
||||
func UserLogin(m *ice.Message, username, password string) bool {
|
||||
if password == "" || _user_login(m, username, password) {
|
||||
m.Log_AUTH(
|
||||
USERROLE, m.Option(ice.MSG_USERROLE, UserRole(m, username)),
|
||||
USERNAME, m.Option(ice.MSG_USERNAME, username),
|
||||
USERNICK, m.Option(ice.MSG_USERNICK, UserNick(m, username)),
|
||||
)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return _user_login(m, username, password)
|
||||
}
|
||||
|
||||
const (
|
||||
@ -102,7 +95,6 @@ const (
|
||||
)
|
||||
const (
|
||||
USER_CREATE = "user.create"
|
||||
USER_REMOVE = "user.remove"
|
||||
)
|
||||
const (
|
||||
INVITE = "invite"
|
||||
@ -125,10 +117,9 @@ func init() {
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create userrole=void,tech username password", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if _user_exists(m, m.Option(USERNAME)) {
|
||||
return
|
||||
if !_user_exists(m, m.Option(USERNAME)) {
|
||||
_user_create(m, m.Option(USERROLE), m.Option(USERNAME), m.Option(PASSWORD))
|
||||
}
|
||||
_user_create(m, m.Option(USERROLE), m.Option(USERNAME), m.Option(PASSWORD))
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...)
|
||||
|
@ -100,10 +100,6 @@ const (
|
||||
BOOT = "boot"
|
||||
NODE = "node"
|
||||
)
|
||||
const (
|
||||
SOURCE = "source"
|
||||
TARGET = "target"
|
||||
)
|
||||
const (
|
||||
GOARCH = "GOARCH"
|
||||
GOOS = "GOOS"
|
||||
|
@ -32,10 +32,12 @@ const (
|
||||
NAME = "name"
|
||||
TEXT = "text"
|
||||
|
||||
INDEX = "index"
|
||||
VALUE = "value"
|
||||
|
||||
LINK = "link"
|
||||
SCAN = "scan"
|
||||
HELP = "help"
|
||||
|
||||
SHORT = "short"
|
||||
FIELD = "field"
|
||||
|
@ -116,6 +116,15 @@ func _cat_list(m *ice.Message, name string) {
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
TEMPLATE = "template"
|
||||
SOURCE = "source"
|
||||
TARGET = "target"
|
||||
|
||||
MASTER = "master"
|
||||
BRANCH = "branch"
|
||||
REPOS = "repos"
|
||||
)
|
||||
const (
|
||||
PATH = "path"
|
||||
FILE = "file"
|
||||
@ -130,7 +139,7 @@ const CAT = "cat"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
CAT: {Name: CAT, Help: "文件", Value: kit.Data(
|
||||
kit.SSH_SOURCE, kit.Dict(
|
||||
SOURCE, kit.Dict(
|
||||
"sh", ice.TRUE, "shy", ice.TRUE, "py", ice.TRUE,
|
||||
"go", ice.TRUE, "vim", ice.TRUE, "js", ice.TRUE,
|
||||
"json", ice.TRUE, "conf", ice.TRUE, "yml", ice.TRUE,
|
||||
|
@ -35,14 +35,14 @@ func (c *Conn) Close() error {
|
||||
}
|
||||
|
||||
func _client_dial(m *ice.Message, arg ...string) {
|
||||
c, e := net.Dial(TCP, m.Option(HOST)+":"+m.Option(PORT))
|
||||
c, e := net.Dial(TCP, m.Option(HOST)+ice.DF+m.Option(PORT))
|
||||
|
||||
c = &Conn{m: m, s: &Stat{}, Conn: c}
|
||||
if e == nil {
|
||||
defer c.Close()
|
||||
}
|
||||
|
||||
switch cb := m.Optionv(kit.Keycb(DIAL)).(type) {
|
||||
switch cb := m.Optionv(kit.Keycb(CLIENT)).(type) {
|
||||
case func(net.Conn, error):
|
||||
cb(c, e)
|
||||
case func(net.Conn):
|
||||
@ -62,11 +62,13 @@ func _client_dial(m *ice.Message, arg ...string) {
|
||||
}
|
||||
|
||||
const (
|
||||
OPEN = "open"
|
||||
CLOSE = "close"
|
||||
ERROR = "error"
|
||||
START = "start"
|
||||
STOP = "stop"
|
||||
PROTO = "proto"
|
||||
STATUS = "status"
|
||||
ERROR = "error"
|
||||
OPEN = "open"
|
||||
CLOSE = "close"
|
||||
START = "start"
|
||||
STOP = "stop"
|
||||
)
|
||||
const (
|
||||
DIAL = "dial"
|
||||
@ -76,25 +78,22 @@ const CLIENT = "client"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
CLIENT: {Name: CLIENT, Help: "客户端", Value: kit.Data(
|
||||
kit.MDB_FIELD, "time,hash,status,type,name,host,port,error,nread,nwrite",
|
||||
mdb.FIELD, "time,hash,status,type,name,host,port,error,nread,nwrite",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(CLIENT, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, kit.Keym(kit.MDB_STATUS), CLOSE)
|
||||
})
|
||||
}},
|
||||
CLIENT: {Name: "client hash auto prunes", Help: "客户端", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(CLIENT, "", mdb.FOREACH, func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, kit.Keym(STATUS), CLOSE)
|
||||
})
|
||||
m.Cmdy(SERVER, mdb.PRUNES)
|
||||
}},
|
||||
DIAL: {Name: "dial type name port=9010 host=", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
_client_dial(m, arg...)
|
||||
}},
|
||||
mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.PRUNES, CLIENT, "", mdb.HASH, kit.MDB_STATUS, ERROR)
|
||||
m.Cmdy(mdb.PRUNES, CLIENT, "", mdb.HASH, kit.MDB_STATUS, CLOSE)
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}, mdb.HashActionStatus()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushButton(kit.Select("", mdb.REMOVE, value[kit.MDB_STATUS] == OPEN))
|
||||
m.PushButton(kit.Select("", mdb.REMOVE, value[STATUS] == OPEN))
|
||||
})
|
||||
}},
|
||||
}})
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -22,12 +23,12 @@ func _host_list(m *ice.Message, name string) {
|
||||
if ips, e := v.Addrs(); m.Assert(e) {
|
||||
for _, x := range ips {
|
||||
ip := strings.Split(x.String(), ice.PS)
|
||||
if strings.Contains(ip[0], ":") || len(ip) == 0 {
|
||||
if strings.Contains(ip[0], ice.DF) || len(ip) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
m.Push(kit.MDB_INDEX, v.Index)
|
||||
m.Push(kit.MDB_NAME, v.Name)
|
||||
m.Push(mdb.INDEX, v.Index)
|
||||
m.Push(mdb.NAME, v.Name)
|
||||
m.Push(aaa.IP, ip[0])
|
||||
m.Push("mask", ip[1])
|
||||
m.Push("hard", v.HardwareAddr.String())
|
||||
@ -37,8 +38,8 @@ func _host_list(m *ice.Message, name string) {
|
||||
}
|
||||
|
||||
if len(m.Appendv(aaa.IP)) == 0 {
|
||||
m.Push(kit.MDB_INDEX, -1)
|
||||
m.Push(kit.MDB_NAME, LOCALHOST)
|
||||
m.Push(mdb.INDEX, -1)
|
||||
m.Push(mdb.NAME, LOCALHOST)
|
||||
m.Push(aaa.IP, "127.0.0.1")
|
||||
m.Push("mask", "255.0.0.0")
|
||||
m.Push("hard", "")
|
||||
@ -74,23 +75,22 @@ const HOST = "host"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
HOST: {Name: HOST, Help: "主机", Value: kit.Data(
|
||||
aaa.BLACK, kit.Data(kit.MDB_SHORT, kit.MDB_TEXT),
|
||||
aaa.WHITE, kit.Data(kit.MDB_SHORT, kit.MDB_TEXT),
|
||||
aaa.BLACK, kit.Data(mdb.SHORT, mdb.TEXT), aaa.WHITE, kit.Data(mdb.SHORT, mdb.TEXT),
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(HOST).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(HOST, aaa.WHITE, value[aaa.IP])
|
||||
})
|
||||
}},
|
||||
HOST: {Name: "host name auto", Help: "主机", Action: map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(HOST).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(HOST, aaa.WHITE, value[aaa.IP])
|
||||
})
|
||||
}},
|
||||
aaa.BLACK: {Name: "black", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Log_CREATE(aaa.BLACK, arg[0])
|
||||
m.Rich(HOST, kit.Keym(aaa.BLACK), kit.Dict(kit.MDB_TEXT, arg[0]))
|
||||
m.Rich(HOST, kit.Keym(aaa.BLACK), kit.Dict(mdb.TEXT, arg[0]))
|
||||
}},
|
||||
aaa.WHITE: {Name: "white", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Log_CREATE(aaa.WHITE, arg[0])
|
||||
m.Rich(HOST, kit.Keym(aaa.WHITE), kit.Dict(kit.MDB_TEXT, arg[0]))
|
||||
m.Rich(HOST, kit.Keym(aaa.WHITE), kit.Dict(mdb.TEXT, arg[0]))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
_host_list(m, kit.Select("", arg, 0))
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -25,7 +26,7 @@ func _port_right(m *ice.Message, arg ...string) string {
|
||||
c.Close()
|
||||
continue
|
||||
}
|
||||
p := path.Join(m.Conf(cli.DAEMON, kit.META_PATH), kit.Format(i))
|
||||
p := path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), kit.Format(i))
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
continue
|
||||
}
|
||||
@ -55,16 +56,16 @@ func init() {
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(cli.DAEMON, kit.META_PATH))
|
||||
m.Option(nfs.DIR_ROOT, m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)))
|
||||
m.Cmd(nfs.DIR, ice.PWD, "time,path,size").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(kit.MDB_TIME, value[kit.MDB_TIME])
|
||||
m.Push(mdb.TIME, value[mdb.TIME])
|
||||
m.Push(PORT, path.Base(value[nfs.PATH]))
|
||||
m.Push(kit.MDB_SIZE, value[kit.MDB_SIZE])
|
||||
m.Push(nfs.SIZE, value[nfs.SIZE])
|
||||
})
|
||||
m.SortInt(PORT)
|
||||
return
|
||||
}
|
||||
m.Option(nfs.DIR_ROOT, path.Join(m.Conf(cli.DAEMON, kit.META_PATH), arg[0]))
|
||||
m.Option(nfs.DIR_ROOT, path.Join(m.Conf(cli.DAEMON, kit.Keym(nfs.PATH)), arg[0]))
|
||||
m.Cmdy(nfs.DIR, arg[1:])
|
||||
}},
|
||||
}})
|
||||
|
@ -22,21 +22,21 @@ func (l Listener) Accept() (net.Conn, error) {
|
||||
return &Conn{m: l.m, h: "", s: &Stat{}, Conn: c}, e
|
||||
}
|
||||
func (l Listener) Close() error {
|
||||
l.m.Cmd(mdb.MODIFY, SERVER, "", mdb.HASH, kit.MDB_HASH, l.h, kit.MDB_STATUS, CLOSE)
|
||||
l.m.Cmd(mdb.MODIFY, SERVER, "", mdb.HASH, mdb.HASH, l.h, STATUS, CLOSE)
|
||||
return l.Listener.Close()
|
||||
}
|
||||
|
||||
func _server_listen(m *ice.Message, arg ...string) {
|
||||
l, e := net.Listen(TCP, m.Option(HOST)+":"+m.Option(PORT))
|
||||
h := m.Cmdx(mdb.INSERT, SERVER, "", mdb.HASH, arg,
|
||||
kit.MDB_STATUS, kit.Select(ERROR, OPEN, e == nil), kit.MDB_ERROR, kit.Format(e))
|
||||
STATUS, kit.Select(ERROR, OPEN, e == nil), ERROR, kit.Format(e))
|
||||
|
||||
l = &Listener{m: m, h: h, s: &Stat{}, Listener: l}
|
||||
if e == nil {
|
||||
defer l.Close()
|
||||
}
|
||||
|
||||
switch cb := m.Optionv(kit.Keycb(LISTEN)).(type) {
|
||||
switch cb := m.Optionv(kit.Keycb(SERVER)).(type) {
|
||||
case func(net.Listener, error):
|
||||
cb(l, e)
|
||||
case func(net.Listener):
|
||||
@ -87,26 +87,22 @@ const SERVER = "server"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
SERVER: {Name: SERVER, Help: "服务器", Value: kit.Data(
|
||||
kit.MDB_FIELD, "time,hash,status,type,name,host,port,error,nconn",
|
||||
mdb.FIELD, "time,hash,status,type,name,host,port,error,nconn",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(SERVER, "", kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, kit.Keym(kit.MDB_STATUS), CLOSE)
|
||||
})
|
||||
m.Cmdy(SERVER, mdb.PRUNES)
|
||||
}},
|
||||
SERVER: {Name: "server hash auto prunes", Help: "服务器", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Richs(SERVER, "", mdb.FOREACH, func(key string, value map[string]interface{}) {
|
||||
kit.Value(value, kit.Keym(STATUS), CLOSE)
|
||||
})
|
||||
m.Cmdy(SERVER, mdb.PRUNES)
|
||||
}},
|
||||
LISTEN: {Name: "LISTEN type name port=9030 host=", Help: "监听", Hand: func(m *ice.Message, arg ...string) {
|
||||
_server_listen(m, arg...)
|
||||
}},
|
||||
mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.PRUNES, SERVER, "", mdb.HASH, kit.MDB_STATUS, ERROR)
|
||||
m.Cmdy(mdb.PRUNES, SERVER, "", mdb.HASH, kit.MDB_STATUS, CLOSE)
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}, mdb.HashActionStatus()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
mdb.HashSelect(m, arg...).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushButton(kit.Select("", mdb.REMOVE, value[kit.MDB_STATUS] == CLOSE))
|
||||
m.PushButton(kit.Select("", mdb.REMOVE, value[STATUS] == CLOSE))
|
||||
})
|
||||
}},
|
||||
}})
|
||||
|
@ -1,8 +1,6 @@
|
||||
package tcp
|
||||
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
)
|
||||
import ice "shylinux.com/x/icebergs"
|
||||
|
||||
const TCP = "tcp"
|
||||
|
||||
|
@ -2,6 +2,5 @@ chapter "tcp"
|
||||
|
||||
field "主机" tcp.host
|
||||
field "端口" tcp.port
|
||||
|
||||
field "服务器" tcp.server
|
||||
field "客户端" tcp.client
|
||||
field "服务器" tcp.server
|
||||
|
@ -17,39 +17,36 @@ import (
|
||||
|
||||
func _dream_list(m *ice.Message) {
|
||||
m.Cmdy(nfs.DIR, m.Config(nfs.PATH), "time,size,name").Table(func(index int, value map[string]string, head []string) {
|
||||
if m.Richs(SPACE, nil, value[kit.MDB_NAME], func(key string, value map[string]interface{}) {
|
||||
m.Push(kit.MDB_TYPE, value[kit.MDB_TYPE])
|
||||
m.Push(kit.MDB_STATUS, cli.START)
|
||||
if m.Richs(SPACE, nil, value[mdb.NAME], func(key string, value map[string]interface{}) {
|
||||
m.Push(mdb.TYPE, value[mdb.TYPE])
|
||||
m.Push(cli.STATUS, cli.START)
|
||||
m.PushButton(cli.STOP)
|
||||
}) == nil {
|
||||
m.Push(kit.MDB_TYPE, WORKER)
|
||||
m.Push(kit.MDB_STATUS, cli.STOP)
|
||||
m.Push(mdb.TYPE, WORKER)
|
||||
m.Push(cli.STATUS, cli.STOP)
|
||||
m.PushButton(cli.START)
|
||||
}
|
||||
})
|
||||
m.SortStrR(kit.MDB_TIME)
|
||||
}
|
||||
func _dream_show(m *ice.Message, name string) {
|
||||
if !strings.Contains(name, "-") || !strings.HasPrefix(name, "20") {
|
||||
name = m.Time("20060102-") + strings.ReplaceAll(name, "-", "_")
|
||||
name = m.Time("20060102-") + kit.ReplaceAll(name, "-", "_")
|
||||
}
|
||||
m.Option(kit.MDB_NAME, name)
|
||||
defer m.ProcessOpen(m.MergePOD(m.Option(mdb.NAME, name)))
|
||||
|
||||
// 任务目录
|
||||
p := path.Join(m.Config(nfs.PATH), name)
|
||||
if m.Option(kit.SSH_REPOS) != "" { // 下载源码
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, m.OptionSimple(kit.SSH_REPOS), nfs.PATH, p)
|
||||
if m.Option(nfs.REPOS) != "" { // 下载源码
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, m.OptionSimple(nfs.REPOS), nfs.PATH, p)
|
||||
} else { // 创建目录
|
||||
os.MkdirAll(p, ice.MOD_DIR)
|
||||
}
|
||||
|
||||
defer m.ProcessOpen(m.MergeURL2("/chat/pod/" + name))
|
||||
|
||||
// 任务模板
|
||||
if m.Option(kit.MDB_TEMPLATE) != "" {
|
||||
if m.Option(nfs.TEMPLATE) != "" {
|
||||
for _, file := range []string{ice.ETC_MISS_SH, ice.SRC_MAIN_SHY, ice.SRC_MAIN_GO, ice.GO_MOD, ice.MAKEFILE} {
|
||||
if _, e := os.Stat(path.Join(p, file)); os.IsNotExist(e) {
|
||||
switch m.Cmdy(nfs.COPY, path.Join(p, file), path.Join(m.Option(kit.MDB_TEMPLATE), file)); file {
|
||||
switch m.Cmdy(nfs.COPY, path.Join(p, file), path.Join(m.Option(nfs.TEMPLATE), file)); file {
|
||||
case ice.GO_MOD:
|
||||
kit.Rewrite(path.Join(p, file), func(line string) string {
|
||||
return kit.Select(line, "module "+name, strings.HasPrefix(line, "module"))
|
||||
@ -64,6 +61,7 @@ func _dream_show(m *ice.Message, name string) {
|
||||
if _, e := os.Stat(miss); os.IsNotExist(e) {
|
||||
m.Cmd(nfs.SAVE, miss, m.Config("miss"))
|
||||
}
|
||||
defer m.Cmdy(nfs.DIR, p)
|
||||
|
||||
if b, e := ioutil.ReadFile(path.Join(p, m.Conf(gdb.SIGNAL, kit.Keym(cli.PID)))); e == nil {
|
||||
if s, e := os.Stat("/proc/" + string(b)); e == nil && s.IsDir() {
|
||||
@ -71,22 +69,22 @@ func _dream_show(m *ice.Message, name string) {
|
||||
return // 已经启动
|
||||
}
|
||||
}
|
||||
|
||||
if m.Richs(SPACE, nil, name, nil) == nil {
|
||||
m.Option(cli.CMD_DIR, p)
|
||||
m.Optionv(cli.CMD_ENV, kit.Simple(
|
||||
cli.CTX_DEV, "http://:"+m.Cmd(SERVE).Append(tcp.PORT),
|
||||
cli.PATH, kit.Path(path.Join(p, ice.BIN))+":"+kit.Path(ice.BIN)+":"+os.Getenv(cli.PATH),
|
||||
cli.USER, ice.Info.UserName, m.Configv(cli.ENV),
|
||||
))
|
||||
|
||||
// 启动任务
|
||||
m.Optionv(cli.CMD_OUTPUT, path.Join(p, m.Config(kit.Keys(cli.ENV, cli.CTX_LOG))))
|
||||
m.Cmd(cli.DAEMON, m.Configv(ice.CMD), ice.DEV, ice.DEV, kit.MDB_NAME, name, m.OptionSimple(RIVER))
|
||||
m.Sleep(ice.MOD_TICK)
|
||||
m.Event(DREAM_CREATE, kit.MDB_TYPE, m.Option(kit.MDB_TYPE), kit.MDB_NAME, name)
|
||||
if m.Richs(SPACE, nil, name, nil) != nil {
|
||||
return // 已经启动
|
||||
}
|
||||
m.Cmdy(nfs.DIR, p)
|
||||
|
||||
m.Optionv(cli.CMD_DIR, p)
|
||||
m.Optionv(cli.CMD_ENV, kit.Simple(
|
||||
cli.CTX_DEV, "http://:"+m.Cmd(SERVE).Append(tcp.PORT),
|
||||
cli.PATH, kit.Path(path.Join(p, ice.BIN))+":"+kit.Path(ice.BIN)+":"+os.Getenv(cli.PATH),
|
||||
cli.USER, ice.Info.UserName, m.Configv(cli.ENV),
|
||||
))
|
||||
m.Optionv(cli.CMD_OUTPUT, path.Join(p, m.Config(kit.Keys(cli.ENV, cli.CTX_LOG))))
|
||||
|
||||
// 启动任务
|
||||
m.Cmd(cli.DAEMON, m.Configv(ice.CMD), ice.DEV, ice.DEV, mdb.NAME, name, m.OptionSimple(RIVER))
|
||||
defer m.Event(DREAM_CREATE, kit.SimpleKV(m.Option(mdb.TYPE), name)...)
|
||||
m.Sleep300ms()
|
||||
}
|
||||
|
||||
const (
|
||||
@ -98,25 +96,12 @@ const DREAM = "dream"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
DREAM: {Name: "dream name path auto start create", Help: "梦想家", Action: map[string]*ice.Action{
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch arg[0] {
|
||||
case kit.MDB_NAME:
|
||||
m.Cmdy(nfs.DIR, m.Config(nfs.PATH), "name,time")
|
||||
case kit.MDB_TEMPLATE:
|
||||
m.Cmdy(nfs.DIR, m.Config(nfs.PATH), "path,size,time")
|
||||
m.SortStrR(nfs.PATH)
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create main=src/main.go@key name=hi@key from=usr/icebergs/misc/bash/bash.go@key", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), "web.code.autogen", mdb.CREATE, arg)
|
||||
m.ProcessInner()
|
||||
}},
|
||||
DREAM: {Name: "dream name path auto start", Help: "梦想家", Action: map[string]*ice.Action{
|
||||
cli.START: {Name: "start name repos river", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
_dream_show(m, m.Option(kit.MDB_NAME, kit.Select(path.Base(m.Option(kit.SSH_REPOS)), m.Option(kit.MDB_NAME))))
|
||||
_dream_show(m, m.Option(mdb.NAME, kit.Select(path.Base(m.Option(nfs.REPOS)), m.Option(mdb.NAME))))
|
||||
}},
|
||||
cli.STOP: {Name: "stop", Help: "停止", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPACE, m.Option(kit.MDB_NAME), "exit", "0")
|
||||
m.Cmdy(SPACE, m.Option(mdb.NAME), "exit", "0")
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
@ -129,7 +114,7 @@ func init() {
|
||||
}},
|
||||
}, Configs: map[string]*ice.Config{
|
||||
DREAM: {Name: DREAM, Help: "梦想家", Value: kit.Data(nfs.PATH, ice.USR_LOCAL_WORK,
|
||||
ice.CMD, []interface{}{"ice.bin", SPACE, tcp.DIAL},
|
||||
ice.CMD, kit.List("ice.bin", SPACE, tcp.DIAL),
|
||||
cli.ENV, kit.Dict(cli.CTX_LOG, ice.BIN_BOOT_LOG),
|
||||
"miss", `#!/bin/bash
|
||||
if [ "$ISH_CONF_PRE" = "" ]; then
|
||||
@ -147,10 +132,10 @@ ish_miss_prepare_install
|
||||
|
||||
# ish_miss_prepare linux-story
|
||||
# ish_miss_prepare mysql-story
|
||||
ish_miss_prepare release
|
||||
# ish_miss_prepare release
|
||||
|
||||
ish_miss_prepare_contexts
|
||||
# ish_miss_prepare_intshell
|
||||
ish_miss_prepare_intshell
|
||||
# ish_miss_prepare_icebergs
|
||||
# ish_miss_prepare_toolkits
|
||||
# ish_miss_prepare_volcanos
|
||||
|
@ -3,44 +3,43 @@ package web
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/aaa"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/ctx"
|
||||
"shylinux.com/x/icebergs/base/lex"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
func _route_travel(m *ice.Message, route string) {
|
||||
m.Richs(SPACE, nil, kit.MDB_FOREACH, func(key string, val map[string]interface{}) {
|
||||
switch val[kit.MDB_TYPE] {
|
||||
m.Richs(SPACE, nil, mdb.FOREACH, func(key string, val map[string]interface{}) {
|
||||
switch val[mdb.TYPE] {
|
||||
case SERVER: // 远程查询
|
||||
if val[kit.MDB_NAME] == ice.Info.NodeName {
|
||||
if val[mdb.NAME] == ice.Info.NodeName {
|
||||
return // 避免循环
|
||||
}
|
||||
|
||||
m.Cmd(SPACE, val[kit.MDB_NAME], ROUTE).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(kit.MDB_TYPE, value[kit.MDB_TYPE])
|
||||
m.Push(kit.SSH_ROUTE, kit.Keys(val[kit.MDB_NAME], value[kit.SSH_ROUTE]))
|
||||
m.Cmd(SPACE, val[mdb.NAME], ROUTE).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(mdb.TYPE, value[mdb.TYPE])
|
||||
m.Push(ROUTE, kit.Keys(val[mdb.NAME], value[ROUTE]))
|
||||
})
|
||||
|
||||
fallthrough
|
||||
case WORKER: // 本机查询
|
||||
m.Push(kit.MDB_TYPE, val[kit.MDB_TYPE])
|
||||
m.Push(kit.SSH_ROUTE, val[kit.MDB_NAME])
|
||||
m.Push(mdb.TYPE, val[mdb.TYPE])
|
||||
m.Push(ROUTE, val[mdb.NAME])
|
||||
}
|
||||
})
|
||||
}
|
||||
func _route_list(m *ice.Message) {
|
||||
// 链接操作
|
||||
m.Table(func(index int, value map[string]string, field []string) {
|
||||
m.PushAnchor(value[kit.SSH_ROUTE], _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[kit.SSH_ROUTE])))
|
||||
m.PushAnchor(value[ROUTE], _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[ROUTE])))
|
||||
|
||||
switch value[kit.MDB_TYPE] {
|
||||
case WORKER:
|
||||
m.PushButton(mdb.CREATE)
|
||||
switch value[mdb.TYPE] {
|
||||
case SERVER:
|
||||
m.PushButton(tcp.START)
|
||||
case WORKER:
|
||||
fallthrough
|
||||
default:
|
||||
m.PushButton("")
|
||||
}
|
||||
@ -49,65 +48,33 @@ func _route_list(m *ice.Message) {
|
||||
// 网卡信息
|
||||
u := kit.ParseURL(m.Option(ice.MSG_USERWEB))
|
||||
m.Cmd(tcp.HOST).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(kit.MDB_TYPE, MYSELF)
|
||||
m.Push(kit.SSH_ROUTE, ice.Info.NodeName)
|
||||
m.Push(mdb.TYPE, MYSELF)
|
||||
m.Push(ROUTE, ice.Info.NodeName)
|
||||
m.PushAnchor(value[aaa.IP], kit.Format("%s://%s:%s", u.Scheme, value[aaa.IP], u.Port()))
|
||||
m.PushButton(tcp.START)
|
||||
})
|
||||
|
||||
// 本机信息
|
||||
m.Push(kit.MDB_TYPE, MYSELF)
|
||||
m.Push(kit.SSH_ROUTE, ice.Info.NodeName)
|
||||
m.Push(mdb.TYPE, MYSELF)
|
||||
m.Push(ROUTE, ice.Info.NodeName)
|
||||
m.PushAnchor(tcp.LOCALHOST, kit.Format("%s://%s:%s", u.Scheme, tcp.LOCALHOST, u.Port()))
|
||||
m.PushButton(tcp.START)
|
||||
|
||||
m.Sort(kit.SSH_ROUTE)
|
||||
m.Sort(ROUTE)
|
||||
}
|
||||
|
||||
const ROUTE = "route"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
ROUTE: {Name: ROUTE, Help: "路由器", Value: kit.Data(kit.MDB_SHORT, kit.SSH_ROUTE)},
|
||||
ROUTE: {Name: ROUTE, Help: "路由器", Value: kit.Data(mdb.SHORT, ROUTE)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ROUTE: {Name: "route route ctx cmd auto spide invite share", Help: "路由器", Action: map[string]*ice.Action{
|
||||
SHARE: {Name: "share", Help: "共享", Hand: func(m *ice.Message, arg ...string) {
|
||||
p := kit.MergeURL(m.Option(ice.MSG_USERWEB), SHARE, m.Cmdx(SHARE, mdb.CREATE, kit.MDB_TYPE, LOGIN))
|
||||
m.EchoAnchor(p)
|
||||
m.EchoScript(p)
|
||||
m.EchoQRCode(p)
|
||||
}},
|
||||
aaa.INVITE: {Name: "invite", Help: "脚本", Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, k := range []string{"base", "core", "misc"} {
|
||||
m.Cmdy("web.code.publish", ice.CONTEXTS, k)
|
||||
}
|
||||
|
||||
m.EchoScript("shell", "# 共享环境", m.Option(ice.MSG_USERWEB))
|
||||
m.EchoAnchor(m.Option(ice.MSG_USERWEB)).Echo("<br/>")
|
||||
m.EchoQRCode(m.Option(ice.MSG_USERWEB))
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
switch m.Option(ctx.ACTION) {
|
||||
case mdb.CREATE:
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), "web.code.autogen", mdb.INPUTS, arg)
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case kit.MDB_NAME:
|
||||
m.Cmdy(nfs.DIR, m.Conf(DREAM, kit.META_PATH), "name,size,time")
|
||||
m.SortStrR(nfs.PATH)
|
||||
|
||||
case kit.MDB_TEMPLATE:
|
||||
m.Cmdy(nfs.DIR, m.Conf(DREAM, kit.META_PATH), "path,size,time")
|
||||
m.SortStrR(nfs.PATH)
|
||||
}
|
||||
}},
|
||||
mdb.CREATE: {Name: "create main=src/main.go@key name=hi@key from=usr/icebergs/misc/bash/bash.go@key", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), "web.code.autogen", mdb.CREATE, arg)
|
||||
ROUTE: {Name: "route route ctx cmd auto invite spide", Help: "路由器", Action: map[string]*ice.Action{
|
||||
aaa.INVITE: {Name: "invite", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), SPACE, aaa.INVITE, arg)
|
||||
m.ProcessInner()
|
||||
}},
|
||||
tcp.START: {Name: "start name repos template", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
cli.START: {Name: "start name repos template", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), DREAM, tcp.START, arg)
|
||||
m.ProcessInner()
|
||||
}},
|
||||
@ -123,14 +90,14 @@ func init() {
|
||||
m.Display("/plugin/story/spide.js?prefix=spide", lex.SPLIT, ice.PT)
|
||||
|
||||
} else if m.Option(ctx.CONTEXT) == "" { // 模块列表 context
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), ctx.CONTEXT, ice.ICE, ctx.CONTEXT).Cut(kit.MDB_NAME).RenameAppend(kit.MDB_NAME, ctx.CONTEXT)
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), ctx.CONTEXT, ice.ICE, ctx.CONTEXT).Cut(mdb.NAME).RenameAppend(mdb.NAME, ctx.CONTEXT)
|
||||
m.Option(lex.SPLIT, ice.PT)
|
||||
|
||||
} else if m.Option(kit.MDB_NAME) == "" { // 命令列表 name
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), ctx.CONTEXT, SPIDE, "", m.Option(ctx.CONTEXT), m.Option(ctx.CONTEXT)).Cut(kit.MDB_NAME)
|
||||
} else if m.Option(mdb.NAME) == "" { // 命令列表 name
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), ctx.CONTEXT, SPIDE, "", m.Option(ctx.CONTEXT), m.Option(ctx.CONTEXT)).Cut(mdb.NAME)
|
||||
|
||||
} else { // 命令详情 index name help meta list
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), ctx.CONTEXT, SPIDE, "", m.Option(ctx.CONTEXT), m.Option(kit.MDB_NAME))
|
||||
m.Cmdy(SPACE, m.Option(ROUTE), ctx.CONTEXT, SPIDE, "", m.Option(ctx.CONTEXT), m.Option(mdb.NAME))
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -140,15 +107,15 @@ func init() {
|
||||
}
|
||||
|
||||
} else if len(arg) == 1 || arg[1] == "" { // 模块列表
|
||||
m.Cmd(SPACE, arg[0], ctx.CONTEXT).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(ice.CTX, kit.Keys(value["ups"], value[kit.MDB_NAME]))
|
||||
m.Push("", value, []string{ice.CTX_STATUS, ice.CTX_STREAM, kit.MDB_HELP})
|
||||
m.Cmd(SPACE, arg[0], ctx.CONTEXT, ice.ICE).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(ice.CTX, kit.Keys(value["ups"], value[mdb.NAME]))
|
||||
m.Push("", value, kit.List(ice.CTX_STATUS, ice.CTX_STREAM, mdb.HELP))
|
||||
})
|
||||
|
||||
} else if len(arg) == 2 || arg[2] == "" { // 命令列表
|
||||
m.Cmd(SPACE, arg[0], ctx.CONTEXT, arg[1], ctx.COMMAND).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Push(ice.CMD, value[kit.MDB_KEY])
|
||||
m.Push("", value, []string{kit.MDB_NAME, kit.MDB_HELP})
|
||||
m.Push(ice.CMD, value[mdb.KEY])
|
||||
m.Push("", value, kit.List(mdb.NAME, mdb.HELP))
|
||||
})
|
||||
|
||||
} else { // 命令详情
|
||||
|
@ -17,16 +17,14 @@ import (
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
var rewriteList = []func(w http.ResponseWriter, r *http.Request) bool{}
|
||||
var rewriteList = []interface{}{}
|
||||
|
||||
func AddRewrite(cb func(w http.ResponseWriter, r *http.Request) bool) {
|
||||
rewriteList = append(rewriteList, cb)
|
||||
}
|
||||
func AddRewrite(cb interface{}) { rewriteList = append(rewriteList, cb) }
|
||||
|
||||
func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
if r.Header.Get("index.module") == "" {
|
||||
r.Header.Set("index.module", m.Prefix())
|
||||
} else { // 模块接口
|
||||
if r.Header.Get("Index-Module") == "" {
|
||||
r.Header.Set("Index-Module", m.Prefix())
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
||||
@ -34,7 +32,9 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
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 != "" {
|
||||
r.Header.Set(ice.MSG_USERIP, ip)
|
||||
if r.Header.Set(ice.MSG_USERIP, ip); r.Header.Get("X-Real-Port") != "" {
|
||||
r.Header.Set(ice.MSG_USERADDR, ip+":"+r.Header.Get("X-Real-Port"))
|
||||
}
|
||||
} else if strings.HasPrefix(r.RemoteAddr, "[") {
|
||||
r.Header.Set(ice.MSG_USERIP, strings.Split(r.RemoteAddr, "]")[0][1:])
|
||||
} else {
|
||||
@ -50,35 +50,33 @@ func _serve_main(m *ice.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
m.Info("")
|
||||
|
||||
defer func() {
|
||||
m.Info("")
|
||||
for k, v := range w.Header() {
|
||||
m.Info("%s: %v", k, kit.Format(v))
|
||||
}
|
||||
m.Info("")
|
||||
}()
|
||||
}
|
||||
|
||||
// 模块回调
|
||||
for _, h := range rewriteList {
|
||||
if h(w, r) {
|
||||
return false
|
||||
if m.Config(LOGHEADERS) == ice.TRUE {
|
||||
m.Info("%s: %v", r.URL.Path, kit.FileLine(h, 3))
|
||||
}
|
||||
}
|
||||
switch h := h.(type) {
|
||||
case func(w http.ResponseWriter, r *http.Request) func():
|
||||
defer h(w, r)
|
||||
|
||||
if r.Method == SPIDE_GET && r.URL.Path == ice.PS {
|
||||
msg := m.Spawn()
|
||||
msg.W, msg.R = w, r
|
||||
repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get("User-Agent"), "Mozilla/5.0"))
|
||||
Render(msg, ice.RENDER_DOWNLOAD, path.Join(m.Config(kit.Keys(repos, nfs.PATH)), m.Config(kit.Keys(repos, kit.MDB_INDEX))))
|
||||
return false // 网站主页
|
||||
}
|
||||
|
||||
if ice.Dump(w, r.URL.Path, func(name string) { RenderType(w, name, "") }) {
|
||||
return false // 打包文件
|
||||
case func(w http.ResponseWriter, r *http.Request) bool:
|
||||
if h(w, r) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
func _serve_params(msg *ice.Message, path string) {
|
||||
switch ls := strings.Split(path, "/"); kit.Select("", ls, 1) {
|
||||
case "share":
|
||||
switch ls := strings.Split(path, ice.PS); kit.Select("", ls, 1) {
|
||||
case SHARE:
|
||||
switch ls[2] {
|
||||
case "local":
|
||||
default:
|
||||
@ -87,25 +85,23 @@ func _serve_params(msg *ice.Message, path string) {
|
||||
}
|
||||
case "chat":
|
||||
switch kit.Select("", ls, 2) {
|
||||
case "pod":
|
||||
case ice.POD:
|
||||
msg.Logs("refer", ls[2], ls[3])
|
||||
msg.Option(ls[2], ls[3])
|
||||
}
|
||||
case "pod":
|
||||
case ice.POD:
|
||||
msg.Logs("refer", ls[1], ls[2])
|
||||
msg.Option(ls[1], ls[2])
|
||||
}
|
||||
}
|
||||
func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.ResponseWriter, r *http.Request) {
|
||||
// 环境变量
|
||||
msg.Option(ice.MSG_OUTPUT, "")
|
||||
// 会话变量
|
||||
msg.Option(ice.MSG_SESSID, "")
|
||||
msg.Option(ice.MSG_ARGS, kit.List())
|
||||
for _, v := range r.Cookies() {
|
||||
msg.Option(v.Name, v.Value)
|
||||
}
|
||||
|
||||
// 请求变量
|
||||
// 请求参数
|
||||
if u, e := url.Parse(r.Header.Get("Referer")); e == nil {
|
||||
_serve_params(msg, u.Path)
|
||||
for k, v := range u.Query() {
|
||||
@ -115,35 +111,16 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
}
|
||||
_serve_params(msg, r.URL.Path)
|
||||
|
||||
// 请求地址
|
||||
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Conf(SPACE, kit.Keym(kit.MDB_DOMAIN)), kit.Select(r.Header.Get("X-Host"), r.Header.Get("Referer"))))
|
||||
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
|
||||
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, msg.Option(ice.MSG_USERIP))
|
||||
}
|
||||
|
||||
if sessid := msg.Option(CookieName(msg.Option(ice.MSG_USERWEB))); sessid != "" {
|
||||
msg.Option(ice.MSG_SESSID, sessid)
|
||||
}
|
||||
|
||||
// 请求数据
|
||||
switch r.Header.Get(ContentType) {
|
||||
case ContentJSON:
|
||||
var data interface{}
|
||||
if e := json.NewDecoder(r.Body).Decode(&data); !msg.Warn(e, ice.ErrNotFound, data) {
|
||||
msg.Log_IMPORT(kit.MDB_VALUE, kit.Format(data))
|
||||
msg.Log_IMPORT(mdb.VALUE, kit.Format(data))
|
||||
msg.Optionv(ice.MSG_USERDATA, data)
|
||||
}
|
||||
kit.Fetch(data, func(key string, value interface{}) { msg.Optionv(key, value) })
|
||||
|
||||
switch d := data.(type) {
|
||||
case map[string]interface{}:
|
||||
for k, v := range d {
|
||||
msg.Optionv(k, v)
|
||||
}
|
||||
}
|
||||
default:
|
||||
r.ParseMultipartForm(kit.Int64(kit.Select("4096", r.Header.Get(ContentLength))))
|
||||
if r.ParseForm(); len(r.PostForm) > 0 {
|
||||
@ -157,7 +134,19 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
}
|
||||
}
|
||||
|
||||
// 请求参数
|
||||
// 请求地址
|
||||
msg.Option(ice.MSG_USERWEB, kit.Select(msg.Config(DOMAIN), kit.Select(r.Header.Get("X-Host"), r.Header.Get("Referer"))))
|
||||
msg.Option(ice.MSG_USERADDR, kit.Select(r.RemoteAddr, r.Header.Get(ice.MSG_USERADDR)))
|
||||
msg.Option(ice.MSG_USERIP, r.Header.Get(ice.MSG_USERIP))
|
||||
msg.Option(ice.MSG_USERUA, r.Header.Get("User-Agent"))
|
||||
msg.R, msg.W = r, w
|
||||
|
||||
// 会话别名
|
||||
if sessid := msg.Option(CookieName(msg.Option(ice.MSG_USERWEB))); sessid != "" {
|
||||
msg.Option(ice.MSG_SESSID, sessid)
|
||||
}
|
||||
|
||||
// 参数转换
|
||||
for k, v := range r.Form {
|
||||
if msg.IsCliUA() {
|
||||
for i, p := range v {
|
||||
@ -169,18 +158,17 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
}
|
||||
}
|
||||
|
||||
// 请求命令
|
||||
if msg.Option(ice.MSG_USERPOD, msg.Option(ice.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 p := strings.TrimPrefix(r.URL.Path, key); p != "" { // 地址命令
|
||||
msg.Optionv(ice.MSG_CMDS, strings.Split(p, ice.PS))
|
||||
}
|
||||
}
|
||||
|
||||
msg.Debug("what %v", msg.FormatMeta())
|
||||
// 执行命令
|
||||
msg.Option(ice.MSG_OUTPUT, "")
|
||||
msg.Option(ice.MSG_ARGS, kit.List())
|
||||
if cmds, ok := _serve_login(msg, key, kit.Simple(msg.Optionv(ice.MSG_CMDS)), w, r); ok {
|
||||
msg.Option(ice.MSG_OPTS, msg.Optionv(ice.MSG_OPTION))
|
||||
msg.Target().Cmd(msg, key, cmds...)
|
||||
msg.Target().Cmd(msg, key, cmds...) // 执行命令
|
||||
msg.Cost(kit.Format("%s %v %v", r.URL.Path, cmds, msg.FormatSize()))
|
||||
}
|
||||
|
||||
@ -188,48 +176,38 @@ func _serve_handle(key string, cmd *ice.Command, msg *ice.Message, w http.Respon
|
||||
Render(msg, msg.Option(ice.MSG_OUTPUT), msg.Optionv(ice.MSG_ARGS).([]interface{})...)
|
||||
}
|
||||
func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWriter, r *http.Request) ([]string, bool) {
|
||||
msg.Option(ice.MSG_USERROLE, aaa.VOID)
|
||||
msg.Option(ice.MSG_USERNAME, "")
|
||||
|
||||
msg.Debug("what %v", msg.FormatMeta())
|
||||
if msg.Option(ice.MSG_SESSID) != "" {
|
||||
aaa.SessCheck(msg, msg.Option(ice.MSG_SESSID))
|
||||
// 会话认证
|
||||
}
|
||||
aaa.SessCheck(msg, msg.Option(ice.MSG_SESSID)) // 会话认证
|
||||
|
||||
if msg.Option(ice.MSG_USERNAME) == "" && msg.Config(tcp.LOCALHOST) == ice.TRUE && tcp.IsLocalHost(msg, msg.Option(ice.MSG_USERIP)) {
|
||||
aaa.UserRoot(msg)
|
||||
// 主机认证
|
||||
aaa.UserRoot(msg) // 主机认证
|
||||
}
|
||||
|
||||
if _, ok := msg.Target().Commands[WEB_LOGIN]; ok {
|
||||
// 权限检查
|
||||
if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" {
|
||||
switch share := msg.Cmd(SHARE, msg.Option(SHARE)); share.Append(mdb.TYPE) {
|
||||
case LOGIN: // 共享认证
|
||||
msg.Option(ice.MSG_USERROLE, share.Append(aaa.USERROLE))
|
||||
msg.Option(ice.MSG_USERNAME, share.Append(aaa.USERNAME))
|
||||
case FIELD: // 共享认证
|
||||
msg.Option(ice.MSG_USERNAME, share.Append(aaa.USERNAME))
|
||||
msg.Option(ice.MSG_USERROLE, share.Append(aaa.USERROLE))
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := msg.Target().Commands[WEB_LOGIN]; ok { // 单点认证
|
||||
msg.Target().Cmd(msg, WEB_LOGIN, kit.Simple(key, cmds)...)
|
||||
return cmds, msg.Result(0) != ice.ErrWarn && msg.Result(0) != ice.FALSE
|
||||
}
|
||||
|
||||
if ls := strings.Split(r.URL.Path, "/"); msg.Config(kit.Keys(aaa.BLACK, ls[1])) == ice.TRUE {
|
||||
if ls := strings.Split(r.URL.Path, ice.PS); msg.Config(kit.Keys(aaa.BLACK, ls[1])) == ice.TRUE {
|
||||
return cmds, false // 黑名单
|
||||
} else if msg.Config(kit.Keys(aaa.WHITE, ls[1])) == ice.TRUE {
|
||||
if msg.Option(ice.MSG_USERNAME) == "" && msg.Option(SHARE) != "" {
|
||||
switch share := msg.Cmd(SHARE, msg.Option(SHARE)); share.Append(kit.MDB_TYPE) {
|
||||
case LOGIN:
|
||||
msg.Option(ice.MSG_USERNAME, share.Append(aaa.USERNAME))
|
||||
msg.Option(ice.MSG_USERROLE, share.Append(aaa.USERROLE))
|
||||
// Render(msg, aaa.SessCreate(msg, share.Append(aaa.USERNAME)))
|
||||
case FIELD:
|
||||
msg.Option(ice.MSG_USERNAME, share.Append(aaa.USERNAME))
|
||||
msg.Option(ice.MSG_USERROLE, share.Append(aaa.USERROLE))
|
||||
}
|
||||
}
|
||||
return cmds, true // 白名单
|
||||
}
|
||||
|
||||
if msg.Warn(msg.Option(ice.MSG_USERNAME) == "", ice.ErrNotLogin, r.URL.Path) {
|
||||
msg.Render(STATUS, http.StatusUnauthorized, ice.ErrNotLogin)
|
||||
return cmds, false // 未登录
|
||||
}
|
||||
if !msg.Right(r.URL.Path) {
|
||||
} else if !msg.Right(r.URL.Path) {
|
||||
msg.Render(STATUS, http.StatusForbidden, ice.ErrNotRight)
|
||||
return cmds, false // 未授权
|
||||
}
|
||||
@ -237,8 +215,8 @@ func _serve_login(msg *ice.Message, key string, cmds []string, w http.ResponseWr
|
||||
}
|
||||
func _serve_spide(m *ice.Message, prefix string, c *ice.Context) {
|
||||
for k := range c.Commands {
|
||||
if strings.HasPrefix(k, "/") {
|
||||
m.Push("path", path.Join(prefix, k)+kit.Select("", "/", strings.HasSuffix(k, "/")))
|
||||
if strings.HasPrefix(k, ice.PS) {
|
||||
m.Push(nfs.PATH, path.Join(prefix, k)+kit.Select("", ice.PS, strings.HasSuffix(k, ice.PS)))
|
||||
}
|
||||
}
|
||||
for k, v := range c.Contexts {
|
||||
@ -248,38 +226,51 @@ func _serve_spide(m *ice.Message, prefix string, c *ice.Context) {
|
||||
|
||||
const (
|
||||
WEB_LOGIN = "_login"
|
||||
SSO = "sso"
|
||||
|
||||
SSO = "sso"
|
||||
DOMAIN = "domain"
|
||||
INDEX = "index"
|
||||
)
|
||||
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, kit.MDB_FIELD, "time,status,name,port,dev",
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,status,name,port,dev",
|
||||
tcp.LOCALHOST, ice.TRUE, aaa.BLACK, kit.Dict(), aaa.WHITE, kit.Dict(
|
||||
LOGIN, ice.TRUE, SHARE, ice.TRUE, SPACE, ice.TRUE,
|
||||
ice.VOLCANOS, ice.TRUE, ice.PUBLISH, ice.TRUE,
|
||||
ice.INTSHELL, ice.TRUE, ice.REQUIRE, ice.TRUE,
|
||||
"help", ice.TRUE, "x", ice.TRUE,
|
||||
ice.HELP, ice.TRUE,
|
||||
), LOGHEADERS, ice.FALSE,
|
||||
|
||||
nfs.PATH, kit.Dict("/", ice.USR_VOLCANOS),
|
||||
ice.VOLCANOS, kit.Dict(nfs.PATH, ice.USR_VOLCANOS, kit.MDB_INDEX, "page/index.html",
|
||||
kit.SSH_REPOS, "https://shylinux.com/x/volcanos", kit.SSH_BRANCH, kit.SSH_MASTER,
|
||||
DOMAIN, "", nfs.PATH, kit.Dict(ice.PS, ice.USR_VOLCANOS),
|
||||
ice.VOLCANOS, kit.Dict(nfs.PATH, ice.USR_VOLCANOS, INDEX, "page/index.html",
|
||||
nfs.REPOS, "https://shylinux.com/x/volcanos", nfs.BRANCH, nfs.MASTER,
|
||||
), ice.PUBLISH, ice.USR_PUBLISH,
|
||||
|
||||
ice.INTSHELL, kit.Dict(nfs.PATH, ice.USR_INTSHELL, kit.MDB_INDEX, ice.INDEX_SH,
|
||||
kit.SSH_REPOS, "https://shylinux.com/x/intshell", kit.SSH_BRANCH, kit.SSH_MASTER,
|
||||
ice.INTSHELL, kit.Dict(nfs.PATH, ice.USR_INTSHELL, INDEX, ice.INDEX_SH,
|
||||
nfs.REPOS, "https://shylinux.com/x/intshell", nfs.BRANCH, nfs.MASTER,
|
||||
), ice.REQUIRE, ".ish/pluged",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(SERVE).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Done(value[kit.MDB_STATUS] == tcp.START)
|
||||
})
|
||||
}},
|
||||
SERVE: {Name: "serve name auto start spide", Help: "服务器", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
||||
if r.Method == SPIDE_GET && r.URL.Path == ice.PS {
|
||||
msg := m.Spawn(SERVE, w, r)
|
||||
repos := kit.Select(ice.INTSHELL, ice.VOLCANOS, strings.Contains(r.Header.Get("User-Agent"), "Mozilla/5.0"))
|
||||
Render(msg, ice.RENDER_DOWNLOAD, path.Join(msg.Config(kit.Keys(repos, nfs.PATH)), msg.Config(kit.Keys(repos, INDEX))))
|
||||
return true // 网站主页
|
||||
}
|
||||
return false
|
||||
})
|
||||
}},
|
||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(SERVE).Table(func(index int, value map[string]string, head []string) {
|
||||
m.Done(value[cli.STATUS] == tcp.START)
|
||||
})
|
||||
}},
|
||||
aaa.BLACK: {Name: "black", Help: "黑名单", Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, k := range arg {
|
||||
m.Log_CREATE(aaa.BLACK, k)
|
||||
@ -297,18 +288,18 @@ func init() {
|
||||
m.Option(tcp.PORT, m.Cmdx(tcp.PORT, aaa.RIGHT))
|
||||
}
|
||||
|
||||
m.Target().Start(m, m.OptionSimple(kit.MDB_NAME, tcp.HOST, tcp.PORT)...)
|
||||
m.Sleep(ice.MOD_TICK)
|
||||
m.Target().Start(m, m.OptionSimple(mdb.NAME, tcp.HOST, tcp.PORT)...)
|
||||
m.Sleep300ms()
|
||||
|
||||
m.Option(kit.MDB_NAME, "")
|
||||
m.Option(mdb.NAME, "")
|
||||
for _, k := range kit.Split(m.Option(ice.DEV)) {
|
||||
m.Cmd(SPACE, tcp.DIAL, ice.DEV, k, kit.MDB_NAME, ice.Info.NodeName)
|
||||
m.Cmd(SPACE, tcp.DIAL, ice.DEV, k, mdb.NAME, ice.Info.NodeName)
|
||||
}
|
||||
}},
|
||||
"spide": {Name: "spide", Help: "架构图", Hand: func(m *ice.Message, arg ...string) {
|
||||
if len(arg) == 0 { // 模块列表
|
||||
_serve_spide(m, "/", m.Target())
|
||||
m.Display("/plugin/story/spide.js", "root", ice.ICE, "prefix", "spide")
|
||||
_serve_spide(m, ice.PS, m.Target())
|
||||
m.StatusTimeCount()
|
||||
return
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func _share_link(m *ice.Message, p string, arg ...interface{}) string {
|
||||
func _share_repos(m *ice.Message, repos string, arg ...string) {
|
||||
prefix := kit.Path(m.Conf(SERVE, kit.Keym(ice.REQUIRE)))
|
||||
if _, e := os.Stat(path.Join(prefix, repos)); e != nil { // 克隆代码
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, kit.SSH_REPOS, "https://"+repos, nfs.PATH, path.Join(prefix, repos))
|
||||
m.Cmd("web.code.git.repos", mdb.CREATE, nfs.REPOS, "https://"+repos, nfs.PATH, path.Join(prefix, repos))
|
||||
}
|
||||
m.RenderDownload(path.Join(prefix, repos, path.Join(arg...)))
|
||||
}
|
||||
|
@ -16,15 +16,15 @@ import (
|
||||
)
|
||||
|
||||
func _space_link(m *ice.Message, pod string, arg ...interface{}) string {
|
||||
return tcp.ReplaceLocalhost(m, m.MergeURL2("/chat/pod/"+pod, arg...))
|
||||
return tcp.ReplaceLocalhost(m, kit.MergePOD(m.Option(ice.MSG_USERWEB), pod, arg...))
|
||||
}
|
||||
func _space_domain(m *ice.Message) (link string) {
|
||||
link = m.Config(kit.MDB_DOMAIN)
|
||||
link = m.Config(DOMAIN)
|
||||
if link == "" {
|
||||
link = m.Cmd(SPACE, ice.DEV, cli.PWD).Append(kit.MDB_LINK)
|
||||
link = m.Cmd(SPACE, ice.DEV, cli.PWD).Append(mdb.LINK)
|
||||
}
|
||||
if link == "" {
|
||||
link = m.Cmd(SPACE, ice.SHY, cli.PWD).Append(kit.MDB_LINK)
|
||||
link = m.Cmd(SPACE, ice.SHY, cli.PWD).Append(mdb.LINK)
|
||||
}
|
||||
if link == "" {
|
||||
link = m.Option(ice.MSG_USERWEB)
|
||||
@ -45,19 +45,20 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
|
||||
host := kit.Format(client[tcp.HOSTNAME])
|
||||
proto := strings.Replace(kit.Format(client[tcp.PROTOCOL]), "http", "ws", 1)
|
||||
uri := kit.MergeURL(proto+"://"+host+"/space/", kit.MDB_TYPE, ice.Info.NodeType, kit.MDB_NAME, name,
|
||||
uri := kit.MergeURL(proto+"://"+host+"/space/", mdb.TYPE, ice.Info.NodeType, mdb.NAME, name,
|
||||
SHARE, m.Conf(cli.RUNTIME, kit.Keys("conf.ctx_share")), RIVER, m.Conf(cli.RUNTIME, kit.Keys("conf.ctx_river")), arg)
|
||||
|
||||
m.Go(func() {
|
||||
u := kit.ParseURL(uri)
|
||||
redial := m.Configm("redial")
|
||||
redial := m.Configm(REDIAL)
|
||||
frame := m.Target().Server().(*Frame)
|
||||
|
||||
for i := 0; i >= 0 && i < kit.Int(redial["c"]); i++ {
|
||||
msg := m.Spawn()
|
||||
msg.Option(kit.Keycb(tcp.DIAL), func(s net.Conn) {
|
||||
ls := strings.Split(host, ":")
|
||||
msg.Cmd(tcp.CLIENT, tcp.DIAL, kit.SimpleKV("type,name,host,port", proto, dev, ls[0], kit.Select("443", ls, 1)), func(s net.Conn) {
|
||||
if s, _, e := websocket.NewClient(s, u, nil, kit.Int(redial["r"]), kit.Int(redial["w"])); !msg.Warn(e) {
|
||||
msg.Rich(SPACE, nil, kit.Dict(SOCKET, s, kit.MDB_TYPE, MASTER, kit.MDB_NAME, dev, kit.MDB_TEXT, host))
|
||||
msg.Rich(SPACE, nil, kit.Dict(SOCKET, s, kit.SimpleKV("", MASTER, dev, host)))
|
||||
msg.Log_CREATE(SPACE, dev, "retry", i, "uri", uri)
|
||||
|
||||
// 连接成功
|
||||
@ -66,8 +67,6 @@ func _space_dial(m *ice.Message, dev, name string, arg ...string) {
|
||||
}
|
||||
}
|
||||
})
|
||||
ls := strings.Split(host, ":")
|
||||
msg.Cmd(tcp.CLIENT, tcp.DIAL, kit.SimpleKV("type,name,host,port", proto, dev, ls[0], kit.Select("443", ls, 1)))
|
||||
|
||||
// 断线重连
|
||||
sleep := time.Duration(rand.Intn(kit.Int(redial["a"])*i+2)+kit.Int(redial["b"])) * time.Millisecond
|
||||
@ -86,17 +85,12 @@ func _space_handle(m *ice.Message, safe bool, send map[string]*ice.Message, c *w
|
||||
source := kit.Simple(msg.Optionv(ice.MSG_SOURCE), name)
|
||||
msg.Log("recv", "%v->%v %s %v", source, target, msg.Detailv(), msg.FormatMeta())
|
||||
|
||||
if len(target) == 0 { // 本地执行
|
||||
if len(target) == 0 {
|
||||
msg.Log_AUTH(aaa.USERROLE, msg.Option(ice.MSG_USERROLE), aaa.USERNAME, msg.Option(ice.MSG_USERNAME))
|
||||
if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe {
|
||||
if msg.Optionv(ice.MSG_HANDLE, ice.TRUE); safe { // 下行命令
|
||||
msg.Go(func() { _space_exec(msg, source, target, c, name) })
|
||||
} else {
|
||||
url := kit.ParseURL(_space_domain(msg))
|
||||
pod := url.Query().Get(ice.POD)
|
||||
if strings.HasPrefix(url.Path, "/chat/pod") {
|
||||
pod = strings.Split(url.Path, ice.PS)[3]
|
||||
}
|
||||
msg.Push(kit.MDB_LINK, kit.MergeURL2(url.String(), "/chat/pod/"+kit.Keys(pod, name), ice.POD, ""))
|
||||
} else { // 上行请求
|
||||
msg.Push(mdb.LINK, kit.MergePOD(_space_domain(msg), name))
|
||||
_space_echo(msg, []string{}, kit.Revert(source)[1:], c, name)
|
||||
}
|
||||
|
||||
@ -179,9 +173,8 @@ func _space_send(m *ice.Message, space string, arg ...string) {
|
||||
// 下发命令
|
||||
_space_echo(m.Set(ice.MSG_DETAIL, arg...), []string{id}, target[1:], socket, target[0])
|
||||
|
||||
m.Option("timeout", m.Config("timeout.c"))
|
||||
m.Call(m.Option("_async") == "", func(res *ice.Message) *ice.Message {
|
||||
// 返回结果
|
||||
m.Option(TIMEOUT, m.Config(kit.Keys(TIMEOUT, "c")))
|
||||
m.Call(m.Option("_async") == "", func(res *ice.Message) *ice.Message { // 返回结果
|
||||
if delete(frame.send, id); res != nil && m != nil {
|
||||
return m.Cost(kit.Format("[%v]->%v %v %v", id, target, arg, m.Copy(res).FormatSize()))
|
||||
}
|
||||
@ -191,34 +184,28 @@ func _space_send(m *ice.Message, space string, arg ...string) {
|
||||
}) == nil, ice.ErrNotFound, space)
|
||||
}
|
||||
func _space_search(m *ice.Message, kind, name, text string, arg ...string) {
|
||||
m.Richs(SPACE, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); !strings.Contains(kit.Format(value[kit.MDB_NAME]), name) {
|
||||
m.Richs(SPACE, nil, mdb.FOREACH, func(key string, value map[string]interface{}) {
|
||||
if value = kit.GetMeta(value); !strings.Contains(kit.Format(value[mdb.NAME]), name) {
|
||||
return
|
||||
}
|
||||
|
||||
switch value[kit.MDB_TYPE] {
|
||||
switch value[mdb.TYPE] {
|
||||
case CHROME:
|
||||
|
||||
case MASTER:
|
||||
m.PushSearch(ice.CMD, SPACE, kit.MDB_TYPE, value[kit.MDB_TYPE], kit.MDB_NAME, value[kit.MDB_NAME],
|
||||
kit.MDB_TEXT, m.Cmd(SPIDE, value[kit.MDB_NAME], ice.OptionFields("client.url")).Append("client.url"), value)
|
||||
|
||||
m.PushSearch(mdb.TEXT, m.Cmd(SPIDE, value[mdb.NAME]).Append("client.url"), value)
|
||||
default:
|
||||
m.PushSearch(ice.CMD, SPACE, kit.MDB_TYPE, value[kit.MDB_TYPE], kit.MDB_NAME, value[kit.MDB_NAME],
|
||||
kit.MDB_TEXT, _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[kit.MDB_NAME])), value)
|
||||
m.PushSearch(mdb.TEXT, _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[mdb.NAME])), value)
|
||||
}
|
||||
})
|
||||
|
||||
if name == "" {
|
||||
port := m.Cmd(SERVE, ice.Option{mdb.FIELDS, tcp.PORT}).Append(tcp.PORT)
|
||||
if port == "" {
|
||||
return
|
||||
}
|
||||
m.Cmd(tcp.HOST).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushSearch(ice.CMD, SPACE, kit.MDB_TYPE, MYSELF, kit.MDB_NAME, value[kit.MDB_NAME],
|
||||
kit.MDB_TEXT, kit.Format("http://%s:%s", value[aaa.IP], port))
|
||||
})
|
||||
if name != "" {
|
||||
return
|
||||
}
|
||||
m.Cmd(SERVE).Table(func(index int, val map[string]string, head []string) {
|
||||
m.Cmd(tcp.HOST).Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushSearch(kit.SimpleKV("", MYSELF, value[mdb.NAME], kit.Format("http://%s:%s", value[aaa.IP], val[tcp.PORT])))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const (
|
||||
@ -232,36 +219,48 @@ const (
|
||||
SPACE_START = "space.start"
|
||||
SPACE_STOP = "space.stop"
|
||||
|
||||
SOCKET = "socket"
|
||||
SOCKET = "socket"
|
||||
BUFFER = "buffer"
|
||||
REDIAL = "redial"
|
||||
TIMEOUT = "timeout"
|
||||
)
|
||||
const SPACE = "space"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
SPACE: {Name: SPACE, Help: "空间站", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,type,name,text",
|
||||
"redial", kit.Dict("a", 3000, "b", 1000, "c", 1000, "r", ice.MOD_BUFS, "w", ice.MOD_BUFS),
|
||||
"timeout", kit.Dict("c", "180s"),
|
||||
mdb.SHORT, mdb.NAME, mdb.FIELD, "time,type,name,text",
|
||||
BUFFER, kit.Dict("r", ice.MOD_BUFS, "w", ice.MOD_BUFS),
|
||||
REDIAL, kit.Dict("a", 3000, "b", 1000, "c", 1000), TIMEOUT, kit.Dict("c", "180s"),
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Conf(SPACE, kit.MDB_HASH, "")
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, SPACE, m.Prefix(SPACE))
|
||||
}},
|
||||
SPACE: {Name: "space name cmd auto", Help: "空间站", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
tcp.DIAL: {Name: "dial dev=ops name river", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
_space_dial(m, m.Option(ice.DEV), kit.Select(ice.Info.NodeName, m.Option(kit.MDB_NAME)))
|
||||
SPACE: {Name: "space name cmd auto invite", Help: "空间站", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(mdb.SEARCH, mdb.CREATE, SPACE, m.PrefixKey())
|
||||
m.Conf(SPACE, mdb.HASH, "")
|
||||
}},
|
||||
mdb.SEARCH: {Name: "search type name text", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
||||
_space_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
}},
|
||||
aaa.INVITE: {Name: "invite", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, k := range []string{ice.MISC, ice.CORE, ice.BASE} {
|
||||
m.Cmdy("web.code.publish", ice.CONTEXTS, k)
|
||||
}
|
||||
|
||||
m.EchoScript("shell", "# 共享环境", m.Option(ice.MSG_USERWEB))
|
||||
m.EchoAnchor(m.Option(ice.MSG_USERWEB)).Echo(ice.NL)
|
||||
m.EchoQRCode(m.Option(ice.MSG_USERWEB))
|
||||
}},
|
||||
tcp.DIAL: {Name: "dial dev=ops name", Help: "连接", Hand: func(m *ice.Message, arg ...string) {
|
||||
_space_dial(m, m.Option(ice.DEV), kit.Select(ice.Info.NodeName, m.Option(mdb.NAME)))
|
||||
}},
|
||||
}, mdb.HashAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) < 2 { // 节点列表
|
||||
if mdb.HashSelect(m, arg...); len(arg) == 0 {
|
||||
m.Table(func(index int, value map[string]string, head []string) {
|
||||
m.PushAnchor(value[kit.MDB_NAME], _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[kit.MDB_NAME])))
|
||||
m.PushAnchor(value[mdb.NAME], _space_link(m, kit.Keys(m.Option(ice.MSG_USERPOD), value[mdb.NAME])))
|
||||
})
|
||||
m.SortStrR(kit.MDB_NAME)
|
||||
m.SortStrR(mdb.NAME)
|
||||
}
|
||||
return
|
||||
}
|
||||
@ -271,28 +270,24 @@ func init() {
|
||||
"/space/": {Name: "/space/ type name share river", Help: "空间站", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if s, e := websocket.Upgrade(m.W, m.R, nil, kit.Int(m.Config("buffer.r")), kit.Int(m.Config("buffer.w"))); m.Assert(e) {
|
||||
text := kit.Select(s.RemoteAddr().String(), m.Option(ice.MSG_USERADDR))
|
||||
name := kit.Select(text, m.Option(kit.MDB_NAME))
|
||||
name = m.Option(kit.MDB_NAME, strings.Replace(name, ".", "_", -1))
|
||||
name = m.Option(kit.MDB_NAME, strings.Replace(name, ":", "-", -1))
|
||||
kind := kit.Select(WORKER, m.Option(kit.MDB_TYPE))
|
||||
|
||||
// 添加节点
|
||||
args := append([]string{kit.MDB_TYPE, kind, kit.MDB_NAME, name}, m.OptionSimple(SHARE, RIVER)...)
|
||||
h := m.Rich(SPACE, nil, kit.Dict(SOCKET, s, kit.MDB_TEXT, text, args))
|
||||
m.Log_CREATE(SPACE, name, "type", kind)
|
||||
name := m.Option(mdb.NAME, kit.ReplaceAll(kit.Select(text, m.Option(mdb.NAME)), ".", "_", ":", "_"))
|
||||
kind := kit.Select(WORKER, m.Option(mdb.TYPE))
|
||||
args := append([]string{mdb.TYPE, kind, mdb.NAME, name}, m.OptionSimple(SHARE, RIVER)...)
|
||||
|
||||
m.Go(func() {
|
||||
defer m.Confv(SPACE, kit.Keys(kit.MDB_HASH, h), "")
|
||||
h := m.Rich(SPACE, nil, kit.Dict(SOCKET, s, mdb.TEXT, text, args))
|
||||
defer m.Confv(SPACE, kit.Keys(mdb.HASH, h), "")
|
||||
m.Log_CREATE(SPACE, name, mdb.TYPE, kind)
|
||||
|
||||
switch kind {
|
||||
case CHROME: // 交互节点
|
||||
m.Go(func(msg *ice.Message) {
|
||||
switch m.Option("cmd") {
|
||||
switch m.Option(ice.CMD) {
|
||||
case cli.PWD:
|
||||
link := kit.MergeURL(_space_domain(msg), "grant", name)
|
||||
msg.Sleep("100ms").Cmd(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link))
|
||||
link := kit.MergeURL(_space_domain(msg), aaa.GRANT, name)
|
||||
msg.Sleep300ms(SPACE, name, cli.PWD, name, link, msg.Cmdx(cli.QRCODE, link))
|
||||
default:
|
||||
msg.Sleep("100ms").Cmd(SPACE, name, cli.PWD, name)
|
||||
msg.Sleep300ms(SPACE, name, cli.PWD, name)
|
||||
}
|
||||
})
|
||||
case WORKER: // 工作节点
|
||||
@ -303,8 +298,7 @@ func init() {
|
||||
defer m.Event(SPACE_STOP, args...)
|
||||
}
|
||||
|
||||
frame := c.Server().(*Frame)
|
||||
_space_handle(m, false, frame.send, s, name)
|
||||
_space_handle(m, false, c.Server().(*Frame).send, s, name)
|
||||
})
|
||||
}
|
||||
}},
|
||||
|
@ -149,7 +149,6 @@ const (
|
||||
PREV = "prev"
|
||||
DATA = "data"
|
||||
|
||||
INDEX = "index"
|
||||
HISTORY = "history"
|
||||
|
||||
PULL = "pull"
|
||||
|
@ -6,22 +6,24 @@ import (
|
||||
"path"
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/tcp"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
type Frame struct {
|
||||
*ice.Message
|
||||
*http.Client
|
||||
*http.Server
|
||||
*http.ServeMux
|
||||
m *ice.Message
|
||||
|
||||
send map[string]*ice.Message
|
||||
}
|
||||
|
||||
func (web *Frame) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if _serve_main(web.m, w, r) {
|
||||
if _serve_main(web.Message, w, r) {
|
||||
web.ServeMux.ServeHTTP(w, r)
|
||||
}
|
||||
}
|
||||
@ -34,36 +36,37 @@ func (web *Frame) Begin(m *ice.Message, arg ...string) ice.Server {
|
||||
}
|
||||
func (web *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
m.Travel(func(p *ice.Context, s *ice.Context) {
|
||||
if w, ok := s.Server().(*Frame); ok {
|
||||
if w.ServeMux != nil {
|
||||
if frame, ok := s.Server().(*Frame); ok {
|
||||
if frame.ServeMux != nil {
|
||||
return
|
||||
}
|
||||
w.ServeMux = http.NewServeMux()
|
||||
frame.ServeMux = http.NewServeMux()
|
||||
|
||||
// 静态路由
|
||||
msg := m.Spawn(s)
|
||||
m.Confm(SERVE, kit.META_PATH, func(key string, value string) {
|
||||
m.Log("route", "%s <- %s <- %s", s.Name, key, value)
|
||||
w.Handle(key, http.StripPrefix(key, http.FileServer(http.Dir(value))))
|
||||
m.Confm(SERVE, kit.Keym(nfs.PATH), func(key string, value string) {
|
||||
m.Log(ROUTE, "%s <- %s <- %s", s.Name, key, value)
|
||||
frame.Handle(key, http.StripPrefix(key, http.FileServer(http.Dir(value))))
|
||||
})
|
||||
|
||||
// 级联路由
|
||||
route := "/" + s.Name + "/"
|
||||
if f, ok := p.Server().(*Frame); ok && f.ServeMux != nil {
|
||||
msg.Log("route", "%s <= %s", p.Name, route)
|
||||
f.Handle(route, http.StripPrefix(path.Dir(route), w))
|
||||
if pframe, ok := p.Server().(*Frame); ok && pframe.ServeMux != nil {
|
||||
route := ice.PS + s.Name + ice.PS
|
||||
msg.Log(ROUTE, "%s <= %s", p.Name, route)
|
||||
pframe.Handle(route, http.StripPrefix(path.Dir(route), frame))
|
||||
}
|
||||
|
||||
// 命令路由
|
||||
m.Travel(func(p *ice.Context, sub *ice.Context, k string, x *ice.Command) {
|
||||
if s == sub && k[0] == '/' {
|
||||
msg.Log("route", "%s <- %s", s.Name, k)
|
||||
w.HandleFunc(k, func(w http.ResponseWriter, r *http.Request) {
|
||||
m.TryCatch(msg.Spawn(), true, func(msg *ice.Message) {
|
||||
_serve_handle(k, x, msg, w, r)
|
||||
})
|
||||
})
|
||||
if s != sub || k[0] != '/' {
|
||||
return
|
||||
}
|
||||
msg.Log(ROUTE, "%s <- %s", s.Name, k)
|
||||
frame.HandleFunc(k, func(frame http.ResponseWriter, r *http.Request) {
|
||||
m.TryCatch(msg.Spawn(), true, func(msg *ice.Message) {
|
||||
_serve_handle(k, x, msg, frame, r)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -71,41 +74,34 @@ func (web *Frame) Start(m *ice.Message, arg ...string) bool {
|
||||
m.Event(SERVE_START)
|
||||
defer m.Event(SERVE_STOP)
|
||||
|
||||
web.m, web.Server = m, &http.Server{Handler: web}
|
||||
web.Message, web.Server = m, &http.Server{Handler: web}
|
||||
switch cb := m.Optionv(kit.Keycb(SERVE)).(type) {
|
||||
case func(http.Handler):
|
||||
cb(web)
|
||||
return true
|
||||
cb(web) // 启动框架
|
||||
default:
|
||||
m.Cmd(tcp.SERVER, tcp.LISTEN, mdb.TYPE, WEB, m.OptionSimple(mdb.NAME, tcp.HOST, tcp.PORT), func(l net.Listener) {
|
||||
m.Cmdy(mdb.INSERT, SERVE, "", mdb.HASH, arg, m.OptionSimple(tcp.PROTO, ice.DEV), cli.STATUS, tcp.START)
|
||||
defer m.Cmd(mdb.MODIFY, SERVE, "", mdb.HASH, m.OptionSimple(mdb.NAME), cli.STATUS, tcp.STOP)
|
||||
m.Warn(web.Server.Serve(l)) // 启动服务
|
||||
})
|
||||
}
|
||||
|
||||
m.Option(kit.Keycb(tcp.LISTEN), func(l net.Listener) {
|
||||
m.Cmdy(mdb.INSERT, SERVE, "", mdb.HASH, arg, kit.MDB_STATUS, tcp.START, kit.MDB_PROTO, m.Option(kit.MDB_PROTO), ice.DEV, m.Option(ice.DEV))
|
||||
defer m.Cmd(mdb.MODIFY, SERVE, "", mdb.HASH, kit.MDB_NAME, m.Option(kit.MDB_NAME), kit.MDB_STATUS, tcp.STOP)
|
||||
|
||||
// 启动服务
|
||||
m.Warn(web.Server.Serve(l))
|
||||
})
|
||||
|
||||
m.Cmd(tcp.SERVER, tcp.LISTEN, kit.MDB_TYPE, WEB, kit.MDB_NAME, m.Option(kit.MDB_NAME),
|
||||
tcp.HOST, m.Option(tcp.HOST), tcp.PORT, m.Option(tcp.PORT))
|
||||
return true
|
||||
}
|
||||
func (web *Frame) Close(m *ice.Message, arg ...string) bool {
|
||||
m.Done(true)
|
||||
return true
|
||||
return m.Done(true)
|
||||
}
|
||||
|
||||
const WEB = "web"
|
||||
const (
|
||||
SERVE_START = "serve.start"
|
||||
SERVE_STOP = "serve.stop"
|
||||
)
|
||||
const WEB = "web"
|
||||
|
||||
var Index = &ice.Context{Name: WEB, Help: "网络模块"}
|
||||
|
||||
func init() {
|
||||
ice.Index.Register(Index, &Frame{},
|
||||
SPIDE, CACHE, STORY, ROUTE,
|
||||
SHARE, SERVE, SPACE, DREAM,
|
||||
SERVE, SPACE, DREAM, ROUTE,
|
||||
SHARE, SPIDE, CACHE, STORY,
|
||||
)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
chapter "web"
|
||||
label "web" `
|
||||
spide cache story route
|
||||
share serve space dream
|
||||
route spide cache story
|
||||
`
|
||||
|
||||
field "蜘蛛侠" web.spide
|
||||
|
@ -75,7 +75,7 @@ field "{{.Option "help"}}" {{.Option "key"}}
|
||||
m.Cmd(nfs.DEFS, dir, string(buf))
|
||||
}
|
||||
func _autogen_source(m *ice.Message, zone, name string) {
|
||||
m.Cmd(nfs.PUSH, ice.SRC_MAIN_SHY, ice.NL, kit.SSH_SOURCE+ice.SP+path.Join(zone, kit.Keys(name, SHY)), ice.NL)
|
||||
m.Cmd(nfs.PUSH, ice.SRC_MAIN_SHY, ice.NL, nfs.SOURCE+ice.SP+path.Join(zone, kit.Keys(name, SHY)), ice.NL)
|
||||
}
|
||||
func _autogen_mod(m *ice.Message, file string) (mod string) {
|
||||
m.Cmd(nfs.DEFS, ice.GO_MOD, kit.Format(`module %s
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@ -11,6 +12,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -77,6 +79,14 @@ const BINPACK = "binpack"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
BINPACK: {Name: "binpack path auto create remove export", Help: "打包", Action: map[string]*ice.Action{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, arg ...string) {
|
||||
web.AddRewrite(func(w http.ResponseWriter, r *http.Request) bool {
|
||||
if ice.Dump(w, r.URL.Path, func(name string) { web.RenderType(w, name, "") }) {
|
||||
return true // 打包文件
|
||||
}
|
||||
return false
|
||||
})
|
||||
}},
|
||||
mdb.CREATE: {Name: "create", Help: "创建", Hand: func(m *ice.Message, arg ...string) {
|
||||
if pack, p, e := kit.Create(ice.SRC_BINPACK_GO); m.Assert(e) {
|
||||
defer pack.Close()
|
||||
|
@ -67,7 +67,7 @@ func init() {
|
||||
}
|
||||
|
||||
// 编译成功
|
||||
m.Log_EXPORT(cli.SOURCE, main, cli.TARGET, file)
|
||||
m.Log_EXPORT(nfs.SOURCE, main, nfs.TARGET, file)
|
||||
m.Cmdy(nfs.DIR, file, "time,path,size,link,action")
|
||||
m.Cmdy(PUBLISH, mdb.CREATE, ice.BIN_ICE_SH)
|
||||
m.Cmdy(PUBLISH, ice.CONTEXTS, ice.CORE)
|
||||
|
@ -173,7 +173,7 @@ func init() {
|
||||
cli.START: {Name: "start link cmd", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
_install_start(m, arg...)
|
||||
}},
|
||||
cli.SOURCE: {Name: "source link path", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
nfs.SOURCE: {Name: "source link path", Help: "源码", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(nfs.DIR_ROOT, path.Join(m.Config(nfs.PATH), kit.TrimExt(m.Option(kit.MDB_LINK)), "_install"))
|
||||
defer m.StatusTime(nfs.PATH, m.Option(nfs.DIR_ROOT))
|
||||
m.Cmdy(nfs.DIR, m.Option(nfs.PATH))
|
||||
@ -197,13 +197,13 @@ func init() {
|
||||
func InstallAction(fields ...string) map[string]*ice.Action {
|
||||
return ice.SelectAction(map[string]*ice.Action{
|
||||
web.DOWNLOAD: {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, web.DOWNLOAD, m.Config(cli.SOURCE))
|
||||
m.Cmdy(INSTALL, web.DOWNLOAD, m.Config(nfs.SOURCE))
|
||||
}},
|
||||
cli.BUILD: {Name: "build", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, cli.BUILD, m.Config(cli.SOURCE))
|
||||
m.Cmdy(INSTALL, cli.BUILD, m.Config(nfs.SOURCE))
|
||||
}},
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, cli.ORDER, m.Config(cli.SOURCE), "_install/bin")
|
||||
m.Cmdy(INSTALL, cli.ORDER, m.Config(nfs.SOURCE), "_install/bin")
|
||||
}},
|
||||
}, fields...)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -41,12 +42,12 @@ func init() {
|
||||
}, PlugAction())},
|
||||
NODE: {Name: "node auto download", Help: "前端", Action: map[string]*ice.Action{
|
||||
web.DOWNLOAD: {Name: "download", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(INSTALL, m.Config(cli.SOURCE))
|
||||
m.Cmdy(INSTALL, m.Config(nfs.SOURCE))
|
||||
}},
|
||||
}},
|
||||
}, Configs: map[string]*ice.Config{
|
||||
NODE: {Name: NODE, Help: "前端", Value: kit.Data(
|
||||
cli.SOURCE, "https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz",
|
||||
nfs.SOURCE, "https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.xz",
|
||||
)},
|
||||
JS: {Name: JS, Help: "js", Value: kit.Data(PLUG, kit.Dict(
|
||||
SPLIT, kit.Dict("space", " \t", "operator", "{[(&.,;!|<>)]}"),
|
||||
|
@ -3,6 +3,7 @@ package code
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -11,7 +12,7 @@ const PYTHON = "python"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
PYTHON: {Name: PYTHON, Help: "脚本命令", Value: kit.Data(
|
||||
cli.SOURCE, "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
||||
nfs.SOURCE, "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
||||
PYTHON, "python", "pip", "pip",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
@ -23,7 +24,7 @@ func init() {
|
||||
m.Cmdy(cli.SYSTEM, m.Config("pip"), "install", arg)
|
||||
}},
|
||||
}, InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(INSTALL, cli.SOURCE, m.Config(cli.SOURCE), arg)
|
||||
m.Cmdy(INSTALL, nfs.SOURCE, m.Config(nfs.SOURCE), arg)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ func init() {
|
||||
kit.MDB_TYPE, "bin", nfs.FILE, "ice.sh", nfs.PATH, ice.BIN_ICE_SH,
|
||||
kit.MDB_TYPE, "bin", nfs.FILE, "ice.bin", nfs.PATH, ice.BIN_ICE_BIN,
|
||||
)),
|
||||
cli.SOURCE, kit.Dict(kit.MDB_LIST, kit.List(
|
||||
nfs.SOURCE, kit.Dict(kit.MDB_LIST, kit.List(
|
||||
kit.MDB_TYPE, "txt", nfs.FILE, "main.go", nfs.PATH, ice.SRC_MAIN_GO,
|
||||
kit.MDB_TYPE, "txt", nfs.FILE, "miss.sh", nfs.PATH, ice.ETC_MISS_SH,
|
||||
kit.MDB_TYPE, "txt", nfs.FILE, "go.mod", nfs.PATH, ice.GO_MOD,
|
||||
|
14
exec.go
14
exec.go
@ -50,15 +50,17 @@ func (m *Message) Assert(expr interface{}) bool {
|
||||
m.Result(ErrPanic, expr)
|
||||
panic(expr)
|
||||
}
|
||||
func (m *Message) Sleep(d string) *Message {
|
||||
func (m *Message) Sleep(d string, arg ...interface{}) *Message {
|
||||
m.Debug("sleep %s %s", d, kit.FileLine(2, 3))
|
||||
time.Sleep(kit.Duration(d))
|
||||
if time.Sleep(kit.Duration(d)); len(arg) > 0 {
|
||||
m.Cmdy(arg...)
|
||||
}
|
||||
return m
|
||||
}
|
||||
func (m *Message) Sleep300ms() *Message { return m.Sleep("30ms") }
|
||||
func (m *Message) Sleep30ms() *Message { return m.Sleep("30ms") }
|
||||
func (m *Message) Sleep3s() *Message { return m.Sleep("3s") }
|
||||
func (m *Message) Sleep30s() *Message { return m.Sleep("30s") }
|
||||
func (m *Message) Sleep300ms(arg ...interface{}) *Message { return m.Sleep("300ms", arg...) }
|
||||
func (m *Message) Sleep30ms(arg ...interface{}) *Message { return m.Sleep("30ms", arg...) }
|
||||
func (m *Message) Sleep3s(arg ...interface{}) *Message { return m.Sleep("3s", arg...) }
|
||||
func (m *Message) Sleep30s(arg ...interface{}) *Message { return m.Sleep("30s", arg...) }
|
||||
func (m *Message) Hold(n int) *Message {
|
||||
for ctx := m.target; ctx != nil; ctx = ctx.context {
|
||||
if ctx.wg != nil {
|
||||
|
3
misc.go
3
misc.go
@ -156,6 +156,9 @@ func (m *Message) AppendTrans(cb func(value string, key string, index int) strin
|
||||
func (m *Message) MergeURL2(url string, arg ...interface{}) string {
|
||||
return kit.MergeURL2(m.Option(MSG_USERWEB), url, arg...)
|
||||
}
|
||||
func (m *Message) MergePOD(name string, arg ...interface{}) string {
|
||||
return kit.MergePOD(m.Option(MSG_USERWEB), name, arg...)
|
||||
}
|
||||
|
||||
func (m *Message) cmd(arg ...interface{}) *Message {
|
||||
opts := map[string]interface{}{}
|
||||
|
@ -61,7 +61,7 @@ const ALPHA = "alpha"
|
||||
|
||||
var Index = &ice.Context{Name: ALPHA, Help: "英汉词典", Configs: map[string]*ice.Config{
|
||||
ALPHA: {Name: ALPHA, Help: "英汉词典", Value: kit.Data(
|
||||
kit.SSH_REPOS, "word-dict", kit.MDB_FIELD, "word,translation,definition",
|
||||
nfs.REPOS, "word-dict", kit.MDB_FIELD, "word,translation,definition",
|
||||
kit.MDB_STORE, path.Join(ice.USR_LOCAL_EXPORT, ALPHA), kit.MDB_FSIZE, "300000",
|
||||
kit.MDB_LIMIT, "50000", kit.MDB_LEAST, "1000",
|
||||
)},
|
||||
|
@ -3,6 +3,7 @@ package bash
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -12,15 +13,15 @@ const BASH = "bash"
|
||||
|
||||
var Index = &ice.Context{Name: BASH, Help: "命令行", Configs: map[string]*ice.Config{
|
||||
BASH: {Name: BASH, Help: "命令行", Value: kit.Data(
|
||||
cli.SOURCE, "http://mirrors.tencent.com/macports/distfiles/bash/5.1_1/bash-5.1.tar.gz",
|
||||
nfs.SOURCE, "http://mirrors.tencent.com/macports/distfiles/bash/5.1_1/bash-5.1.tar.gz",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
BASH: {Name: "bash path auto order build download", Help: "命令行", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(cli.SOURCE), "_install/bin")
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(nfs.SOURCE), "_install/bin")
|
||||
}},
|
||||
}, code.InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.SOURCE, m.Config(cli.SOURCE), arg)
|
||||
m.Cmdy(code.INSTALL, nfs.SOURCE, m.Config(nfs.SOURCE), arg)
|
||||
}},
|
||||
}}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package bash
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
@ -12,15 +13,15 @@ const ZSH = "zsh"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
ZSH: {Name: ZSH, Help: "命令行", Value: kit.Data(
|
||||
cli.SOURCE, "https://nchc.dl.sourceforge.net/project/zsh/zsh/5.8/zsh-5.8.tar.xz",
|
||||
nfs.SOURCE, "https://nchc.dl.sourceforge.net/project/zsh/zsh/5.8/zsh-5.8.tar.xz",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
ZSH: {Name: "zsh path auto order build download", Help: "命令行", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(cli.SOURCE), "_install/bin")
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(nfs.SOURCE), "_install/bin")
|
||||
}},
|
||||
}, code.InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.SOURCE, m.Config(cli.SOURCE), arg)
|
||||
m.Cmdy(code.INSTALL, nfs.SOURCE, m.Config(nfs.SOURCE), arg)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -23,7 +24,7 @@ var Index = &ice.Context{Name: CHROME, Help: "浏览器", Configs: map[string]*i
|
||||
})
|
||||
}},
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(cli.SOURCE), "_install/bin")
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(nfs.SOURCE), "_install/bin")
|
||||
}},
|
||||
}, code.InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(web.SPACE, CHROME, CHROME, arg)
|
||||
|
@ -3,6 +3,7 @@ package git
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -12,16 +13,16 @@ const GIT = "git"
|
||||
|
||||
var Index = &ice.Context{Name: GIT, Help: "代码库", Configs: map[string]*ice.Config{
|
||||
GIT: {Name: GIT, Help: "代码库", Value: kit.Data(
|
||||
cli.SOURCE, "http://mirrors.tencent.com/macports/distfiles/git-cinnabar/git-2.31.1.tar.gz",
|
||||
nfs.SOURCE, "http://mirrors.tencent.com/macports/distfiles/git-cinnabar/git-2.31.1.tar.gz",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
GIT: {Name: "git path auto order build download", Help: "代码库", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmd(code.INSTALL, cli.ORDER, m.Config(cli.SOURCE), "_install/bin")
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(cli.SOURCE), "_install/libexec/git-core")
|
||||
m.Cmd(code.INSTALL, cli.ORDER, m.Config(nfs.SOURCE), "_install/bin")
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, m.Config(nfs.SOURCE), "_install/libexec/git-core")
|
||||
}},
|
||||
}, code.InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.SOURCE, m.Config(cli.SOURCE), arg)
|
||||
m.Cmdy(code.INSTALL, nfs.SOURCE, m.Config(nfs.SOURCE), arg)
|
||||
}},
|
||||
}}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/mdb"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
)
|
||||
|
||||
@ -14,7 +15,7 @@ func init() {
|
||||
Index.Merge(&ice.Context{Configs: map[string]*ice.Config{
|
||||
WUBI: {Name: WUBI, Help: "输入法", Value: kit.Data(
|
||||
kit.MDB_STORE, path.Join(ice.USR_LOCAL_EXPORT, INPUT, WUBI), kit.MDB_FSIZE, "200000",
|
||||
kit.MDB_SHORT, "zone", kit.SSH_REPOS, "wubi-dict",
|
||||
kit.MDB_SHORT, "zone", nfs.REPOS, "wubi-dict",
|
||||
kit.MDB_LIMIT, "5000", kit.MDB_LEAST, "1000",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
|
@ -138,7 +138,7 @@ func _ssh_conn(m *ice.Message, cb func(*ssh.Client), arg ...string) {
|
||||
return m.Option(aaa.PASSWORD), nil
|
||||
}))
|
||||
|
||||
m.Option(kit.Keycb(tcp.DIAL), func(c net.Conn) {
|
||||
m.Option(kit.Keycb(tcp.CLIENT), func(c net.Conn) {
|
||||
conn, chans, reqs, err := ssh.NewClientConn(c, m.Option(tcp.HOST)+":"+m.Option(tcp.PORT), &ssh.ClientConfig{
|
||||
User: m.Option(aaa.USERNAME), Auth: methods, BannerCallback: func(message string) error { return nil },
|
||||
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil },
|
||||
|
@ -123,7 +123,7 @@ func init() {
|
||||
m.Cmd(SERVICE, mdb.IMPORT, AUTHKEY, m.Option(AUTHKEY))
|
||||
}
|
||||
|
||||
m.Option(kit.Keycb(tcp.LISTEN), func(c net.Conn) { m.Go(func() { _ssh_accept(m, kit.Hashs(m.Option(tcp.PORT)), c) }) })
|
||||
m.Option(kit.Keycb(tcp.SERVER), func(c net.Conn) { m.Go(func() { _ssh_accept(m, kit.Hashs(m.Option(tcp.PORT)), c) }) })
|
||||
m.Go(func() {
|
||||
m.Cmdy(tcp.SERVER, tcp.LISTEN, kit.MDB_TYPE, SSH, kit.MDB_NAME, tcp.PORT, tcp.PORT, m.Option(tcp.PORT))
|
||||
})
|
||||
|
@ -3,6 +3,7 @@ package tmux
|
||||
import (
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -12,7 +13,7 @@ const TMUX = "tmux"
|
||||
|
||||
var Index = &ice.Context{Name: TMUX, Help: "工作台", Configs: map[string]*ice.Config{
|
||||
TMUX: {Name: TMUX, Help: "工作台", Value: kit.Data(
|
||||
cli.SOURCE, "http://mirrors.tencent.com/macports/distfiles/tmux/tmux-3.2.tar.gz",
|
||||
nfs.SOURCE, "http://mirrors.tencent.com/macports/distfiles/tmux/tmux-3.2.tar.gz",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
TMUX: {Name: "tmux path auto start order build download", Help: "服务", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
@ -20,10 +21,10 @@ var Index = &ice.Context{Name: TMUX, Help: "工作台", Configs: map[string]*ice
|
||||
m.Optionv(code.PREPARE, func(p string) []string {
|
||||
return []string{"-S", kit.Path(m.Option(cli.CMD_DIR, p), "tmux.socket"), "new-session", "-dn", "miss"}
|
||||
})
|
||||
m.Cmdy(code.INSTALL, cli.START, m.Config(cli.SOURCE), "bin/tmux")
|
||||
m.Cmdy(code.INSTALL, cli.START, m.Config(nfs.SOURCE), "bin/tmux")
|
||||
}},
|
||||
}, code.InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.SOURCE, m.Config(cli.SOURCE), arg)
|
||||
m.Cmdy(code.INSTALL, nfs.SOURCE, m.Config(nfs.SOURCE), arg)
|
||||
}},
|
||||
}}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
ice "shylinux.com/x/icebergs"
|
||||
"shylinux.com/x/icebergs/base/cli"
|
||||
"shylinux.com/x/icebergs/base/nfs"
|
||||
"shylinux.com/x/icebergs/base/web"
|
||||
"shylinux.com/x/icebergs/core/code"
|
||||
kit "shylinux.com/x/toolkits"
|
||||
@ -20,19 +21,19 @@ const VIM = "vim"
|
||||
|
||||
var Index = &ice.Context{Name: VIM, Help: "编辑器", Configs: map[string]*ice.Config{
|
||||
VIM: {Name: VIM, Help: "编辑器", Value: kit.Data(
|
||||
cli.SOURCE, "http://mirrors.tencent.com/macports/distfiles/vim/vim-8.2.2681.tar.gz",
|
||||
nfs.SOURCE, "http://mirrors.tencent.com/macports/distfiles/vim/vim-8.2.2681.tar.gz",
|
||||
)},
|
||||
}, Commands: map[string]*ice.Command{
|
||||
VIM: {Name: "vim path auto order build download", Help: "编辑器", Action: ice.MergeAction(map[string]*ice.Action{
|
||||
cli.BUILD: {Name: "build", Help: "构建", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.BUILD, _vim_pkg(m, m.Config(cli.SOURCE)), "--enable-multibyte=yes",
|
||||
m.Cmdy(code.INSTALL, cli.BUILD, _vim_pkg(m, m.Config(nfs.SOURCE)), "--enable-multibyte=yes",
|
||||
"--enable-pythoninterp=yes", "--enable-luainterp=yes", "--enable-cscope=yes")
|
||||
}},
|
||||
cli.ORDER: {Name: "order", Help: "加载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, _vim_pkg(m, m.Config(cli.SOURCE)), "_install/bin")
|
||||
m.Cmdy(code.INSTALL, cli.ORDER, _vim_pkg(m, m.Config(nfs.SOURCE)), "_install/bin")
|
||||
}},
|
||||
}, code.InstallAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(code.INSTALL, cli.SOURCE, _vim_pkg(m, m.Config(cli.SOURCE)), arg)
|
||||
m.Cmdy(code.INSTALL, nfs.SOURCE, _vim_pkg(m, m.Config(nfs.SOURCE)), arg)
|
||||
}},
|
||||
}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user