diff --git a/base/cli/qrcode.go b/base/cli/qrcode.go index 0f374589..085fc0ee 100644 --- a/base/cli/qrcode.go +++ b/base/cli/qrcode.go @@ -2,12 +2,13 @@ package cli import ( "encoding/base64" - "github.com/skip2/go-qrcode" "image/color" "math/rand" "strconv" "strings" + "github.com/skip2/go-qrcode" + ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/aaa" kit "github.com/shylinux/toolkits" @@ -125,9 +126,9 @@ func init() { m.Option(SIZE, kit.Select("240", arg, 3)) if aaa.SessIsCli(m) { - _qrcode_cli(m, arg[0]) + _qrcode_cli(m, kit.Select("hi", arg, 0)) } else { - _qrcode_web(m, arg[0]) + _qrcode_web(m, kit.Select("hi", arg, 0)) } }}, }, diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index 507aafba..a369b881 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -404,12 +404,13 @@ const ( SELECT = "select" DELETE = "delete" REMOVE = "remove" - REVERT = "revert" EXPORT = "export" IMPORT = "import" PRUNES = "prunes" INPUTS = "inputs" + REPEAT = "repeat" + REVERT = "revert" ) const ( CACHE_LIMIT = "cache.limit" diff --git a/base/ssh/channel.go b/base/ssh/channel.go index d9e105c3..32193420 100644 --- a/base/ssh/channel.go +++ b/base/ssh/channel.go @@ -55,7 +55,7 @@ func _ssh_watch(m *ice.Message, meta map[string]string, h string, input io.Reade m.Cmdy(mdb.INSERT, CHANNEL, kit.Keys(kit.MDB_HASH, h), mdb.LIST, kit.MDB_TYPE, CMD, kit.MDB_TEXT, cmd) i = 0 default: - if i += n; i >= 4096 { + if i += n; i >= ice.MOD_BUFS { i = 0 } } @@ -80,6 +80,9 @@ func init() { m.Cmdy(mdb.PRUNES, SERVICE, "", mdb.HASH, kit.MDB_STATUS, tcp.ERROR) m.Cmdy(mdb.PRUNES, CHANNEL, "", mdb.HASH, kit.MDB_STATUS, tcp.CLOSE) }}, + mdb.REPEAT: {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(CHANNEL, kit.MDB_ACTION, ctx.COMMAND, CMD, m.Option(kit.MDB_TEXT)) + }}, ctx.COMMAND: {Name: "command cmd=pwd", Help: "命令", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.INSERT, CHANNEL, kit.Keys(kit.MDB_HASH, m.Option(kit.MDB_HASH)), mdb.LIST, kit.MDB_TYPE, CMD, kit.MDB_TEXT, m.Option(CMD)) m.Richs(CHANNEL, "", m.Option(kit.MDB_HASH), func(key string, value map[string]interface{}) { @@ -89,9 +92,6 @@ func init() { }) m.ProcessRefresh("300ms") }}, - "repeat": {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(CHANNEL, kit.MDB_ACTION, ctx.COMMAND, CMD, m.Option("text")) - }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 通道列表 m.Fields(len(arg) == 0, "time,hash,status,username,hostport,tty,count") @@ -106,7 +106,7 @@ func init() { // 通道命令 m.Fields(len(arg) == 1, "time,id,type,text") m.Cmdy(mdb.SELECT, CHANNEL, kit.Keys(kit.MDB_HASH, arg[0]), mdb.LIST, kit.MDB_ID, arg[1:]) - m.PushAction("repeat") + m.PushAction(mdb.REPEAT) }}, }, }) diff --git a/base/ssh/connect.go b/base/ssh/connect.go index 96c9388c..76e46ae0 100644 --- a/base/ssh/connect.go +++ b/base/ssh/connect.go @@ -30,7 +30,7 @@ func _ssh_open(m *ice.Message, arg ...string) { // 设置宽高 w, h, _ := terminal.GetSize(fd) - c.Write([]byte(fmt.Sprintf("height:%d,width:%d\n", h, w))) + c.Write([]byte(fmt.Sprintf("#height:%d,width:%d\n", h, w))) // 初始命令 for _, item := range kit.Simple(m.Optionv(kit.MDB_LIST)) { @@ -68,7 +68,7 @@ func _ssh_dial(m *ice.Message, cb func(net.Conn), arg ...string) { w, h, _ := terminal.GetSize(int(os.Stdin.Fd())) buf := make([]byte, ice.MOD_BUFS) if n, e := c.Read(buf); m.Assert(e) { - fmt.Sscanf(string(buf[:n]), "height:%d,width:%d", &h, &w) + fmt.Sscanf(string(buf[:n]), "#height:%d,width:%d", &h, &w) } m.Go(func() { @@ -202,7 +202,6 @@ func init() { m.Richs(CONNECT, "", m.Option(kit.MDB_HASH), func(key string, value map[string]interface{}) { client, _ = value[CONNECT].(*ssh.Client) }) - m.Debug("what %v", client) h := m.Rich(SESSION, "", kit.Data(kit.MDB_STATUS, tcp.OPEN, CONNECT, m.Option(kit.MDB_HASH))) if session, e := _ssh_session(m, h, client); m.Assert(e) { diff --git a/base/ssh/scripts.go b/base/ssh/scripts.go index 07ab4aef..b56a5e93 100644 --- a/base/ssh/scripts.go +++ b/base/ssh/scripts.go @@ -104,8 +104,6 @@ type Frame struct { last string ps1 []string ps2 []string - - exit bool } func (f *Frame) prompt(m *ice.Message, list ...string) *Frame { @@ -238,7 +236,7 @@ func (f *Frame) parse(m *ice.Message, line string) string { return "" } func (f *Frame) scan(m *ice.Message, h, line string) *Frame { - m.Option(kit.Keycb(RETURN), func() { f.exit = true }) + m.Option(kit.Keycb(RETURN), func() { f.close() }) f.ps1 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS1))) f.ps2 = kit.Simple(m.Confv(PROMPT, kit.Keym(PS2))) ps := f.ps1 @@ -246,7 +244,7 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { m.Sleep("300ms") m.I, m.O = f.stdin, f.stdout bio := bufio.NewScanner(f.stdin) - for f.prompt(m, ps...); bio.Scan() && !f.exit; f.prompt(m, ps...) { + for f.prompt(m, ps...); bio.Scan() && f.stdin != nil; f.prompt(m, ps...) { if h == STDIO && len(bio.Text()) == 0 { continue // 空行 } @@ -255,6 +253,9 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { f.count++ if len(bio.Text()) == 0 { + if strings.Count(line, "`")%2 == 1 { + line += "\n" + } continue // 空行 } @@ -280,6 +281,14 @@ func (f *Frame) scan(m *ice.Message, h, line string) *Frame { } return f } +func (f *Frame) close() { + fmt.Printf("what %v\n", 123) + if stdin, ok := f.stdin.(io.Closer); ok { + stdin.Close() + f.stdin = nil + fmt.Printf("what %v\n", 123) + } +} func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server { return f @@ -350,9 +359,8 @@ const ( TARGET = "target" PROMPT = "prompt" PRINTF = "printf" - RETURN = "return" - SCREEN = "screen" + RETURN = "return" ) func init() { @@ -366,8 +374,8 @@ func init() { }, Commands: map[string]*ice.Command{ SOURCE: {Name: "source hash id limit offend auto", Help: "脚本解析", Action: map[string]*ice.Action{ - "repeat": {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(SCREEN, m.Option("text")) + mdb.REPEAT: {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(SCREEN, m.Option(kit.MDB_TEXT)) m.ProcessInner() }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -392,7 +400,7 @@ func init() { // 命令列表 m.Fields(len(arg) == 1 || arg[1] == "", "time,id,text") m.Cmdy(mdb.SELECT, SOURCE, kit.Keys(kit.MDB_HASH, arg[0]), mdb.LIST, kit.MDB_ID, arg[1:]) - m.PushAction("repeat") + m.PushAction(mdb.REPEAT) }}, TARGET: {Name: "target name 执行:button", Help: "当前模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { f := m.Target().Server().(*Frame) diff --git a/base/ssh/session.go b/base/ssh/session.go index df48c958..d5a99400 100644 --- a/base/ssh/session.go +++ b/base/ssh/session.go @@ -80,8 +80,8 @@ func init() { }) m.ProcessRefresh("300ms") }}, - "repeat": {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(SESSION, kit.MDB_ACTION, ctx.COMMAND, CMD, m.Option("text")) + mdb.REPEAT: {Name: "repeat", Help: "执行", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(SESSION, kit.MDB_ACTION, ctx.COMMAND, CMD, m.Option(kit.MDB_TEXT)) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { @@ -97,7 +97,7 @@ func init() { m.Fields(len(arg) == 1, "time,id,type,text") m.Cmdy(mdb.SELECT, SESSION, kit.Keys(kit.MDB_HASH, arg[0]), mdb.LIST, kit.MDB_ID, arg[1:]) m.Table(func(index int, value map[string]string, head []string) { - m.PushButton(kit.Select("", "repeat", value["type"] == "cmd")) + m.PushButton(kit.Select("", mdb.REPEAT, value[kit.MDB_TYPE] == CMD)) }) }}, }, diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go index 6faf1778..565934ff 100644 --- a/base/ssh/ssh.go +++ b/base/ssh/ssh.go @@ -19,8 +19,8 @@ var Index = &ice.Context{Name: SSH, Help: "终端模块", Commands: map[string]* }) }}, ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if _, ok := m.Target().Server().(*Frame); ok { - m.Done(true) + if f, ok := m.Target().Server().(*Frame); ok { + f.close() } m.Save() }}, diff --git a/core/code/code.go b/core/code/code.go index 83d88da9..c44a0c09 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -13,7 +13,7 @@ var Index = &ice.Context{Name: CODE, Help: "编程中心", Commands: map[string] ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() m.Conf(PUBLISH, kit.Keym(ice.CONTEXTS), _contexts) - m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, "web.code.publish") + m.Cmd(aaa.ROLE, aaa.WHITE, aaa.VOID, m.Prefix(PUBLISH)) }}, ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save() diff --git a/core/code/go.go b/core/code/go.go index 933bf656..9101104f 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -211,6 +211,8 @@ func init() { "msg", FUNCTION, "m", FUNCTION, + "false", STRING, + "true", STRING, "nil", STRING, "-1", STRING, "0", STRING, diff --git a/core/code/js.go b/core/code/js.go index a84ec1b8..391a536a 100644 --- a/core/code/js.go +++ b/core/code/js.go @@ -1,14 +1,14 @@ package code import ( + "path" + ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/web" kit "github.com/shylinux/toolkits" - - "path" ) const JS = "js" diff --git a/go.sum b/go.sum index f897e888..9a591e85 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,13 @@ github.com/AaronO/go-git-http v0.0.0-20161214145340-1d9485b3a98f/go.mod h1:+6Yuq73F9068Na+mSBNXCvyuxvgw4f/g5ii40e3U8Sc= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/shylinux/toolkits v0.2.3 h1:UdE5dUKtc+iVeco9sFrlj98BxVJADYoLNeywTnLrSMc= github.com/shylinux/toolkits v0.2.3/go.mod h1:oMwi/N00I2cXenmcAkqikEncTzB4u5JhTQ9mO5xj7sY= +github.com/shylinux/toolkits v0.2.4 h1:2TaRBYdt15dE9vTUTO++6aF66vOZNd+ruP3be1C4zaY= +github.com/shylinux/toolkits v0.2.4/go.mod h1:oMwi/N00I2cXenmcAkqikEncTzB4u5JhTQ9mO5xj7sY= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= diff --git a/init.go b/init.go index 884ec9ec..b1a93a4d 100644 --- a/init.go +++ b/init.go @@ -1,8 +1,6 @@ package ice import ( - kit "github.com/shylinux/toolkits" - "fmt" "io" "os" @@ -10,6 +8,8 @@ import ( "sync" "sync/atomic" "time" + + kit "github.com/shylinux/toolkits" ) var Info = struct { diff --git a/meta.go b/meta.go index e5d62bb1..34109d44 100644 --- a/meta.go +++ b/meta.go @@ -1,14 +1,14 @@ package ice import ( - kit "github.com/shylinux/toolkits" - "bytes" "encoding/csv" "fmt" "sort" "strconv" "strings" + + kit "github.com/shylinux/toolkits" ) func (m *Message) Add(key string, arg ...string) *Message {