aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/c_exec.go41
-rw-r--r--src/e_events.go2
-rw-r--r--src/i_ui.go2
3 files changed, 40 insertions, 5 deletions
diff --git a/src/c_exec.go b/src/c_exec.go
index b5b6cf6..b9990d9 100644
--- a/src/c_exec.go
+++ b/src/c_exec.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_exec.go
- * Fri Feb 02 11:44:44 2024
+ * Tue Apr 23 17:47:58 2024
* Joe
*
* exec the command at some point
@@ -53,6 +53,7 @@ package main
import (
"bytes"
+ "math/rand/v2"
"os"
"os/exec"
"strconv"
@@ -227,11 +228,45 @@ func c_format_cmd(host *HostNode, opts HardOpts,
return cmd_fmt, cmd_env
}
+func c_redirect_ssh(host *HostNode, local_port uint16) error {
+ // TODO: here
+ rdr_fmt := []string{}
+ rdr_fmt = append(rdr_fmt, "ssh", "-f")
+ rdr_fmt = append(rdr_fmt, "-L",
+ strconv.Itoa(int(local_port)) + ":" +
+ host.Host + ":" +
+ strconv.Itoa(int(host.Port)))
+ if len(host.Jump.Priv) > 0 {
+ rdr_fmt = append(rdr_fmt, "-i", host.Jump.Priv)
+ }
+ if host.Jump.Port != 0 {
+ rdr_fmt = append(rdr_fmt, "-p", strconv.Itoa(int(host.Jump.Port)))
+ }
+ rdr_fmt = append(rdr_fmt, host.Jump.User + "@" + host.Jump.Host,
+ "-", "sleep", "5")
+ if err := exec.Command(rdr_fmt[0], rdr_fmt[1:]...).Run(); err != nil {
+ return err
+ }
+ return nil
+}
+
func c_exec(host *HostNode, opts HardOpts, ui *HardUI) {
if host == nil {
return
}
- cmd_fmt, cmd_env := c_format_cmd(host, opts, ui)
+ tmp_host := host
+ if host.Protocol == PROTOCOL_RDP && len(host.Jump.Host) != 0 {
+ local_host := "127.0.0.1"
+ local_port := uint16(rand.IntN(40000) + 4389)
+ ui.s.Fini()
+ if err := c_redirect_ssh(host, local_port); err != nil {
+ c_error_mode("ssh tunneling", err, ui)
+ return
+ }
+ tmp_host.Host = local_host
+ tmp_host.Port = local_port
+ }
+ cmd_fmt, cmd_env := c_format_cmd(tmp_host, opts, ui)
if cmd_fmt == nil {
return
}
@@ -253,7 +288,7 @@ func c_exec(host *HostNode, opts HardOpts, ui *HardUI) {
ui.s.Show()
}
if err, err_str := c_exec_cmd(cmd_fmt, cmd_env, silent);
- err != nil && host.Protocol == 2 {
+ err != nil && host.Protocol == PROTOCOL_CMD {
c_error_mode(err_str, err, ui)
}
if opts.Loop == false {
diff --git a/src/e_events.go b/src/e_events.go
index 742aa41..b089a03 100644
--- a/src/e_events.go
+++ b/src/e_events.go
@@ -186,7 +186,7 @@ func e_reload_data(data *HardData) {
data.opts = c_get_options(conf_dir, &data.load_err)
}
data.data_dir = c_get_data_dir(&data.ui)
- if data.data_dir == "" {
+ if len(data.data_dir) == 0 {
return
}
g_load_count = -1
diff --git a/src/i_ui.go b/src/i_ui.go
index f327629..b19921b 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -667,7 +667,7 @@ func i_ui(data_dir string) {
ui.dim[W], ui.dim[H], _ = term.GetSize(0)
var load_err []error
conf_dir := c_get_conf_dir(&load_err)
- if conf_dir == "" {
+ if len(conf_dir) == 0 {
opts = DEFAULT_OPTS
} else {
opts = c_get_options(conf_dir, &load_err)