diff options
author | Joe <rbo@gmx.us> | 2024-02-02 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-02-02 20:20:20 +0100 |
commit | 61050cce1900715e105f6e41dd02a5e313e242de (patch) | |
tree | 7e112edf0dba94f4d5567c59e15baa26c31b69a3 | |
parent | massive change (diff) | |
download | hardflip-61050cce1900715e105f6e41dd02a5e313e242de.tar.gz hardflip-61050cce1900715e105f6e41dd02a5e313e242de.tar.bz2 hardflip-61050cce1900715e105f6e41dd02a5e313e242de.tar.xz hardflip-61050cce1900715e105f6e41dd02a5e313e242de.tar.zst hardflip-61050cce1900715e105f6e41dd02a5e313e242de.zip |
flexin hard
-rw-r--r-- | src/c_exec.go | 37 | ||||
-rw-r--r-- | src/i_info.go | 8 |
2 files changed, 24 insertions, 21 deletions
diff --git a/src/c_exec.go b/src/c_exec.go index 36bff33..c62c8d5 100644 --- a/src/c_exec.go +++ b/src/c_exec.go @@ -97,7 +97,7 @@ func c_format_ssh_jump(host *HostNode) string { return jump_fmt } -func c_format_ssh(host *HostNode, pass string) []string { +func c_format_ssh(host *HostNode, pass string) ([]string, []string) { cmd_fmt := []string{} if len(pass) > 0 { cmd_fmt = append(cmd_fmt, "sshpass", "-p", pass) @@ -114,10 +114,10 @@ func c_format_ssh(host *HostNode, pass string) []string { cmd_fmt = append(cmd_fmt, "-p", strconv.Itoa(int(host.Port))) } cmd_fmt = append(cmd_fmt, host.User + "@" + host.Host) - return cmd_fmt + return cmd_fmt, nil } -func c_format_rdp(host *HostNode, pass string) []string { +func c_format_rdp(host *HostNode, pass string) ([]string, []string) { cmd_fmt := []string{"xfreerdp"} cmd_fmt = append(cmd_fmt, @@ -155,7 +155,7 @@ func c_format_rdp(host *HostNode, pass string) []string { cmd_fmt = append(cmd_fmt, "/size:" + strconv.Itoa(int(host.Width)) + "x" + strconv.Itoa(int(host.Height))) - return cmd_fmt + return cmd_fmt, nil } func c_format_openstack(host *HostNode, pass string) ([]string, []string) { @@ -177,12 +177,19 @@ func c_format_openstack(host *HostNode, pass string) ([]string, []string) { return cmd_fmt, cmd_env } +func c_format_command(host *HostNode, pass string) ([]string, []string){ + return append(host.Shell, host.Host), nil +} + func c_format_cmd(host *HostNode, opts HardOpts, ui *HardUI) ([]string, []string) { - var cmd_fmt, cmd_env []string + type format_func func(*HostNode, string) ([]string, []string) var pass string gpg, term := opts.GPG, opts.Term + if host.Protocol > PROTOCOL_MAX { + return nil, nil + } if len(gpg) > 0 && gpg != "plain" && len(host.Pass) > 0 { i_draw_msg(ui.s, 1, ui.style[STYLE_BOX], ui.dim, " GnuPG ") text := "decryption using gpg..." @@ -199,18 +206,13 @@ func c_format_cmd(host *HostNode, opts HardOpts, } pass = strings.TrimSuffix(pass, "\n") } - switch host.Protocol { - case 0: - cmd_fmt = c_format_ssh(host, pass) - case 1: - cmd_fmt = c_format_rdp(host, pass) - case 2: - cmd_fmt = append(host.Shell, host.Host) - case 3: - cmd_fmt, cmd_env = c_format_openstack(host, pass) - default: - return nil, nil + fp := [PROTOCOL_MAX + 1]format_func{ + c_format_ssh, + c_format_rdp, + c_format_command, + c_format_openstack, } + cmd_fmt, cmd_env := fp[host.Protocol](host, pass) if len(term) > 0 { // TODO: setsid if term == "$TERMINAL" { @@ -246,7 +248,8 @@ func c_exec(host *HostNode, opts HardOpts, ui *HardUI) { ui.style[STYLE_DEF], text) ui.s.Show() } - if err, err_str := c_exec_cmd(cmd_fmt, cmd_env, silent); err != nil { + if err, err_str := c_exec_cmd(cmd_fmt, cmd_env, silent); + err != nil && host.Protocol == 2 { c_error_mode(err_str, err, ui) } if opts.Loop == false { diff --git a/src/i_info.go b/src/i_info.go index 76dcdad..60a38c0 100644 --- a/src/i_info.go +++ b/src/i_info.go @@ -57,8 +57,6 @@ import ( "github.com/gdamore/tcell/v2" ) -type info_func func(HardUI, *HostNode, int) int - func i_info_dirs(ui HardUI, dir *DirsNode) { line := 2 if line > ui.dim[H] - 3 { @@ -366,6 +364,8 @@ func i_info_note(ui HardUI, host *HostNode, line int) { } func i_draw_info_panel(ui HardUI, percent bool, litems *ItemsList) { + type info_func func(HardUI, *HostNode, int) int + i_draw_box(ui.s, (ui.dim[W] / 3), 0, ui.dim[W] - 1, ui.dim[H] - 2, ui.style[STYLE_BOX], ui.style[STYLE_HEAD], " Infos ", false) @@ -410,13 +410,13 @@ func i_draw_info_panel(ui HardUI, percent bool, litems *ItemsList) { if litems.curr.Host.Protocol > PROTOCOL_MAX { return } - fn := [PROTOCOL_MAX + 1]info_func{ + fp := [PROTOCOL_MAX + 1]info_func{ i_info_ssh, i_info_rdp, i_info_cmd, i_info_openstack, } - line = fn[litems.curr.Host.Protocol](ui, litems.curr.Host, line) + line = fp[litems.curr.Host.Protocol](ui, litems.curr.Host, line) i_info_note(ui, litems.curr.Host, line) } } |