1
0
mirror of https://shylinux.com/x/icebergs synced 2025-04-26 17:44:05 +08:00
This commit is contained in:
shaoying 2020-06-18 13:12:07 +08:00
parent 623ca683db
commit 072ae38c88
12 changed files with 47 additions and 28 deletions

View File

@ -4,6 +4,8 @@ import (
"github.com/shylinux/icebergs" "github.com/shylinux/icebergs"
"github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/cli"
"github.com/shylinux/toolkits" "github.com/shylinux/toolkits"
"strings"
) )
func _user_list(m *ice.Message) { func _user_list(m *ice.Message) {
@ -16,6 +18,7 @@ func _user_login(m *ice.Message, name, word string) (ok bool) {
if value[PASSWORD] == "" { if value[PASSWORD] == "" {
ok, value[PASSWORD] = true, word ok, value[PASSWORD] = true, word
} else if value[PASSWORD] == word { } else if value[PASSWORD] == word {
m.Log_AUTH(USERNAME, name, PASSWORD, strings.Repeat("*", len(word)))
ok = true ok = true
} }
}) })
@ -46,7 +49,6 @@ func UserLogin(m *ice.Message, username, password string) bool {
if _user_login(m, username, password) { if _user_login(m, username, password) {
m.Option(ice.MSG_USERNAME, username) m.Option(ice.MSG_USERNAME, username)
m.Option(ice.MSG_USERROLE, UserRole(m, username)) m.Option(ice.MSG_USERROLE, UserRole(m, username))
m.Option(ice.MSG_SESSID, SessCreate(m, m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE)))
return true return true
} }
return false return false

View File

@ -28,8 +28,11 @@ func _system_show(m *ice.Message, cmd *exec.Cmd) {
err := bytes.NewBuffer(make([]byte, 0, 1024)) err := bytes.NewBuffer(make([]byte, 0, 1024))
cmd.Stdout = out cmd.Stdout = out
cmd.Stderr = err cmd.Stderr = err
defer func() {
m.Cost("%v exit: %v out: %v err: %v ",
cmd.Args, cmd.ProcessState.ExitCode(), out.Len(), err.Len())
}()
defer m.Cost("%v exit: %v out: %v err: %v ", cmd.Args, 0, out.Len(), err.Len())
if e := cmd.Run(); e != nil { if e := cmd.Run(); e != nil {
m.Warn(e != nil, "%v run: %s", cmd.Args, kit.Select(e.Error(), err.String())) m.Warn(e != nil, "%v run: %s", cmd.Args, kit.Select(e.Error(), err.String()))
} }

View File

@ -103,8 +103,8 @@ func _cache_watch(m *ice.Message, key, file string) {
func _cache_catch(m *ice.Message, arg ...string) []string { func _cache_catch(m *ice.Message, arg ...string) []string {
if r, ok := m.Optionv("response").(*http.Response); ok { if r, ok := m.Optionv("response").(*http.Response); ok {
return _cache_download(m, r, arg...) return _cache_download(m, r, arg...)
} else if m.R != nil { // } else if m.R != nil {
return _cache_upload(m, arg...) // return _cache_upload(m, arg...)
} }
if f, e := os.Open(arg[2]); m.Assert(e) { if f, e := os.Open(arg[2]); m.Assert(e) {
@ -187,6 +187,10 @@ func init() {
_cache_show(m, "", "", "") _cache_show(m, "", "", "")
} }
}}, }},
kit.MDB_INSERT: {Name: "insert type name", Help: "插入", Hand: func(m *ice.Message, arg ...string) {
arg = _cache_catch(m, arg[0], arg[1])
_cache_save(m, arg[0], arg[1], arg[2], arg[3], arg[4:]...)
}},
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
if len(arg) == 0 { if len(arg) == 0 {
_cache_list(m, "") _cache_list(m, "")

View File

@ -8,12 +8,6 @@ import (
"os" "os"
) )
const (
EXPORT = "usr/export/web.favor/favor.csv"
)
var FAVOR = ice.Name("favor", Index)
func _favor_list(m *ice.Message, zone, id string, fields ...string) { func _favor_list(m *ice.Message, zone, id string, fields ...string) {
m.Richs(FAVOR, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) { m.Richs(FAVOR, nil, kit.Select(kit.MDB_FOREACH, zone), func(key string, val map[string]interface{}) {
if val = val[kit.MDB_META].(map[string]interface{}); zone == "" { if val = val[kit.MDB_META].(map[string]interface{}); zone == "" {
@ -248,6 +242,12 @@ func FavorShow(m *ice.Message, kind string, name, text interface{}, arg ...strin
return m return m
} }
const (
EXPORT = "usr/export/web.favor/favor.csv"
)
var FAVOR = ice.Name("favor", Index)
func init() { func init() {
Index.Merge(&ice.Context{ Index.Merge(&ice.Context{
Configs: map[string]*ice.Config{ Configs: map[string]*ice.Config{

View File

@ -26,9 +26,12 @@ func Login(msg *ice.Message, w http.ResponseWriter, r *http.Request) bool {
if !msg.Options(ice.MSG_USERNAME) && tcp.IPIsLocal(msg, msg.Option(ice.MSG_USERIP)) { if !msg.Options(ice.MSG_USERNAME) && tcp.IPIsLocal(msg, msg.Option(ice.MSG_USERIP)) {
// 自动认证 // 自动认证
if aaa.UserLogin(msg, cli.UserName, cli.PassWord) { if aaa.UserLogin(msg, cli.UserName, cli.PassWord) {
if strings.HasPrefix(msg.Option(ice.MSG_USERUA), "Mozilla/5.0") {
msg.Option(ice.MSG_SESSID, aaa.SessCreate(msg, msg.Option(ice.MSG_USERNAME), msg.Option(ice.MSG_USERROLE)))
Render(msg, "cookie", msg.Option(ice.MSG_SESSID)) Render(msg, "cookie", msg.Option(ice.MSG_SESSID))
} }
} }
}
if s, ok := msg.Target().Commands[ice.WEB_LOGIN]; ok { if s, ok := msg.Target().Commands[ice.WEB_LOGIN]; ok {
// 权限检查 // 权限检查

View File

@ -42,7 +42,7 @@ func Format(key string, arg ...interface{}) string {
} }
func Render(msg *ice.Message, cmd string, args ...interface{}) { func Render(msg *ice.Message, cmd string, args ...interface{}) {
if cmd != "" { if cmd != "" {
msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args) defer func() { msg.Log(ice.LOG_EXPORT, "%s: %v", cmd, args) }()
} }
switch arg := kit.Simple(args...); cmd { switch arg := kit.Simple(args...); cmd {
case ice.RENDER_VOID: case ice.RENDER_VOID:
@ -73,6 +73,7 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
if len(arg) > 0 { if len(arg) > 0 {
msg.W.Write([]byte(kit.Format(arg[0], args[1:]...))) msg.W.Write([]byte(kit.Format(arg[0], args[1:]...)))
} else { } else {
args = append(args, "length:", len(msg.Result()))
msg.W.Write([]byte(msg.Result())) msg.W.Write([]byte(msg.Result()))
} }

View File

@ -167,7 +167,7 @@ func init() {
_action_share_show(m, arg[0], arg[1], arg[2], arg[3:]...) _action_share_show(m, arg[0], arg[1], arg[2], arg[3:]...)
return return
} }
if arg[3] == "action" && _action_action(m, arg[3]) { if len(arg) > 3 && arg[3] == "action" && _action_action(m, arg[3]) {
// 前置命令 // 前置命令
return return
} }

View File

@ -81,14 +81,11 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
"/storm.add", "/storm.add",
}), }),
"white", kit.Dict("void", []interface{}{ "white", kit.Dict("void", []interface{}{
"/toast", "/header",
"/carte",
"/tutor",
"/login",
"/river", "/river",
"/storm", "/storm",
"/action", "/action",
"web.wiki.note", "/footer",
}), }),
)}, )},
}, },
@ -156,6 +153,7 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
case "login": case "login":
// 密码登录 // 密码登录
if len(arg) > 2 && aaa.UserLogin(m, arg[1], arg[2]) { if len(arg) > 2 && aaa.UserLogin(m, arg[1], arg[2]) {
m.Option(ice.MSG_SESSID, aaa.SessCreate(m, m.Option(ice.MSG_USERNAME), m.Option(ice.MSG_USERROLE)))
web.Render(m, "cookie", m.Option(ice.MSG_SESSID)) web.Render(m, "cookie", m.Option(ice.MSG_SESSID))
} }
@ -175,6 +173,9 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心",
} }
} }
if m.Right(m.Option(ice.MSG_USERURL), m.Optionv("cmds")) {
return
}
// 登录检查 // 登录检查
if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") { if m.Warn(!m.Options(ice.MSG_USERNAME), "not login") {
if m.Option("share") == "" { if m.Option("share") == "" {

View File

@ -52,25 +52,26 @@ func _pprof_show(m *ice.Message, zone string, id string) {
list := []string{} list := []string{}
m.Grows(PPROF, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { m.Grows(PPROF, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) {
task.Put(val, func(task *task.Task) error { task.Put(val, func(task *task.Task) error {
m.Sleep("1s")
// 压测命令 // 压测命令
m.Sleep("1s").Log_EXPORT(kit.MDB_META, PPROF, kit.MDB_ZONE, zone, kit.MDB_VALUE, kit.Format(value)) m.Log_EXPORT(kit.MDB_META, PPROF, kit.MDB_ZONE, zone, kit.MDB_VALUE, kit.Format(value))
cmd := kit.Format(value[kit.MDB_TYPE]) cmd := kit.Format(value[kit.MDB_TYPE])
arg := kit.Format(value[kit.MDB_TEXT]) arg := kit.Format(value[kit.MDB_TEXT])
res := web.FavorShow(m.Spawn(), cmd, kit.Format(value[kit.MDB_NAME]), res := web.FavorShow(m.Spawn(), cmd, kit.Format(value[kit.MDB_NAME]),
arg, kit.Simple(value[kit.MDB_EXTRA])...).Result() arg, kit.Simple(value[kit.MDB_EXTRA])...).Result()
web.FavorInsert(m, favor, cmd, arg, res) m.Cmd(web.FAVOR, favor, cmd, arg, res)
list = append(list, cmd+": "+arg, res) list = append(list, cmd+": "+arg, res)
return nil return nil
}) })
}) })
// 收藏程序 // 收藏程序
bin := web.CacheCatch(m.Spawn(), kit.MIME_FILE, kit.Format(val[BINNARY])).Append(kit.MDB_TEXT) bin := m.Cmd(web.CACHE, "catch", kit.MIME_FILE, kit.Format(val[BINNARY])).Append(kit.MDB_TEXT)
web.FavorInsert(m, favor, kit.MIME_FILE, bin, val[BINNARY]) m.Cmd(web.FAVOR, favor, kit.MIME_FILE, bin, val[BINNARY])
// 性能分析 // 性能分析
msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", val[SERVICE]), "seconds", kit.Select("5", kit.Format(val[SECONDS]))) msg := m.Cmd(ice.WEB_SPIDE, "self", "cache", "GET", kit.Select("/code/pprof/profile", val[SERVICE]), "seconds", kit.Select("5", kit.Format(val[SECONDS])))
web.FavorInsert(m, favor, PPROF, msg.Append(kit.MDB_TEXT), kit.Keys(zone, "pd.gz")) m.Cmd(web.FAVOR, favor, PPROF, msg.Append(kit.MDB_TEXT), kit.Keys(zone, "pd.gz"))
// 结果摘要 // 结果摘要
cmd := kit.Simple(m.Confv(PPROF, "meta.pprof"), "-text", val[BINNARY], msg.Append(kit.MDB_TEXT)) cmd := kit.Simple(m.Confv(PPROF, "meta.pprof"), "-text", val[BINNARY], msg.Append(kit.MDB_TEXT))
@ -78,7 +79,7 @@ func _pprof_show(m *ice.Message, zone string, id string) {
if len(res) > 20 { if len(res) > 20 {
res = res[:20] res = res[:20]
} }
web.FavorInsert(m, favor, ice.TYPE_SHELL, strings.Join(cmd, " "), strings.Join(res, "\n")) m.Cmd(web.FAVOR, favor, ice.TYPE_SHELL, strings.Join(cmd, " "), strings.Join(res, "\n"))
list = append(list, ice.TYPE_SHELL+": "+strings.Join(cmd, " "), strings.Join(res, "\n")) list = append(list, ice.TYPE_SHELL+": "+strings.Join(cmd, " "), strings.Join(res, "\n"))
// 结果展示 // 结果展示
@ -88,7 +89,7 @@ func _pprof_show(m *ice.Message, zone string, id string) {
m.Cmd(cli.DAEMON, m.Confv(PPROF, "meta.pprof"), "-http="+p, val[BINNARY], msg.Append(kit.MDB_TEXT)) m.Cmd(cli.DAEMON, m.Confv(PPROF, "meta.pprof"), "-http="+p, val[BINNARY], msg.Append(kit.MDB_TEXT))
url := "http://" + p + "/ui/top" url := "http://" + p + "/ui/top"
web.FavorInsert(m, favor, ice.TYPE_SPIDE, url, msg.Append(kit.MDB_TEXT)) m.Cmd(web.FAVOR, favor, ice.TYPE_SPIDE, url, msg.Append(kit.MDB_TEXT))
m.Set(ice.MSG_RESULT).Echo(url).Echo(" \n").Echo("\n") m.Set(ice.MSG_RESULT).Echo(url).Echo(" \n").Echo("\n")
m.Echo(strings.Join(list, "\n")).Echo("\n") m.Echo(strings.Join(list, "\n")).Echo("\n")

View File

@ -34,7 +34,7 @@ func (m *Message) log(level string, str string, arg ...interface{}) *Message {
} }
switch level { switch level {
case LOG_INFO, LOG_WARN, "refer", "form": case LOG_CMDS, LOG_INFO, LOG_WARN, "refer", "form":
default: default:
_, file, line, _ := runtime.Caller(2) _, file, line, _ := runtime.Caller(2)
ls := strings.Split(file, "/") ls := strings.Split(file, "/")

View File

@ -75,7 +75,7 @@ func _input_find(m *ice.Message, method, word, limit string) {
} else { } else {
if method == WORD && i == 0 { if method == WORD && i == 0 {
// 添加收藏 // 添加收藏
web.FavorInsert(m, "input.word", "input", line[2], line[4], "id", line[3], WEIGHT, line[6]) // web.FavorInsert(m.Spawn(), "input.word", "input", line[2], line[4], "id", line[3], WEIGHT, line[6])
} }
// 输出词汇 // 输出词汇

View File

@ -133,7 +133,11 @@ func (c *Context) Register(s *Context, x Server, name ...string) *Context {
s.server = x s.server = x
return s return s
} }
func (c *Context) Merge(s *Context, x Server) *Context { func (c *Context) Merge(s *Context, x Server, name ...string) *Context {
for _, n := range name {
Name(n, s)
}
if c.Commands == nil { if c.Commands == nil {
c.Commands = map[string]*Command{} c.Commands = map[string]*Command{}
} }