Skip to content

Commit

Permalink
This ensures that internal packages are reference by go.mod
Browse files Browse the repository at this point in the history
This fixes references in `go.mod` so that the build will reference the internal packages ensuring development work behaves as expected prior. Also fixes some error reporting from DHCP and ISO Reader.
  • Loading branch information
thebsdbox committed Nov 18, 2019
1 parent aab9ff5 commit fa1b5a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions pkg/certs/go.mod
@@ -0,0 +1,3 @@
module github.com/plunder-app/plunder/pkg/certs

go 1.12
16 changes: 10 additions & 6 deletions pkg/services/serverDHCP.go
Expand Up @@ -39,6 +39,7 @@ func (h *DHCPSettings) ServeDHCP(p dhcp.Packet, msgType dhcp.MessageType, option
mac := strings.ToLower(p.CHAddr().String())
log.Debugf("DCHP Message Type: [%v] from MAC Address [%s]", msgType, mac)

// Retrieve teh deployment type
deploymentType := FindDeploymentConfigFromMac(mac)
// Convert the : in the mac address to dashes to make life easier
dashMac := strings.Replace(mac, ":", "-", -1)
Expand Down Expand Up @@ -67,12 +68,11 @@ func (h *DHCPSettings) ServeDHCP(p dhcp.Packet, msgType dhcp.MessageType, option

// if DHCP option "OptionUserClass" is set to iPXE then we know that it's default booted to the correct bootloader
if string(options[dhcp.OptionUserClass]) == "iPXE" {
// Look up the deployment type from the server mac address
log.Infof("Mac address [%s] is assigned a [%s] deployment type", mac, deploymentType)

// This will ensure that the leasing table is kept updated for when a server was last seen
h.leaseHander(deploymentType, mac)

// TODO - This can be removed and left in the REQUEST section only

// if an entry doesnt exist then drop it to a default type, if not then it has its own specific
if httpPaths[fmt.Sprintf("%s.ipxe", dashMac)] == "" {
h.Options[dhcp.OptionBootFileName] = []byte("http://" + h.IP.String() + "/" + deploymentType + ".ipxe")
Expand Down Expand Up @@ -102,13 +102,18 @@ func (h *DHCPSettings) ServeDHCP(p dhcp.Packet, msgType dhcp.MessageType, option
if leaseNum := dhcp.IPRange(h.Start, reqIP) - 1; leaseNum >= 0 && leaseNum < h.LeaseRange {
if l, exists := h.Leases[leaseNum]; !exists || l.MAC == p.CHAddr().String() {

// Specify the new lease
h.Leases[leaseNum] = Lease{
MAC: p.CHAddr().String(),
Expiry: time.Now().Add(h.LeaseDuration),
}

// Convert the : in the mac address to dashes to make life easier
//dashMac := strings.Replace(mac, ":", "-", -1)
// if DHCP option "OptionUserClass" is set to iPXE then we know that it's default booted to the correct bootloader
if string(options[dhcp.OptionUserClass]) == "iPXE" {
// Only Print out this notification if it's from the iPXE Boot loader
log.Infof("Mac address [%s] is assigned a [%s] deployment type", mac, deploymentType)
}

// if an entry doesnt exist then drop it to a default type, if not then it has its own specific
if httpPaths[fmt.Sprintf("%s.ipxe", dashMac)] == "" {
h.Options[dhcp.OptionBootFileName] = []byte("http://" + h.IP.String() + "/" + deploymentType + ".ipxe")
Expand All @@ -124,7 +129,6 @@ func (h *DHCPSettings) ServeDHCP(p dhcp.Packet, msgType dhcp.MessageType, option
return dhcp.ReplyPacket(p, dhcp.NAK, h.IP, nil, 0, nil)

case dhcp.Release, dhcp.Decline:
//nic := p.CHAddr().String()
for i, v := range h.Leases {
if v.MAC == mac {
log.Debugf("Releasing lease for [%s]", mac)
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/serverHTTPISO.go
Expand Up @@ -67,7 +67,7 @@ func iso9660PathSanitiser(unsanitisedPath string) string {
}

//rebuild the path uppercase
rebuildPath := strings.ToUpper(fmt.Sprintf("%s/%s", filepath.Dir(unsanitisedPath), isoFilename))
rebuildPath := strings.ToLower(fmt.Sprintf("%s/%s", filepath.Dir(unsanitisedPath), isoFilename))

// strD replacer
replacer := strings.NewReplacer("+", "_", "-", "_", " ", "_", "~", "_")
Expand Down Expand Up @@ -127,15 +127,15 @@ func isoReader(w http.ResponseWriter, r *http.Request) {
if err == io.EOF {
w.WriteHeader(http.StatusNotFound)
io.WriteString(w, fmt.Sprintf("Unable to read/find file %s", isoPath))

log.Error(fmt.Sprintf("Unable to read/find file %s", isoPath))
return
}
if err != nil {
log.Error(err)
return
}

if strings.ToUpper(f.Name()) == isoPath {
if f.Name() == isoPath {
freader := f.Sys().(io.Reader)
buf := new(bytes.Buffer)
buf.ReadFrom(freader)
Expand Down
3 changes: 3 additions & 0 deletions pkg/ssh/go.mod
@@ -0,0 +1,3 @@
module github.com/plunder-app/plunder/pkg/ssh

go 1.12

0 comments on commit fa1b5a9

Please sign in to comment.