2018-11-30 20:20:43 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2019-01-14 18:43:20 +00:00
|
|
|
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/utils"
|
|
|
|
|
2018-11-30 20:20:43 +00:00
|
|
|
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config"
|
|
|
|
)
|
|
|
|
|
2019-01-14 18:31:46 +00:00
|
|
|
// CreateShellAliases will create shell aliases and fmt.Println them
|
2019-01-14 18:39:13 +00:00
|
|
|
func CreateShellAliases(data []string, username string, config config.Config, debug bool) {
|
|
|
|
if debug {
|
|
|
|
defer utils.LogElapsedTime("Create Shell Aliases")
|
|
|
|
}
|
2018-11-30 20:20:43 +00:00
|
|
|
for _, i := range data {
|
|
|
|
splitStrings := strings.Split(i, " ")
|
|
|
|
hostname := splitStrings[0]
|
|
|
|
txt := splitStrings[2]
|
|
|
|
|
2018-12-05 23:07:17 +00:00
|
|
|
useJump := config.UseJump
|
|
|
|
|
2018-11-30 20:20:43 +00:00
|
|
|
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
|
|
|
|
2019-01-14 15:28:19 +00:00
|
|
|
host := strings.TrimSuffix(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") {
|
2019-01-14 18:31:46 +00:00
|
|
|
port := strings.TrimPrefix(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"
|
2018-12-04 20:32:02 +00:00
|
|
|
} else if osFamily[1] == "Ubiquiti" {
|
|
|
|
sudo = ""
|
2018-12-04 19:41:32 +00:00
|
|
|
} 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") {
|
2019-01-14 18:31:46 +00:00
|
|
|
user := strings.TrimPrefix(i, "REMOTE_USER=")
|
2018-12-04 20:03:05 +00:00
|
|
|
remoteUser = user
|
2018-12-04 03:17:07 +00:00
|
|
|
}
|
2018-11-30 20:20:43 +00:00
|
|
|
}
|
2019-01-14 18:39:13 +00:00
|
|
|
if debug {
|
|
|
|
fmt.Println("Disabled Output due to Debug Mode")
|
|
|
|
} else if useJump {
|
2018-12-05 23:07:17 +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)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("alias %v=\\'%v %v %v %v %v %v\n", host, message, rac, racOpts, remoteUser, fqdn, sudo)
|
|
|
|
}
|
2018-11-30 20:20:43 +00:00
|
|
|
}
|
|
|
|
}
|