forked from x/icebergs
opt some
This commit is contained in:
parent
0d04318b47
commit
42fbc992a1
@ -12,6 +12,25 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func _port_list(m *ice.Message) string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
func _port_get(m *ice.Message) string {
|
||||||
|
current := kit.Int(m.Conf(PORT, "meta.current"))
|
||||||
|
end := kit.Int(m.Conf(PORT, "meta.end"))
|
||||||
|
if current >= end {
|
||||||
|
current = kit.Int(m.Conf(PORT, "meta.begin"))
|
||||||
|
}
|
||||||
|
for i := current; i < end; i++ {
|
||||||
|
if m.Cmd(cli.SYSTEM, "lsof", "-i", kit.Format(":%d", i)).Append(cli.CMD_CODE) != "0" {
|
||||||
|
m.Conf(PORT, "meta.current", i)
|
||||||
|
m.Log_CREATE(PORT, i)
|
||||||
|
return kit.Format("%d", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func _ip_list(m *ice.Message, ifname string) {
|
func _ip_list(m *ice.Message, ifname string) {
|
||||||
if ifs, e := net.Interfaces(); m.Assert(e) {
|
if ifs, e := net.Interfaces(); m.Assert(e) {
|
||||||
for _, v := range ifs {
|
for _, v := range ifs {
|
||||||
@ -43,34 +62,8 @@ func _ip_islocal(m *ice.Message, ip string) (ok bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := m.Spawn()
|
return m.Richs(IP, kit.Keys("meta.white"), ip, nil) != nil
|
||||||
_ip_list(msg, "")
|
|
||||||
msg.Table(func(index int, value map[string]string, head []string) {
|
|
||||||
if value["ip"] == ip {
|
|
||||||
ok = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return ok
|
|
||||||
}
|
}
|
||||||
func _port_list(m *ice.Message) string {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
func _port_get(m *ice.Message) string {
|
|
||||||
current := kit.Int(m.Conf(PORT, "meta.current"))
|
|
||||||
end := kit.Int(m.Conf(PORT, "meta.end"))
|
|
||||||
if current >= end {
|
|
||||||
current = kit.Int(m.Conf(PORT, "meta.begin"))
|
|
||||||
}
|
|
||||||
for i := current; i < end; i++ {
|
|
||||||
if m.Cmd(cli.SYSTEM, "lsof", "-i", kit.Format(":%d", i)).Append(cli.CMD_CODE) != "0" {
|
|
||||||
m.Conf(PORT, "meta.current", i)
|
|
||||||
m.Log_CREATE(PORT, i)
|
|
||||||
return kit.Format("%d", i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func IPIsLocal(m *ice.Message, ip string) bool {
|
func IPIsLocal(m *ice.Message, ip string) bool {
|
||||||
return _ip_islocal(m, ip)
|
return _ip_islocal(m, ip)
|
||||||
}
|
}
|
||||||
@ -82,15 +75,26 @@ const (
|
|||||||
|
|
||||||
var Index = &ice.Context{Name: "tcp", Help: "通信模块",
|
var Index = &ice.Context{Name: "tcp", Help: "通信模块",
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
PORT: &ice.Config{Name: "port", Help: "端口", Value: kit.Data(
|
PORT: {Name: "port", Help: "端口", Value: kit.Data(
|
||||||
"begin", 10000, "current", 10000, "end", 20000,
|
"begin", 10000, "current", 10000, "end", 20000,
|
||||||
)},
|
)},
|
||||||
|
IP: {Name: "ip", Help: "地址", Value: kit.Data(
|
||||||
|
"black", kit.Dict(),
|
||||||
|
"white", kit.Data(kit.MDB_SHORT, kit.MDB_TEXT),
|
||||||
|
)},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
|
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() }},
|
||||||
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(PORT) }},
|
ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(PORT) }},
|
||||||
|
|
||||||
IP: {Name: "ip", Help: "地址", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
IP: {Name: "ip", Help: "地址", Action: map[string]*ice.Action{
|
||||||
|
"white": {Name: "show ip", Help: "白名单", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Rich(IP, kit.Keys("meta.white"), kit.Dict(
|
||||||
|
kit.MDB_NAME, "",
|
||||||
|
kit.MDB_TEXT, arg[0],
|
||||||
|
))
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
_ip_list(m, "")
|
_ip_list(m, "")
|
||||||
}},
|
}},
|
||||||
PORT: {Name: "port", Help: "端口", Action: map[string]*ice.Action{
|
PORT: {Name: "port", Help: "端口", Action: map[string]*ice.Action{
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
ice "github.com/shylinux/icebergs"
|
ice "github.com/shylinux/icebergs"
|
||||||
"github.com/shylinux/icebergs/base/cli"
|
"github.com/shylinux/icebergs/base/cli"
|
||||||
"github.com/shylinux/icebergs/base/gdb"
|
"github.com/shylinux/icebergs/base/gdb"
|
||||||
|
"github.com/shylinux/icebergs/base/mdb"
|
||||||
"github.com/shylinux/icebergs/base/web"
|
"github.com/shylinux/icebergs/base/web"
|
||||||
"github.com/shylinux/icebergs/core/code"
|
"github.com/shylinux/icebergs/core/code"
|
||||||
kit "github.com/shylinux/toolkits"
|
kit "github.com/shylinux/toolkits"
|
||||||
@ -12,20 +13,86 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const DOCKER = "docker"
|
const DOCKER = "docker"
|
||||||
|
const (
|
||||||
|
IMAGE = "image"
|
||||||
|
CONTAINER = "container"
|
||||||
|
)
|
||||||
|
|
||||||
var Index = &ice.Context{Name: "docker", Help: "虚拟机",
|
var Index = &ice.Context{Name: "docker", Help: "虚拟机",
|
||||||
Caches: map[string]*ice.Cache{},
|
Caches: map[string]*ice.Cache{},
|
||||||
Configs: map[string]*ice.Config{
|
Configs: map[string]*ice.Config{
|
||||||
INSTALL: {Name: "install", Help: "安装", Value: kit.Data("path", "usr/install",
|
DOCKER: {Name: "docker", Help: "虚拟机", Value: kit.Data(
|
||||||
"linux", "https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz",
|
kit.MDB_SHORT, "name", "build", []interface{}{}),
|
||||||
"darwin", "https://dl.google.com/go/go1.14.2.darwin-amd64.pkg",
|
},
|
||||||
"windows", "https://dl.google.com/go/go1.14.2.windows-amd64.msi",
|
|
||||||
"source", "https://dl.google.com/go/go1.14.2.src.tar.gz",
|
|
||||||
"target", "usr/local",
|
|
||||||
)},
|
|
||||||
DOCKER: {Name: "docker", Help: "虚拟机", Value: kit.Data(kit.MDB_SHORT, "name", "build", []interface{}{})},
|
|
||||||
},
|
},
|
||||||
Commands: map[string]*ice.Command{
|
Commands: map[string]*ice.Command{
|
||||||
|
IMAGE: {Name: "image", Help: "镜像管理", Meta: kit.Dict("detail", []string{"运行", "清理", "删除"}), List: ListLook("IMAGE_ID"), Action: map[string]*ice.Action{
|
||||||
|
"run": {Name: "run", Help: "运行", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmdy(cli.SYSTEM, DOCKER, "run", "-dt", m.Option("REPOSITORY")+":"+m.Option("TAG"))
|
||||||
|
}},
|
||||||
|
"prune": {Name: "prune", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmdy(cli.SYSTEM, DOCKER, "prune", "-f")
|
||||||
|
}},
|
||||||
|
mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmdy(cli.SYSTEM, DOCKER, "rm", m.Option("IMAGE_ID"))
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
prefix := []string{cli.SYSTEM, DOCKER, IMAGE}
|
||||||
|
if len(arg) > 0 {
|
||||||
|
// 容器详情
|
||||||
|
res := m.Cmdx(prefix, "inspect", arg[0])
|
||||||
|
m.Push("detail", kit.KeyValue(map[string]interface{}{}, "", kit.Parse(nil, "", kit.Split(res)...)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 镜像列表
|
||||||
|
m.Split(strings.Replace(m.Cmdx(prefix, "ls"), "IMAGE ID", "IMAGE_ID", 1), "index", " ", "\n")
|
||||||
|
m.Sort("REPOSITORY")
|
||||||
|
}},
|
||||||
|
CONTAINER: {Name: "container", Help: "容器管理", List: ListLook("CONTAINER_ID"), Meta: kit.Dict("detail", []string{"进入", "启动", "停止", "重启", "清理", "编辑", "删除"}), Action: map[string]*ice.Action{
|
||||||
|
"prune": {Name: "prune", Help: "清理", Hand: func(m *ice.Message, arg ...string) {
|
||||||
|
m.Cmdy(cli.SYSTEM, DOCKER, "prune", "-f")
|
||||||
|
m.Cmdy(prefix, "prune", "-f")
|
||||||
|
}},
|
||||||
|
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
|
prefix := []string{cli.SYSTEM, DOCKER, CONTAINER}
|
||||||
|
if len(arg) > 1 && arg[0] == "action" {
|
||||||
|
switch arg[1] {
|
||||||
|
case "进入":
|
||||||
|
m.Cmdy(cli.SYSTEM, "tmux", "new-window", "-t", m.Option("NAMES"), "-n", m.Option("NAMES"),
|
||||||
|
"-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+m.Option("NAMES")+" bash").Set("append")
|
||||||
|
return
|
||||||
|
case "停止":
|
||||||
|
m.Cmdy(prefix, "stop", m.Option("CONTAINER_ID"))
|
||||||
|
case "启动":
|
||||||
|
m.Cmdy(prefix, "start", m.Option("CONTAINER_ID"))
|
||||||
|
case "重启":
|
||||||
|
m.Cmdy(prefix, "restart", m.Option("CONTAINER_ID"))
|
||||||
|
case "清理":
|
||||||
|
m.Cmdy(prefix, "prune", "-f")
|
||||||
|
case "modify":
|
||||||
|
switch arg[2] {
|
||||||
|
case "NAMES":
|
||||||
|
m.Cmdy(prefix, "rename", arg[4], arg[3])
|
||||||
|
}
|
||||||
|
case "delete":
|
||||||
|
m.Cmdy(prefix, "rm", m.Option("CONTAINER_ID")).Set("append")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(arg) > 0 {
|
||||||
|
// 容器详情
|
||||||
|
res := m.Cmdx(prefix, "inspect", arg[0])
|
||||||
|
m.Push("detail", kit.KeyValue(map[string]interface{}{}, "", kit.Parse(nil, "", kit.Split(res)...)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 容器列表
|
||||||
|
m.Split(strings.Replace(m.Cmdx(prefix, "ls", "-a"), "CONTAINER ID", "CONTAINER_ID", 1), "index", " ", "\n")
|
||||||
|
m.Sort("NAMES")
|
||||||
|
}},
|
||||||
|
|
||||||
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
"init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||||
m.Watch(gdb.DREAM_START, m.Prefix("auto"))
|
m.Watch(gdb.DREAM_START, m.Prefix("auto"))
|
||||||
|
|
||||||
@ -65,77 +132,6 @@ var Index = &ice.Context{Name: "docker", Help: "虚拟机",
|
|||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
|
|
||||||
"image": {Name: "image", Help: "镜像管理", Meta: kit.Dict("detail", []string{"运行", "清理", "删除"}), List: ListLook("IMAGE_ID"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
prefix := []string{cli.SYSTEM, "docker", "image"}
|
|
||||||
if len(arg) > 1 && arg[0] == "action" {
|
|
||||||
switch arg[1] {
|
|
||||||
case "运行":
|
|
||||||
m.Cmdy(prefix[:2], "run", "-dt", m.Option("REPOSITORY")+":"+m.Option("TAG")).Set("append")
|
|
||||||
return
|
|
||||||
case "清理":
|
|
||||||
m.Cmdy(prefix, "prune", "-f").Set("append")
|
|
||||||
return
|
|
||||||
case "delete":
|
|
||||||
m.Cmdy(prefix, "rm", m.Option("IMAGE_ID")).Set("append")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) > 0 {
|
|
||||||
// 容器详情
|
|
||||||
res := m.Cmdx(prefix, "inspect", arg[0])
|
|
||||||
m.Push("detail", kit.KeyValue(map[string]interface{}{}, "", kit.Parse(nil, "", kit.Split(res)...)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) > 0 {
|
|
||||||
// 下载镜像
|
|
||||||
m.Cmdy(prefix, "pull", arg[0]+":"+kit.Select("latest", arg, 1)).Set("append")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 镜像列表
|
|
||||||
m.Split(strings.Replace(m.Cmdx(prefix, "ls"), "IMAGE ID", "IMAGE_ID", 1), "index", " ", "\n")
|
|
||||||
m.Sort("REPOSITORY")
|
|
||||||
}},
|
|
||||||
"container": {Name: "container", Help: "容器管理", List: ListLook("CONTAINER_ID"), Meta: kit.Dict("detail", []string{"进入", "启动", "停止", "重启", "清理", "编辑", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
||||||
prefix := []string{cli.SYSTEM, "docker", "container"}
|
|
||||||
if len(arg) > 1 && arg[0] == "action" {
|
|
||||||
switch arg[1] {
|
|
||||||
case "进入":
|
|
||||||
m.Cmdy(cli.SYSTEM, "tmux", "new-window", "-t", m.Option("NAMES"), "-n", m.Option("NAMES"),
|
|
||||||
"-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+m.Option("NAMES")+" bash").Set("append")
|
|
||||||
return
|
|
||||||
case "停止":
|
|
||||||
m.Cmdy(prefix, "stop", m.Option("CONTAINER_ID"))
|
|
||||||
case "启动":
|
|
||||||
m.Cmdy(prefix, "start", m.Option("CONTAINER_ID"))
|
|
||||||
case "重启":
|
|
||||||
m.Cmdy(prefix, "restart", m.Option("CONTAINER_ID"))
|
|
||||||
case "清理":
|
|
||||||
m.Cmdy(prefix, "prune", "-f")
|
|
||||||
case "modify":
|
|
||||||
switch arg[2] {
|
|
||||||
case "NAMES":
|
|
||||||
m.Cmdy(prefix, "rename", arg[4], arg[3])
|
|
||||||
}
|
|
||||||
case "delete":
|
|
||||||
m.Cmdy(prefix, "rm", m.Option("CONTAINER_ID")).Set("append")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(arg) > 0 {
|
|
||||||
// 容器详情
|
|
||||||
res := m.Cmdx(prefix, "inspect", arg[0])
|
|
||||||
m.Push("detail", kit.KeyValue(map[string]interface{}{}, "", kit.Parse(nil, "", kit.Split(res)...)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 容器列表
|
|
||||||
m.Split(strings.Replace(m.Cmdx(prefix, "ls", "-a"), "CONTAINER ID", "CONTAINER_ID", 1), "index", " ", "\n")
|
|
||||||
m.Sort("NAMES")
|
|
||||||
}},
|
|
||||||
"command": {Name: "command", Help: "命令", List: kit.List(
|
"command": {Name: "command", Help: "命令", List: kit.List(
|
||||||
kit.MDB_INPUT, "text", "name", "CONTAINER_ID",
|
kit.MDB_INPUT, "text", "name", "CONTAINER_ID",
|
||||||
kit.MDB_INPUT, "text", "name", "cmd", "className", "args cmd",
|
kit.MDB_INPUT, "text", "name", "cmd", "className", "args cmd",
|
||||||
|
@ -78,7 +78,7 @@ var Index = &ice.Context{Name: "totp", Help: "动态码",
|
|||||||
|
|
||||||
if len(arg) == 1 {
|
if len(arg) == 1 {
|
||||||
// 创建密钥
|
// 创建密钥
|
||||||
arg = append(arg, gen(30))
|
arg = append(arg, _totp_gen(30))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加密钥
|
// 添加密钥
|
||||||
@ -94,7 +94,7 @@ var Index = &ice.Context{Name: "totp", Help: "动态码",
|
|||||||
m.Push("time", m.Time())
|
m.Push("time", m.Time())
|
||||||
m.Push("rest", per-time.Now().Unix()%per)
|
m.Push("rest", per-time.Now().Unix()%per)
|
||||||
m.Push("name", value["name"])
|
m.Push("name", value["name"])
|
||||||
m.Push("code", get(kit.Format(value["text"]), kit.Int(kit.Select("6", value["number"])), per))
|
m.Push("code", _totp_get(kit.Format(value["text"]), kit.Int(kit.Select("6", value["number"])), per))
|
||||||
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -102,7 +102,7 @@ var Index = &ice.Context{Name: "totp", Help: "动态码",
|
|||||||
|
|
||||||
m.Richs("totp", nil, arg[0], func(key string, value map[string]interface{}) {
|
m.Richs("totp", nil, arg[0], func(key string, value map[string]interface{}) {
|
||||||
// 获取密码
|
// 获取密码
|
||||||
m.Echo(get(kit.Format(value["text"]), kit.Int(kit.Select("6", arg, 1)), kit.Int64(kit.Select("30", arg, 2))))
|
m.Echo(_totp_get(kit.Format(value["text"]), kit.Int(kit.Select("6", arg, 1)), kit.Int64(kit.Select("30", arg, 2))))
|
||||||
})
|
})
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user