mirror of
https://shylinux.com/x/icebergs
synced 2025-04-26 01:24:05 +08:00
add cli.qrcode
This commit is contained in:
parent
d57610e4cd
commit
2e8b5bb803
@ -1,6 +1,8 @@
|
||||
package aaa
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
@ -41,6 +43,12 @@ func SessCheck(m *ice.Message, sessid string) {
|
||||
func SessCreate(m *ice.Message, username string) string {
|
||||
return m.Option(ice.MSG_SESSID, _sess_create(m, username))
|
||||
}
|
||||
func SessIsCli(m *ice.Message) bool {
|
||||
if m.Option(ice.MSG_USERUA) == "" || strings.Contains(m.Option(ice.MSG_USERUA), "curl") {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const (
|
||||
IP = "ip"
|
||||
|
@ -139,6 +139,9 @@ func init() {
|
||||
_user_search(m, arg[0], arg[1], kit.Select("", arg, 2))
|
||||
}
|
||||
}},
|
||||
"login": {Name: "login", Help: "登录", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.EchoQRCode("hi")
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Fields(len(arg) == 0, "time,username,userzone,usernick")
|
||||
m.Cmdy(mdb.SELECT, USER, "", mdb.HASH, USERNAME, arg)
|
||||
|
@ -96,4 +96,6 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块",
|
||||
},
|
||||
}
|
||||
|
||||
func init() { ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, PYTHON, OUTPUT, PROGRESS) }
|
||||
func init() {
|
||||
ice.Index.Register(Index, nil, RUNTIME, SYSTEM, DAEMON, QRCODE, PYTHON, OUTPUT, PROGRESS)
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ func init() {
|
||||
PYTHON: {Name: "python", Help: "脚本命令", Value: kit.Data(
|
||||
"python", "python",
|
||||
"source", "http://mirrors.sohu.com/python/3.5.2/Python-3.5.2.tar.xz",
|
||||
"qrcode", `import pyqrcode; print(pyqrcode.create('%s').terminal(module_color='%s', quiet_zone=1))`,
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
@ -30,11 +29,6 @@ func init() {
|
||||
m.Cmdy("web.code.install", "start", m.Conf(PYTHON, "meta.source"), "bin/python3")
|
||||
}},
|
||||
|
||||
"qrcode": {Name: "qrcode text color", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
prefix := []string{SYSTEM, m.Conf(PYTHON, "meta.python")}
|
||||
m.Cmdy(prefix, "-c", kit.Format(m.Conf(PYTHON, "meta.qrcode"),
|
||||
kit.Select("hello world", m.Option("text")), kit.Select("blue", m.Option("color"))))
|
||||
}},
|
||||
"pip": {Name: "pip", Help: "安装", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(SYSTEM, m.Conf(PYTHON, "meta.pip"), "install", arg)
|
||||
}},
|
||||
|
@ -1,17 +1,63 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
|
||||
"github.com/skip2/go-qrcode"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _qrcode_cli(m *ice.Message, arg ...string) {
|
||||
fg := qrcodeTerminal.ConsoleColors.BrightBlue
|
||||
bg := qrcodeTerminal.ConsoleColors.BrightWhite
|
||||
switch m.Option("fg") {
|
||||
case "black":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightBlack
|
||||
case "red":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightRed
|
||||
case "green":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightGreen
|
||||
case "yellow":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightYellow
|
||||
case "blue":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightBlue
|
||||
case "cyan":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightCyan
|
||||
case "magenta":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightMagenta
|
||||
case "white":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightWhite
|
||||
}
|
||||
obj := qrcodeTerminal.New2(fg, bg, qrcodeTerminal.QRCodeRecoveryLevels.Medium)
|
||||
m.Echo("%s", *obj.Get(arg[0]))
|
||||
}
|
||||
func _qrcode_web(m *ice.Message, arg ...string) {
|
||||
buf := bytes.NewBuffer(make([]byte, 0, ice.MOD_BUFS))
|
||||
if qr, e := qrcode.New(arg[0], qrcode.Medium); m.Assert(e) {
|
||||
m.Assert(qr.Write(kit.Int(kit.Select("240", arg, 1)), buf))
|
||||
}
|
||||
src := "data:image/png;base64," + base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
m.Echo(`<img src="%s" title='%s' height=%s>`, src, arg[0], kit.Select("240", arg, 1))
|
||||
}
|
||||
|
||||
const QRCODE = "qrcode"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
QRCODE: {Name: "qrcode", Help: "二维码", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
QRCODE: {Name: "qrcode", Help: "二维码", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
QRCODE: {Name: "qrcode text auto", Help: "二维码", Action: map[string]*ice.Action{}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if aaa.SessIsCli(m) {
|
||||
_qrcode_cli(m, arg...)
|
||||
return
|
||||
}
|
||||
_qrcode_web(m, arg...)
|
||||
}},
|
||||
},
|
||||
})
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
qrcodeTerminal "github.com/Baozisoftware/qrcode-terminal-go"
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
@ -82,9 +81,6 @@ const (
|
||||
CMD_CODE = "cmd_code"
|
||||
)
|
||||
|
||||
const (
|
||||
QRCODE = "qrcode"
|
||||
)
|
||||
const SYSTEM = "system"
|
||||
|
||||
func init() {
|
||||
@ -93,32 +89,7 @@ func init() {
|
||||
SYSTEM: {Name: SYSTEM, Help: "系统命令", Value: kit.Data()},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
SYSTEM: {Name: "system id auto", Help: "系统命令", Action: map[string]*ice.Action{
|
||||
QRCODE: {Name: "qrcode text fg bg lv", Help: "二维码", Hand: func(m *ice.Message, arg ...string) {
|
||||
fg := qrcodeTerminal.ConsoleColors.BrightBlue
|
||||
bg := qrcodeTerminal.ConsoleColors.BrightWhite
|
||||
switch m.Option("fg") {
|
||||
case "black":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightBlack
|
||||
case "red":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightRed
|
||||
case "green":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightGreen
|
||||
case "yellow":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightYellow
|
||||
case "blue":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightBlue
|
||||
case "cyan":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightCyan
|
||||
case "magenta":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightMagenta
|
||||
case "white":
|
||||
fg = qrcodeTerminal.ConsoleColors.BrightWhite
|
||||
}
|
||||
obj := qrcodeTerminal.New2(fg, bg, qrcodeTerminal.QRCodeRecoveryLevels.Medium)
|
||||
m.Echo("%s", *obj.Get(m.Option(kit.MDB_TEXT)))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
SYSTEM: {Name: "system id auto", Help: "系统命令", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
|
||||
|
||||
if len(arg) == 0 || kit.Int(arg[0]) > 0 {
|
||||
m.Option("_control", "_page")
|
||||
|
@ -3,7 +3,6 @@ package ssh
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
@ -25,7 +24,7 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
||||
fmt.Fprint(msg.O, msg.Result())
|
||||
|
||||
case ice.RENDER_QRCODE:
|
||||
fmt.Fprint(msg.O, msg.Cmdx(cli.PYTHON, "qrcode", kit.Format(args[0], args[1:]...)))
|
||||
fmt.Fprint(msg.O, msg.Cmdx("cli.qrcode", kit.Format(args[0], args[1:]...)))
|
||||
|
||||
case ice.RENDER_DOWNLOAD:
|
||||
if f, e := os.Open(arg[0]); e == nil {
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/skip2/go-qrcode"
|
||||
|
||||
"fmt"
|
||||
"net/http"
|
||||
@ -48,10 +47,8 @@ func Render(msg *ice.Message, cmd string, args ...interface{}) {
|
||||
}
|
||||
|
||||
case ice.RENDER_QRCODE: // text [size]
|
||||
if qr, e := qrcode.New(arg[0], qrcode.Medium); msg.Assert(e) {
|
||||
msg.W.Header().Set(ContentType, ContentPNG)
|
||||
msg.Assert(qr.Write(kit.Int(kit.Select("256", arg, 1)), msg.W))
|
||||
}
|
||||
msg.W.Header().Set(ContentType, ContentPNG)
|
||||
fmt.Fprint(msg.W, msg.Cmdx("cli.qrcode", arg))
|
||||
|
||||
case ice.RENDER_RESULT:
|
||||
if len(arg) > 0 { // [str [arg...]]
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/tcp"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
"github.com/shylinux/icebergs/core/wiki"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
@ -110,8 +109,8 @@ func init() {
|
||||
m.Cmdy(mdb.SELECT, RIVER, kit.Keys(kit.MDB_HASH, m.Option(ice.MSG_RIVER), AUTH), mdb.HASH, kit.MDB_HASH, arg)
|
||||
m.PushAction(mdb.REMOVE)
|
||||
if len(arg) > 0 {
|
||||
m.Push("qrcode", m.Cmdx(wiki.IMAGE, "qrcode", kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, m.Option("share"))))
|
||||
m.Push("inner", m.Cmdx(wiki.SPARK, "inner", kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, m.Option("share"))))
|
||||
m.PushQRCode("qrcode", kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, m.Option("share")))
|
||||
m.PushScript("script", kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, m.Option("share")))
|
||||
}
|
||||
}},
|
||||
NODE: {Name: "node name ctx cmd auto insert invite", Help: "设备", Action: map[string]*ice.Action{
|
||||
@ -246,8 +245,8 @@ func init() {
|
||||
USER: {Name: "user username auto insert invite", Help: "用户", Action: map[string]*ice.Action{
|
||||
aaa.INVITE: {Name: "invite", Help: "邀请", Hand: func(m *ice.Message, arg ...string) {
|
||||
share := m.Option(web.SHARE, m.Cmdx(m.Prefix(AUTH), mdb.CREATE, kit.MDB_TYPE, USER))
|
||||
m.Cmdy(wiki.SPARK, "inner", kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, share))
|
||||
m.Cmdy(wiki.IMAGE, "qrcode", kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, share))
|
||||
m.EchoScript(kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, share))
|
||||
m.EchoQRCode(kit.MergeURL(m.Option(ice.MSG_USERWEB), RIVER, m.Option(ice.MSG_RIVER), web.SHARE, share))
|
||||
m.Render("")
|
||||
}},
|
||||
mdb.INSERT: {Name: "insert username", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
|
17
misc.go
17
misc.go
@ -1,16 +1,12 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/skip2/go-qrcode"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func (m *Message) Prefix(arg ...string) string {
|
||||
@ -115,6 +111,10 @@ func (m *Message) PushSearchWeb(cmd string, name string) {
|
||||
|
||||
func Render(m *Message, cmd string, args ...interface{}) string {
|
||||
if m.Option(MSG_USERUA) == "" || strings.Contains(m.Option(MSG_USERUA), "curl") {
|
||||
switch arg := kit.Simple(args...); cmd {
|
||||
case RENDER_QRCODE: // text [size]
|
||||
return m.Cmdx("cli.qrcode", arg[0])
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -150,12 +150,7 @@ func Render(m *Message, cmd string, args ...interface{}) string {
|
||||
return fmt.Sprintf(`<video src="%s" height=%s controls>`, arg[0], kit.Select("120", arg, 1))
|
||||
|
||||
case RENDER_QRCODE: // text [size]
|
||||
buf := bytes.NewBuffer(make([]byte, 0, MOD_BUFS))
|
||||
if qr, e := qrcode.New(arg[0], qrcode.Medium); m.Assert(e) {
|
||||
m.Assert(qr.Write(kit.Int(kit.Select("240", arg, 1)), buf))
|
||||
}
|
||||
src := "data:image/png;base64," + base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
return fmt.Sprintf(`<img src="%s" title='%s' height=%s>`, src, arg[0], kit.Select("240", arg, 1))
|
||||
return m.Cmdx("cli.qrcode", arg[0])
|
||||
|
||||
case RENDER_SCRIPT: // type text
|
||||
if len(arg) == 1 && arg[0] != kit.SSH_BREAK {
|
||||
|
@ -13,7 +13,7 @@ func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
"/qrcode": {Name: "/qrcode", Help: "二维码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, cli.QRCODE, kit.MDB_TEXT, m.Option(kit.MDB_TEXT))
|
||||
m.Cmdy(cli.QRCODE, m.Option(kit.MDB_TEXT))
|
||||
}},
|
||||
"/input": {Name: "/input", Help: "补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
list := kit.Split(m.Option("line"), m.Option("break"))
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
"github.com/shylinux/icebergs/core/wiki"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"path"
|
||||
@ -85,8 +84,8 @@ var Index = &ice.Context{Name: TMUX, Help: "工作台",
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
text := m.Cmdx(cli.SYSTEM, TMUX, "show-buffer")
|
||||
m.Cmdy(wiki.IMAGE, "qrcode", text)
|
||||
m.Cmdy(wiki.SPARK, "inner", text)
|
||||
m.EchoQRCode(text)
|
||||
m.EchoScript(text)
|
||||
m.Render("")
|
||||
}},
|
||||
BUFFER: {Name: "buffer name value auto export import", Help: "缓存", Action: map[string]*ice.Action{
|
||||
|
Loading…
x
Reference in New Issue
Block a user