diff --git a/etc/init.shy b/etc/init.shy index 88d395f4..bc1f539b 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -1,5 +1,3 @@ source common.shy source local.shy -~ssh - remote auto diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go index 717472d7..0fda204d 100644 --- a/src/contexts/cli/cli.go +++ b/src/contexts/cli/cli.go @@ -102,7 +102,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心", "init_env": []interface{}{"ctx_dev", "ctx_box", "ctx_root", "ctx_home", "USER"}, "script": map[string]interface{}{"sh": "bash", "shy": "source", "py": "python"}, "init_shy": "etc/init.shy", "exit_shy": "etc/exit.shy", - "web_port": ":9094", "ssh_port": ":9090", + "web_port": ":9094", "ssh_port": ":9090", "ssh_ports": []interface{}{}, }, Help: "运行环境"}, "alias": &ctx.Config{Name: "alias", Value: map[string]interface{}{ diff --git a/src/contexts/nfs/nfs.go b/src/contexts/nfs/nfs.go index c980f61b..35c09e9c 100644 --- a/src/contexts/nfs/nfs.go +++ b/src/contexts/nfs/nfs.go @@ -1518,7 +1518,7 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心", "remote": &ctx.Command{Name: "remote listen|dial args...", Help: "启动文件服务, args: 参考tcp模块, listen命令的参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { if _, ok := m.Target().Server.(*NFS); m.Assert(ok) { //{{{ m.Sess("tcp").Call(func(sub *ctx.Message) *ctx.Message { - if sub.Options("hostport") { + if sub.Has("hostport") { return sub } sub.Sess("ms_source", sub) diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index 08014a5f..7383b6ba 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -59,9 +59,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", case "listen": m.Call(func(nfs *ctx.Message) *ctx.Message { - if nfs.Options("hostport") { // 监听端口 - m.Conf("runtime", "ssh_port", nfs.Option("hostport")) + if nfs.Has("hostport") { + m.Conf("runtime", "ssh_ports", nfs.Optionv("hostport")) } + if !m.Confs("runtime", "node.sess") { if !m.Confs("runtime", "node.cert") { // 设备注册 msg := m.Cmd("aaa.rsa", "gen", "common", m.Confv("runtime", "node")) diff --git a/src/contexts/tcp/tcp.go b/src/contexts/tcp/tcp.go index cb7b871a..a73e84f7 100644 --- a/src/contexts/tcp/tcp.go +++ b/src/contexts/tcp/tcp.go @@ -57,18 +57,21 @@ func (tcp *TCP) Begin(m *ctx.Message, arg ...string) ctx.Server { return tcp } func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { + address := []string{} if arg[1] == "consul" { - if arg[1] = m.Cmdx("web.get", "dev", arg[2], "temp", "hostport.0"); arg[1] == "" { - return true - } + m.Cmd("web.get", "dev", arg[2], "temp", "hostport").Table(func(line map[string]string) { + address = append(address, line["value"]) + }) for i := 2; i < len(arg)-1; i++ { arg[i] = arg[i+1] } if len(arg) > 2 { arg = arg[:len(arg)-1] } + } else { + address = append(address, m.Cap("address", m.Confx("address", arg, 1))) } - m.Cap("address", m.Confx("address", arg, 1)) + m.Cap("security", m.Confx("security", arg, 2)) m.Cap("protocol", m.Confx("protocol", arg, 3)) @@ -80,14 +83,17 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { m.Assert(e) conf := &tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true} - for i := 0; i < m.Confi("retry", "counts"); i++ { - if c, e := tls.Dial(m.Cap("protocol"), m.Cap("address"), conf); e == nil { - tcp.Conn = c - break - } else { - m.Log("info", "dial %s:%s %s", m.Cap("protocol"), m.Cap("address"), e) + for _, p := range address { + for i := 0; i < m.Confi("retry", "counts"); i++ { + if c, e := tls.Dial(m.Cap("protocol"), p, conf); e == nil { + m.Cap("address", p) + tcp.Conn = c + break + } else { + m.Log("info", "dial %s:%s %s", m.Cap("protocol"), m.Cap("address"), e) + } + time.Sleep(kit.Duration(m.Conf("retry", "interval"))) } - time.Sleep(kit.Duration(m.Conf("retry", "interval"))) } } else { for i := 0; i < m.Confi("retry", "counts"); i++ { @@ -142,7 +148,12 @@ func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool { m.Cap("stream", fmt.Sprintf("%s", tcp.Addr()))) addr := strings.Split(tcp.Addr().String(), ":") - m.Back(m.Spawn(m.Source()).Add("option", "hostport", fmt.Sprintf("%s:%s", m.Cmd("tcp.ifconfig", "eth0").Append("ip"), addr[len(addr)-1]))) + + ports := []interface{}{} + m.Cmd("tcp.ifconfig").Table(func(line map[string]string) { + ports = append(ports, fmt.Sprintf("%s:%s", line["ip"], addr[len(addr)-1])) + }) + m.Back(m.Spawn(m.Source()).Put("option", "hostport", ports)) } for { diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 6eba85cf..7ba14ce9 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -1027,7 +1027,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", return }}, "/shadow": &ctx.Command{Name: "/shadow", Help: "暗网", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { - m.Append("hostport", m.Conf("runtime", "ssh_port")) + m.Confm("runtime", "ssh_ports", func(index int, value string) { + m.Add("append", "hostport", value) + }) return }}, "/login": &ctx.Command{Name: "/login", Help: "认证", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {