Adding things.

This commit is contained in:
Matt Burchett 2018-11-30 14:20:43 -06:00
parent 6702518916
commit 0b5df4f058
5 changed files with 60 additions and 5 deletions

View File

@ -6,13 +6,16 @@ import (
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config" "git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/resolver" "git.linuxrocker.com/mattburchett/go_tab-magic/pkg/resolver"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/shell"
) )
func main() { func main() {
var c string var c string
var user string
var debug bool var debug bool
flag.StringVar(&c, "config", "", "Configuration to load") flag.StringVar(&c, "config", "", "Configuration to load")
flag.StringVar(&user, "user", "", "user for aliases")
flag.BoolVar(&debug, "debug", false, "Enables Debugging Mode") flag.BoolVar(&debug, "debug", false, "Enables Debugging Mode")
flag.Parse() flag.Parse()
@ -21,10 +24,15 @@ func main() {
log.Fatal("You need to specify a configuration file.") log.Fatal("You need to specify a configuration file.")
} }
if user == "" {
log.Fatal("Username is not specified.")
}
cfg, err := config.GetConfig(c, debug) cfg, err := config.GetConfig(c, debug)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
resolver.PerformZoneTransfer(cfg) data := resolver.PerformZoneTransfer(cfg)
shell.CreateShellAliases(data, user, cfg)
} }

View File

@ -1,5 +1,7 @@
{ {
"resolver": "172.19.0.5", "resolver": "172.19.0.5",
"resolverPort": 53, "resolverPort": 53,
"domains": [ "kc.linuxrocker.com"] "domains": [ "kc.linuxrocker.com"],
"jumpHost": "jump01.kc.linuxrocker.com",
"splitString": ".linuxrocker"
} }

View File

@ -12,6 +12,8 @@ type Config struct {
Resolver string `json:"resolver"` Resolver string `json:"resolver"`
ResolverPort int `json:"resolverPort"` ResolverPort int `json:"resolverPort"`
Domains []string `json:"domains"` Domains []string `json:"domains"`
JumpHost string `json:"jumpHost"`
SplitString string `json:"splitString"`
} }
//GetConfig gets the configuration values for the api using the file in the supplied configPath. //GetConfig gets the configuration values for the api using the file in the supplied configPath.

View File

@ -30,7 +30,7 @@ func lookupName(fqdn, serverAddr string) (string, error) {
return "", errors.New("no A record returned") return "", errors.New("no A record returned")
} }
func PerformZoneTransfer(config config.Config) { func PerformZoneTransfer(config config.Config) []string {
data := make([]string, 0) data := make([]string, 0)
// Do the transfer // Do the transfer
@ -73,10 +73,13 @@ func PerformZoneTransfer(config config.Config) {
} }
} }
fmt.Println(data) fmt.Println(data)
resultsToJSON(data) // resultsToJSON(data)
return data
} }
func resultsToJSON(data []string) { func resultsToJSON(data []string) {
jsonData := make([][]byte, 0)
for _, i := range data { for _, i := range data {
splitStrings := strings.Split(i, " ") splitStrings := strings.Split(i, " ")
hostname := splitStrings[0] hostname := splitStrings[0]
@ -87,7 +90,7 @@ func resultsToJSON(data []string) {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
fmt.Println(string(b)) jsonData = append(jsonData, b)
} }

40
pkg/shell/shell.go Normal file
View File

@ -0,0 +1,40 @@
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 := ""
host := strings.TrimRight(hostname, stringSplit)
fqdn := strings.TrimLeft(hostname, stringSplit)
greentext := "tput -T xterm setaf 2; "
// 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\"'", 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\"'", host, message, prerac, hop, username, jump, rac, racOpts, remoteUser, fqdn, sudo)
}
}
}