aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-02-01 20:20:20 +0100
committerJoe <rbo@gmx.us>2024-02-01 20:20:20 +0100
commit80f8e7ecc663ca85e7dab7d4e60c8c6113bc4e9d (patch)
tree998a6f700c1088ae1f5c137bdd89765ab2f37b04
parentok (diff)
downloadhardflip-80f8e7ecc663ca85e7dab7d4e60c8c6113bc4e9d.tar.gz
hardflip-80f8e7ecc663ca85e7dab7d4e60c8c6113bc4e9d.tar.bz2
hardflip-80f8e7ecc663ca85e7dab7d4e60c8c6113bc4e9d.tar.xz
hardflip-80f8e7ecc663ca85e7dab7d4e60c8c6113bc4e9d.tar.zst
hardflip-80f8e7ecc663ca85e7dab7d4e60c8c6113bc4e9d.zip
stackin
Diffstat (limited to '')
-rw-r--r--ROADMAP.md2
-rw-r--r--src/c_defs.go2
-rw-r--r--src/c_exec.go41
-rw-r--r--src/c_lhosts.go18
-rw-r--r--src/c_parse.go2
-rw-r--r--src/i_info.go99
6 files changed, 114 insertions, 50 deletions
diff --git a/ROADMAP.md b/ROADMAP.md
index 65bda3e..de784a5 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -21,7 +21,7 @@
## v0.5
-- [ ] single commands
+- [x] single commands
- [ ] openstack
## v0.6
diff --git a/src/c_defs.go b/src/c_defs.go
index f989808..2ec2346 100644
--- a/src/c_defs.go
+++ b/src/c_defs.go
@@ -92,7 +92,7 @@ const (
)
var (
- HOST_ICONS = [2]string{" ", " ", ""}
+ HOST_ICONS = [4]string{" ", " ", " ", "󰞵 "}
DIRS_ICONS = [2]string{" ", " "}
)
diff --git a/src/c_exec.go b/src/c_exec.go
index e8869f2..4ca6eea 100644
--- a/src/c_exec.go
+++ b/src/c_exec.go
@@ -60,9 +60,12 @@ import (
"github.com/gdamore/tcell/v2"
)
-func c_exec_cmd(cmd_fmt []string) {
+func c_exec_cmd(cmd_fmt, cmd_env []string) {
cmd := exec.Command(cmd_fmt[0], cmd_fmt[1:]...)
+ if cmd_env != nil {
+ cmd.Env = append(cmd.Env, cmd_env...)
+ }
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
@@ -147,8 +150,28 @@ func c_format_rdp(host *HostNode, pass string) []string {
return cmd_fmt
}
-func c_format_cmd(host *HostNode, opts HardOpts, ui *HardUI) []string {
- var cmd_fmt []string
+func c_format_openstack(host *HostNode, pass string) ([]string, []string) {
+ cmd_fmt := []string{"openstack"}
+ cmd_env := []string{
+ "OS_USERNAME=" + host.User,
+ "OS_PASSWORD=" + pass,
+ "OS_AUTH_URL=" + host.Host,
+ "OS_USER_DOMAIN_ID=" + host.Stack.UserDomainId,
+ "OS_PROJECT_ID=" + host.Stack.ProjectId,
+ "OS_IDENTITY_API_VERSION=" + host.Stack.IdentityAPI,
+ "OS_IMAGE_API_VERSION=" + host.Stack.ImageAPI,
+ "OS_NETWORK_API_VERSION=" + host.Stack.NetworkAPI,
+ "OS_VOLUME_API_VERSION=" + host.Stack.VolumeAPI,
+ "OS_REGION_NAME=" + host.Stack.RegionName,
+ "OS_ENDPOINT_TYPE=" + host.Stack.EndpointType,
+ "OS_INTERFACE=" + host.Stack.Interface,
+ }
+ return cmd_fmt, cmd_env
+}
+
+func c_format_cmd(host *HostNode, opts HardOpts,
+ ui *HardUI) ([]string, []string) {
+ var cmd_fmt, cmd_env []string
var pass string
gpg, term := opts.GPG, opts.Term
@@ -158,7 +181,7 @@ func c_format_cmd(host *HostNode, opts HardOpts, ui *HardUI) []string {
if err != nil {
c_error_mode(host.Parent.path() + host.Filename +
": password decryption failed", err, ui)
- return nil
+ return nil, nil
}
pass = strings.TrimSuffix(pass, "\n")
}
@@ -167,6 +190,10 @@ func c_format_cmd(host *HostNode, opts HardOpts, ui *HardUI) []string {
cmd_fmt = c_format_ssh(host, pass)
case 1:
cmd_fmt = c_format_rdp(host, pass)
+ case 2:
+ cmd_fmt = []string{"/bin/sh", "-c", host.Host}
+ case 3:
+ cmd_fmt, cmd_env = c_format_openstack(host, pass)
default:
c_die("you fucked up joe, users cant see this", nil)
}
@@ -177,7 +204,7 @@ func c_format_cmd(host *HostNode, opts HardOpts, ui *HardUI) []string {
}
cmd_fmt = append([]string{"setsid", term, "-e"}, cmd_fmt...)
}
- return cmd_fmt
+ return cmd_fmt, cmd_env
}
func c_exec(host *HostNode, opts HardOpts, ui *HardUI) {
@@ -186,12 +213,12 @@ func c_exec(host *HostNode, opts HardOpts, ui *HardUI) {
if host == nil {
return
}
- cmd_fmt := c_format_cmd(host, opts, ui)
+ cmd_fmt, cmd_env := c_format_cmd(host, opts, ui)
if cmd_fmt == nil {
return
}
ui.s.Fini()
- c_exec_cmd(cmd_fmt)
+ c_exec_cmd(cmd_fmt, cmd_env)
if opts.Loop == false {
os.Exit(0)
} else {
diff --git a/src/c_lhosts.go b/src/c_lhosts.go
index 626e7b3..39800f6 100644
--- a/src/c_lhosts.go
+++ b/src/c_lhosts.go
@@ -51,6 +51,19 @@
package main
+
+type StackSettings struct {
+ UserDomainId string `yaml:"user_domain_id"`
+ ProjectId string `yaml:"project_id"`
+ IdentityAPI string `yaml:"identity_api_version"`
+ ImageAPI string `yaml:"image_api_version"`
+ NetworkAPI string `yaml:"network_api_version"`
+ VolumeAPI string `yaml:"volume_api_version"`
+ RegionName string `yaml:"region_name"`
+ EndpointType string `yaml:"endpoint_type"`
+ Interface string `yaml:"interface"`
+}
+
type JumpSettings struct {
Host string `yaml:"host"`
Port uint16 `yaml:"port"`
@@ -61,6 +74,8 @@ type JumpSettings struct {
// 0: ssh
// 1: rdp
+// 2: single cmd
+// 3: openstack
type HostNode struct {
Protocol int8 `yaml:"type"`
Name string `yaml:"name"`
@@ -77,6 +92,7 @@ type HostNode struct {
Dynamic bool `yaml:"dynamic"`
Note string `yaml:"note"`
Drive map[string]string `yaml:"drive"`
+ Stack StackSettings `yaml:"openstack"`
Filename string
Parent *DirsNode
next *HostNode
@@ -144,6 +160,8 @@ func (host *HostNode) protocol_str() string {
switch host.Protocol {
case 0: return "SSH"
case 1: return "RDP"
+ case 2: return "Single command"
+ case 3: return "OpenStack"
default: return ""
}
}
diff --git a/src/c_parse.go b/src/c_parse.go
index 3f71f99..4bb70dd 100644
--- a/src/c_parse.go
+++ b/src/c_parse.go
@@ -115,7 +115,7 @@ func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) {
if host.Height == 0 {
host.Height = 1200
}
- } else if host.Protocol > 1 {
+ } else if host.Protocol > 3 {
return nil, errors.New(file + ": unknown protocol")
}
if host.Quality > 2 {
diff --git a/src/i_info.go b/src/i_info.go
index b2fdc05..019ea69 100644
--- a/src/i_info.go
+++ b/src/i_info.go
@@ -89,12 +89,12 @@ func i_info_panel_dirs(ui HardUI, dir *DirsNode) {
ui.style[STYLE_DEF], dir.path()[1:])
}
-func i_info_panel_host(ui HardUI, host *HostNode) {
- host_type := host.protocol_str()
+func i_info_panel_name_type(ui HardUI, host *HostNode) int {
line := 2
if line > ui.dim[H] - 3 {
- return
+ return line
}
+ host_type := host.protocol_str()
// name, type
i_draw_text(ui.s,
(ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
@@ -103,7 +103,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.Name)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
i_draw_text(ui.s,
(ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
@@ -111,21 +111,34 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
i_draw_text(ui.s,
(ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host_type)
- if line += 2; line > ui.dim[H] - 3 {
- return
- }
+ return line + 2
+}
+
+func i_info_panel_host(ui HardUI, host *HostNode, line int) int {
if line > ui.dim[H] - 3 {
- return
+ return line
}
// host, port
- i_draw_text(ui.s,
- (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
- ui.style[STYLE_TITLE], "Host: ")
- i_draw_text(ui.s,
- (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
- ui.style[STYLE_DEF], host.Host)
- if line += 1; line > ui.dim[H] - 3 {
- return
+ if host.Protocol == 2 {
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
+ ui.style[STYLE_TITLE], "Command: ")
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 12, line, ui.dim[W] - 2, line,
+ ui.style[STYLE_DEF], host.Host)
+ if line += 1; line > ui.dim[H] - 3 {
+ return line
+ }
+ } else {
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
+ ui.style[STYLE_TITLE], "Host: ")
+ i_draw_text(ui.s,
+ (ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
+ ui.style[STYLE_DEF], host.Host)
+ }
+ if line += 1; line > ui.dim[H] - 3 || host.Protocol == 2 {
+ return line
}
i_draw_text(ui.s,
(ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
@@ -134,7 +147,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], strconv.Itoa(int(host.Port)))
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
// RDP shit
if host.Protocol == 1 {
@@ -146,12 +159,12 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 11, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.Domain)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
}
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
// user infos
i_draw_text(ui.s,
@@ -161,7 +174,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.User)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
if len(host.Pass) > 0 {
i_draw_text(ui.s,
@@ -171,7 +184,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], "***")
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
if host.Protocol == 0 && len(host.Priv) > 0 {
@@ -182,11 +195,11 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 12, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.Priv)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
// jump
if host.Protocol == 0 && len(host.Jump.Host) > 0 {
@@ -194,7 +207,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
ui.style[STYLE_TITLE], "Jump settings: ")
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
i_draw_text(ui.s,
(ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line,
@@ -203,7 +216,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.Jump.Host)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
i_draw_text(ui.s,
(ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line,
@@ -212,7 +225,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], strconv.Itoa(int(host.Jump.Port)))
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
i_draw_text(ui.s,
(ui.dim[W] / 3) + 4, line, ui.dim[W] - 2, line,
@@ -221,7 +234,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.Jump.User)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
if len(host.Jump.Pass) > 0 {
i_draw_text(ui.s,
@@ -231,7 +244,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 10, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], "***")
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
if host.Protocol == 0 && len(host.Jump.Priv) > 0 {
@@ -242,11 +255,11 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 13, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.Jump.Priv)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
// RDP shit
@@ -261,7 +274,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
strconv.Itoa(int(host.Width)) + "x" +
strconv.Itoa(int(host.Height)))
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
i_draw_text(ui.s,
(ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
@@ -270,7 +283,7 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 19, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], strconv.FormatBool(host.Dynamic))
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
i_draw_text(ui.s,
(ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
@@ -279,14 +292,14 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
(ui.dim[W] / 3) + 12, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], qual[host.Quality])
if line += 2; line > ui.dim[H] - 3 {
- return
+ return line
}
if host.Drive != nil {
i_draw_text(ui.s,
(ui.dim[W] / 3) + 3, line, ui.dim[W] - 2, line,
ui.style[STYLE_TITLE], "Drives: ")
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
for share, path := range host.Drive {
i_draw_text(ui.s,
@@ -297,14 +310,21 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
ui.dim[W] - 2, line,
ui.style[STYLE_DEF], path)
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
if line += 1; line > ui.dim[H] - 3 {
- return
+ return line
}
}
}
+ return line
+}
+
+func i_info_panel_note(ui HardUI, host *HostNode, line int) {
+ if line > ui.dim[H] - 3 {
+ return
+ }
// note
if len(host.Note) > 0 {
i_draw_text(ui.s,
@@ -313,9 +333,6 @@ func i_info_panel_host(ui HardUI, host *HostNode) {
i_draw_text(ui.s,
(ui.dim[W] / 3) + 9, line, ui.dim[W] - 2, line,
ui.style[STYLE_DEF], host.Note)
- if line += 1; line > ui.dim[H] - 3 {
- return
- }
}
}
@@ -360,6 +377,8 @@ func i_draw_info_panel(ui HardUI, percent bool, litems *ItemsList) {
} else if litems.curr.is_dir() == true {
i_info_panel_dirs(ui, litems.curr.Dirs)
} else {
- i_info_panel_host(ui, litems.curr.Host)
+ line := i_info_panel_name_type(ui, litems.curr.Host)
+ line = i_info_panel_host(ui, litems.curr.Host, line)
+ i_info_panel_note(ui, litems.curr.Host, line)
}
}