aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe <rbo@gmx.us>2024-04-09 20:20:20 +0200
committerJoe <rbo@gmx.us>2024-04-09 20:20:20 +0200
commit7b6a12ee62afca66f4f58f8789a9388d56944897 (patch)
tree1471c7c64776486dd6046225cf8de026a53c0061
parentmuch better roadmap (diff)
downloadhardflip-7b6a12ee62afca66f4f58f8789a9388d56944897.tar.gz
hardflip-7b6a12ee62afca66f4f58f8789a9388d56944897.tar.bz2
hardflip-7b6a12ee62afca66f4f58f8789a9388d56944897.tar.xz
hardflip-7b6a12ee62afca66f4f58f8789a9388d56944897.tar.zst
hardflip-7b6a12ee62afca66f4f58f8789a9388d56944897.zip
going good
Diffstat (limited to '')
-rw-r--r--src/c_exec.go2
-rw-r--r--src/c_init.go4
-rw-r--r--src/c_lhosts.go68
-rw-r--r--src/c_litems.go2
-rw-r--r--src/i_events.go30
-rw-r--r--src/i_host.go2
-rw-r--r--src/i_insert.go42
-rw-r--r--src/i_ui.go2
8 files changed, 97 insertions, 55 deletions
diff --git a/src/c_exec.go b/src/c_exec.go
index 8c7adfd..b5b6cf6 100644
--- a/src/c_exec.go
+++ b/src/c_exec.go
@@ -204,7 +204,7 @@ func c_format_cmd(host *HostNode, opts HardOpts,
var err error
pass, err = c_decrypt_str(host.Pass)
if err != nil {
- c_error_mode(host.Parent.path() + host.Filename +
+ c_error_mode(host.parent.path() + host.filename +
": password decryption failed", err, ui)
return nil, nil
}
diff --git a/src/c_init.go b/src/c_init.go
index 82c21b0..a24e3d4 100644
--- a/src/c_init.go
+++ b/src/c_init.go
@@ -97,8 +97,8 @@ func c_recurse_data_dir(dir, root string, opts HardOpts,
if err != nil {
*load_err = append(*load_err, err)
} else if host_node != nil {
- host_node.Filename = filename
- host_node.Parent = &dir_node
+ host_node.filename = filename
+ host_node.parent = &dir_node
if len(opts.GPG) == 0 {
host_node.Pass = ""
}
diff --git a/src/c_lhosts.go b/src/c_lhosts.go
index 009febf..6e69a79 100644
--- a/src/c_lhosts.go
+++ b/src/c_lhosts.go
@@ -53,23 +53,23 @@ 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"`
+ UserDomainID string `yaml:"user_domain_id,omitempty"`
+ ProjectID string `yaml:"project_id,omitempty"`
+ IdentityAPI string `yaml:"identity_api_version,omitempty"`
+ ImageAPI string `yaml:"image_api_version,omitempty"`
+ NetworkAPI string `yaml:"network_api_version,omitempty"`
+ VolumeAPI string `yaml:"volume_api_version,omitempty"`
+ RegionName string `yaml:"region_name,omitempty"`
+ EndpointType string `yaml:"endpoint_type,omitempty"`
+ Interface string `yaml:"interface,omitempty"`
}
type JumpSettings struct {
- Host string `yaml:"host"`
- Port uint16 `yaml:"port"`
- User string `yaml:"user"`
- Pass string `yaml:"pass"`
- Priv string `yaml:"priv"`
+ Host string `yaml:"host,omitempty"`
+ Port uint16 `yaml:"port,omitempty"`
+ User string `yaml:"user,omitempty"`
+ Pass string `yaml:"pass,omitempty"`
+ Priv string `yaml:"priv,omitempty"`
}
// 0: ssh
@@ -78,26 +78,26 @@ type JumpSettings struct {
// 3: openstack
type HostNode struct {
Protocol int8 `yaml:"type"`
- Name string `yaml:"name"`
- Host string `yaml:"host"`
- Port uint16 `yaml:"port"`
- User string `yaml:"user"`
- Pass string `yaml:"pass"`
- Priv string `yaml:"priv"`
- RDPFile string `yaml:"rdp_file"`
- Jump JumpSettings `yaml:"jump"`
- Quality uint8 `yaml:"quality"`
- Domain string `yaml:"domain"`
- Width uint16 `yaml:"width"`
- Height uint16 `yaml:"height"`
- Dynamic bool `yaml:"dynamic"`
- Note string `yaml:"note"`
- Drive map[string]string `yaml:"drive"`
- Silent bool `yaml:"silent"`
- Shell []string `yaml:"shell"`
- Stack StackSettings `yaml:"openstack"`
- Filename string
- Parent *DirsNode
+ Name string `yaml:"name,omitempty"`
+ Host string `yaml:"host,omitempty"`
+ Port uint16 `yaml:"port,omitempty"`
+ User string `yaml:"user,omitempty"`
+ Pass string `yaml:"pass,omitempty"`
+ Priv string `yaml:"priv,omitempty"`
+ RDPFile string `yaml:"rdp_file,omitempty"`
+ Jump JumpSettings `yaml:"jump,omitempty"`
+ Quality uint8 `yaml:"quality,omitempty"`
+ Domain string `yaml:"domain,omitempty"`
+ Width uint16 `yaml:"width,omitempty"`
+ Height uint16 `yaml:"height,omitempty"`
+ Dynamic bool `yaml:"dynamic,omitempty"`
+ Note string `yaml:"note,omitempty"`
+ Drive map[string]string `yaml:"drive,omitempty"`
+ Silent bool `yaml:"silent,omitempty"`
+ Shell []string `yaml:"shell,omitempty"`
+ Stack StackSettings `yaml:"openstack,omitempty"`
+ filename string
+ parent *DirsNode
next *HostNode
}
diff --git a/src/c_litems.go b/src/c_litems.go
index 67240c3..b71a008 100644
--- a/src/c_litems.go
+++ b/src/c_litems.go
@@ -224,7 +224,7 @@ func (item *ItemsNode) path_node() *DirsNode {
if item.is_dir() == true {
return item.Dirs
} else {
- return item.Host.Parent
+ return item.Host.parent
}
}
diff --git a/src/i_events.go b/src/i_events.go
index de0a99a..a82c953 100644
--- a/src/i_events.go
+++ b/src/i_events.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/i_events.go
- * Thu Mar 14 10:38:55 2024
+ * Tue Apr 09 14:34:02 2024
* Joe
*
* events in the code
@@ -174,8 +174,8 @@ func i_reload_data(data *HardData) {
tmp_name = data.litems.curr.Dirs.Name
tmp_parent_path = data.litems.curr.Dirs.Parent.path()
} else {
- tmp_name = data.litems.curr.Host.Filename
- tmp_parent_path = data.litems.curr.Host.Parent.path()
+ tmp_name = data.litems.curr.Host.filename
+ tmp_parent_path = data.litems.curr.Host.parent.path()
}
}
conf_dir := c_get_conf_dir(&data.load_err)
@@ -205,8 +205,8 @@ func i_reload_data(data *HardData) {
}
}
} else {
- if curr.Host.Filename == tmp_name {
- if curr.Host.Parent.path() == tmp_parent_path {
+ if curr.Host.filename == tmp_name {
+ if curr.Host.parent.path() == tmp_parent_path {
data.litems.curr = curr
return
}
@@ -263,14 +263,14 @@ func i_delete_host(data *HardData) error {
if host == nil {
return nil
}
- file_path := data.data_dir + host.Parent.path() + host.Filename
+ file_path := data.data_dir + host.parent.path() + host.filename
if err := os.Remove(file_path); err != nil {
c_error_mode("can't remove " + file_path, err, &data.ui)
return err
}
tmp := data.litems.curr.prev
- host.Parent.lhost.del(host)
+ host.parent.lhost.del(host)
data.litems.del(data.litems.curr)
if tmp == nil {
tmp = data.litems.head
@@ -321,7 +321,6 @@ func i_set_protocol_defaults(data *HardData, in *HostNode) {
switch in.Protocol {
case PROTOCOL_SSH:
in.Port = 22
- in.Jump.Port = 22
data.ui.insert_sel_max = 11
case PROTOCOL_RDP:
in.Port = 3389
@@ -543,7 +542,7 @@ func i_events(data *HardData) {
data.insert.Name = ui.buff
ui.buff = ""
if data.litems.curr != nil {
- data.insert.Parent = data.litems.curr.path_node()
+ data.insert.parent = data.litems.curr.path_node()
}
} else {
i_readline(event, data)
@@ -622,11 +621,11 @@ func i_events(data *HardData) {
break
} else {
name := data.insert.Name
- parent := data.insert.Parent
+ parent := data.insert.parent
data.insert = nil
data.insert = &HostNode{}
data.insert.Name = name
- data.insert.Parent = parent
+ data.insert.parent = parent
data.insert.Protocol = int8(event.Rune() - 48 - 1)
data.ui.insert_sel_ok = false
ui.s.HideCursor()
@@ -645,7 +644,13 @@ func i_events(data *HardData) {
data.opts.GPG)
data.insert.Pass = pass
case 5: data.insert.Priv = ui.buff
- case 6: data.insert.Jump.Host = ui.buff
+ case 6:
+ data.insert.Jump.Host = ui.buff
+ if len(ui.buff) > 0 {
+ data.insert.Jump.Port = 22
+ } else {
+ data.insert.Jump.Port = 0
+ }
case 7:
tmp, _ := strconv.Atoi(ui.buff)
data.insert.Jump.Port = uint16(tmp)
@@ -665,7 +670,6 @@ func i_events(data *HardData) {
}
}
}
- // TODO: reset data.insert to nil on validate
case MKDIR_MODE:
if event.Key() == tcell.KeyEscape ||
event.Key() == tcell.KeyCtrlC {
diff --git a/src/i_host.go b/src/i_host.go
index 76334e1..903f556 100644
--- a/src/i_host.go
+++ b/src/i_host.go
@@ -114,7 +114,7 @@ func i_draw_host_panel(ui HardUI, icons bool,
if ptr.is_dir() == false && ptr.Host != nil {
i_host_panel_host(ui,
icons,
- ptr.Host.Parent.Depth,
+ ptr.Host.parent.Depth,
ptr.Host,
litems.curr.Host,
line)
diff --git a/src/i_insert.go b/src/i_insert.go
index f57c458..ea1310d 100644
--- a/src/i_insert.go
+++ b/src/i_insert.go
@@ -43,7 +43,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* hardflip: src/i_insert.go
- * Fri Apr 05 14:19:38 2024
+ * Tue Apr 09 14:56:56 2024
* Joe
*
* insert a new host
@@ -53,14 +53,48 @@ package main
import (
"errors"
+ "fmt"
"os"
"strconv"
+ "strings"
"github.com/gdamore/tcell/v2"
+ "gopkg.in/yaml.v3"
)
+func i_insert_format_filename(name, path string) string {
+ str := name
+
+ if len(name) == 0 {
+ return ""
+ }
+ str = strings.ToLower(str) + ".yml"
+ return str
+}
+
func i_insert_host(data *HardData, insert *HostNode) {
- tmp_next := data.litems.curr.next
+ data.ui.s.Fini()
+ fmt.Println(i_insert_format_filename(insert.Name,
+ data.data_dir + insert.parent.path()))
+ fmt.Println(data.data_dir + insert.parent.path())
+ os.Exit(0)
+ _, err := yaml.Marshal(insert)
+ if err != nil {
+ return
+ }
+ // err = os.WriteFile(i_insert_format_filename(insert.Name))
+ item := &ItemsNode{
+ data.litems.curr.ID + 1,
+ nil,
+ insert,
+ data.litems.curr,
+ data.litems.curr.next,
+ }
+ data.litems.curr.next = item
+ data.litems.reset_id()
+ data.litems.curr = data.litems.curr.next
+ data.ui.mode = NORMAL_MODE
+ data.insert = nil
}
func i_insert_check_ok(data *HardData, insert *HostNode) {
@@ -73,6 +107,10 @@ func i_insert_check_ok(data *HardData, insert *HostNode) {
if insert.Port == 0 {
data.insert_err = append(data.insert_err, errors.New("port can't be 0"))
}
+ if len(insert.Jump.Host) > 0 && insert.Jump.Port == 0 {
+ data.insert_err = append(data.insert_err,
+ errors.New("jump port can't be 0"))
+ }
if insert.Protocol == PROTOCOL_SSH && len(insert.Priv) != 0 {
file := insert.Priv
if file[0] == '~' {
diff --git a/src/i_ui.go b/src/i_ui.go
index 7500b9f..37e1912 100644
--- a/src/i_ui.go
+++ b/src/i_ui.go
@@ -440,7 +440,7 @@ func i_draw_delete_msg(ui HardUI, item *ItemsNode) {
text = "Really delete this directory and all of its content?"
} else {
text = "Really delete this host?"
- file += item.Host.Filename
+ file += item.Host.filename
}
file = file[1:]
i_draw_msg(ui.s, 2, ui.style[BOX_STYLE], ui.dim, " Delete ")