diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/c_defs.go | 44 | ||||
-rw-r--r-- | src/c_exec.go | 18 | ||||
-rw-r--r-- | src/c_init.go | 2 | ||||
-rw-r--r-- | src/c_parse.go | 8 | ||||
-rw-r--r-- | src/i_insert.go | 29 |
5 files changed, 65 insertions, 36 deletions
diff --git a/src/c_defs.go b/src/c_defs.go index cc4c264..81b192b 100644 --- a/src/c_defs.go +++ b/src/c_defs.go @@ -71,31 +71,41 @@ m: mkdir - ) const ( - NORMAL_MODE = 0 - DELETE_MODE = 1 - LOAD_MODE = 2 - ERROR_MODE = 3 - WELCOME_MODE = 4 - MKDIR_MODE = 5 - INSERT_MODE = 6 + NORMAL_MODE = iota + DELETE_MODE + LOAD_MODE + ERROR_MODE + WELCOME_MODE + MKDIR_MODE + INSERT_MODE +) + +const ( + W = 0 + H = 1 ) const ( - W = 0 - H = 1 ERROR_MSG = 0 ERROR_ERR = 1 - DEF_STYLE = 0 - DIR_STYLE = 1 - BOX_STYLE = 2 - HEAD_STYLE = 3 - ERR_STYLE = 4 - TITLE_STYLE = 5 - BOT_STYLE = 6 ) const ( - PROTOCOL_MAX = 3 + DEF_STYLE = iota + DIR_STYLE + BOX_STYLE + HEAD_STYLE + ERR_STYLE + TITLE_STYLE + BOT_STYLE +) + +const ( + PROTOCOL_SSH = iota + PROTOCOL_RDP + PROTOCOL_CMD + PROTOCOL_OS + PROTOCOL_MAX = PROTOCOL_OS ) var ( diff --git a/src/c_exec.go b/src/c_exec.go index 9e96188..8c7adfd 100644 --- a/src/c_exec.go +++ b/src/c_exec.go @@ -168,14 +168,14 @@ func c_format_openstack(host *HostNode, pass string) ([]string, []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_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 @@ -236,7 +236,7 @@ func c_exec(host *HostNode, opts HardOpts, ui *HardUI) { return } silent := false - if host.Protocol == 2 { + if host.Protocol == PROTOCOL_CMD { silent = host.Silent } if silent == false { diff --git a/src/c_init.go b/src/c_init.go index 57f8b19..82c21b0 100644 --- a/src/c_init.go +++ b/src/c_init.go @@ -93,7 +93,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, ui) + host_node, err := c_read_yaml_file(root + dir + filename) if err != nil { *load_err = append(*load_err, err) } else if host_node != nil { diff --git a/src/c_parse.go b/src/c_parse.go index 5375874..ce7803e 100644 --- a/src/c_parse.go +++ b/src/c_parse.go @@ -70,7 +70,7 @@ func c_parse_opts(file string) (HardOpts, error) { return opts, err } -func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) { +func c_read_yaml_file(file string) (*HostNode, error) { var host HostNode yaml_file, err := os.ReadFile(file) @@ -92,7 +92,7 @@ func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) { return nil, nil } } - if host.Protocol == 0 { + if host.Protocol == PROTOCOL_SSH { if host.Port == 0 { host.Port = 22 } @@ -107,7 +107,7 @@ func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) { host.Jump.User = "root" } } - } else if host.Protocol == 1 { + } else if host.Protocol == PROTOCOL_RDP { if len(host.User) == 0 { host.User = "Administrator" } @@ -120,7 +120,7 @@ func c_read_yaml_file(file string, ui *HardUI) (*HostNode, error) { if host.Height == 0 { host.Height = 1200 } - } else if host.Protocol == 2 { + } else if host.Protocol == PROTOCOL_CMD { if len(host.Shell) == 0 { host.Shell = []string{"/bin/sh", "-c"} } diff --git a/src/i_insert.go b/src/i_insert.go index d35a1c2..8c91640 100644 --- a/src/i_insert.go +++ b/src/i_insert.go @@ -43,7 +43,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/i_insert.go - * Wed Mar 27 16:43:21 2024 + * Fri Mar 29 12:15:41 2024 * Joe * * insert a new host @@ -61,12 +61,31 @@ import ( func i_insert_check_ok(data *HardData, insert *HostNode) { if len(insert.Name) == 0 { - data.insert_err = append(data.insert_err, - errors.New("no name")) + data.insert_err = append(data.insert_err, errors.New("no name")) } if len(insert.Host) == 0 { - data.insert_err = append(data.insert_err, - errors.New("no host")) + data.insert_err = append(data.insert_err, errors.New("no host")) + } + if insert.Port == 0 { + data.insert_err = append(data.insert_err, errors.New("port can't be 0")) + } + if insert.Protocol == PROTOCOL_SSH && len(insert.Priv) != 0 { + file := insert.Priv + if file[0] == '~' { + home_dir, err := os.UserHomeDir() + if err != nil { + return + } + file = home_dir + file[1:] + } + if stat, err := os.Stat(file); + err != nil { + data.insert_err = append(data.insert_err, errors.New(file + + ": file does not exist")) + } else if stat.IsDir() == true { + data.insert_err = append(data.insert_err, errors.New(file + + ": file is a directory")) + } } // TODO: here } |