forked from x/ContextOS
mac syn 0.2.0 同步修改
This commit is contained in:
parent
941b593ade
commit
6b43f2b627
@ -7,6 +7,7 @@ import ( // {{{
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -27,8 +28,10 @@ func (aaa *AAA) session(meta string) string { // {{{
|
|||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
func (aaa *AAA) Spawn(c *ctx.Context, m *ctx.Message, arg ...string) ctx.Server {
|
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{
|
||||||
|
"sessid": &ctx.Cache{Name: "会话标识", Value: "", Help: "用户的会话标识"},
|
||||||
|
}
|
||||||
c.Configs = map[string]*ctx.Config{}
|
c.Configs = map[string]*ctx.Config{}
|
||||||
|
|
||||||
s := new(AAA)
|
s := new(AAA)
|
||||||
@ -36,7 +39,8 @@ func (aaa *AAA) Spawn(c *ctx.Context, m *ctx.Message, arg ...string) ctx.Server
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aaa *AAA) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
// }}}
|
||||||
|
func (aaa *AAA) Begin(m *ctx.Message, arg ...string) ctx.Server { // {{{
|
||||||
aaa.Caches["group"] = &ctx.Cache{Name: "用户组", Value: m.Conf("rootname"), Help: "用户组"}
|
aaa.Caches["group"] = &ctx.Cache{Name: "用户组", Value: m.Conf("rootname"), Help: "用户组"}
|
||||||
aaa.Caches["username"] = &ctx.Cache{Name: "用户名", Value: m.Conf("rootname"), Help: "用户名"}
|
aaa.Caches["username"] = &ctx.Cache{Name: "用户名", Value: m.Conf("rootname"), Help: "用户名"}
|
||||||
aaa.Caches["password"] = &ctx.Cache{Name: "密码", Value: "", Help: "用户密码,加密存储", Hand: func(m *ctx.Message, x *ctx.Cache, arg ...string) string {
|
aaa.Caches["password"] = &ctx.Cache{Name: "密码", Value: "", Help: "用户密码,加密存储", Hand: func(m *ctx.Message, x *ctx.Cache, arg ...string) string {
|
||||||
@ -46,16 +50,23 @@ func (aaa *AAA) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
|||||||
return hex.EncodeToString(bs[:])
|
return hex.EncodeToString(bs[:])
|
||||||
} else {
|
} else {
|
||||||
bs := md5.Sum([]byte(fmt.Sprintln("用户密码:%s", arg[0])))
|
bs := md5.Sum([]byte(fmt.Sprintln("用户密码:%s", arg[0])))
|
||||||
if x.Value != hex.EncodeToString(bs[:]) {
|
m.Assert(x.Value == hex.EncodeToString(bs[:]), "密码错误")
|
||||||
m.Assert("error:", "密码错误")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return x.Value
|
return x.Value
|
||||||
// }}}
|
// }}}
|
||||||
}}
|
}}
|
||||||
aaa.Caches["sessid"] = &ctx.Cache{Name: "会话标识", Value: "", Help: "用户的会话标识"}
|
aaa.Caches["time"] = &ctx.Cache{Name: "登录时间", Value: fmt.Sprintf("%d", time.Now().Unix()), Help: "用户登录时间", Hand: func(m *ctx.Message, x *ctx.Cache, arg ...string) string {
|
||||||
aaa.Caches["time"] = &ctx.Cache{Name: "登录时间", Value: "", Help: "用户登录时间"}
|
if len(arg) > 0 { // {{{
|
||||||
|
return x.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
n, e := strconv.Atoi(x.Value)
|
||||||
|
m.Assert(e)
|
||||||
|
|
||||||
|
return time.Unix(int64(n), 0).Format("15:03:04")
|
||||||
|
// }}}
|
||||||
|
}}
|
||||||
|
|
||||||
if len(arg) > 0 {
|
if len(arg) > 0 {
|
||||||
m.Cap("username", arg[0])
|
m.Cap("username", arg[0])
|
||||||
@ -64,21 +75,27 @@ func (aaa *AAA) Begin(m *ctx.Message, arg ...string) ctx.Server {
|
|||||||
if len(arg) > 1 {
|
if len(arg) > 1 {
|
||||||
m.Cap("group", arg[1])
|
m.Cap("group", arg[1])
|
||||||
}
|
}
|
||||||
|
m.Capi("nuser", 1)
|
||||||
|
|
||||||
return aaa
|
return aaa
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aaa *AAA) Start(m *ctx.Message, arg ...string) bool {
|
// }}}
|
||||||
|
func (aaa *AAA) Start(m *ctx.Message, arg ...string) bool { // {{{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (aaa *AAA) Close(m *ctx.Message, arg ...string) bool {
|
// }}}
|
||||||
|
func (aaa *AAA) Close(m *ctx.Message, arg ...string) bool { // {{{
|
||||||
|
m.Master = Index
|
||||||
if m.Cap("username") != m.Conf("rootname") {
|
if m.Cap("username") != m.Conf("rootname") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||||
Caches: map[string]*ctx.Cache{
|
Caches: map[string]*ctx.Cache{
|
||||||
"nuser": &ctx.Cache{Name: "用户数量", Value: "0", Help: "用户数量"},
|
"nuser": &ctx.Cache{Name: "用户数量", Value: "0", Help: "用户数量"},
|
||||||
@ -87,14 +104,14 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
"rootname": &ctx.Config{Name: "根用户名", Value: "root", Help: "根用户名"},
|
"rootname": &ctx.Config{Name: "根用户名", Value: "root", Help: "根用户名"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
Commands: map[string]*ctx.Command{
|
||||||
"login": &ctx.Command{Name: "login [sessid]|[[group] username password]]", Help: "", Hand: func(c *ctx.Context, m *ctx.Message, key string, arg ...string) string {
|
"login": &ctx.Command{Name: "login [sessid]|[[group] username password]]", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) string {
|
||||||
m.Master = m.Target
|
m.Master = m.Target // {{{
|
||||||
aaa := m.Target.Server.(*AAA) // {{{
|
aaa := m.Target.Server.(*AAA)
|
||||||
|
|
||||||
switch len(arg) {
|
switch len(arg) {
|
||||||
case 0:
|
case 0:
|
||||||
m.Travel(m.Target, func(m *ctx.Message) bool {
|
m.Travel(m.Target, func(m *ctx.Message) bool {
|
||||||
m.Echo("%s(%s): %s\n", m.Target.Name, m.Cap("group"), m.Cap("sessid"))
|
m.Echo("%s(%s): %s\n", m.Target.Name, m.Cap("group"), m.Cap("time"))
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
case 1:
|
case 1:
|
||||||
@ -125,7 +142,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
m.Cap("sessid", aaa.session(arg[0]))
|
m.Cap("sessid", aaa.session(arg[0]))
|
||||||
m.Cap("time", fmt.Sprintf("%d", time.Now().Unix()))
|
m.Cap("time", fmt.Sprintf("%d", time.Now().Unix()))
|
||||||
} else {
|
} else {
|
||||||
m = msg
|
m.Target = msg.Target
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Cap("password", arg[1])
|
m.Cap("password", arg[1])
|
||||||
|
@ -17,7 +17,7 @@ func (ssh *SSH) Start(m *ctx.Message, arg ...string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ssh *SSH) Spawn(c *ctx.Context, m *ctx.Message, arg ...string) ctx.Server {
|
func (ssh *SSH) 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.Commands = map[string]*ctx.Command{}
|
c.Commands = map[string]*ctx.Command{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user