diff options
Diffstat (limited to '')
-rw-r--r-- | c_init.go | 33 | ||||
-rw-r--r-- | c_josh.go | 16 | ||||
-rw-r--r-- | c_lhosts.go | 99 | ||||
-rw-r--r-- | c_parse.go | 74 | ||||
-rw-r--r-- | c_utils.go | 6 |
5 files changed, 183 insertions, 45 deletions
@@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * josh: src/c_init.go - * Thu, 14 Dec 2023 19:21:22 +0100 + * Fri, 15 Dec 2023 11:43:39 +0100 * Joe * * init functions @@ -52,12 +52,12 @@ import ( "io/ioutil" "os" "path/filepath" - "gopkg.in/yaml.v3" ) -// This function will go get the data folder and try to create it if it does -// not exist. The first path being checked is $XDG_DATA_HOME then -// $HOME/.local/share. It returns the full data directory path. +// this function will go get the data folder and try to create it if it does +// not exist +// the first path being checked is $XDG_DATA_HOME then $HOME/.local/share +// it returns the full data directory path func c_get_data_dir() string { var ptr *string var home string @@ -82,27 +82,8 @@ func c_get_data_dir() string { return *ptr } -func c_read_yaml_file(file string) { - var host host - yaml_file, err := ioutil.ReadFile(file) - - if err != nil { - c_die("error reading file " + file, err) - } - if err = yaml.Unmarshal(yaml_file, &host); err != nil { - c_die("error reading yaml file " + file, err) - } - if len(host.User) == 0 { - host.User = "root" - } - if host.Port == 0 { - host.Port = 22 - } - fmt.Println(host) -} - -// This function recurses into the specified root directory in order to load -// every yaml file into memory. +// 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) { files, err := ioutil.ReadDir(root + dir) if err != nil { @@ -47,22 +47,6 @@ package main -import ( -) - -// 0: ssh -// 1: rdp -type host struct { - ID int64 - Type int8 `yaml:"type"` - Host string `yaml:"host"` - Port uint16 `yaml:"port"` - User string `yaml:"user"` - Pass string `yaml:"pass"` - Jump string `yaml:"jump"` - Priv string `yaml:"priv"` -} - func main() { var data_dir string diff --git a/c_lhosts.go b/c_lhosts.go new file mode 100644 index 0000000..d2cb992 --- /dev/null +++ b/c_lhosts.go @@ -0,0 +1,99 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2023 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * josh: src/c_lhosts.go + * Fri, 15 Dec 2023 10:01:11 +0100 + * Joe + * + * the hosts linked list + */ + +package main + +// 0: ssh +// 1: rdp +type HostNode struct { + ID uint64 + Type int8 `yaml:"type"` + Host string `yaml:"host"` + Port uint16 `yaml:"port"` + User string `yaml:"user"` + Pass string `yaml:"pass"` + Jump string `yaml:"jump"` + Priv string `yaml:"priv"` + next *HostNode +} + +type HostList struct { + head *HostNode +} + +// adds a host node to the list +func (lhost *HostList) add_back(node *HostNode) { + new_node := node + + if lhost.head == nil { + lhost.head = new_node + return + } + curr := lhost.head + for curr.next != nil { + curr = curr.next + } + curr.next = new_node +} + +// removes a host node from the list +func (lhost *HostList) remove(id uint64) { + if lhost.head == nil { + return + } + if lhost.head.ID == id { + lhost.head = lhost.head.next + return + } + curr := lhost.head + for curr.next != nil && curr.next.ID != id { + curr = curr.next + } + if curr.next != nil { + curr.next = curr.next.next + } +} diff --git a/c_parse.go b/c_parse.go new file mode 100644 index 0000000..eef9ee1 --- /dev/null +++ b/c_parse.go @@ -0,0 +1,74 @@ +/* + * ======================== + * ===== =============== + * ====== ================ + * ====== ================ + * ====== ==== ==== == + * ====== === == = = + * ====== === = == = + * = === === = == ==== + * = === === = == = = + * == ===== ==== == + * ======================== + * + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2023 Joe + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOE ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL JOE BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * josh: src/c_parse.go + * Fri, 15 Dec 2023 10:02:29 +0100 + * Joe + * + * parsing of the global data + */ + +package main + +import ( + "fmt" + "io/ioutil" + "gopkg.in/yaml.v3" +) + +func c_read_yaml_file(file string) *HostNode { + var host HostNode + yaml_file, err := ioutil.ReadFile(file) + + if err != nil { + c_die("error reading file " + file, err) + } + if err = yaml.Unmarshal(yaml_file, &host); err != nil { + c_die("error reading yaml file " + file, err) + } + if len(host.User) == 0 { + host.User = "root" + } + if host.Port == 0 { + host.Port = 22 + } + fmt.Println(host) + return &host +} @@ -53,9 +53,9 @@ import ( ) // c_die displays an error string to the stderr fd and exits the program -// with the return code 1. -// It takes an optional err argument of the error type as a complement of -// information. +// with the return code 1 +// it takes an optional err argument of the error type as a complement of +// information func c_die(str string, err error) { fmt.Fprintf(os.Stderr, "error: %s", str) if err != nil { |