1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 01:24:05 +08:00
This commit is contained in:
shylinux 2020-07-25 13:41:52 +08:00
parent 5b41af897b
commit de6f46f718
6 changed files with 43 additions and 48 deletions

View File

@ -12,7 +12,7 @@ import (
func _user_list(m *ice.Message) {
m.Richs(USER, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
m.Push(key, value, []string{kit.MDB_TIME, USERNAME, USERNICK})
m.Push(key, value, []string{kit.MDB_TIME, USERNICK, USERNAME})
})
}
func _user_login(m *ice.Message, name, word string) (ok bool) {

View File

@ -83,6 +83,20 @@ func init() {
_system_show(m, cmd)
}
}},
"ssh_user": {Name: "ssh_user", Help: "ssh_user", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
msg := m.Cmd(SYSTEM, "who")
msg.Split(msg.Result(), "name term begin", " \t", "\n")
msg.Table(func(index int, value map[string]string, head []string) {
m.Push("name", value["name"])
m.Push("term", value["term"])
ls := strings.Split(value["begin"], " (")
t, _ := time.Parse("Jan 2 15:04", ls[0])
m.Push("begin", t.Format("2006-01-02 15:04:05"))
m.Push("ip", value["ip"])
m.Push("duration", value["duration"])
})
}},
},
}, nil)
}

View File

@ -2,47 +2,26 @@ package code
import (
ice "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/mdb"
kit "github.com/shylinux/toolkits"
"os"
qrs "github.com/skip2/go-qrcode"
"github.com/tuotoo/qrcode"
)
func init() {
Index.Register(&ice.Context{Name: "qrc", Help: "二维码",
Index.Register(&ice.Context{Name: QRCODE, Help: "二维码",
Configs: map[string]*ice.Config{
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data(
"plug", `{"display": {"height": "400px"}}`,
)},
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data()},
},
Commands: map[string]*ice.Command{
"list": {Name: "list name", Help: "列表", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if f, e := os.Open(arg[0]); e == nil {
defer f.Close()
if q, e := qrcode.Decode(f); e == nil {
m.Echo(q.Content)
return
}
}
m.Echo("hello world")
}},
"save": {Name: "save name text", Help: "保存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if qr, e := qrs.New(kit.Select(m.Option("content"), arg, 1), qrs.Medium); m.Assert(e) {
if f, e := os.Create(arg[0]); m.Assert(e) {
defer f.Close()
m.Debug(m.Option("content"))
m.Assert(qr.Write(kit.Int(kit.Select("256", arg, 2)), f))
m.Echo(arg[0])
}
}
}},
"plug": {Name: "plug name text", Help: "插件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo(m.Conf(QRCODE, "meta.plug"))
}},
"show": {Name: "show name", Help: "渲染", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo(`<img src="/share/local/%s?pod=%s">`, arg[0], m.Option(ice.MSG_USERPOD))
QRCODE: {Name: "qrcode", Help: "二维码", Action: map[string]*ice.Action{
mdb.INSERT: {Hand: func(m *ice.Message, arg ...string) {
m.Grow(QRCODE, kit.Keys(m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM)), func(index int, value map[string]interface{}) {
m.Push("", value, []string{kit.MDB_TIME, kit.MDB_TEXT})
})
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Grow(QRCODE, kit.Keys(m.Option(ice.MSG_RIVER), m.Option(ice.MSG_STORM)), func(index int, value map[string]interface{}) {
m.Push("", value, []string{kit.MDB_TIME, kit.MDB_TEXT})
})
}},
},
}, nil)

View File

@ -358,7 +358,7 @@ func init() {
}
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
_field_show(m, arg[0], arg[1], arg[2:]...)
_field_show(m, strings.ReplaceAll(arg[0], " ", "_"), arg[1], arg[2:]...)
}},
SHELL: {Name: "shell [name] cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 1 {

View File

@ -56,6 +56,7 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
m.Echo(arg[0])
}},
"/login/": {Name: "/login/", Help: "登录", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
switch arg[0] {
case "code":
@ -67,17 +68,15 @@ var Index = &ice.Context{Name: "mp", Help: "小程序",
case "info":
// 用户信息
m.Richs(aaa.SESS, nil, m.Option(ice.MSG_SESSID), func(key string, value map[string]interface{}) {
m.Richs(aaa.USER, nil, value["username"], func(key string, value map[string]interface{}) {
value["gender"] = m.Option("gender")
value["avatar"] = m.Option("avatarUrl")
value["nickname"] = m.Option("nickName")
value["language"] = m.Option("language")
value["province"] = m.Option("province")
value["country"] = m.Option("country")
value["city"] = m.Option("city")
})
})
m.Cmd(aaa.USER, mdb.MODIFY, m.Option(ice.MSG_USERNAME),
"gender", m.Option("gender"),
"avatar", m.Option("avatarUrl"),
"usernick", m.Option("nickName"),
"language", m.Option("language"),
"province", m.Option("province"),
"country", m.Option("country"),
"city", m.Option("city"),
)
case "scan":
m.Cmd(web.FAVOR, "device", "scan", m.Option("name"), m.Option("text"))

View File

@ -6,8 +6,11 @@ refer "" `
源码 https://github.com/shylinux/icebergs/blob/master/misc/mp/mp.go
`
field "用户" user
chapter "应用"
section "二维码"
field "qrcode 源码" web.code.inner args `[ usr/icebergs core/code/qrcode.go 1 ]`
chapter "项目"
section "icebergs"
field "icebergs_统计" web.code.git.trend args `[ icebergs ]` action `{ height 200 speed 20 }`
field "icebergs_源码" web.code.inner args `[ usr/icebergs misc/mp/mp.go 1 ]`