mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 09:14:06 +08:00
add aaa.short
This commit is contained in:
parent
22274aed00
commit
ac2a42a6fd
@ -1,2 +1,8 @@
|
|||||||
|
~cli
|
||||||
|
upgrade plugin context
|
||||||
|
upgrade plugin storage
|
||||||
|
upgrade plugin love
|
||||||
|
|
||||||
~aaa
|
~aaa
|
||||||
role root user shy shaoying
|
role root user shy shaoying
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ call Keys("Statment", ["var", "let"])
|
|||||||
call Keys("Statment", ["if", "else", "else if", "for", "end"])
|
call Keys("Statment", ["if", "else", "else if", "for", "end"])
|
||||||
call Keys("Statment", ["label", "goto"])
|
call Keys("Statment", ["label", "goto"])
|
||||||
" context nfs
|
" context nfs
|
||||||
call Keys("SubCommand", ["import", "export", "load", "save"])
|
" call Keys("SubCommand", ["import", "export", "load", "save"])
|
||||||
|
|
||||||
" context ctx
|
" context ctx
|
||||||
call Keys("Argument", ["list", "map"])
|
call Keys("Argument", ["list", "map"])
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
config save var/data/work.json work
|
config save var/data/work.json work
|
||||||
~aaa
|
~aaa
|
||||||
config save var/tmp/auth.json auth
|
config save var/tmp/auth.json auth
|
||||||
|
config save var/tmp/short.json short
|
||||||
~cli
|
~cli
|
||||||
config save var/tmp/runtime.json runtime
|
config save var/tmp/runtime.json runtime
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
~cli
|
~cli
|
||||||
config load tmp/runtime.json runtime
|
config load var/tmp/runtime.json runtime
|
||||||
~aaa
|
~aaa
|
||||||
config load tmp/auth.json auth
|
config load var/tmp/short.json short
|
||||||
|
config load var/tmp/auth.json auth
|
||||||
~ssh
|
~ssh
|
||||||
config load var/data/work.json work
|
config load var/data/work.json work
|
||||||
config load var/data/flow.json flow
|
config load var/data/flow.json flow
|
||||||
@ -14,5 +15,4 @@
|
|||||||
source local.shy
|
source local.shy
|
||||||
|
|
||||||
~cli
|
~cli
|
||||||
upgrade plugin context
|
|
||||||
upgrade plugin love
|
|
||||||
|
@ -2,6 +2,7 @@ package aaa
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/gomail.v2"
|
"gopkg.in/gomail.v2"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"contexts/ctx"
|
"contexts/ctx"
|
||||||
"toolkit"
|
"toolkit"
|
||||||
@ -101,6 +102,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
"secrete": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
"secrete": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
||||||
}, Help: "散列"},
|
}, Help: "散列"},
|
||||||
|
|
||||||
|
"short": &ctx.Config{Name: "short", Value: map[string]interface{}{}, Help: "散列"},
|
||||||
"email": &ctx.Config{Name: "email", Value: map[string]interface{}{
|
"email": &ctx.Config{Name: "email", Value: map[string]interface{}{
|
||||||
"self": "shylinux@163.com", "smtp": "smtp.163.com", "port": "25",
|
"self": "shylinux@163.com", "smtp": "smtp.163.com", "port": "25",
|
||||||
}, Help: "邮件服务"},
|
}, Help: "邮件服务"},
|
||||||
@ -602,7 +604,38 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
"short": &ctx.Command{Name: "short", Help: "短码", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
|
// cc2309e0cb95ab3cabced1b3e7141105
|
||||||
|
if len(arg) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
length := 6
|
||||||
|
short := arg[0][:length]
|
||||||
|
|
||||||
|
if len(arg[0]) == 32 {
|
||||||
|
m.Confm("aaa.short", short, func(index int, value string) {
|
||||||
|
if value == arg[0] {
|
||||||
|
m.Echo("%s%02x", short, index)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if m.Result() != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Confv("aaa.short", []string{short, "-2"}, arg[0])
|
||||||
|
if v, ok := m.Confv("aaa.short", short).([]interface{}); ok {
|
||||||
|
m.Echo("%s%02x", short, len(v)-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if i, e := strconv.ParseInt(arg[0][length:], 16, 64); e == nil {
|
||||||
|
m.Echo(m.Conf("aaa.short", []interface{}{short, int(i)}))
|
||||||
|
} else {
|
||||||
|
m.Echo(arg[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}},
|
||||||
"relay": &ctx.Command{Name: "relay [rid] [check userrole]|[count num]|[share [type [role [name [count]]]]]", Help: "授权", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"relay": &ctx.Command{Name: "relay [rid] [check userrole]|[count num]|[share [type [role [name [count]]]]]", Help: "授权", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
// 授权列表
|
// 授权列表
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
|
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-09-21 10:07:14", "com.mac", 573,
|
"2019-09-21 18:02:29", "mac", 621,
|
||||||
}
|
}
|
||||||
|
@ -202,6 +202,13 @@ func (m *Message) Format(arg ...interface{}) string {
|
|||||||
}
|
}
|
||||||
return strings.Join(meta, " ")
|
return strings.Join(meta, " ")
|
||||||
}
|
}
|
||||||
|
func (m *Message) Short(arg ...string) {
|
||||||
|
for _, k := range arg {
|
||||||
|
if v := m.Option(k); v != "" && len(v) != 32 {
|
||||||
|
m.Option(k, m.Cmdx("aaa.short", v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
func (m *Message) Err(str string, arg ...interface{}) {
|
func (m *Message) Err(str string, arg ...interface{}) {
|
||||||
m.Echo("").Echo("error: ").Echo(str, arg...)
|
m.Echo("").Echo("error: ").Echo(str, arg...)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package ssh
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"contexts/ctx"
|
"contexts/ctx"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sort"
|
"sort"
|
||||||
@ -134,6 +133,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
},
|
},
|
||||||
}, Help: "组件列表"},
|
}, Help: "组件列表"},
|
||||||
|
|
||||||
|
"data": {Name: "data", Value: map[string]interface{}{"path": "var/data"}, Help: "聊天数据"},
|
||||||
"flow": {Name: "flow", Value: map[string]interface{}{}, Help: "聊天群组"},
|
"flow": {Name: "flow", Value: map[string]interface{}{}, Help: "聊天群组"},
|
||||||
"work": {Name: "work", Value: map[string]interface{}{}, Help: "工作信息"},
|
"work": {Name: "work", Value: map[string]interface{}{}, Help: "工作信息"},
|
||||||
"node": {Name: "node", Value: map[string]interface{}{}, Help: "节点信息"},
|
"node": {Name: "node", Value: map[string]interface{}{}, Help: "节点信息"},
|
||||||
@ -467,8 +467,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
|
|
||||||
for _, v := range arg[1:] {
|
for _, v := range arg[1:] {
|
||||||
data := m.Confm("flow", []string{m.Option("river"), "data", v})
|
data := m.Confm("flow", []string{m.Option("river"), "data", v})
|
||||||
kit.Marshal(data["meta"], path.Join("var/data", m.Option("river"), v, "/meta.json"))
|
kit.Marshal(data["meta"], path.Join(m.Conf("ssh.data", "path"), m.Option("river"), v, "/meta.json"))
|
||||||
kit.Marshal(data["list"], path.Join("var/data", m.Option("river"), v, "/list.csv"))
|
kit.Marshal(data["list"], path.Join(m.Conf("ssh.data", "path"), m.Option("river"), v, "/list.csv"))
|
||||||
|
|
||||||
l := len(data["list"].([]interface{}))
|
l := len(data["list"].([]interface{}))
|
||||||
m.Push("table", v).Push("count", l)
|
m.Push("table", v).Push("count", l)
|
||||||
@ -536,23 +536,32 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
m.Confv("flow", []string{m.Option("river"), "data", arg[1], "list", kit.Format(index), arg[i]}, arg[i+1])
|
m.Confv("flow", []string{m.Option("river"), "data", arg[1], "list", kit.Format(index), arg[i]}, arg[i+1])
|
||||||
}
|
}
|
||||||
case "import":
|
case "import":
|
||||||
msg := m.Cmd("nfs.import", arg[2:])
|
if len(arg) < 3 {
|
||||||
|
m.Cmdy("ssh.data", "show", arg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
id := m.Confi("flow", []string{m.Option("river"), "data", arg[1], "meta", "count"})
|
id := m.Confi("flow", []string{m.Option("river"), "data", arg[1], "meta", "count"})
|
||||||
msg.Table(func(maps map[string]string) {
|
m.Cmd("nfs.import", arg[2:]).Table(func(maps map[string]string) {
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
extra := map[string]interface{}{}
|
|
||||||
for k, v := range maps {
|
for k, v := range maps {
|
||||||
m.Push(k, v)
|
m.Push(k, v)
|
||||||
data[k] = v
|
data[k] = v
|
||||||
}
|
}
|
||||||
json.Unmarshal(([]byte)(maps["extra"]), &data)
|
|
||||||
data["extra"] = extra
|
|
||||||
id++
|
|
||||||
data["id"] = id
|
|
||||||
|
|
||||||
|
if id++; id == 1 {
|
||||||
|
m.Cmd("ssh.data", "create", arg[1], data)
|
||||||
|
}
|
||||||
|
|
||||||
|
data["id"] = id
|
||||||
|
data["extra"] = kit.UnMarshalm(maps["extra"])
|
||||||
m.Confv("flow", []string{m.Option("river"), "data", arg[1], "list", "-2"}, data)
|
m.Confv("flow", []string{m.Option("river"), "data", arg[1], "list", "-2"}, data)
|
||||||
})
|
})
|
||||||
m.Confi("flow", []string{m.Option("river"), "data", arg[1], "meta", "count"}, id)
|
m.Confi("flow", []string{m.Option("river"), "data", arg[1], "meta", "count"}, id)
|
||||||
|
m.Cmd("ssh.data", "save", arg[1])
|
||||||
|
case "export":
|
||||||
|
m.Append("directory", path.Join(m.Conf("ssh.data", "path"), m.Option("river"), arg[1], "/list.csv"))
|
||||||
|
m.Table()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
@ -328,7 +328,8 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
// 命令语句
|
// 命令语句
|
||||||
map[string]interface{}{"page": "word", "hash": "word", "word": []interface{}{"mul{", "~", "!", "\\?", "\\?\\?", "exe", "str", "[\\-a-zA-Z0-9_:/.%*]+", "=", "<", ">$", ">@", ">", "\\|", "}"}},
|
map[string]interface{}{"page": "word", "hash": "word", "word": []interface{}{"mul{", "~", "!", "\\?", "\\?\\?", "exe", "str", "[\\-a-zA-Z0-9_:/.%*]+", "=", "<", ">$", ">@", ">", "\\|", "}"}},
|
||||||
map[string]interface{}{"page": "cmd", "hash": "cmd", "word": []interface{}{"rep{", "word", "}"}},
|
map[string]interface{}{"page": "cmd", "hash": "cmd", "word": []interface{}{"rep{", "word", "}"}},
|
||||||
map[string]interface{}{"page": "com", "hash": "com", "word": []interface{}{"mul{", ";", "#[^\n]*\n?", "\n", "}"}},
|
map[string]interface{}{"page": "com", "hash": "cmd", "word": []interface{}{"rep{", ";", "cmd", "}"}},
|
||||||
|
map[string]interface{}{"page": "com", "hash": "com", "word": []interface{}{"mul{", "#[^\n]*\n?", "\n", "}"}},
|
||||||
map[string]interface{}{"page": "line", "hash": "line", "word": []interface{}{"opt{", "mul{", "stm", "cmd", "}", "}", "com"}},
|
map[string]interface{}{"page": "line", "hash": "line", "word": []interface{}{"opt{", "mul{", "stm", "cmd", "}", "}", "com"}},
|
||||||
|
|
||||||
// 复合语句
|
// 复合语句
|
||||||
@ -348,6 +349,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
map[string]interface{}{"page": "stm", "hash": "else", "word": []interface{}{"else", "opt{", "if", "exp", "}"}},
|
map[string]interface{}{"page": "stm", "hash": "else", "word": []interface{}{"else", "opt{", "if", "exp", "}"}},
|
||||||
map[string]interface{}{"page": "stm", "hash": "end", "word": []interface{}{"end"}},
|
map[string]interface{}{"page": "stm", "hash": "end", "word": []interface{}{"end"}},
|
||||||
|
|
||||||
|
// 标签语句
|
||||||
map[string]interface{}{"page": "stm", "hash": "label", "word": []interface{}{"label", "key"}},
|
map[string]interface{}{"page": "stm", "hash": "label", "word": []interface{}{"label", "key"}},
|
||||||
map[string]interface{}{"page": "stm", "hash": "goto", "word": []interface{}{"goto", "key"}},
|
map[string]interface{}{"page": "stm", "hash": "goto", "word": []interface{}{"goto", "key"}},
|
||||||
/*
|
/*
|
||||||
@ -373,6 +375,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
|
|||||||
"text": true,
|
"text": true,
|
||||||
"select": true,
|
"select": true,
|
||||||
"button": true,
|
"button": true,
|
||||||
|
"upfile": true,
|
||||||
"textarea": true,
|
"textarea": true,
|
||||||
"exports": true,
|
"exports": true,
|
||||||
"feature": true,
|
"feature": true,
|
||||||
|
@ -6,6 +6,24 @@ import (
|
|||||||
"toolkit"
|
"toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func check(m *ctx.Message, arg []string) ([]string, string, bool) {
|
||||||
|
if !m.Options("sessid") || !m.Options("username") {
|
||||||
|
return nil, "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
rid := m.Option("river")
|
||||||
|
if len(arg[0]) != 32 {
|
||||||
|
arg[0] = m.Cmdx("aaa.short", arg[0])
|
||||||
|
}
|
||||||
|
if m.Confs("flow", arg[0]) {
|
||||||
|
rid, arg = arg[0], arg[1:]
|
||||||
|
}
|
||||||
|
if rid != "" && len(rid) != 32 {
|
||||||
|
rid = m.Cmdx("aaa.short", rid)
|
||||||
|
}
|
||||||
|
return arg, rid, true
|
||||||
|
}
|
||||||
|
|
||||||
var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||||
Caches: map[string]*ctx.Cache{},
|
Caches: map[string]*ctx.Cache{},
|
||||||
Configs: map[string]*ctx.Config{
|
Configs: map[string]*ctx.Config{
|
||||||
@ -98,7 +116,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
case "relay":
|
case "relay":
|
||||||
relay := m.Cmdx("aaa.relay", "share", arg[1:])
|
relay := m.Cmdx("aaa.relay", "share", arg[1:])
|
||||||
m.Log("info", "relay: %s", relay)
|
m.Log("info", "relay: %s", relay)
|
||||||
m.Echo(relay)
|
m.Echo(m.Cmdx("aaa.short", relay))
|
||||||
return
|
return
|
||||||
case "rename":
|
case "rename":
|
||||||
m.Cmd("aaa.auth", "username", m.Option("username"), "data", "nickname", arg[1])
|
m.Cmd("aaa.auth", "username", m.Option("username"), "data", "nickname", arg[1])
|
||||||
@ -193,7 +211,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Push("key", key)
|
m.Push("key", m.Cmdx("aaa.short", key))
|
||||||
m.Push("nick", kit.Chains(value, "conf.nick"))
|
m.Push("nick", kit.Chains(value, "conf.nick"))
|
||||||
m.Push("create_user", kit.Chains(value, "conf.create_user"))
|
m.Push("create_user", kit.Chains(value, "conf.create_user"))
|
||||||
m.Push("create_time", kit.Chains(value, "conf.create_time"))
|
m.Push("create_time", kit.Chains(value, "conf.create_time"))
|
||||||
@ -214,9 +232,10 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rid := m.Option("river")
|
// 登录失败
|
||||||
if m.Confs("flow", arg[0]) {
|
arg, rid, ok := check(m, arg)
|
||||||
rid, arg = arg[0], arg[1:]
|
if !ok {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch arg[0] {
|
switch arg[0] {
|
||||||
@ -279,15 +298,11 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
}},
|
}},
|
||||||
"storm": &ctx.Command{Name: "storm [rid] [[delete] group [index [arg...]]]", Help: "风雨", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"storm": &ctx.Command{Name: "storm [rid] [[delete] group [index [arg...]]]", Help: "风雨", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
// 登录失败
|
// 登录失败
|
||||||
if !m.Options("sessid") || !m.Options("username") {
|
arg, rid, ok := check(m, arg)
|
||||||
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rid := m.Option("river")
|
|
||||||
if m.Confs("flow", arg[0]) {
|
|
||||||
rid, arg = arg[0], arg[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// 命令列表
|
// 命令列表
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
m.Confm("flow", []string{rid, "tool"}, func(key string, value map[string]interface{}) {
|
m.Confm("flow", []string{rid, "tool"}, func(key string, value map[string]interface{}) {
|
||||||
@ -312,8 +327,9 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
m.Set("option", "init")
|
m.Set("option", "init")
|
||||||
m.Set("option", "view")
|
m.Set("option", "view")
|
||||||
if len(arg) == 1 {
|
if len(arg) == 1 {
|
||||||
|
short := m.Cmdx("aaa.short", rid)
|
||||||
m.Confm("flow", []string{rid, "tool", arg[0], "list"}, func(index int, tool map[string]interface{}) {
|
m.Confm("flow", []string{rid, "tool", arg[0], "list"}, func(index int, tool map[string]interface{}) {
|
||||||
m.Push("river", rid)
|
m.Push("river", short)
|
||||||
m.Push("storm", arg[0])
|
m.Push("storm", arg[0])
|
||||||
m.Push("action", index)
|
m.Push("action", index)
|
||||||
|
|
||||||
@ -346,15 +362,11 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
}},
|
}},
|
||||||
"steam": &ctx.Command{Name: "steam rid [user node]|[spawn name [route group index name]...]", Help: "天空", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
"steam": &ctx.Command{Name: "steam rid [user node]|[spawn name [route group index name]...]", Help: "天空", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||||
// 登录失败
|
// 登录失败
|
||||||
if !m.Options("sessid") || !m.Options("username") {
|
arg, rid, ok := check(m, arg)
|
||||||
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rid := m.Option("river")
|
|
||||||
if m.Confs("flow", arg[0]) {
|
|
||||||
rid, arg = arg[0], arg[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// 上传请求
|
// 上传请求
|
||||||
if up := m.Conf("flow", []string{rid, "conf.route"}); up != m.Conf("runtime", "node.route") {
|
if up := m.Conf("flow", []string{rid, "conf.route"}); up != m.Conf("runtime", "node.route") {
|
||||||
m.Cmdy("ssh._remote", up, "context", "chat", "steam", rid, arg)
|
m.Cmdy("ssh._remote", up, "context", "chat", "steam", rid, arg)
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
kit imports "导入" "" "" private "ssh.data" "import" \
|
|
||||||
text "love" name table \
|
|
||||||
text "" name file \
|
|
||||||
button "导入"
|
|
||||||
|
|
||||||
fun meet "第一眼" private \
|
fun meet "第一眼" private \
|
||||||
text "love" name table imports plugin_table \
|
text "love" name table imports plugin_table \
|
||||||
@ -11,9 +7,9 @@ fun meet "第一眼" private \
|
|||||||
|
|
||||||
if $2 == "" || $3 == ""
|
if $2 == "" || $3 == ""
|
||||||
copy ssh.data show _
|
copy ssh.data show _
|
||||||
return
|
else
|
||||||
end
|
|
||||||
copy ssh.data insert _ when _ where __
|
copy ssh.data insert _ when _ where __
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \
|
kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \
|
||||||
@ -34,8 +30,8 @@ fun delay "以后告诉你" private \
|
|||||||
|
|
||||||
if $2 == "" || $3 == ""
|
if $2 == "" || $3 == ""
|
||||||
copy ssh.data show _
|
copy ssh.data show _
|
||||||
return
|
else
|
||||||
end
|
|
||||||
copy ssh.data insert _ when _ what __
|
copy ssh.data insert _ when _ what __
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package kit
|
package kit
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/md5"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -64,15 +68,15 @@ func Split(str string, c byte, n int) []string {
|
|||||||
}
|
}
|
||||||
func FmtSize(size int64) string {
|
func FmtSize(size int64) string {
|
||||||
if size > 1<<30 {
|
if size > 1<<30 {
|
||||||
return fmt.Sprintf("%d.%dG", size>>30, (size>>20)%1024*100/1024)
|
return fmt.Sprintf("%d.%dG", size>>30, (size>>20)%1024*100>>10)
|
||||||
}
|
}
|
||||||
|
|
||||||
if size > 1<<20 {
|
if size > 1<<20 {
|
||||||
return fmt.Sprintf("%d.%dM", size>>20, (size>>10)%1024*100/1024)
|
return fmt.Sprintf("%d.%dM", size>>20, (size>>10)%1024*100>>10)
|
||||||
}
|
}
|
||||||
|
|
||||||
if size > 1<<10 {
|
if size > 1<<10 {
|
||||||
return fmt.Sprintf("%d.%dK", size>>10, size%1024*100/1024)
|
return fmt.Sprintf("%d.%dK", size>>10, size%1024*100>>10)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%dB", size)
|
return fmt.Sprintf("%dB", size)
|
||||||
@ -164,3 +168,41 @@ func IsLocalIP(ip string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
func Hashx(f io.Reader) string {
|
||||||
|
md := md5.New()
|
||||||
|
io.Copy(md, f)
|
||||||
|
h := md.Sum(nil)
|
||||||
|
return hex.EncodeToString(h[:])
|
||||||
|
}
|
||||||
|
func Lines(p string, args ...interface{}) []string {
|
||||||
|
b, e := ioutil.ReadFile(p)
|
||||||
|
if e != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
bs := bytes.Split(b, []byte("\n"))
|
||||||
|
|
||||||
|
res := make([]string, 0, len(bs))
|
||||||
|
for _, v := range bs {
|
||||||
|
if len(args) > 0 {
|
||||||
|
switch arg := args[0].(type) {
|
||||||
|
case func(string) string:
|
||||||
|
res = append(res, arg(string(v)))
|
||||||
|
continue
|
||||||
|
case func(string):
|
||||||
|
arg(string(v))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res = append(res, string(v))
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
func Linex(p string) map[string]string {
|
||||||
|
meta := map[string]string{}
|
||||||
|
Lines(p, func(value string) {
|
||||||
|
if strings.Contains(value, ":") {
|
||||||
|
bs := strings.SplitN(value, ":", 2)
|
||||||
|
meta[strings.TrimSpace(bs[0])] = strings.TrimSpace(bs[1])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return meta
|
||||||
|
}
|
||||||
|
@ -204,4 +204,30 @@ ctx = context = {
|
|||||||
xhr.setRequestHeader("Accept", "application/json")
|
xhr.setRequestHeader("Accept", "application/json")
|
||||||
xhr.send(args.join("&"))
|
xhr.send(args.join("&"))
|
||||||
},
|
},
|
||||||
|
Upload: function(file, cb, detail) {
|
||||||
|
var data = new FormData()
|
||||||
|
data.append("upload", file)
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest()
|
||||||
|
xhr.onload = function(event) {
|
||||||
|
var msg = JSON.parse(xhr.responseText||'{"result":[]}')
|
||||||
|
typeof cb == "function" && cb(event, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.onreadystatechange = function() {
|
||||||
|
if (xhr.readyState != 4) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (xhr.status != 200) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.upload.onprogress = function(event) {
|
||||||
|
typeof detail == "function" && detail(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
xhr.open("POST", "/upload", true)
|
||||||
|
xhr.send(data)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
@ -723,6 +723,9 @@ function Plugin(page, pane, field, runs) {
|
|||||||
name = item.name || "input"
|
name = item.name || "input"
|
||||||
var input = {type: "input", name: name, data: item}
|
var input = {type: "input", name: name, data: item}
|
||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
|
case "upfile":
|
||||||
|
item.type = "file"
|
||||||
|
break
|
||||||
case "select":
|
case "select":
|
||||||
kit.classList.add(item, "args")
|
kit.classList.add(item, "args")
|
||||||
input.type = "select", input.list = item.values.map(function(value) {
|
input.type = "select", input.list = item.values.map(function(value) {
|
||||||
@ -868,6 +871,14 @@ function Plugin(page, pane, field, runs) {
|
|||||||
plugin.show_after(plugin.msg)
|
plugin.show_after(plugin.msg)
|
||||||
},
|
},
|
||||||
show_after: function(msg) {},
|
show_after: function(msg) {},
|
||||||
|
upload: function(event) {
|
||||||
|
ctx.Upload(option.upload.files[0], function(event, msg) {
|
||||||
|
kit.OrderTable(kit.AppendTable(kit.AppendChilds(output, "table"), ctx.Table(msg), msg.append))
|
||||||
|
page.ontoast("上传成功")
|
||||||
|
}, function(event) {
|
||||||
|
page.ontoast(), page.ontoast("上传进度 "+parseInt(event.loaded*100/event.total)+"%")
|
||||||
|
})
|
||||||
|
},
|
||||||
ondaemon: {
|
ondaemon: {
|
||||||
inner: function(msg, cb) {
|
inner: function(msg, cb) {
|
||||||
output.style.maxWidth = pane.target.clientWidth-20+"px"
|
output.style.maxWidth = pane.target.clientWidth-20+"px"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user