aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/c_defs.go22
-rw-r--r--src/i_events.go115
-rw-r--r--src/i_insert.go87
-rw-r--r--src/i_ui.go23
4 files changed, 183 insertions, 64 deletions
diff --git a/src/c_defs.go b/src/c_defs.go
index 81b192b..12d1f18 100644
--- a/src/c_defs.go
+++ b/src/c_defs.go
@@ -108,6 +108,28 @@ const (
PROTOCOL_MAX = PROTOCOL_OS
)
+const (
+ INS_PROTOCOL = iota
+ INS_SSH_HOST
+ INS_SSH_PORT
+ INS_SSH_USER
+ INS_SSH_PASS
+ INS_SSH_PRIV
+ INS_SSH_JUMP_HOST
+ INS_SSH_JUMP_PORT
+ INS_SSH_JUMP_USER
+ INS_SSH_JUMP_PASS
+ INS_SSH_JUMP_PRIV
+ INS_SSH_OK
+ INS_RDP_HOST
+ INS_RDP_PORT
+ INS_RDP_DOMAIN
+ INS_RDP_USER
+ INS_RDP_PASS
+ // TODO: here
+ INS_RDP_OK
+)
+
var (
HOST_ICONS = [4]string{" ", " ", " ", "󰅟 "}
DIRS_ICONS = [2]string{" ", " "}
diff --git a/src/i_events.go b/src/i_events.go
index 96d2872..2178d7d 100644
--- a/src/i_events.go
+++ b/src/i_events.go
@@ -321,14 +321,14 @@ func i_set_protocol_defaults(data *HardData, in *HostNode) {
switch in.Protocol {
case PROTOCOL_SSH:
in.Port = 22
- data.ui.insert_sel_max = 11
+ data.ui.insert_sel_max = INS_SSH_OK
case PROTOCOL_RDP:
in.Port = 3389
in.Quality = 2
in.Width = 1600
in.Height = 1200
in.Dynamic = true
- data.ui.insert_sel_max = 4
+ data.ui.insert_sel_max = INS_RDP_OK
case PROTOCOL_CMD:
in.Shell = []string{"/bin/sh", "-c"}
data.ui.insert_sel_max = 2
@@ -566,37 +566,60 @@ func i_events(data *HardData) {
} else if event.Rune() == 'j' ||
event.Key() == tcell.KeyDown ||
event.Key() == tcell.KeyTab {
- if data.ui.insert_sel < data.ui.insert_sel_max {
+ if data.insert.Protocol == PROTOCOL_RDP &&
+ data.ui.insert_sel == INS_PROTOCOL {
+ data.ui.insert_sel = INS_RDP_HOST
+ } else if data.ui.insert_sel < data.ui.insert_sel_max {
data.ui.insert_sel += 1
}
} else if event.Rune() == 'k' ||
event.Key() == tcell.KeyUp {
- if data.ui.insert_sel > 0 {
+ if data.insert.Protocol == PROTOCOL_RDP &&
+ data.ui.insert_sel == INS_RDP_HOST {
+ data.ui.insert_sel = INS_PROTOCOL
+ } else if data.ui.insert_sel > INS_PROTOCOL {
data.ui.insert_sel -= 1
}
} else if event.Rune() == 'g' ||
event.Rune() == 'h' ||
event.Key() == tcell.KeyLeft {
- data.ui.insert_sel = 0
+ data.ui.insert_sel = INS_PROTOCOL
} else if event.Rune() == 'G' ||
event.Rune() == 'l' ||
event.Key() == tcell.KeyRight {
data.ui.insert_sel = data.ui.insert_sel_max
- } else if event.Key() == tcell.KeyEnter {
+ } else if event.Rune() == 'i' ||
+ event.Rune() == 'a' ||
+ event.Key() == tcell.KeyEnter {
data.ui.insert_sel_ok = true
switch data.ui.insert_sel {
- case 1: ui.buff = data.insert.Host
- case 2: ui.buff = strconv.Itoa(int(data.insert.Port))
- case 3: ui.buff = data.insert.User
- case 4: break
- case 5: ui.buff = data.insert.Priv
- case 6: ui.buff = data.insert.Jump.Host
- case 7: ui.buff = strconv.Itoa(int(
- data.insert.Jump.Port))
- case 8: ui.buff = data.insert.Jump.User
- case 9: break
- case 10: ui.buff = data.insert.Jump.Priv
- case 11:
+ case INS_SSH_HOST,
+ INS_RDP_HOST:
+ ui.buff = data.insert.Host
+ case INS_SSH_PORT,
+ INS_RDP_PORT:
+ if data.insert.Port > 0 {
+ ui.buff = strconv.Itoa(int(data.insert.Port))
+ }
+ case INS_SSH_USER,
+ INS_RDP_USER:
+ ui.buff = data.insert.User
+ case INS_SSH_PASS,
+ INS_RDP_PASS:
+ break
+ case INS_SSH_PRIV: ui.buff = data.insert.Priv
+ case INS_SSH_JUMP_HOST: ui.buff = data.insert.Jump.Host
+ case INS_SSH_JUMP_PORT:
+ if data.insert.Jump.Port > 0 {
+ ui.buff = strconv.Itoa(int(
+ data.insert.Jump.Port))
+ }
+ case INS_SSH_JUMP_USER: ui.buff = data.insert.Jump.User
+ case INS_SSH_JUMP_PASS: break
+ case INS_SSH_JUMP_PRIV: ui.buff = data.insert.Jump.Priv
+ case INS_RDP_DOMAIN: ui.buff = data.insert.Domain
+ case INS_SSH_OK,
+ INS_RDP_OK:
data.ui.insert_sel_ok = false
i_insert_check_ok(data, data.insert)
if data.insert_err != nil {
@@ -613,7 +636,7 @@ func i_events(data *HardData) {
ui.s.HideCursor()
}
switch data.ui.insert_sel {
- case 0:
+ case INS_PROTOCOL:
if event.Rune() < '1' || event.Rune() > '4' {
data.ui.insert_sel_ok = false
ui.buff = ""
@@ -631,35 +654,57 @@ func i_events(data *HardData) {
ui.s.HideCursor()
i_set_protocol_defaults(data, data.insert)
}
- case 1, 2, 3, 4, 5, 6, 7, 8, 9, 10:
+ case INS_SSH_HOST,
+ INS_SSH_PORT,
+ INS_SSH_USER,
+ INS_SSH_PASS,
+ INS_SSH_PRIV,
+ INS_SSH_JUMP_HOST,
+ INS_SSH_JUMP_PORT,
+ INS_SSH_JUMP_USER,
+ INS_SSH_JUMP_PASS,
+ INS_SSH_JUMP_PRIV,
+ INS_RDP_HOST,
+ INS_RDP_PORT,
+ INS_RDP_DOMAIN,
+ INS_RDP_USER,
+ INS_RDP_PASS:
if event.Key() == tcell.KeyEnter {
switch data.ui.insert_sel {
- case 1: data.insert.Host = ui.buff
- case 2:
+ case INS_SSH_HOST,
+ INS_RDP_HOST:
+ data.insert.Host = ui.buff
+ case INS_SSH_PORT,
+ INS_RDP_PORT:
tmp, _ := strconv.Atoi(ui.buff)
data.insert.Port = uint16(tmp)
- case 3: data.insert.User = ui.buff
- case 4:
- pass, _ := c_encrypt_str(ui.buff,
+ case INS_SSH_USER,
+ INS_RDP_USER:
+ data.insert.User = ui.buff
+ case INS_SSH_PASS,
+ INS_RDP_PASS:
+ data.insert.Pass, _ = c_encrypt_str(ui.buff,
data.opts.GPG)
- data.insert.Pass = pass
- case 5: data.insert.Priv = ui.buff
- case 6:
+ case INS_SSH_PRIV: data.insert.Priv = ui.buff
+ case INS_SSH_JUMP_HOST:
data.insert.Jump.Host = ui.buff
if len(ui.buff) > 0 {
data.insert.Jump.Port = 22
} else {
data.insert.Jump.Port = 0
}
- case 7:
+ case INS_SSH_JUMP_PORT:
tmp, _ := strconv.Atoi(ui.buff)
data.insert.Jump.Port = uint16(tmp)
- case 8: data.insert.Jump.User = ui.buff
- case 9:
- pass, _ := c_encrypt_str(ui.buff,
- data.opts.GPG)
- data.insert.Jump.Pass = pass
- case 10: data.insert.Jump.Priv = ui.buff
+ case INS_SSH_JUMP_USER:
+ data.insert.Jump.User = ui.buff
+ case INS_SSH_JUMP_PASS:
+ data.insert.Jump.Pass, _ =
+ c_encrypt_str(ui.buff, data.opts.GPG)
+ case INS_SSH_JUMP_PRIV:
+ data.insert.Jump.Priv = ui.buff
+ case INS_RDP_DOMAIN:
+ data.insert.Domain = ui.buff
}
data.ui.insert_sel_ok = false
ui.buff = ""
diff --git a/src/i_insert.go b/src/i_insert.go
index fd9b852..d9a3e40 100644
--- a/src/i_insert.go
+++ b/src/i_insert.go
@@ -172,7 +172,8 @@ func i_draw_text_box(ui HardUI, line int, dim Quad, label, content string,
if l <= dim.L { l = dim.L + 1 }
i_draw_text(ui.s, l, line, ui.dim[W] / 2, line,
ui.style[DEF_STYLE], label)
- if (id == 4 || id == 9) && len(content) > 0 {
+ if (id == INS_SSH_PASS || id == INS_SSH_JUMP_PASS || id == INS_RDP_PASS) &&
+ len(content) > 0 {
content = "***"
}
if red == true {
@@ -211,6 +212,8 @@ func i_draw_ok_butt(ui HardUI, line int, id, selected int) {
}
func i_draw_insert_panel(ui HardUI, in *HostNode) {
+ type draw_insert_func func(ui HardUI, line int, win Quad, in *HostNode) int
+
if len(in.Name) == 0 {
return
}
@@ -229,16 +232,53 @@ func i_draw_insert_panel(ui HardUI, in *HostNode) {
0, ui.insert_sel, false)
line += 2
var end_line int
- switch in.Protocol {
- case PROTOCOL_SSH:
- end_line = i_draw_insert_ssh(ui, line, win, in)
+ fp := [PROTOCOL_MAX + 1]draw_insert_func{
+ i_draw_insert_ssh,
+ i_draw_insert_rdp,
+ i_draw_insert_cmd,
+ i_draw_insert_os,
}
+ end_line = fp[in.Protocol](ui, line, win, in)
if win.T + end_line >= win.B {
ui.s.SetContent(ui.dim[W] / 2, win.B, '▼', nil, ui.style[BOX_STYLE])
// TODO: scroll or something
}
}
+func i_draw_insert_os(ui HardUI, line int, win Quad, in *HostNode) int {
+ return 0
+}
+
+func i_draw_insert_cmd(ui HardUI, line int, win Quad, in *HostNode) int {
+ return 0
+}
+
+func i_draw_insert_rdp(ui HardUI, line int, win Quad, in *HostNode) int {
+ // red := false
+ if win.T + line >= win.B { return line }
+ text := "---- Host settings ----"
+ i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1,
+ win.T + line, ui.style[DEF_STYLE], text)
+ if line += 2; win.T + line >= win.B { return line }
+ i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host,
+ INS_RDP_HOST, ui.insert_sel, false)
+ if line += 1; win.T + line >= win.B { return line }
+ i_draw_text_box(ui, win.T + line, win, "Port", strconv.Itoa(int(in.Port)),
+ INS_RDP_PORT, ui.insert_sel, false);
+ if line += 1; win.T + line >= win.B { return line }
+ i_draw_text_box(ui, win.T + line, win, "Domain", in.Domain,
+ INS_RDP_DOMAIN, ui.insert_sel, false);
+ if line += 2; win.T + line >= win.B { return line }
+ i_draw_text_box(ui, win.T + line, win, "User", in.User,
+ INS_RDP_USER, ui.insert_sel, false)
+ if line += 1; win.T + line >= win.B { return line }
+ i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass,
+ INS_RDP_PASS, ui.insert_sel, false)
+ if line += 2; win.T + line >= win.B { return line }
+ i_draw_ok_butt(ui, win.T + line, INS_RDP_OK, ui.insert_sel)
+ return line
+}
+
func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int {
red := false
if win.T + line >= win.B { return line }
@@ -246,17 +286,17 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int {
i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1,
win.T + line, ui.style[DEF_STYLE], text)
if line += 2; win.T + line >= win.B { return line }
- i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host, 1, ui.insert_sel,
- false)
+ i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Host,
+ INS_SSH_HOST, ui.insert_sel, false)
if line += 1; win.T + line >= win.B { return line }
i_draw_text_box(ui, win.T + line, win, "Port", strconv.Itoa(int(in.Port)),
- 2, ui.insert_sel, false);
+ INS_SSH_PORT, ui.insert_sel, false);
if line += 2; win.T + line >= win.B { return line }
- i_draw_text_box(ui, win.T + line, win, "User", in.User, 3, ui.insert_sel,
- false)
+ i_draw_text_box(ui, win.T + line, win, "User", in.User,
+ INS_SSH_USER, ui.insert_sel, false)
if line += 1; win.T + line >= win.B { return line }
- i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass, 4, ui.insert_sel,
- false)
+ i_draw_text_box(ui, win.T + line, win, "Pass", in.Pass,
+ INS_SSH_PASS, ui.insert_sel, false)
if line += 1; win.T + line >= win.B { return line }
if len(in.Priv) > 0 {
file := in.Priv
@@ -269,8 +309,8 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int {
red = true
}
}
- i_draw_text_box(ui, win.T + line, win, "SSH private key",
- in.Priv, 5, ui.insert_sel, red)
+ i_draw_text_box(ui, win.T + line, win, "SSH private key", in.Priv,
+ INS_SSH_PRIV, ui.insert_sel, red)
if red == true {
if line += 1; win.T + line >= win.B { return line }
text := "file does not exist"
@@ -283,17 +323,18 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int {
i_draw_text(ui.s, ui.dim[W] / 2 - len(text) / 2, win.T + line, win.R - 1,
win.T + line, ui.style[DEF_STYLE], text)
if line += 2; win.T + line >= win.B { return line }
- i_draw_text_box(ui, win.T + line, win, "Host/IP",
- in.Jump.Host, 6, ui.insert_sel, false)
+ i_draw_text_box(ui, win.T + line, win, "Host/IP", in.Jump.Host,
+ INS_SSH_JUMP_HOST, ui.insert_sel, false)
if line += 1; win.T + line >= win.B { return line }
i_draw_text_box(ui, win.T + line, win, "Port",
- strconv.Itoa(int(in.Jump.Port)), 7, ui.insert_sel, false)
+ strconv.Itoa(int(in.Jump.Port)),
+ INS_SSH_JUMP_PORT, ui.insert_sel, false)
if line += 2; win.T + line >= win.B { return line }
- i_draw_text_box(ui, win.T + line, win, "User",
- in.Jump.User, 8, ui.insert_sel, false)
+ i_draw_text_box(ui, win.T + line, win, "User", in.Jump.User,
+ INS_SSH_JUMP_USER, ui.insert_sel, false)
if line += 1; win.T + line >= win.B { return line }
- i_draw_text_box(ui, win.T + line, win, "Pass",
- in.Jump.Pass, 9, ui.insert_sel, false)
+ i_draw_text_box(ui, win.T + line, win, "Pass", in.Jump.Pass,
+ INS_SSH_JUMP_PASS, ui.insert_sel, false)
if line += 1; win.T + line >= win.B { return line}
if len(in.Jump.Priv) > 0 {
file := in.Jump.Priv
@@ -306,8 +347,8 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int {
red = true
}
}
- i_draw_text_box(ui, win.T + line, win, "SSH private key",
- in.Jump.Priv, 10, ui.insert_sel, red)
+ i_draw_text_box(ui, win.T + line, win, "SSH private key", in.Jump.Priv,
+ INS_SSH_JUMP_PRIV, ui.insert_sel, red)
if red == true {
if line += 1; win.T + line >= win.B { return line }
text := "file does not exist"
@@ -315,6 +356,6 @@ func i_draw_insert_ssh(ui HardUI, line int, win Quad, in *HostNode) int {
win.R - 1, win.T + line, ui.style[ERR_STYLE], text)
}
if line += 2; win.T + line >= win.B { return line }
- i_draw_ok_butt(ui, win.T + line, 11, ui.insert_sel)
+ i_draw_ok_butt(ui, win.T + line, INS_SSH_OK, ui.insert_sel)
return line
}
diff --git a/src/i_ui.go b/src/i_ui.go
index 37e1912..ea76488 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -679,19 +679,30 @@ func i_ui(data_dir string) {
i_draw_insert_panel(data.ui, data.insert)
if data.ui.insert_sel_ok == true {
switch data.ui.insert_sel {
- case 0:
+ case INS_PROTOCOL:
i_prompt_type(data.ui)
- case 1, 6:
+ case INS_SSH_HOST,
+ INS_SSH_JUMP_HOST,
+ INS_RDP_HOST:
i_prompt_generic(data.ui, "Host/IP: ", false, "")
- case 2, 7:
+ case INS_SSH_PORT,
+ INS_SSH_JUMP_PORT,
+ INS_RDP_PORT:
i_prompt_generic(data.ui, "Port: ", false, "")
- case 3, 8:
+ case INS_SSH_USER,
+ INS_SSH_JUMP_USER,
+ INS_RDP_USER:
i_prompt_generic(data.ui, "User: ", false, "")
- case 4, 9:
+ case INS_SSH_PASS,
+ INS_SSH_JUMP_PASS,
+ INS_RDP_PASS:
i_prompt_generic(data.ui, "Pass: ", true, "")
- case 5, 10:
+ case INS_SSH_PRIV,
+ INS_SSH_JUMP_PRIV:
i_prompt_generic(data.ui, "Private key: ",
false, home_dir)
+ case INS_RDP_DOMAIN:
+ i_prompt_generic(data.ui, "Domain: ", false, "")
}
} else if data.insert_err != nil {
i_draw_insert_err_msg(data.ui, data.insert_err)