diff options
author | Joe <rbo@gmx.us> | 2024-01-31 20:20:20 +0100 |
---|---|---|
committer | Joe <rbo@gmx.us> | 2024-01-31 20:20:20 +0100 |
commit | 808cc138f401cb5d398567f66ef4987f8be5af7a (patch) | |
tree | 89dcfa89744ce055c9bdeacb13f1bd1c983a3fc2 /src | |
parent | mkay (diff) | |
download | hardflip-808cc138f401cb5d398567f66ef4987f8be5af7a.tar.gz hardflip-808cc138f401cb5d398567f66ef4987f8be5af7a.tar.bz2 hardflip-808cc138f401cb5d398567f66ef4987f8be5af7a.tar.xz hardflip-808cc138f401cb5d398567f66ef4987f8be5af7a.tar.zst hardflip-808cc138f401cb5d398567f66ef4987f8be5af7a.zip |
decrypting gpg at parse time was too fucking slow i had to overcome
Diffstat (limited to 'src')
-rw-r--r-- | src/c_exec.go | 57 | ||||
-rw-r--r-- | src/c_init.go | 15 | ||||
-rw-r--r-- | src/c_parse.go | 3 | ||||
-rw-r--r-- | src/i_events.go | 15 |
4 files changed, 49 insertions, 41 deletions
diff --git a/src/c_exec.go b/src/c_exec.go index 145d1f0..dd8fc9d 100644 --- a/src/c_exec.go +++ b/src/c_exec.go @@ -55,6 +55,9 @@ import ( "os" "os/exec" "strconv" + "strings" + + "github.com/gdamore/tcell/v2" ) func c_exec_cmd(cmd_fmt []string) { @@ -83,10 +86,10 @@ func c_format_ssh_jump(host *HostNode) string { return jump_fmt } -func c_format_ssh(host *HostNode) []string { +func c_format_ssh(host *HostNode, pass string) []string { cmd_fmt := []string{} - if len(host.Pass) > 0 { - cmd_fmt = append(cmd_fmt, "sshpass", "-p", host.Pass) + if len(pass) > 0 { + cmd_fmt = append(cmd_fmt, "sshpass", "-p", pass) } cmd_fmt = append(cmd_fmt, "ssh") @@ -103,7 +106,7 @@ func c_format_ssh(host *HostNode) []string { return cmd_fmt } -func c_format_rdp(host *HostNode) []string { +func c_format_rdp(host *HostNode, pass string) []string { cmd_fmt := []string{"xfreerdp"} cmd_fmt = append(cmd_fmt, @@ -112,8 +115,8 @@ func c_format_rdp(host *HostNode) []string { if len(host.Domain) > 0 { cmd_fmt = append(cmd_fmt, "/d:" + host.Domain) } - if len(host.Pass) > 0 { - cmd_fmt = append(cmd_fmt, "/p:" + host.Pass) + if len(pass) > 0 { + cmd_fmt = append(cmd_fmt, "/p:" + pass) } if host.Port != 0 { cmd_fmt = append(cmd_fmt, "/port:" + strconv.Itoa(int(host.Port))) @@ -139,14 +142,26 @@ func c_format_rdp(host *HostNode) []string { return cmd_fmt } -func c_format_cmd(host *HostNode, term string) { +func c_format_cmd(host *HostNode, opts HardOpts, ui *HardUI) []string { var cmd_fmt []string + var pass string + gpg, term := opts.GPG, opts.Term + if len(gpg) > 0 && gpg != "plain" && len(host.Pass) > 0 { + var err error + pass, err = c_decrypt_str(host.Pass) + if err != nil { + c_error_mode(host.Parent.path() + host.Filename + + ": password decryption failed", err, ui) + return nil + } + pass = strings.TrimSuffix(pass, "\n") + } switch host.Protocol { case 0: - cmd_fmt = c_format_ssh(host) + cmd_fmt = c_format_ssh(host, pass) case 1: - cmd_fmt = c_format_rdp(host) + cmd_fmt = c_format_rdp(host, pass) default: c_die("you fucked up joe, users cant see this", nil) } @@ -157,12 +172,30 @@ func c_format_cmd(host *HostNode, term string) { } cmd_fmt = append([]string{"setsid", term, "-e"}, cmd_fmt...) } - c_exec_cmd(cmd_fmt) + return cmd_fmt } -func c_exec(host *HostNode, term string) { +func c_exec(host *HostNode, opts HardOpts, ui *HardUI) { + var err error + if host == nil { return } - c_format_cmd(host, term) + cmd_fmt := c_format_cmd(host, opts, ui) + if cmd_fmt == nil { + return + } + ui.s.Fini() + c_exec_cmd(cmd_fmt) + if opts.Loop == false { + os.Exit(0) + } else { + if ui.s, err = tcell.NewScreen(); err != nil { + c_die("view", err) + } + if err := ui.s.Init(); err != nil { + c_die("view", err) + } + ui.s.SetStyle(ui.style[DEF_STYLE]) + } } diff --git a/src/c_init.go b/src/c_init.go index f09da57..f89ce47 100644 --- a/src/c_init.go +++ b/src/c_init.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_init.go - * Thu Jan 18 16:23:10 2024 + * Wed Jan 31 14:10:00 2024 * Joe * * init functions @@ -52,11 +52,8 @@ package main import ( - "errors" - "fmt" "os" "path/filepath" - "strings" ) type HardOpts struct { @@ -93,7 +90,7 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, c_recurse_data_dir(dir + filename + "/", root, opts, ldirs, file.Name(), &dir_node, depth + 1, ui, load_err) } else if filepath.Ext(filename) == ".yml" { - host_node, err := c_read_yaml_file(root + dir + filename, opts, ui) + host_node, err := c_read_yaml_file(root + dir + filename, ui) if err != nil { *load_err = append(*load_err, err) } else if host_node != nil { @@ -101,14 +98,6 @@ func c_recurse_data_dir(dir, root string, opts HardOpts, host_node.Parent = &dir_node if len(opts.GPG) == 0 { host_node.Pass = "" - } else if opts.GPG != "plain" && len(host_node.Pass) > 0 { - host_node.Pass, err = c_decrypt_str(host_node.Pass) - if err != nil { - str := fmt.Sprintf("%s%s: password decryption: %v\n", - dir, filename, err) - *load_err = append(*load_err, errors.New(str)) - } - host_node.Pass = strings.TrimSuffix(host_node.Pass, "\n") } dir_node.lhost.add_back(host_node) } diff --git a/src/c_parse.go b/src/c_parse.go index 2a7b881..faa8223 100644 --- a/src/c_parse.go +++ b/src/c_parse.go @@ -58,8 +58,7 @@ import ( "gopkg.in/yaml.v3" ) -func c_read_yaml_file(file string, - opts HardOpts, ui *HardUI) (*HostNode, error) { +func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) { var host HostNode yaml_file, err := os.ReadFile(file) diff --git a/src/i_events.go b/src/i_events.go index e70b480..becc2ee 100644 --- a/src/i_events.go +++ b/src/i_events.go @@ -241,7 +241,6 @@ func i_delete_host(data *HardData) error { // screen events such as keypresses func i_events(data *HardData) { - var err error ui := &data.ui event := ui.s.PollEvent() switch event := event.(type) { @@ -297,19 +296,7 @@ func i_events(data *HardData) { if data.litems.curr == nil { break } else if data.litems.curr.is_dir() == false { - ui.s.Fini() - c_exec(data.litems.curr.Host, data.opts.Term) - if data.opts.Loop == false { - os.Exit(0) - } else { - if ui.s, err = tcell.NewScreen(); err != nil { - c_die("view", err) - } - if err := ui.s.Init(); err != nil { - c_die("view", err) - } - ui.s.SetStyle(ui.style[DEF_STYLE]) - } + c_exec(data.litems.curr.Host, data.opts, ui) } else if data.litems.curr.Dirs != nil && data.folds[data.litems.curr.Dirs] == nil { i_fold_dir(data, data.litems.curr) |