Compare commits

..

No commits in common. "master" and "JumpBoolOption" have entirely different histories.

7 changed files with 48 additions and 55 deletions

View File

@ -22,4 +22,4 @@ For Tab_Magic to do proper host detection, The following TXT record options are
* 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 - You will be able to specify a custom username for the remote host.
* REMOTE_USER - This is not implemented yet, but you will be able to specify a custom username for the remote host.

View File

@ -10,25 +10,29 @@ import (
)
func main() {
var c = flag.String("config", "", "Configuration to load")
var user = flag.String("user", "", "user for aliases")
var debug = flag.Bool("debug", false, "Enables Debugging Mode")
var c string
var user string
var debug bool
flag.StringVar(&c, "config", "", "Configuration to load")
flag.StringVar(&user, "user", "", "user for aliases")
flag.BoolVar(&debug, "debug", false, "Enables Debugging Mode")
flag.Parse()
// Stop the app if they're missing required flags.
if *c == "" {
if c == "" {
log.Fatal("You need to specify a configuration file.")
}
if *user == "" {
log.Fatal("You must specify a username.")
if user == "" {
log.Fatal("Username is not specified.")
}
cfg, err := config.GetConfig(*c, *debug)
cfg, err := config.GetConfig(c, debug)
if err != nil {
log.Fatal(err)
}
data := resolver.PerformZoneTransfer(cfg, *debug)
shell.CreateShellAliases(data, *user, cfg, *debug)
data := resolver.PerformZoneTransfer(cfg)
shell.CreateShellAliases(data, user, cfg)
}

View File

@ -4,6 +4,6 @@
"domains": [ "kc.linuxrocker.com"],
"jumpHost": "jump01.kc.linuxrocker.com",
"useJump": false,
"splitString": ".linuxrocker.com",
"splitString": ".linuxrocker",
"windowsGeometry": "1600x900"
}

View File

@ -1,13 +1,11 @@
package model
// Results is for DNS results
type Results struct {
IP string `json:"ip"`
Hostname string `json:"hostname"`
TXT string `json:"TXT"`
TXT string `json:"TXT`
}
// UniqResults is for Unique DNS Results
type UniqResults struct {
IP string `json:"ip"`
Hostname string `json:"hostname"`

View File

@ -1,22 +1,19 @@
package resolver
import (
"encoding/json"
"errors"
"fmt"
"log"
"strings"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/utils"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/model"
"github.com/miekg/dns"
)
// LookupName returns IPv4 address from A record or error.
func lookupName(fqdn, serverAddr string, debug bool) (string, error) {
if debug {
defer utils.LogElapsedTime("Lookup Name")
}
func lookupName(fqdn, serverAddr string) (string, error) {
m := &dns.Msg{}
m.SetQuestion(dns.Fqdn(fqdn), dns.TypeA)
in, err := dns.Exchange(m, serverAddr)
@ -33,11 +30,7 @@ func lookupName(fqdn, serverAddr string, debug bool) (string, error) {
return "", errors.New("no A record returned")
}
// PerformZoneTransfer performs zone transfers and gathers a list from config.Domains
func PerformZoneTransfer(config config.Config, debug bool) []string {
if debug {
defer utils.LogElapsedTime("Perform Zone Transfer")
}
func PerformZoneTransfer(config config.Config) []string {
data := make([]string, 0)
// Do the transfer
@ -57,7 +50,7 @@ func PerformZoneTransfer(config config.Config, debug bool) []string {
case *dns.TXT:
txt = string(v.Txt[0])
hostname = v.Hdr.Name
cip, err := lookupName(strings.TrimRight(v.Hdr.Name, "."), server, debug)
cip, err := lookupName(strings.TrimRight(v.Hdr.Name, "."), server)
if err != nil || cip == "" {
continue
}
@ -66,7 +59,7 @@ func PerformZoneTransfer(config config.Config, debug bool) []string {
ip = v.A.String()
hostname = v.Hdr.Name
case *dns.CNAME:
cip, err := lookupName(v.Target, server, debug)
cip, err := lookupName(v.Target, server)
if err != nil || cip == "" {
continue
}
@ -79,6 +72,26 @@ func PerformZoneTransfer(config config.Config, debug bool) []string {
}
}
}
// fmt.Println(data)
// resultsToJSON(data)
return data
}
func resultsToJSON(data []string) {
jsonData := make([][]byte, 0)
for _, i := range data {
splitStrings := strings.Split(i, " ")
hostname := splitStrings[0]
ip := splitStrings[1]
txt := splitStrings[2]
dns := &model.Results{IP: ip, Hostname: hostname, TXT: txt}
b, err := json.Marshal(dns)
if err != nil {
fmt.Println(err)
}
jsonData = append(jsonData, b)
}
}

View File

@ -4,16 +4,10 @@ import (
"fmt"
"strings"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/utils"
"git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config"
)
// CreateShellAliases will create shell aliases and fmt.Println them
func CreateShellAliases(data []string, username string, config config.Config, debug bool) {
if debug {
defer utils.LogElapsedTime("Create Shell Aliases")
}
func CreateShellAliases(data []string, username string, config config.Config) {
for _, i := range data {
splitStrings := strings.Split(i, " ")
hostname := splitStrings[0]
@ -32,7 +26,7 @@ func CreateShellAliases(data []string, username string, config config.Config, de
prerac := ""
windowsGeometry := config.WindowsGeometry
host := strings.TrimSuffix(hostname, stringSplit)
host := strings.TrimRight(hostname, stringSplit)
fqdn := hostname
greentext := "tput -T xterm setaf 2; "
@ -46,7 +40,7 @@ func CreateShellAliases(data []string, username string, config config.Config, de
for _, i := range txtSplit {
if strings.Contains(i, "SSH_PORT") {
port := strings.TrimPrefix(i, "SSH_PORT=")
port := strings.TrimLeft(i, "SSH_PORT=")
racOpts = fmt.Sprintf("-AXt -p %v -l", port)
} else if strings.Contains(i, "OS_FAMILY") {
osFamily := strings.Split(i, "=")
@ -64,13 +58,12 @@ func CreateShellAliases(data []string, username string, config config.Config, de
sudo = ""
}
} else if strings.Contains(i, "REMOTE_USER") {
user := strings.TrimPrefix(i, "REMOTE_USER=")
user := strings.TrimLeft(i, "REMOTE_USER=")
remoteUser = user
}
}
if debug {
fmt.Println("Disabled Output due to Debug Mode")
} else if useJump {
if useJump {
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)

View File

@ -1,15 +0,0 @@
package utils
import (
"log"
"time"
)
//LogElapsedTime provides a function that can be used to log the time elapsed between when this function is invoked, to the time the returned function is invoked.
//Adding "defer LogElapsedTime("my log")" at the beginning of any function will log the time it takes to execute that function.
func LogElapsedTime(what string) func() {
start := time.Now()
return func() {
log.Printf("%s, Total Time Taken: %v\n", what, time.Since(start))
}
}