go_tab-magic/pkg/shell/shell.go

65 lines
1.8 KiB
Go
Raw Normal View History

2018-11-30 20:20:43 +00:00
package shell
import (
"fmt"
"strings"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config"
)
func CreateShellAliases(data []string, username string, config config.Config) {
for _, i := range data {
splitStrings := strings.Split(i, " ")
hostname := splitStrings[0]
txt := splitStrings[2]
jump := config.JumpHost
stringSplit := config.SplitString
remoteUser := username
sudo := "sudo su -"
rac := "ssh"
racOpts := "-AXt -l"
hop := "ssh -AXt"
prerac := ""
2018-12-04 03:17:07 +00:00
windowsGeometry := config.WindowsGeometry
2018-11-30 20:20:43 +00:00
host := strings.TrimRight(hostname, stringSplit)
2018-11-30 20:24:42 +00:00
fqdn := hostname
2018-11-30 20:20:43 +00:00
greentext := "tput -T xterm setaf 2; "
2018-12-04 03:17:07 +00:00
redtext := "tput -T xterm setaf 1; "
2018-11-30 20:20:43 +00:00
resettext := "tput -T xterm sgr0; "
message := fmt.Sprintf("%vecho \"Authenticating as: %v\";%v", greentext, remoteUser, resettext)
2018-12-04 03:17:07 +00:00
// TXT Record Parsing
2018-12-04 19:41:32 +00:00
txtSplit := strings.Split(txt, ";")
for _, i := range txtSplit {
if strings.Contains(i, "SSH_PORT") {
port := strings.TrimLeft(i, "SSH_PORT=")
2018-12-04 20:06:22 +00:00
racOpts = fmt.Sprintf("-AXt -p %v -l", port)
2018-12-04 19:41:32 +00:00
} else if strings.Contains(i, "OS_FAMILY") {
osFamily := strings.Split(i, "=")
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 = ""
}
2018-12-04 20:03:05 +00:00
} else if strings.Contains(i, "REMOTE_USER") {
user := strings.TrimLeft(i, "REMOTE_USER=")
remoteUser = user
2018-12-04 03:17:07 +00:00
}
2018-11-30 20:20:43 +00:00
}
2018-12-04 03:17:07 +00:00
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)
2018-11-30 20:20:43 +00:00
}
}