ssh

package
v0.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SOURCE = "source"
	TARGET = "target"
	PROMPT = "prompt"
	QRCODE = "qrcode"
	RETURN = "return"
	REMOTE = "remote"
)
View Source
const (
	STDIO = "stdio"
)

Variables

View Source
var Index = &ice.Context{Name: "ssh", Help: "终端模块",
	Caches: map[string]*ice.Cache{},
	Configs: map[string]*ice.Config{
		SOURCE: {Name: "prompt", Help: "命令提示", Value: kit.Data(
			web.FAVOR, "cmd.history",
		)},
		PROMPT: {Name: "prompt", Help: "命令提示", Value: kit.Data(
			"PS1", []interface{}{"\033[33;44m", "count", "[", "time", "]", "\033[5m", "target", "\033[0m", "\033[44m", ">", "\033[0m ", "\033[?25h", "\033[32m"},
			"PS2", []interface{}{"count", " ", "target", "> "},
		)},
		REMOTE: {Name: "remote", Help: "远程连接", Value: kit.Data()},
	},
	Commands: map[string]*ice.Command{
		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) {
			if _, ok := m.Target().Server().(*Frame); ok {
				m.Done()
			}
		}},

		SOURCE: {Name: "source file", Help: "脚本解析", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			if _, e := os.Stat(arg[0]); e != nil {
				arg[0] = path.Join(path.Dir(m.Option("_script")), arg[0])
			}
			m.Option("_script", arg[0])
			m.Starts(strings.Replace(arg[0], ".", "_", -1), arg[0], arg[0:]...)
		}},
		TARGET: {Name: "target name", Help: "当前模块", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			m.Search(arg[0], func(p *ice.Context, s *ice.Context, key string) {
				f := m.Target().Server().(*Frame)
				f.target = s
				f.prompt(m)
			})
		}},
		PROMPT: {Name: "prompt arg...", Help: "命令提示", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			f := m.Target().Server().(*Frame)
			f.ps1 = arg
			f.prompt(m)
		}},
		QRCODE: {Name: "qrcode arg...", Help: "命令提示", Action: map[string]*ice.Action{
			"json": {Name: "json [key val]...", Help: "json", Hand: func(m *ice.Message, arg ...string) {
				val := map[string]interface{}{}
				for i := 0; i < len(arg)-1; i += 2 {
					kit.Value(val, arg[i], arg[i+1])
				}
				f := m.Target().Server().(*Frame)
				f.printf(m, m.Cmdx(cli.PYTHON, "qrcode", kit.Format(val)))
			}},
		}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			f := m.Target().Server().(*Frame)
			f.printf(m, m.Cmdx(cli.PYTHON, "qrcode", strings.Join(arg, "")))
		}},
		RETURN: {Name: "return", Help: "结束脚本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			f := m.Target().Server().(*Frame)
			f.exit = true
		}},

		REMOTE: {Name: "remote user remote port local", Help: "远程连接", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			key := m.Rich(REMOTE, nil, kit.Dict(
				"user", arg[0], "remote", arg[1], "port", arg[2], "local", arg[3],
			))
			m.Echo(key)
			m.Info(key)

			m.Gos(m, func(m *ice.Message) {
				for {
					m.Cmd(cli.SYSTEM, "ssh", "-CNR", kit.Format("%s:%s:22", arg[2], kit.Select("localhost", arg, 3)),
						kit.Format("%s@%s", arg[0], arg[1]))
					m.Info("reconnect after 10s")
					time.Sleep(time.Second * 10)
				}
			})
		}},
	},
}

Functions

func Render added in v0.1.21

func Render(msg *ice.Message, cmd string, args ...interface{})

Types

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

func (*Frame) Begin

func (f *Frame) Begin(m *ice.Message, arg ...string) ice.Server

func (*Frame) Close

func (f *Frame) Close(m *ice.Message, arg ...string) bool

func (*Frame) Spawn

func (f *Frame) Spawn(m *ice.Message, c *ice.Context, arg ...string) ice.Server

func (*Frame) Start

func (f *Frame) Start(m *ice.Message, arg ...string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL