aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--c_init.go3
-rw-r--r--c_lhosts.go8
-rw-r--r--c_parse.go14
-rw-r--r--go.mod2
-rw-r--r--i_ui.go131
5 files changed, 112 insertions, 46 deletions
diff --git a/c_init.go b/c_init.go
index e06084b..5454928 100644
--- a/c_init.go
+++ b/c_init.go
@@ -49,7 +49,6 @@ package main
import (
"fmt"
- "io/ioutil"
"os"
"path/filepath"
)
@@ -85,7 +84,7 @@ func c_get_data_dir() string {
// this function recurses into the specified root directory in order to load
// every yaml file into memory
func c_recurse_data_dir(dir string, root string, lhost *HostList) {
- files, err := ioutil.ReadDir(root + dir)
+ files, err := os.ReadDir(root + dir)
if err != nil {
c_die("could not read data directory", err)
}
diff --git a/c_lhosts.go b/c_lhosts.go
index d98305c..c556fd5 100644
--- a/c_lhosts.go
+++ b/c_lhosts.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/c_lhosts.go
- * Fri, 15 Dec 2023 17:26:58 +0100
+ * Tue, 19 Dec 2023 11:32:56 +0100
* Joe
*
* the hosts linked list
@@ -63,10 +63,14 @@ type HostNode struct {
JumpUser string `yaml:"jump_user"`
JumpPass string `yaml:"jump_pass"`
JumpPriv string `yaml:"jump_priv"`
+ Quality string `yaml:"quality"`
+ Domain string `yaml:"domain"`
+ Width uint16 `yaml:"width"`
+ Height uint16 `yaml:"height"`
Note string `yaml:"note"`
Filename string
Folder string
- next *HostNode
+ next *HostNode
}
type HostList struct {
diff --git a/c_parse.go b/c_parse.go
index 43a270c..b341f7e 100644
--- a/c_parse.go
+++ b/c_parse.go
@@ -48,13 +48,13 @@
package main
import (
- "io/ioutil"
+ "os"
"gopkg.in/yaml.v3"
)
func c_read_yaml_file(file string) *HostNode {
var host HostNode
- yaml_file, err := ioutil.ReadFile(file)
+ yaml_file, err := os.ReadFile(file)
if err != nil {
c_die("error reading file " + file, err)
@@ -75,12 +75,20 @@ func c_read_yaml_file(file string) *HostNode {
if len(host.User) == 0 {
host.User = "root"
}
+ if len(host.Jump) > 0 {
+ if host.JumpPort == 0 {
+ host.JumpPort = 22
+ }
+ if len(host.JumpUser) == 0 {
+ host.JumpUser = "root"
+ }
+ }
} else if host.Type == 1 {
if host.Port == 0 {
host.Port = 3389
}
} else if host.Type > 1 {
- host_type = "Unknown"
+ return nil
}
return &host
}
diff --git a/go.mod b/go.mod
index a68dd53..bdddbdc 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
module hf
-go 1.18
+go 1.21.5
require (
github.com/gdamore/tcell/v2 v2.7.0
diff --git a/i_ui.go b/i_ui.go
index 407f269..a1f60e8 100644
--- a/i_ui.go
+++ b/i_ui.go
@@ -123,20 +123,28 @@ func i_hosts_panel(s tcell.Screen,
}
spaces := ""
i := 0
- for i < (term_w / 3) - len(host.Folder + host.Name) - 3 {
+ for i < (term_w / 3) - len(host.Folder + host.Name) - 2 {
spaces += " "
i++
}
+ if host.Type == 0 {
+ i_draw_text(s,
+ 1, int(host.ID) + 1, term_w / 3, int(host.ID) + 1,
+ style, "  " + host.Folder + host.Name + spaces)
+ } else if host.Type == 1 {
+ i_draw_text(s,
+ 1, int(host.ID) + 1, term_w / 3, int(host.ID) + 1,
+ style, "  " + host.Folder + host.Name + spaces)
+ }
i_draw_text(s,
- 1, int(host.ID) + 1, term_w / 3 - 1, int(host.ID) + 1,
- style, " " + host.Folder + host.Name + spaces)
+ 4, int(host.ID) + 1, term_w / 3, int(host.ID) + 1,
+ style, host.Folder + host.Name + spaces)
host = host.next
}
i_draw_text(s,
1, term_h - 2, (term_w / 3) - 1, term_h - 1,
def_style, " " + strconv.Itoa(int(sel_max)) + " hosts ")
}
-
func i_info_panel(s tcell.Screen,
term_w, term_h int,
def_style tcell.Style, lhost *HostList, sel uint64) {
@@ -147,7 +155,6 @@ func i_info_panel(s tcell.Screen,
curr_line := 2
var host_type string
var pass string
- var port int
i_draw_box(s, (term_w / 3) + 1, 0,
term_w - 1, term_h - 2,
@@ -156,8 +163,6 @@ func i_info_panel(s tcell.Screen,
host_type = "SSH"
} else if host.Type == 1 {
host_type = "RDP"
- } else if host.Type > 1 {
- host_type = "Unknown"
}
if len(host.Pass) > 0 {
pass = "***"
@@ -189,7 +194,7 @@ func i_info_panel(s tcell.Screen,
title_style, "Port: ")
i_draw_text(s,
(term_w / 3) + 10, curr_line, term_w - 2, curr_line,
- def_style, strconv.Itoa(port))
+ def_style, strconv.Itoa(int(host.Port)))
curr_line += 2
i_draw_text(s,
(term_w / 3) + 4, curr_line, term_w - 2, curr_line,
@@ -205,6 +210,85 @@ func i_info_panel(s tcell.Screen,
(term_w / 3) + 10, curr_line, term_w - 2, curr_line,
def_style, pass)
curr_line += 1
+ if host.Type == 0 && len(host.Priv) > 0 {
+ i_draw_text(s,
+ (term_w / 3) + 4, curr_line, term_w - 2, curr_line,
+ title_style, "Privkey: ")
+ i_draw_text(s,
+ (term_w / 3) + 13, curr_line, term_w - 2, curr_line,
+ def_style, host.Priv)
+ curr_line += 1
+ }
+ curr_line += 1
+ if host.Type == 0 && len(host.Jump) > 0 {
+ i_draw_text(s,
+ (term_w / 3) + 4, curr_line, term_w - 2, curr_line,
+ title_style, "Jump settings: ")
+ curr_line += 1
+ i_draw_text(s,
+ (term_w / 3) + 6, curr_line, term_w - 2, curr_line,
+ title_style, "Jump host: ")
+ i_draw_text(s,
+ (term_w / 3) + 17, curr_line, term_w - 2, curr_line,
+ def_style, host.Jump)
+ curr_line += 1
+ i_draw_text(s,
+ (term_w / 3) + 6, curr_line, term_w - 2, curr_line,
+ title_style, "Jump port: ")
+ i_draw_text(s,
+ (term_w / 3) + 17, curr_line, term_w - 2, curr_line,
+ def_style, strconv.Itoa(int(host.JumpPort)))
+ curr_line += 1
+ i_draw_text(s,
+ (term_w / 3) + 6, curr_line, term_w - 2, curr_line,
+ title_style, "Jump user: ")
+ i_draw_text(s,
+ (term_w / 3) + 17, curr_line, term_w - 2, curr_line,
+ def_style, host.JumpUser)
+ curr_line += 2
+ }
+ i_draw_text(s,
+ (term_w / 3) + 4, curr_line, term_w - 2, curr_line,
+ title_style, "Note: ")
+ i_draw_text(s,
+ (term_w / 3) + 10, curr_line, term_w - 2, curr_line,
+ def_style, host.Note)
+ curr_line += 1
+}
+
+func i_events(s tcell.Screen,
+ sel *uint64, sel_max *uint64,
+ lhost *HostList, quit func()) {
+ event := s.PollEvent()
+ switch event := event.(type) {
+ case *tcell.EventResize:
+ s.Sync()
+ case *tcell.EventKey:
+ if event.Key() == tcell.KeyEscape ||
+ event.Key() == tcell.KeyCtrlC ||
+ event.Rune() == 'q' ||
+ event.Rune() == 'Q' {
+ quit()
+ os.Exit(0)
+ }
+ if event.Rune() == 'j' ||
+ event.Key() == tcell.KeyDown {
+ if *sel < *sel_max - 1 {
+ *sel += 1
+ }
+ }
+ if event.Rune() == 'k' ||
+ event.Key() == tcell.KeyUp {
+ if *sel > 0 {
+ *sel -= 1
+ }
+ }
+ if event.Key() == tcell.KeyEnter {
+ quit()
+ c_exec(*sel, lhost)
+ os.Exit(0)
+ }
+ }
}
func i_ui(lhost *HostList) {
@@ -232,35 +316,6 @@ func i_ui(lhost *HostList) {
i_hosts_panel(screen, term_w, term_h, def_style, lhost, sel, sel_max)
i_info_panel(screen, term_w, term_h, def_style, lhost, sel)
screen.Show()
- event := screen.PollEvent()
- switch event := event.(type) {
- case *tcell.EventResize:
- screen.Sync()
- case *tcell.EventKey:
- if event.Key() == tcell.KeyEscape ||
- event.Key() == tcell.KeyCtrlC ||
- event.Rune() == 'q' ||
- event.Rune() == 'Q' {
- quit()
- os.Exit(0)
- }
- if event.Rune() == 'j' ||
- event.Key() == tcell.KeyDown {
- if sel < sel_max - 1 {
- sel += 1
- }
- }
- if event.Rune() == 'k' ||
- event.Key() == tcell.KeyUp {
- if sel > 0 {
- sel -= 1
- }
- }
- if event.Key() == tcell.KeyEnter {
- quit()
- c_exec(sel, lhost)
- os.Exit(0)
- }
- }
+ i_events(screen, &sel, &sel_max, lhost, quit)
}
}