diff --git a/README.md b/README.md new file mode 100644 index 0000000..0afe517 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# Tab Magic + +Tab Magic is a shell-alias building tool for *NIX operating systems. + +It utilizes doing a DNS zone-transfer and building bash aliases based on A, CNAME, and TXT records. + +You will need to create a config.json with your information in it: + +```json +{ + "resolver": "172.19.0.5", + "resolverPort": 53, + "domains": [ "kc.linuxrocker.com"], + "jumpHost": "jump01.kc.linuxrocker.com", + "splitString": ".linuxrocker", + "windowsGeometry": "1600x900" +} +``` + +For Tab_Magic to do proper host detection, The following TXT record options are available: + +* SSH_PORT - SSH Port will allow you to specify a custom SSH Port for the remote host. Valid: 1-65536 +* OS_FAMILY - Can be either "ESXi", "Ubiquiti", or "Windows". If ESXi, it will log in as root with no sudo opts. If Ubiquiti, it will not use sudo. If Windows, it will use the rdesktop command line tool. +* REMOTE_USER - This is not implemented yet, but you will be able to specify a custom username for the remote host. \ No newline at end of file diff --git a/config.json b/config.json index fff3e74..6d5f5a2 100644 --- a/config.json +++ b/config.json @@ -3,5 +3,6 @@ "resolverPort": 53, "domains": [ "kc.linuxrocker.com"], "jumpHost": "jump01.kc.linuxrocker.com", - "splitString": ".linuxrocker" + "splitString": ".linuxrocker", + "windowsGeometry": "1600x900" } \ No newline at end of file diff --git a/pkg/config/config.go b/pkg/config/config.go index 852fb82..44e5f00 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -9,11 +9,12 @@ import ( // Config - This struct will hold configuration components. type Config struct { - Resolver string `json:"resolver"` - ResolverPort int `json:"resolverPort"` - Domains []string `json:"domains"` - JumpHost string `json:"jumpHost"` - SplitString string `json:"splitString"` + Resolver string `json:"resolver"` + ResolverPort int `json:"resolverPort"` + Domains []string `json:"domains"` + JumpHost string `json:"jumpHost"` + SplitString string `json:"splitString"` + WindowsGeometry string `json:"windowsGeometry"` } //GetConfig gets the configuration values for the api using the file in the supplied configPath. diff --git a/pkg/shell/shell.go b/pkg/shell/shell.go index 5feef40..de02913 100644 --- a/pkg/shell/shell.go +++ b/pkg/shell/shell.go @@ -22,19 +22,35 @@ func CreateShellAliases(data []string, username string, config config.Config) { racOpts := "-AXt -l" hop := "ssh -AXt" prerac := "" + windowsGeometry := config.WindowsGeometry host := strings.TrimRight(hostname, stringSplit) fqdn := hostname greentext := "tput -T xterm setaf 2; " - // redtext := "tput -T xterm setaf 1; " + redtext := "tput -T xterm setaf 1; " resettext := "tput -T xterm sgr0; " message := fmt.Sprintf("%vecho \"Authenticating as: %v\";%v", greentext, remoteUser, resettext) - if txt == "" { - fmt.Printf("alias %v=\\'%v%v%v %v@%v \"%v %v %v %v %v\"'\n", host, message, prerac, hop, username, jump, rac, racOpts, remoteUser, fqdn, sudo) - } else { - fmt.Printf("alias %v=\\'%v%v%v %v@%v \"%v %v %v %v %v\"'\n", host, message, prerac, hop, username, jump, rac, racOpts, remoteUser, fqdn, sudo) + // TXT Record Parsing + if strings.Contains(txt, "SSH_PORT") { + port := strings.TrimLeft(txt, "SSH_PORT=") + racOpts = fmt.Sprintf("ssh -AXt -p %v -l", port) + } else if strings.Contains(txt, "OS_FAMILY") { + osFamily := strings.Split(txt, "=") + if osFamily[1] == "ESXi" { + sudo = "" + remoteUser = "root" + } else if osFamily[1] == "Windows" { + prerac = fmt.Sprintf("%vecho \"Password: \"; %v", redtext, resettext) + hop = "ssh -XCAT" + rac = "rdesktop" + windowsDomain := "" + racOpts = fmt.Sprintf("-r clipboard:CLIPBOARD -a 16 -k en-us -g %v -p - %v -u", windowsGeometry, windowsDomain) + sudo = "" + } } + + fmt.Printf("alias %v=\\'%v%v%v %v@%v \"%v %v %v %v %v\"'\n", host, message, prerac, hop, username, jump, rac, racOpts, remoteUser, fqdn, sudo) } }