mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-29 18:19:22 +08:00
mac add nothing
This commit is contained in:
parent
7707e086e5
commit
8f6c23e4c2
@ -1,6 +1,5 @@
|
|||||||
|
login root root
|
||||||
config debug on
|
config debug on
|
||||||
~aaa login root root
|
~ssh
|
||||||
|
listen ":9090"
|
||||||
~web serve ./ ":9090"
|
|
||||||
# source etc/local.shy
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import ( // {{{
|
|||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
type AAA struct {
|
type AAA struct {
|
||||||
|
share map[string]*ctx.Context
|
||||||
sessions map[string]*ctx.Context
|
sessions map[string]*ctx.Context
|
||||||
*ctx.Context
|
*ctx.Context
|
||||||
}
|
}
|
||||||
@ -43,6 +44,14 @@ func (aaa *AAA) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server
|
|||||||
c.Caches = map[string]*ctx.Cache{}
|
c.Caches = map[string]*ctx.Cache{}
|
||||||
c.Configs = map[string]*ctx.Config{}
|
c.Configs = map[string]*ctx.Config{}
|
||||||
|
|
||||||
|
c.Index = map[string]*ctx.Context{
|
||||||
|
"void": &ctx.Context{Name: "void", Help: "void",
|
||||||
|
Caches: map[string]*ctx.Cache{"group": &ctx.Cache{}},
|
||||||
|
Configs: map[string]*ctx.Config{"rootname": &ctx.Config{}},
|
||||||
|
Commands: map[string]*ctx.Command{"login": &ctx.Command{}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
s := new(AAA)
|
s := new(AAA)
|
||||||
s.Context = c
|
s.Context = c
|
||||||
return s
|
return s
|
||||||
@ -90,7 +99,6 @@ func (aaa *AAA) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
m.Cap("sessid", aaa.Session(arg[1]))
|
m.Cap("sessid", aaa.Session(arg[1]))
|
||||||
Pulse.Capi("nuser", 1)
|
Pulse.Capi("nuser", 1)
|
||||||
aaa.Owner = aaa.Context
|
aaa.Owner = aaa.Context
|
||||||
aaa.Group = arg[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Log("info", m.Source(), "%s login %s %s", Pulse.Cap("nuser"), m.Cap("group"), m.Cap("username"))
|
m.Log("info", m.Source(), "%s login %s %s", Pulse.Cap("nuser"), m.Cap("group"), m.Cap("username"))
|
||||||
@ -141,7 +149,6 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
m.Target(s)
|
m.Target(s)
|
||||||
m.Assert(int64(m.Capi("expire")) > time.Now().Unix(), "会话失败")
|
m.Assert(int64(m.Capi("expire")) > time.Now().Unix(), "会话失败")
|
||||||
|
|
||||||
m.Source().Group, m.Source().Owner = m.Cap("group"), m.Target()
|
|
||||||
m.Log("info", m.Source(), "logon %s %s", m.Cap("username"), m.Cap("group"))
|
m.Log("info", m.Source(), "logon %s %s", m.Cap("username"), m.Cap("group"))
|
||||||
m.Echo(m.Cap("username"))
|
m.Echo(m.Cap("username"))
|
||||||
case 2, 3:
|
case 2, 3:
|
||||||
@ -153,6 +160,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
msg := m
|
msg := m
|
||||||
if username == Pulse.Conf("rootname") {
|
if username == Pulse.Conf("rootname") {
|
||||||
msg = Pulse.Spawn(Pulse.Target())
|
msg = Pulse.Spawn(Pulse.Target())
|
||||||
|
ctx.Index.Sessions["aaa"] = msg
|
||||||
msg.Set("detail", group, username).Target().Start(msg)
|
msg.Set("detail", group, username).Target().Start(msg)
|
||||||
} else if msg = Pulse.Find(username, false); msg == nil {
|
} else if msg = Pulse.Find(username, false); msg == nil {
|
||||||
m.Start(username, "认证用户", group, username)
|
m.Start(username, "认证用户", group, username)
|
||||||
@ -164,12 +172,32 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
msg.Target().Sessions["aaa"] = msg
|
msg.Target().Sessions["aaa"] = msg
|
||||||
|
|
||||||
msg.Cap("password", password)
|
msg.Cap("password", password)
|
||||||
m.Source().Sessions["aaa"] = msg
|
|
||||||
// m.Source().Group, m.Source().Owner = msg.Cap("group"), msg.Target()
|
m.Login(msg)
|
||||||
aaa.sessions[m.Cap("sessid")] = msg.Target()
|
aaa.sessions[m.Cap("sessid")] = msg.Target()
|
||||||
m.Echo(msg.Cap("sessid"))
|
m.Echo(msg.Cap("sessid"))
|
||||||
} // }}}
|
} // }}}
|
||||||
}},
|
}},
|
||||||
|
"share": &ctx.Command{Name: "share user", Help: "用户登录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
if len(arg) == 0 { // {{{
|
||||||
|
aaa := m.Target().Server.(*AAA)
|
||||||
|
for k, v := range aaa.share {
|
||||||
|
m.Echo("%s: %s", k, v.Name)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
group := m.Sess("aaa").Cap("group")
|
||||||
|
m.Travel(c, func(msg *ctx.Message) bool {
|
||||||
|
aaa := msg.Target().Server.(*AAA)
|
||||||
|
if aaa.share == nil {
|
||||||
|
aaa.share = make(map[string]*ctx.Context)
|
||||||
|
}
|
||||||
|
aaa.share[group] = m.Target()
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
// }}}
|
||||||
|
}},
|
||||||
"md5": &ctx.Command{Name: "md5 [file filename][content]", Help: "散列",
|
"md5": &ctx.Command{Name: "md5 [file filename][content]", Help: "散列",
|
||||||
Formats: map[string]int{"file": 1},
|
Formats: map[string]int{"file": 1},
|
||||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
@ -334,7 +362,14 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
Index: map[string]*ctx.Context{
|
Index: map[string]*ctx.Context{
|
||||||
"void": &ctx.Context{Name: "void", Commands: map[string]*ctx.Command{"login": &ctx.Command{}}},
|
"void": &ctx.Context{Name: "void", Help: "void",
|
||||||
|
Caches: map[string]*ctx.Cache{"group": &ctx.Cache{}},
|
||||||
|
Configs: map[string]*ctx.Config{"rootname": &ctx.Config{}},
|
||||||
|
Commands: map[string]*ctx.Command{
|
||||||
|
"login": &ctx.Command{},
|
||||||
|
"check": &ctx.Command{},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +228,7 @@ func (cli *CLI) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
m.Cap("init.shy", arg[0])
|
m.Cap("init.shy", arg[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// m.Sess("nfs", "nfs")
|
cli.nfs = m.Sesss("nfs", "nfs")
|
||||||
cli.nfs = m.Find("nfs")
|
|
||||||
// m.Target().Sessions["nfs"] = cli.nfs
|
// m.Target().Sessions["nfs"] = cli.nfs
|
||||||
if m.Has("stdio") {
|
if m.Has("stdio") {
|
||||||
cli.nfs.Cmd("scan", m.Cap("stream", "stdio"), m.Spawn(m.Target()).Cmd("source", m.Cap("init.shy")).Get("result"))
|
cli.nfs.Cmd("scan", m.Cap("stream", "stdio"), m.Spawn(m.Target()).Cmd("source", m.Cap("init.shy")).Get("result"))
|
||||||
@ -581,14 +580,20 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}},
|
}},
|
||||||
"cmd": &ctx.Command{Name: "cmd word", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"cmd": &ctx.Command{Name: "cmd word", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) && !m.Caps("skip") { // {{{
|
if cli, ok := m.Target().Server.(*CLI); m.Assert(ok) && !m.Caps("skip") { // {{{
|
||||||
msg := m.Spawn(cli.target)
|
detail := []string{}
|
||||||
|
|
||||||
if a, ok := cli.alias[arg[0]]; ok {
|
if a, ok := cli.alias[arg[0]]; ok {
|
||||||
msg.Set("detail", a...)
|
detail = append(detail, a...)
|
||||||
msg.Meta["detail"] = append(msg.Meta["detail"], arg[1:]...)
|
detail = append(detail, arg[1:]...)
|
||||||
} else {
|
} else {
|
||||||
msg.Set("detail", arg...)
|
detail = append(detail, arg...)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := m.Spawn(cli.target)
|
||||||
|
msg.Cmd(detail)
|
||||||
|
if msg.Target().Context() != nil || msg.Target() == ctx.Index {
|
||||||
|
cli.target = msg.Target()
|
||||||
}
|
}
|
||||||
msg.Cmd()
|
|
||||||
|
|
||||||
if !msg.Hand && cli.Owner == ctx.Index.Owner {
|
if !msg.Hand && cli.Owner == ctx.Index.Owner {
|
||||||
msg.Hand = true
|
msg.Hand = true
|
||||||
@ -616,10 +621,6 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.Target().Context() != nil || msg.Target() == ctx.Index {
|
|
||||||
cli.target = msg.Target()
|
|
||||||
}
|
|
||||||
|
|
||||||
m.Cap("target", cli.target.Name)
|
m.Cap("target", cli.target.Name)
|
||||||
m.Set("result", msg.Meta["result"]...)
|
m.Set("result", msg.Meta["result"]...)
|
||||||
m.Capi("last", 0, msg.Code())
|
m.Capi("last", 0, msg.Code())
|
||||||
@ -745,6 +746,19 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
Index: map[string]*ctx.Context{
|
||||||
|
"void": &ctx.Context{Name: "void",
|
||||||
|
Caches: map[string]*ctx.Cache{
|
||||||
|
"nserver": &ctx.Cache{},
|
||||||
|
},
|
||||||
|
Configs: map[string]*ctx.Config{
|
||||||
|
"bench.log": &ctx.Config{},
|
||||||
|
},
|
||||||
|
Commands: map[string]*ctx.Command{
|
||||||
|
"cmd": &ctx.Command{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -19,7 +19,11 @@ import ( // {{{
|
|||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
func Right(str string) bool {
|
func Right(str string) bool {
|
||||||
return str != "" && str != "0" && str != "false"
|
switch str {
|
||||||
|
case "", "0", "false", "off":
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
@ -74,10 +78,8 @@ type Context struct {
|
|||||||
Sessions map[string]*Message
|
Sessions map[string]*Message
|
||||||
Exit chan bool
|
Exit chan bool
|
||||||
|
|
||||||
Index map[string]*Context
|
|
||||||
Groups map[string]*Context
|
|
||||||
Owner *Context
|
Owner *Context
|
||||||
Group string
|
Index map[string]*Context
|
||||||
password string
|
password string
|
||||||
|
|
||||||
Server
|
Server
|
||||||
@ -105,6 +107,76 @@ func (c *Context) Register(s *Context, x Server) (password string) { // {{{
|
|||||||
return s.password
|
return s.password
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
func (c *Context) Check(m *Message, arg ...string) bool { // {{{
|
||||||
|
if g, ok := c.Index["void"]; ok && g != nil {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "caches":
|
||||||
|
_, ok = g.Caches[arg[1]]
|
||||||
|
case "configs":
|
||||||
|
_, ok = g.Configs[arg[1]]
|
||||||
|
case "commands":
|
||||||
|
_, ok = g.Commands[arg[1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
aaa := m
|
||||||
|
for msg := m; msg != nil && msg.code != 0 && msg != msg.message; msg = msg.message {
|
||||||
|
aaa = nil
|
||||||
|
if a, ok := msg.Sessions["aaa"]; ok {
|
||||||
|
aaa = a
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if aaa == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Owner == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Owner == aaa.target {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
group := aaa.Cap("group")
|
||||||
|
if group == aaa.Conf("rootname") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if g, ok := c.Index[group]; ok && g != nil {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "caches":
|
||||||
|
_, ok = g.Caches[arg[1]]
|
||||||
|
case "configs":
|
||||||
|
_, ok = g.Configs[arg[1]]
|
||||||
|
case "commands":
|
||||||
|
_, ok = g.Commands[arg[1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Log("check", nil, "%s %d %v failure", c.Name, m.code, arg)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (c *Context) Spawn(m *Message, name string, help string) *Context { // {{{
|
func (c *Context) Spawn(m *Message, name string, help string) *Context { // {{{
|
||||||
s := &Context{Name: name, Help: help, root: c.root, context: c}
|
s := &Context{Name: name, Help: help, root: c.root, context: c}
|
||||||
@ -135,7 +207,6 @@ func (c *Context) Begin(m *Message) *Context { // {{{
|
|||||||
|
|
||||||
c.master = m.master.master
|
c.master = m.master.master
|
||||||
c.Owner = m.master.Owner
|
c.Owner = m.master.Owner
|
||||||
c.Group = m.master.Group
|
|
||||||
|
|
||||||
m.Log("begin", nil, "%d context %v %v", m.root.Capi("ncontext", 1), m.Meta["detail"], m.Meta["option"])
|
m.Log("begin", nil, "%d context %v %v", m.root.Capi("ncontext", 1), m.Meta["detail"], m.Meta["option"])
|
||||||
for k, x := range c.Configs {
|
for k, x := range c.Configs {
|
||||||
@ -274,32 +345,14 @@ func (c *Context) Has(key ...string) bool { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
type Session struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Callback struct {
|
type Callback struct {
|
||||||
ncall int
|
ncall int
|
||||||
hand func(msg *Message) (sub *Message)
|
hand func(msg *Message) (sub *Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Feedback struct {
|
|
||||||
nfeed int
|
|
||||||
hand func(msg *Message) (sub *Message)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
time time.Time
|
|
||||||
code int
|
code int
|
||||||
Hand bool
|
time time.Time
|
||||||
|
|
||||||
Recv chan bool
|
|
||||||
Wait chan bool
|
|
||||||
Meta map[string][]string
|
|
||||||
Data map[string]interface{}
|
|
||||||
|
|
||||||
messages []*Message
|
|
||||||
message *Message
|
|
||||||
root *Message
|
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
source *Context
|
source *Context
|
||||||
@ -307,8 +360,20 @@ type Message struct {
|
|||||||
target *Context
|
target *Context
|
||||||
Index int
|
Index int
|
||||||
|
|
||||||
|
Meta map[string][]string
|
||||||
|
Data map[string]interface{}
|
||||||
|
|
||||||
|
Sessions map[string]*Message
|
||||||
|
messages []*Message
|
||||||
|
message *Message
|
||||||
|
root *Message
|
||||||
|
|
||||||
callback Callback
|
callback Callback
|
||||||
|
|
||||||
|
Wait chan bool
|
||||||
|
Recv chan bool
|
||||||
|
Hand bool
|
||||||
|
|
||||||
Template *Message
|
Template *Message
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,12 +412,23 @@ func (m *Message) Target(s ...*Context) *Context { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
|
func (m *Message) Login(aaa *Message) { // {{{
|
||||||
|
m.source.Owner = m.target
|
||||||
|
for msg := m; msg != nil; msg = msg.message {
|
||||||
|
if nfs, ok := msg.Sessions["nfs"]; ok {
|
||||||
|
nfs.Sessions["aaa"] = aaa
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
func (m *Message) Log(action string, ctx *Context, str string, arg ...interface{}) { // {{{
|
func (m *Message) Log(action string, ctx *Context, str string, arg ...interface{}) { // {{{
|
||||||
if !m.Options("log") {
|
if !m.Options("log") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if l := m.Sess("log"); l != nil {
|
if l := m.Sesss("log"); l != nil {
|
||||||
l.Options("log", false)
|
l.Options("log", false)
|
||||||
l.Cmd("log", action, fmt.Sprintf(str, arg...))
|
l.Cmd("log", action, fmt.Sprintf(str, arg...))
|
||||||
}
|
}
|
||||||
@ -361,6 +437,29 @@ func (m *Message) Log(action string, ctx *Context, str string, arg ...interface{
|
|||||||
// }}}
|
// }}}
|
||||||
func (m *Message) Check(s *Context, arg ...string) bool { // {{{
|
func (m *Message) Check(s *Context, arg ...string) bool { // {{{
|
||||||
return true
|
return true
|
||||||
|
if m.root.target.Sessions == nil || m.root.target.Sessions["aaa"] == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if g, ok := s.Index["void"]; ok && g != nil {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "caches":
|
||||||
|
_, ok = g.Caches[arg[1]]
|
||||||
|
case "configs":
|
||||||
|
_, ok = g.Configs[arg[1]]
|
||||||
|
case "commands":
|
||||||
|
_, ok = g.Commands[arg[1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
aaa := m
|
aaa := m
|
||||||
for msg := m; msg != nil && msg.code != 0 && msg != msg.message; msg = msg.message {
|
for msg := m; msg != nil && msg.code != 0 && msg != msg.message; msg = msg.message {
|
||||||
if a, ok := msg.Target().Sessions["aaa"]; ok {
|
if a, ok := msg.Target().Sessions["aaa"]; ok {
|
||||||
@ -368,6 +467,38 @@ func (m *Message) Check(s *Context, arg ...string) bool { // {{{
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if aaa == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
group := aaa.Cap("group")
|
||||||
|
if group == aaa.Conf("rootname") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if g, ok := s.Index[group]; ok && g != nil {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "caches":
|
||||||
|
_, ok = g.Caches[arg[1]]
|
||||||
|
case "configs":
|
||||||
|
_, ok = g.Configs[arg[1]]
|
||||||
|
case "commands":
|
||||||
|
_, ok = g.Commands[arg[1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("check %s %s %v false\n", group, s.Name, arg)
|
||||||
|
return false
|
||||||
|
|
||||||
if aaa.target.Caches == nil {
|
if aaa.target.Caches == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -375,11 +506,6 @@ func (m *Message) Check(s *Context, arg ...string) bool { // {{{
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
group := aaa.target.Caches["group"].Value
|
|
||||||
if group == "root" {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
g, ok := s.Index[group]
|
g, ok := s.Index[group]
|
||||||
gg, gok := s.Index["void"]
|
gg, gok := s.Index["void"]
|
||||||
|
|
||||||
@ -430,6 +556,63 @@ func (m *Message) Check(s *Context, arg ...string) bool { // {{{
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
func (m *Message) Permit(s *Context, arg ...string) bool { // {{{
|
||||||
|
|
||||||
|
if m.root.target.Sessions == nil || m.root.target.Sessions["aaa"] == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if aaa := m.Sesss("aaa"); aaa != nil {
|
||||||
|
|
||||||
|
if g, ok := s.Index["void"]; ok && g != nil {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "caches":
|
||||||
|
_, ok = g.Caches[arg[1]]
|
||||||
|
case "configs":
|
||||||
|
_, ok = g.Configs[arg[1]]
|
||||||
|
case "commands":
|
||||||
|
_, ok = g.Commands[arg[1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group := aaa.Cap("group")
|
||||||
|
if group == aaa.Conf("rootname") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if g, ok := s.Index[group]; ok && g != nil {
|
||||||
|
if len(arg) < 2 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
switch arg[0] {
|
||||||
|
case "caches":
|
||||||
|
_, ok = g.Caches[arg[1]]
|
||||||
|
case "configs":
|
||||||
|
_, ok = g.Configs[arg[1]]
|
||||||
|
case "commands":
|
||||||
|
_, ok = g.Commands[arg[1]]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (m *Message) Assert(e interface{}, msg ...string) bool { // {{{
|
func (m *Message) Assert(e interface{}, msg ...string) bool { // {{{
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
@ -524,6 +707,7 @@ func (m *Message) Spawn(c *Context, key ...string) *Message { // {{{
|
|||||||
m.messages = make([]*Message, 0, 10)
|
m.messages = make([]*Message, 0, 10)
|
||||||
}
|
}
|
||||||
m.messages = append(m.messages, msg)
|
m.messages = append(m.messages, msg)
|
||||||
|
msg.Sessions = make(map[string]*Message)
|
||||||
|
|
||||||
msg.Wait = make(chan bool)
|
msg.Wait = make(chan bool)
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
@ -676,6 +860,36 @@ func (m *Message) Sess(key string, arg ...string) *Message { // {{{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
func (m *Message) Sesss(key string, arg ...string) *Message { // {{{
|
||||||
|
if _, ok := m.Sessions[key]; !ok && len(arg) > 0 {
|
||||||
|
root := true
|
||||||
|
if len(arg) > 2 {
|
||||||
|
root = Right(arg[2])
|
||||||
|
}
|
||||||
|
method := "find"
|
||||||
|
if len(arg) > 1 {
|
||||||
|
method = arg[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
switch method {
|
||||||
|
case "find":
|
||||||
|
m.Sessions[key] = m.Find(arg[0], root)
|
||||||
|
case "search":
|
||||||
|
m.Sessions[key] = m.Search(arg[0], root)[0]
|
||||||
|
}
|
||||||
|
return m.Sessions[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
for msg := m; msg != nil; msg = msg.message {
|
||||||
|
if x, ok := msg.Sessions[key]; ok {
|
||||||
|
return m.Spawn(x.target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
func (m *Message) Call(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message { // {{{
|
func (m *Message) Call(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message { // {{{
|
||||||
@ -691,7 +905,7 @@ func (m *Message) Back(msg *Message) *Message { // {{{
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Log("callback", nil, "%v %v", msg.Meta["result"], msg.Meta["append"])
|
m.Log("cb", nil, "%d %v %v", msg.code, msg.Meta["result"], msg.Meta["append"])
|
||||||
|
|
||||||
m.callback.ncall++
|
m.callback.ncall++
|
||||||
if sub := m.callback.hand(msg); sub != nil && m.message != nil && m.message != m {
|
if sub := m.callback.hand(msg); sub != nil && m.message != nil && m.message != m {
|
||||||
@ -704,16 +918,11 @@ func (m *Message) Back(msg *Message) *Message { // {{{
|
|||||||
// }}}
|
// }}}
|
||||||
func (m *Message) CallBack(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message { // {{{
|
func (m *Message) CallBack(cb func(msg *Message) (sub *Message), arg ...interface{}) *Message { // {{{
|
||||||
wait := make(chan bool)
|
wait := make(chan bool)
|
||||||
m.Log("fuck", nil, "callback 1")
|
|
||||||
go m.Call(func(sub *Message) *Message {
|
go m.Call(func(sub *Message) *Message {
|
||||||
m.Log("fuck", nil, "callback 4")
|
|
||||||
wait <- true
|
wait <- true
|
||||||
m.Log("fuck", nil, "callback 5")
|
|
||||||
return cb(sub)
|
return cb(sub)
|
||||||
}, arg...)
|
}, arg...)
|
||||||
m.Log("fuck", nil, "callback 2")
|
|
||||||
<-wait
|
<-wait
|
||||||
m.Log("fuck", nil, "callback 3")
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1031,23 +1240,7 @@ func (m *Message) Exec(key string, arg ...string) string { // {{{
|
|||||||
for _, c := range []*Context{m.target, m.target.master, m.target.Owner, m.source, m.source.master, m.source.Owner} {
|
for _, c := range []*Context{m.target, m.target.master, m.target.Owner, m.source, m.source.master, m.source.Owner} {
|
||||||
for s := c; s != nil; s = s.context {
|
for s := c; s != nil; s = s.context {
|
||||||
|
|
||||||
m.master = m.source
|
if x, ok := s.Commands[key]; ok && x.Hand != nil && c.Check(m, "commands", key) {
|
||||||
if x, ok := s.Commands[key]; ok && x.Hand != nil && m.Check(c, "commands", key) {
|
|
||||||
aaa := m.Sess("aaa")
|
|
||||||
if group := aaa.Cap("group"); group != "root" {
|
|
||||||
aaa.Log("cmd", s, "fuck, %d %s %v %v %s %s", len(m.target.Historys), key, arg, m.Meta["option"], group, group)
|
|
||||||
if index, ok := s.Index[group]; ok {
|
|
||||||
if _, ok := index.Commands[key]; ok {
|
|
||||||
m.Log("cmd", s, "%d %s %v %v", len(m.target.Historys), key, arg, m.Meta["option"])
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// continue
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.AssertOne(m, true, func(m *Message) {
|
m.AssertOne(m, true, func(m *Message) {
|
||||||
m.Log("cmd", s, "%d %s %v %v", len(m.target.Historys), key, arg, m.Meta["option"])
|
m.Log("cmd", s, "%d %s %v %v", len(m.target.Historys), key, arg, m.Meta["option"])
|
||||||
|
|
||||||
@ -1338,7 +1531,15 @@ func (m *Message) Cap(key string, arg ...string) string { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
var Pulse = &Message{code: 0, time: time.Now(), Wait: make(chan bool), source: Index, master: Index, target: Index}
|
var Pulse = &Message{
|
||||||
|
code: 0,
|
||||||
|
time: time.Now(),
|
||||||
|
Wait: make(chan bool),
|
||||||
|
source: Index,
|
||||||
|
master: Index,
|
||||||
|
target: Index,
|
||||||
|
Sessions: make(map[string]*Message),
|
||||||
|
}
|
||||||
var Index = &Context{Name: "ctx", Help: "模块中心",
|
var Index = &Context{Name: "ctx", Help: "模块中心",
|
||||||
Caches: map[string]*Cache{
|
Caches: map[string]*Cache{
|
||||||
"debug": &Cache{Name: "服务数量", Value: "true", Help: "显示已经启动运行模块的数量"},
|
"debug": &Cache{Name: "服务数量", Value: "true", Help: "显示已经启动运行模块的数量"},
|
||||||
@ -1426,7 +1627,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.Echo("\033[32msessions:\033[0m\n")
|
m.Echo("\033[32msessions:\033[0m\n")
|
||||||
for k, v := range m.target.Sessions {
|
for k, v := range m.Sessions {
|
||||||
m.Echo("%s %s\n", k, v.Format())
|
m.Echo("%s %s\n", k, v.Format())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1458,6 +1659,11 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
m.Echo(" %s: %v\n", k, ms[i].Meta[k])
|
m.Echo(" %s: %v\n", k, ms[i].Meta[k])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.Echo("sessions:\n")
|
||||||
|
for k, v := range ms[i].Sessions {
|
||||||
|
m.Echo(" %s: %s\n", k, v.Format())
|
||||||
|
}
|
||||||
|
|
||||||
if ms[i].callback.hand != nil {
|
if ms[i].callback.hand != nil {
|
||||||
m.Echo("callback: %d\n", ms[i].callback.ncall)
|
m.Echo("callback: %d\n", ms[i].callback.ncall)
|
||||||
}
|
}
|
||||||
@ -1491,7 +1697,6 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
if ms[i].code == n {
|
if ms[i].code == n {
|
||||||
switch arg[1] {
|
switch arg[1] {
|
||||||
case "option", "session", "callback", "feedback":
|
case "option", "session", "callback", "feedback":
|
||||||
m.Echo("get")
|
|
||||||
msg := ms[i].Spawn(ms[i].target)
|
msg := ms[i].Spawn(ms[i].target)
|
||||||
msg.Cmd(arg[1:])
|
msg.Cmd(arg[1:])
|
||||||
m.Copy(msg, "result")
|
m.Copy(msg, "result")
|
||||||
@ -1522,15 +1727,16 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
m.Echo("%d(%s->%s): %v\n", msg.code, msg.source.Name, msg.target.Name, msg.Meta["detail"])
|
m.Echo("%d(%s->%s): %v\n", msg.code, msg.source.Name, msg.target.Name, msg.Meta["detail"])
|
||||||
}
|
}
|
||||||
for _, k := range msg.Meta["option"] {
|
for _, k := range msg.Meta["option"] {
|
||||||
for _, v := range msg.Meta[k] {
|
if v, ok := msg.Meta[k]; ok {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Echo(" %s: %v\n", k, v)
|
m.Echo(" %s: %v\n", k, v)
|
||||||
} else if k == arg[0] {
|
} else if k == arg[0] {
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
msg.Option(k, arg[1])
|
msg.Option(k, arg[1])
|
||||||
}
|
}
|
||||||
m.Echo("msg(%s->%s): %d(%s)\n", msg.source.Name, msg.target.Name, msg.code, msg.time.Format("15:04:05"))
|
if len(v) > 0 {
|
||||||
m.Echo(" %s: %v\n", k, v)
|
m.Echo("%v", v[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1542,28 +1748,14 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Echo("%d(%s->%s): %v\n", msg.code, msg.source.Name, msg.target.Name, msg.Meta["detail"])
|
m.Echo("%d(%s->%s): %v\n", msg.code, msg.source.Name, msg.target.Name, msg.Meta["detail"])
|
||||||
}
|
}
|
||||||
for k, v := range msg.target.Sessions {
|
for k, v := range msg.Sessions {
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Echo(" %s(%s->%s): %d(%s)\n", k, v.source.Name, v.target.Name, v.code, msg.time.Format("15:04:05"))
|
m.Echo(" %s(%s->%s): %d(%s)\n", k, v.source.Name, v.target.Name, v.code, msg.time.Format("15:04:05"))
|
||||||
} else if k == arg[0] {
|
} else if k == arg[0] {
|
||||||
switch arg[1] {
|
if len(arg) > 1 {
|
||||||
case "cache":
|
sub := msg.Sesss(k).Cmd(arg[1:])
|
||||||
sub := msg.Sess(k)
|
|
||||||
sub.Cmd("cache", arg[2:])
|
|
||||||
m.Copy(sub, "result")
|
m.Copy(sub, "result")
|
||||||
return
|
return
|
||||||
case "config":
|
|
||||||
sub := msg.Sess(k)
|
|
||||||
sub.Cmd("config", arg[2:])
|
|
||||||
m.Copy(sub, "result")
|
|
||||||
return
|
|
||||||
case "command":
|
|
||||||
sub := msg.Sess(k)
|
|
||||||
sub.Cmd("command", arg[2:])
|
|
||||||
m.Copy(sub, "result")
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
msg.target.Sessions[arg[0]] = msg.Find(arg[1])
|
|
||||||
}
|
}
|
||||||
m.Echo("msg(%s->%s): %d(%s)\n", msg.source.Name, msg.target.Name, msg.code, msg.time.Format("15:04:05"))
|
m.Echo("msg(%s->%s): %d(%s)\n", msg.source.Name, msg.target.Name, msg.code, msg.time.Format("15:04:05"))
|
||||||
m.Echo(" %s(%s->%s): %d(%s)\n", k, v.source.Name, v.target.Name, msg.code, msg.time.Format("15:04:05"))
|
m.Echo(" %s(%s->%s): %d(%s)\n", k, v.source.Name, v.target.Name, msg.code, msg.time.Format("15:04:05"))
|
||||||
@ -1711,24 +1903,37 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"server": &Command{Name: "server [start|exit|switch][args]", Help: "服务启动停止切换", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
"server": &Command{Name: "server [spawn|begin|start|close|][args]", Help: "服务启动停止切换", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||||
switch len(arg) { // {{{
|
switch len(arg) { // {{{
|
||||||
case 0:
|
case 0:
|
||||||
m.Travel(m.target.root, func(m *Message) bool {
|
m.Travel(m.target.root, func(msg *Message) bool {
|
||||||
if x, ok := m.target.Caches["status"]; ok {
|
if msg.Cap("status") == "start" {
|
||||||
m.Echo("%s(%s): %s\n", m.target.Name, x.Value, m.target.Help)
|
msg.Echo("%s(%s): %s\n", msg.target.Name, msg.Cap("stream"), msg.target.Help)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
default:
|
default:
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
|
case "spawn":
|
||||||
|
if len(arg) > 1 {
|
||||||
|
msg := m.Spawn(m.Target())
|
||||||
|
msg.Detail(0, arg[2:])
|
||||||
|
msg.Target().Spawn(msg, arg[0], arg[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
case "begin":
|
||||||
|
msg := m.Spawn(m.Target())
|
||||||
|
msg.Detail(0, arg)
|
||||||
|
msg.Target().Begin(msg)
|
||||||
case "start":
|
case "start":
|
||||||
m.Meta = nil
|
msg := m.Spawn(m.Target())
|
||||||
m.Set("detail", arg[1:]...).target.Start(m)
|
msg.Detail(0, arg)
|
||||||
case "stop":
|
msg.Target().Begin(msg)
|
||||||
m.Set("detail", arg[1:]...).target.Close(m)
|
case "close":
|
||||||
case "switch":
|
msg := m.Spawn(m.Target())
|
||||||
|
msg.Detail(0, arg)
|
||||||
|
msg.Target().Begin(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
@ -1937,38 +2142,60 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"group": &Command{
|
"right": &Command{
|
||||||
Name: "group current [add|del group [cache|config|command item]]",
|
Name: "right [share|add|del group [cache|config|command item]]",
|
||||||
Help: "用户组管理,查看、添加、删除用户组或是接口",
|
Help: "用户组管理,查看、添加、删除用户组或是接口",
|
||||||
Formats: map[string]int{"add": 0, "del": 0, "cache": 0, "config": 0, "command": 0},
|
Formats: map[string]int{"add": 0, "del": 0, "cache": 0, "config": 0, "command": 0},
|
||||||
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
Hand: func(m *Message, c *Context, key string, arg ...string) {
|
||||||
index := m.Target().Index // {{{
|
index := m.Target().Index // {{{
|
||||||
|
if index == nil {
|
||||||
|
m.Target().Index = map[string]*Context{}
|
||||||
|
}
|
||||||
|
|
||||||
current := m.Target()
|
current := m.Target()
|
||||||
if len(arg) > 0 && arg[0] != "root" {
|
aaa := m.Sesss("aaa")
|
||||||
current = index[arg[0]]
|
void := index["void"]
|
||||||
if current == nil {
|
if aaa != nil && aaa.Cap("group") != aaa.Conf("rootname") {
|
||||||
|
if current = index[aaa.Cap("group")]; current == nil {
|
||||||
|
if void != nil {
|
||||||
|
m.Echo("%s:caches\n", void.Name)
|
||||||
|
for k, c := range void.Caches {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Value)
|
||||||
|
}
|
||||||
|
m.Echo("%s:configs\n", void.Name)
|
||||||
|
for k, c := range void.Configs {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Value)
|
||||||
|
}
|
||||||
|
m.Echo("%s:commands\n", void.Name)
|
||||||
|
for k, c := range void.Commands {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Name)
|
||||||
|
}
|
||||||
|
m.Echo("%s:contexts\n", void.Name)
|
||||||
|
for k, c := range void.Index {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
group := current
|
group := current
|
||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
group = current.Index[arg[1]]
|
group = current.Index[arg[0]]
|
||||||
}
|
}
|
||||||
|
|
||||||
item := ""
|
item := ""
|
||||||
if len(arg) > 2 {
|
if len(arg) > 1 {
|
||||||
item = arg[2]
|
item = arg[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case m.Has("add"):
|
case m.Has("add"):
|
||||||
if group == nil {
|
if group == nil {
|
||||||
if _, ok := index[arg[1]]; ok {
|
if _, ok := index[arg[0]]; ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
group = &Context{Name: arg[1]}
|
group = &Context{Name: arg[0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
@ -1998,8 +2225,8 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
if current.Index == nil {
|
if current.Index == nil {
|
||||||
current.Index = map[string]*Context{}
|
current.Index = map[string]*Context{}
|
||||||
}
|
}
|
||||||
current.Index[arg[1]] = group
|
current.Index[arg[0]] = group
|
||||||
index[arg[1]] = group
|
index[arg[0]] = group
|
||||||
|
|
||||||
case m.Has("del"):
|
case m.Has("del"):
|
||||||
if group == nil {
|
if group == nil {
|
||||||
@ -2027,42 +2254,69 @@ var Index = &Context{Name: "ctx", Help: "模块中心",
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
m.Echo("%s:caches\n", current.Name)
|
m.Echo("%s:caches\n", current.Name)
|
||||||
|
if void != nil {
|
||||||
|
for k, c := range void.Caches {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
for k, c := range current.Caches {
|
for k, c := range current.Caches {
|
||||||
m.Echo(" %s: %s\n", k, c.Value)
|
m.Echo(" %s: %s\n", k, c.Value)
|
||||||
}
|
}
|
||||||
m.Echo("%s:configs\n", current.Name)
|
m.Echo("%s:configs\n", current.Name)
|
||||||
|
if void != nil {
|
||||||
|
for k, c := range void.Configs {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
for k, c := range current.Configs {
|
for k, c := range current.Configs {
|
||||||
m.Echo(" %s: %s\n", k, c.Value)
|
m.Echo(" %s: %s\n", k, c.Value)
|
||||||
}
|
}
|
||||||
m.Echo("%s:commands\n", current.Name)
|
m.Echo("%s:commands\n", current.Name)
|
||||||
|
if void != nil {
|
||||||
|
for k, c := range void.Commands {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
for k, c := range current.Commands {
|
for k, c := range current.Commands {
|
||||||
m.Echo(" %s: %s\n", k, c.Name)
|
m.Echo(" %s: %s\n", k, c.Name)
|
||||||
}
|
}
|
||||||
m.Echo("%s:contexts\n", current.Name)
|
m.Echo("%s:contexts\n", current.Name)
|
||||||
|
if void != nil {
|
||||||
|
for k, c := range void.Index {
|
||||||
|
m.Echo(" %s: %s\n", k, c.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
for k, c := range current.Index {
|
for k, c := range current.Index {
|
||||||
m.Echo(" %s: %s\n", k, c.Name)
|
m.Echo(" %s: %s\n", k, c.Name)
|
||||||
}
|
}
|
||||||
} // }}}
|
} // }}}
|
||||||
}},
|
}},
|
||||||
"pulse": &Command{Name: "arg name", Help: "查看日志", Hand: func(m *Message, c *Context, key string, arg ...string) {
|
|
||||||
p := m.Target().Pulse
|
|
||||||
m.Echo("%d\n", p.code)
|
|
||||||
m.Echo("%v\n", p.Meta["detail"])
|
|
||||||
m.Echo("%v\n", p.Meta["option"])
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
Index: map[string]*Context{
|
Index: map[string]*Context{
|
||||||
"void": &Context{Name: "void",
|
"void": &Context{Name: "void",
|
||||||
Caches: map[string]*Cache{},
|
Caches: map[string]*Cache{
|
||||||
|
"nmessage": &Cache{},
|
||||||
|
"ncontext": &Cache{},
|
||||||
|
"nserver": &Cache{},
|
||||||
|
},
|
||||||
Configs: map[string]*Config{
|
Configs: map[string]*Config{
|
||||||
|
"debug": &Config{},
|
||||||
"bench.log": &Config{},
|
"bench.log": &Config{},
|
||||||
},
|
},
|
||||||
Commands: map[string]*Command{
|
Commands: map[string]*Command{
|
||||||
"message": &Command{},
|
"message": &Command{},
|
||||||
|
"option": &Command{},
|
||||||
|
"session": &Command{},
|
||||||
|
"callback": &Command{},
|
||||||
|
"feedback": &Command{},
|
||||||
|
|
||||||
"context": &Command{},
|
"context": &Command{},
|
||||||
|
"server": &Command{},
|
||||||
"command": &Command{},
|
"command": &Command{},
|
||||||
"config": &Command{},
|
"config": &Command{},
|
||||||
"cache": &Command{},
|
"cache": &Command{},
|
||||||
|
|
||||||
|
"right": &Command{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2087,7 +2341,6 @@ func Start(args ...string) {
|
|||||||
Pulse.Conf("start", args[3])
|
Pulse.Conf("start", args[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
Index.Group = "root"
|
|
||||||
Index.Owner = Index.contexts["aaa"]
|
Index.Owner = Index.contexts["aaa"]
|
||||||
Index.master = Index.contexts["cli"]
|
Index.master = Index.contexts["cli"]
|
||||||
for _, m := range Pulse.Search("") {
|
for _, m := range Pulse.Search("") {
|
||||||
@ -2095,14 +2348,8 @@ func Start(args ...string) {
|
|||||||
m.target.Begin(m)
|
m.target.Begin(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
Pulse.Sess("aaa", "aaa")
|
|
||||||
Pulse.Sess("log", "log").Conf("bench.log", Pulse.Conf("bench.log"))
|
|
||||||
Pulse.Options("log", true)
|
Pulse.Options("log", true)
|
||||||
|
Pulse.Sesss("log", "log").Conf("bench.log", Pulse.Conf("bench.log"))
|
||||||
Pulse.callback.hand = func(msg *Message) *Message {
|
|
||||||
msg.Log("fuck", nil, "%v", msg.Meta["result"])
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, m := range Pulse.Search(Pulse.Conf("start")) {
|
for _, m := range Pulse.Search(Pulse.Conf("start")) {
|
||||||
m.Set("detail", Pulse.Conf("init.shy")).Set("option", "stdio").target.Start(m)
|
m.Set("detail", Pulse.Conf("init.shy")).Set("option", "stdio").target.Start(m)
|
||||||
|
@ -436,6 +436,11 @@ var Index = &ctx.Context{Name: "lex", Help: "词法中心",
|
|||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
Index: map[string]*ctx.Context{
|
||||||
|
"void": &ctx.Context{Name: "void", Help: "void",
|
||||||
|
Commands: map[string]*ctx.Command{"parse": &ctx.Command{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -169,16 +169,31 @@ var Index = &ctx.Context{Name: "log", Help: "日志中心",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmd := strings.Join(arg[1:], "")
|
||||||
|
|
||||||
if nfs := m.Sess("nfs"); nfs != nil {
|
if nfs := m.Sess("nfs"); nfs != nil {
|
||||||
if nfs.Options("log", false); color > 0 {
|
if nfs.Options("log", false); color > 0 {
|
||||||
nfs.Cmd("write", fmt.Sprintf("%s\033[%dm%s%s %s\033[0m\n", date, color, code, action, strings.Join(arg[1:], "")))
|
nfs.Cmd("write", fmt.Sprintf("%s\033[%dm%s%s %s\033[0m\n", date, color, code, action, cmd))
|
||||||
} else {
|
} else {
|
||||||
nfs.Cmd("write", fmt.Sprintf("%s%s%s %s\n", date, code, action, strings.Join(arg[1:], "")))
|
nfs.Cmd("write", fmt.Sprintf("%s%s%s %s\n", date, code, action, cmd))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // }}}
|
} // }}}
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
Index: map[string]*ctx.Context{
|
||||||
|
"void": &ctx.Context{Name: "void", Help: "void",
|
||||||
|
Configs: map[string]*ctx.Config{
|
||||||
|
"flag_code": &ctx.Config{},
|
||||||
|
"flag_action": &ctx.Config{},
|
||||||
|
"flag_name": &ctx.Config{},
|
||||||
|
"flag_color": &ctx.Config{},
|
||||||
|
"flag_time": &ctx.Config{},
|
||||||
|
"flag_date": &ctx.Config{},
|
||||||
|
},
|
||||||
|
Commands: map[string]*ctx.Command{"log": &ctx.Command{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -187,21 +202,23 @@ func init() {
|
|||||||
ctx.Index.Register(Index, log)
|
ctx.Index.Register(Index, log)
|
||||||
|
|
||||||
log.color = map[string]int{
|
log.color = map[string]int{
|
||||||
"error": 31,
|
"error": 31,
|
||||||
"check": 31,
|
"check": 31,
|
||||||
"cmd": 32,
|
"cmd": 32,
|
||||||
"conf": 33,
|
"conf": 33,
|
||||||
"search": 35,
|
"search": 35,
|
||||||
"find": 35,
|
"find": 35,
|
||||||
"callback": 35,
|
"cb": 35,
|
||||||
"lock": 35,
|
"lock": 35,
|
||||||
"spawn": 35,
|
"spawn": 35,
|
||||||
"begin": 36,
|
"begin": 36,
|
||||||
"start": 36,
|
"start": 36,
|
||||||
"close": 36,
|
"close": 36,
|
||||||
"debug": 0,
|
"debug": 0,
|
||||||
|
}
|
||||||
|
log.slient = map[string]bool{
|
||||||
|
"lock": true,
|
||||||
}
|
}
|
||||||
log.slient = map[string]bool{}
|
|
||||||
log.module = map[string]map[string]bool{
|
log.module = map[string]map[string]bool{
|
||||||
"log": {"cmd": true},
|
"log": {"cmd": true},
|
||||||
"lex": {"cmd": true, "debug": true},
|
"lex": {"cmd": true, "debug": true},
|
||||||
|
@ -429,6 +429,9 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
|
|
||||||
nfs.Message = m
|
nfs.Message = m
|
||||||
if socket, ok := m.Data["io"]; ok {
|
if socket, ok := m.Data["io"]; ok {
|
||||||
|
m.Cap("stream", m.Source().Name)
|
||||||
|
// m.Sesss("aaa", "aaa").Cmd("login", "demo", "demo")
|
||||||
|
|
||||||
nfs.io = socket.(io.ReadWriteCloser)
|
nfs.io = socket.(io.ReadWriteCloser)
|
||||||
nfs.Reader = bufio.NewReader(nfs.io)
|
nfs.Reader = bufio.NewReader(nfs.io)
|
||||||
nfs.Writer = bufio.NewWriter(nfs.io)
|
nfs.Writer = bufio.NewWriter(nfs.io)
|
||||||
@ -463,6 +466,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if msg.Has("detail") {
|
if msg.Has("detail") {
|
||||||
|
msg.Target(m.Sessions["ssh"].Target())
|
||||||
msg.Log("info", nil, "%d recv", m.Capi("nrecv", 1))
|
msg.Log("info", nil, "%d recv", m.Capi("nrecv", 1))
|
||||||
msg.Log("info", nil, "detail: %v", msg.Meta["detail"])
|
msg.Log("info", nil, "detail: %v", msg.Meta["detail"])
|
||||||
msg.Log("info", nil, "option: %v", msg.Meta["option"])
|
msg.Log("info", nil, "option: %v", msg.Meta["option"])
|
||||||
@ -472,27 +476,24 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
cmd := msg
|
cmd := msg
|
||||||
cmd.Call(func(sub *ctx.Message) *ctx.Message {
|
cmd.Call(func(sub *ctx.Message) *ctx.Message {
|
||||||
for _, v := range sub.Meta["result"] {
|
for _, v := range sub.Meta["result"] {
|
||||||
n, e := fmt.Fprintf(nfs.Writer, "result: %s\n", url.QueryEscape(v))
|
_, e := fmt.Fprintf(nfs.Writer, "result: %s\n", url.QueryEscape(v))
|
||||||
sub.Assert(e)
|
sub.Assert(e)
|
||||||
sub.Log("fuck", nil, "write %d", n)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub.Append("nsend", sub.Option("nsend"))
|
sub.Append("nsend", sub.Option("nsend"))
|
||||||
for _, k := range sub.Meta["append"] {
|
for _, k := range sub.Meta["append"] {
|
||||||
for _, v := range sub.Meta[k] {
|
for _, v := range sub.Meta[k] {
|
||||||
n, e := fmt.Fprintf(nfs.Writer, "%s: %s\n", k, v)
|
_, e := fmt.Fprintf(nfs.Writer, "%s: %s\n", k, v)
|
||||||
sub.Assert(e)
|
sub.Assert(e)
|
||||||
sub.Log("fuck", nil, "write %d", n)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub.Log("info", nil, "%d send", sub.Optioni("nsend"))
|
sub.Log("info", nil, "%d recv", sub.Optioni("nsend"))
|
||||||
sub.Log("info", nil, "result: %v", sub.Meta["result"])
|
sub.Log("info", nil, "result: %v", sub.Meta["result"])
|
||||||
sub.Log("info", nil, "append: %v", sub.Meta["append"])
|
sub.Log("info", nil, "append: %v", sub.Meta["append"])
|
||||||
|
|
||||||
n, e := fmt.Fprintf(nfs.Writer, "\n")
|
_, e := fmt.Fprintf(nfs.Writer, "\n")
|
||||||
sub.Assert(e)
|
sub.Assert(e)
|
||||||
sub.Log("sub", nil, "write %d", n)
|
|
||||||
e = nfs.Writer.Flush()
|
e = nfs.Writer.Flush()
|
||||||
sub.Assert(e)
|
sub.Assert(e)
|
||||||
|
|
||||||
@ -549,7 +550,7 @@ func (nfs *NFS) Start(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
|
|
||||||
cli := m.Reply()
|
cli := m.Reply()
|
||||||
nfs.cli = cli
|
nfs.cli = cli
|
||||||
yac := m.Sess("yac", cli.Conf("yac"))
|
yac := m.Sesss("yac", cli.Conf("yac"))
|
||||||
bio := bufio.NewScanner(nfs)
|
bio := bufio.NewScanner(nfs)
|
||||||
|
|
||||||
if m.Cap("stream") == "stdio" {
|
if m.Cap("stream") == "stdio" {
|
||||||
@ -690,31 +691,27 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
}},
|
}},
|
||||||
|
|
||||||
"listen": &ctx.Command{Name: "listen args...", Help: "启动文件服务, args: 参考tcp模块, listen命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"listen": &ctx.Command{Name: "listen args...", Help: "启动文件服务, args: 参考tcp模块, listen命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
msg := m.Find("tcp") // {{{
|
if _, ok := m.Target().Server.(*NFS); m.Assert(ok) { //{{{
|
||||||
msg.Call(func(com *ctx.Message) *ctx.Message {
|
m.Find("tcp").Call(func(com *ctx.Message) *ctx.Message {
|
||||||
sub := com.Spawn(m.Target())
|
sub := com.Spawn(m.Target())
|
||||||
sub.Put("option", "target", m.Source())
|
sub.Put("option", "target", m.Source())
|
||||||
sub.Put("option", "io", com.Data["io"])
|
sub.Put("option", "io", com.Data["io"])
|
||||||
sub.Cmd(com.Meta["detail"])
|
sub.Start(fmt.Sprintf("file%d", Pulse.Capi("nfile", 1)), "打开文件")
|
||||||
sub.Cap("stream", com.Target().Name)
|
return sub
|
||||||
return sub
|
}, m.Meta["detail"])
|
||||||
}, m.Meta["detail"])
|
}
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"accept": &ctx.Command{Name: "accept args...", Help: "连接文件服务, args: 参考tcp模块, dial命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
|
||||||
m.Start(fmt.Sprintf("file%d", Pulse.Capi("nfile", 1)), "打开文件")
|
|
||||||
}},
|
|
||||||
"dial": &ctx.Command{Name: "dial args...", Help: "连接文件服务, args: 参考tcp模块, dial命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"dial": &ctx.Command{Name: "dial args...", Help: "连接文件服务, args: 参考tcp模块, dial命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
msg := m.Sess("com", "tcp") // {{{
|
if _, ok := m.Target().Server.(*NFS); m.Assert(ok) { //{{{
|
||||||
msg.CallBack(func(com *ctx.Message) *ctx.Message {
|
m.Find("tcp").Call(func(com *ctx.Message) *ctx.Message {
|
||||||
sub := com.Spawn(m.Target())
|
sub := com.Spawn(m.Target())
|
||||||
sub.Put("option", "target", m.Source())
|
sub.Put("option", "target", m.Source())
|
||||||
sub.Put("option", "io", com.Data["io"])
|
sub.Put("option", "io", com.Data["io"])
|
||||||
sub.Start(fmt.Sprintf("file%d", Pulse.Capi("nfile", 1)), "打开文件")
|
sub.Start(fmt.Sprintf("file%d", Pulse.Capi("nfile", 1)), "打开文件")
|
||||||
sub.Cap("stream", com.Target().Name)
|
return sub
|
||||||
m.Target(sub.Target())
|
}, m.Meta["detail"])
|
||||||
return sub
|
}
|
||||||
}, m.Meta["detail"])
|
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"send": &ctx.Command{Name: "send [file] args...", Help: "连接文件服务, args: 参考tcp模块, dial命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"send": &ctx.Command{Name: "send [file] args...", Help: "连接文件服务, args: 参考tcp模块, dial命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
@ -933,6 +930,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
|||||||
"save": &ctx.Command{},
|
"save": &ctx.Command{},
|
||||||
"load": &ctx.Command{},
|
"load": &ctx.Command{},
|
||||||
"genqr": &ctx.Command{},
|
"genqr": &ctx.Command{},
|
||||||
|
"write": &ctx.Command{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1,20 +1,16 @@
|
|||||||
package ssh // {{{
|
package ssh // {{{
|
||||||
// }}}
|
// }}}
|
||||||
import ( // {{{
|
import ( // {{{
|
||||||
"bufio"
|
|
||||||
"contexts"
|
"contexts"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
type SSH struct {
|
type SSH struct {
|
||||||
send map[string]*ctx.Message
|
nfs *ctx.Context
|
||||||
*bufio.Writer
|
|
||||||
*bufio.Reader
|
|
||||||
net.Conn
|
|
||||||
|
|
||||||
*ctx.Context
|
*ctx.Context
|
||||||
}
|
}
|
||||||
@ -39,6 +35,8 @@ func (ssh *SSH) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (ssh *SSH) Start(m *ctx.Message, arg ...string) bool { // {{{
|
func (ssh *SSH) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||||
|
ssh.nfs = m.Source()
|
||||||
|
m.Cap("stream", m.Source().Name)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +51,7 @@ func (ssh *SSH) Close(m *ctx.Message, arg ...string) bool { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
func Done(m *ctx.Message, lock chan bool) {
|
func Done(m *ctx.Message, lock chan bool) { // {{{
|
||||||
m.Log("lock", nil, "done before %v", m.Meta["detail"])
|
m.Log("lock", nil, "done before %v", m.Meta["detail"])
|
||||||
if m.Options("stdio") {
|
if m.Options("stdio") {
|
||||||
lock <- true
|
lock <- true
|
||||||
@ -61,7 +59,8 @@ func Done(m *ctx.Message, lock chan bool) {
|
|||||||
m.Log("lock", nil, "done after %v", m.Meta["detail"])
|
m.Log("lock", nil, "done after %v", m.Meta["detail"])
|
||||||
}
|
}
|
||||||
|
|
||||||
func Wait(m *ctx.Message, lock chan bool) {
|
// }}}
|
||||||
|
func Wait(m *ctx.Message, lock chan bool) { // {{{
|
||||||
m.Log("lock", nil, "wait before %v", m.Meta["detail"])
|
m.Log("lock", nil, "wait before %v", m.Meta["detail"])
|
||||||
if m.Options("stdio") {
|
if m.Options("stdio") {
|
||||||
<-lock
|
<-lock
|
||||||
@ -69,6 +68,8 @@ func Wait(m *ctx.Message, lock chan bool) {
|
|||||||
m.Log("lock", nil, "wait after %v", m.Meta["detail"])
|
m.Log("lock", nil, "wait after %v", m.Meta["detail"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
var Pulse *ctx.Message
|
var Pulse *ctx.Message
|
||||||
var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||||
Caches: map[string]*ctx.Cache{
|
Caches: map[string]*ctx.Cache{
|
||||||
@ -89,24 +90,24 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"listen": &ctx.Command{Name: "listen address protocol", Help: "监听连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"listen": &ctx.Command{Name: "listen address protocol", Help: "监听连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
msg := m.Find("nfs") // {{{
|
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
|
||||||
msg.Call(func(file *ctx.Message) *ctx.Message {
|
m.Find("nfs").Call(func(file *ctx.Message) *ctx.Message {
|
||||||
sub := file.Spawn(m.Target())
|
sub := file.Spawn(m.Target())
|
||||||
sub.Start(fmt.Sprintf("host%d", Pulse.Capi("nhost", 1)), "远程主机")
|
sub.Start(fmt.Sprintf("host%d", Pulse.Capi("nhost", 1)), "远程主机")
|
||||||
sub.Cap("stream", file.Target().Name)
|
// sub.Sesss("nfs").Cmd("send", "route", sub.Target().Name, m.Cap("route"))
|
||||||
|
return sub
|
||||||
sub.Sess("file", "nfs."+file.Target().Name)
|
}, m.Meta["detail"])
|
||||||
sub.Sess("file").Cmd("send", "route", sub.Target().Name, msg.Cap("route"))
|
}
|
||||||
return sub
|
|
||||||
}, m.Meta["detail"])
|
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"dial": &ctx.Command{Name: "dial address protocol", Help: "建立连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"dial": &ctx.Command{Name: "dial address protocol", Help: "建立连接", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
msg := m.Sess("file", "nfs") // {{{
|
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
|
||||||
msg.Call(func(file *ctx.Message) *ctx.Message {
|
m.Find("nfs").Call(func(file *ctx.Message) *ctx.Message {
|
||||||
m.Cap("stream", file.Target().Name)
|
sub := file.Spawn(m.Target())
|
||||||
return m
|
sub.Target().Start(sub)
|
||||||
}, m.Meta["detail"])
|
return sub
|
||||||
|
}, m.Meta["detail"])
|
||||||
|
}
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"route": &ctx.Command{Name: "route", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"route": &ctx.Command{Name: "route", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
@ -114,81 +115,69 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Cap("route", arg[1]+"."+arg[0])
|
m.Cap("route", arg[1]+"."+arg[0])
|
||||||
info := map[string]string{"route": m.Cap("route")}
|
info := map[string]string{"route": m.Cap("route")}
|
||||||
|
|
||||||
msg := m.Sess("file")
|
msg := m.Sesss("nfs")
|
||||||
msg.Put("option", "data", info)
|
msg.Put("option", "data", info)
|
||||||
msg.Cmd("json", m.Conf("route.json"))
|
msg.Cmd("json", m.Conf("route.json"))
|
||||||
|
|
||||||
png := m.Sess("file")
|
png := m.Sesss("nfs")
|
||||||
png.Cmd("genqr", m.Conf("route.png"), msg.Result(0))
|
png.Cmd("genqr", m.Conf("route.png"), msg.Result(0))
|
||||||
|
|
||||||
m.Back(m)
|
m.Back(m)
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
|
"who": &ctx.Command{Name: "who", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
|
aaa := m.Sesss("aaa")
|
||||||
|
m.Echo(aaa.Cap("group"))
|
||||||
|
}},
|
||||||
"pwd": &ctx.Command{Name: "pwd", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"pwd": &ctx.Command{Name: "pwd", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
m.Echo(m.Cap("route")) // {{{
|
m.Echo(m.Cap("route")) // {{{
|
||||||
m.Back(m)
|
m.Back(m)
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"send": &ctx.Command{Name: "send route cmd arg...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"send": &ctx.Command{Name: "send [route domain] cmd arg...", Help: "远程执行",
|
||||||
if _, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
|
Formats: map[string]int{"route": 1},
|
||||||
lock := make(chan bool)
|
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
if len(arg[0]) == 0 {
|
if ssh, ok := m.Target().Server.(*SSH); m.Assert(ok) { // {{{
|
||||||
msg := m.Spawn(m.Target()).Cmd(arg[1:])
|
|
||||||
m.Copy(msg, "result")
|
|
||||||
m.Copy(msg, "append")
|
|
||||||
m.Back(m)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
miss := true
|
target := strings.Split(m.Option("route"), ".")
|
||||||
self := true
|
if len(target) == 0 {
|
||||||
target := strings.Split(arg[0], ".")
|
if m.Options("nsend") {
|
||||||
m.Travel(m.Target(), func(m *ctx.Message) bool {
|
msg := m.Spawn(m.Target())
|
||||||
if self {
|
msg.Cmd(arg)
|
||||||
self = false
|
m.Back(msg)
|
||||||
return true
|
} else {
|
||||||
}
|
msg := m.Spawn(ssh.nfs)
|
||||||
|
msg.Call(func(host *ctx.Message) *ctx.Message {
|
||||||
if m.Target().Name == target[0] {
|
return m.Copy(host, "result").Copy(host, "append")
|
||||||
msg := m.Sess("file")
|
}, "send", "send", arg)
|
||||||
msg.Call(func(host *ctx.Message) *ctx.Message {
|
}
|
||||||
m.Copy(host, "result")
|
|
||||||
m.Copy(host, "append")
|
|
||||||
Done(m, lock)
|
|
||||||
return m
|
|
||||||
}, "send", "send", strings.Join(target[1:], "."), arg[1:])
|
|
||||||
|
|
||||||
miss = false
|
|
||||||
}
|
|
||||||
return miss
|
|
||||||
})
|
|
||||||
|
|
||||||
if miss {
|
|
||||||
if target[0] == m.Conf("route") {
|
|
||||||
m.Spawn(m.Target()).Call(func(host *ctx.Message) *ctx.Message {
|
|
||||||
m.Copy(host, "result")
|
|
||||||
m.Copy(host, "append")
|
|
||||||
Done(m, lock)
|
|
||||||
return m
|
|
||||||
}, "send", strings.Join(target[1:], "."), arg[1:])
|
|
||||||
} else if m.Cap("route") != "ssh" {
|
|
||||||
msg := m.Sess("file")
|
|
||||||
msg.Call(func(host *ctx.Message) *ctx.Message {
|
|
||||||
m.Copy(host, "result")
|
|
||||||
m.Copy(host, "append")
|
|
||||||
m.Back(m)
|
|
||||||
Done(m, lock)
|
|
||||||
return nil
|
|
||||||
}, "send", "send", arg)
|
|
||||||
} else {
|
|
||||||
m.Back(m)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
miss := true
|
||||||
|
m.Travel(c, func(m *ctx.Message) bool {
|
||||||
|
if ssh, ok := m.Target().Server.(*SSH); ok && m.Target().Name == target[0] {
|
||||||
|
msg := m.Spawn(ssh.nfs)
|
||||||
|
msg.Option("route", strings.Join(target[1:], "."))
|
||||||
|
msg.Call(func(host *ctx.Message) *ctx.Message {
|
||||||
|
return m.Copy(host, "result").Copy(host, "append")
|
||||||
|
}, "send", "send", arg)
|
||||||
|
|
||||||
|
miss = false
|
||||||
|
}
|
||||||
|
return miss
|
||||||
|
})
|
||||||
|
|
||||||
|
if ssh, ok := c.Server.(*SSH); m.Assert(ok) && ssh.nfs != nil {
|
||||||
|
msg := m.Spawn(ssh.nfs)
|
||||||
|
msg.Option("route", m.Option("route"))
|
||||||
|
msg.Call(func(host *ctx.Message) *ctx.Message {
|
||||||
|
return m.Copy(host, "result").Copy(host, "append")
|
||||||
|
}, "send", "send", arg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Wait(m, lock)
|
// }}}
|
||||||
}
|
}},
|
||||||
// }}}
|
|
||||||
}},
|
|
||||||
"good": &ctx.Command{Name: "good", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
"good": &ctx.Command{Name: "good", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
||||||
m.Append("share", m.Cap("share")) // {{{
|
m.Append("share", m.Cap("share")) // {{{
|
||||||
m.Append("level", m.Cap("level"))
|
m.Append("level", m.Cap("level"))
|
||||||
@ -201,31 +190,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Back(m)
|
m.Back(m)
|
||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
"register": &ctx.Command{Name: "remote detail...", Help: "远程执行", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
|
|
||||||
ssh, ok := m.Target().Server.(*SSH)
|
|
||||||
m.Assert(ok)
|
|
||||||
|
|
||||||
m.Capi("nsend", 1)
|
|
||||||
m.Add("option", "nrecv", m.Cap("nsend"))
|
|
||||||
ssh.send[m.Cap("nsend")] = m
|
|
||||||
|
|
||||||
for _, v := range arg {
|
|
||||||
fmt.Fprintf(ssh.Writer, "detail: %v\n", v)
|
|
||||||
}
|
|
||||||
for _, k := range m.Meta["option"] {
|
|
||||||
if k == "args" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, v := range m.Meta[k] {
|
|
||||||
fmt.Fprintf(ssh.Writer, "%s: %s\n", k, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Fprintf(ssh.Writer, "\n")
|
|
||||||
ssh.Writer.Flush()
|
|
||||||
|
|
||||||
m.Recv = make(chan bool)
|
|
||||||
<-m.Recv
|
|
||||||
}},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,7 +173,6 @@ func (web *WEB) Trans(m *ctx.Message, key string, hand func(*ctx.Message, *ctx.C
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) { // {{{
|
func (web *WEB) ServeHTTP(w http.ResponseWriter, r *http.Request) { // {{{
|
||||||
web.Log("fuck", nil, "why")
|
|
||||||
if web.Message != nil {
|
if web.Message != nil {
|
||||||
log.Println()
|
log.Println()
|
||||||
web.Log("cmd", nil, "%v %s %s", r.RemoteAddr, r.Method, r.URL)
|
web.Log("cmd", nil, "%v %s %s", r.RemoteAddr, r.Method, r.URL)
|
||||||
|
@ -373,6 +373,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
m.Assert(ok)
|
m.Assert(ok)
|
||||||
|
|
||||||
if cli, ok := m.Data["cli"].(*ctx.Context); m.Assert(ok) {
|
if cli, ok := m.Data["cli"].(*ctx.Context); m.Assert(ok) {
|
||||||
|
m.Sessions["cli"] = m.Spawn(cli)
|
||||||
cli, rest, word := yac.parse(m, cli, page, void, strings.Join(arg[2:], " "))
|
cli, rest, word := yac.parse(m, cli, page, void, strings.Join(arg[2:], " "))
|
||||||
m.Data["cli"] = cli
|
m.Data["cli"] = cli
|
||||||
m.Result(0, rest, word)
|
m.Result(0, rest, word)
|
||||||
@ -431,6 +432,11 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
// }}}
|
// }}}
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
Index: map[string]*ctx.Context{
|
||||||
|
"void": &ctx.Context{Name: "void", Help: "void",
|
||||||
|
Commands: map[string]*ctx.Command{"parse": &ctx.Command{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user