Skip to content

Commit

Permalink
autoprovision by mac address
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Jan 22, 2021
1 parent d6e420a commit 02096b7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
18 changes: 15 additions & 3 deletions autoprovision.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,24 @@ import (
"log"
"net/http"
"os"
"regexp"
)

func autoProvision() error {
if len(TkID) < 8 {
return errors.New("TkID Configuration Provisioning XML File should be at least 8 characters!")
var err error
var macaddress []string
macaddress, err = getMacAddr()
if err != nil {
return errors.New("TkID Configuration Provisioning XML Filenaame Not Found And Cannot Get Mac Address ")
}
for _, a := range macaddress {
re, err := regexp.Compile(`(:)`)
if err != nil {
log.Fatal(err)
}
TkID = re.ReplaceAllString(a, "")
}
}

if string(TkID[len(TkID)-4]) != ".xml" {
Expand All @@ -57,9 +70,8 @@ func autoProvision() error {
}

fileURL := URL + TkID
log.Println("debug: Contacting Provisioning Server to Download XML Config File")
log.Println("info: Trying to Autoprovision with URL: ", fileURL)
err := DownloadFile(SaveFilePath, SaveFilename, fileURL)

if err != nil {
return errors.New(fmt.Sprintf("error: DownloadFile Module Returned an Error: ", err))
}
Expand Down
14 changes: 14 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,17 @@ func dayTimeWithinRange(dayTimeWithinRange dayScheduleStruct) (bool, bool, bool,
return false, dayTimeWithinRange.defaultLogic, dayTimeWithinRange.stopOnMatch, nil
}

func getMacAddr() ([]string, error) {
ifas, err := net.Interfaces()
if err != nil {
return nil, err
}
var as []string
for _, ifa := range ifas {
a := ifa.HardwareAddr.String()
if a != "" {
as = append(as, a)
}
}
return as, nil
}
2 changes: 1 addition & 1 deletion xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (

//version and release date
const (
talkkonnectVersion string = "1.56.03"
talkkonnectVersion string = "1.56.04"
talkkonnectReleased string = "January 22 2021"
)

Expand Down

0 comments on commit 02096b7

Please sign in to comment.