Compare commits
No commits in common. "5ad1f6ae43861a386aa5180cf98187c0657724ae" and "ca59f1e25f332bd83082494e7bae46b7b76e7d84" have entirely different histories.
5ad1f6ae43
...
ca59f1e25f
12 changed files with 123 additions and 254 deletions
|
@ -4,7 +4,8 @@ import "github.com/google/uuid"
|
||||||
|
|
||||||
type EFIApp struct {
|
type EFIApp struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
DevicePath string `json:"device_path"`
|
Path string `json:"path"`
|
||||||
|
DiskID string `json:"disk_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding"
|
"encoding"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +20,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var spaceByte = []byte(" ")
|
var spaceByte = []byte(" ")
|
||||||
var commaByte = []byte(";")
|
var commaByte = []byte(",")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
keyID = "id"
|
keyID = "id"
|
||||||
|
@ -141,13 +140,9 @@ func (am *acceptMessage) UnmarshalBinary(data []byte) error {
|
||||||
|
|
||||||
func (am *acceptMessage) MarshalBinary() (data []byte, err error) {
|
func (am *acceptMessage) MarshalBinary() (data []byte, err error) {
|
||||||
action := []byte(am.Action().String())
|
action := []byte(am.Action().String())
|
||||||
// efiApp := strings.ReplaceAll(am.efiApp, `\`, `\\`)
|
|
||||||
// efiApp = strings.ReplaceAll(efiApp, "File(", "")
|
|
||||||
efiApp := strings.ReplaceAll(am.efiApp, "File(", "")
|
|
||||||
efiApp, _ = strings.CutSuffix(efiApp, ")")
|
|
||||||
params := [][]byte{
|
params := [][]byte{
|
||||||
[]byte(fmt.Sprintf("%s=%s", keyID, am.id.String())),
|
[]byte(fmt.Sprintf("%s=%s", keyID, am.id.String())),
|
||||||
[]byte(fmt.Sprintf("%s=%s", keyEfiApp, efiApp)),
|
[]byte(fmt.Sprintf("%s=%s", keyEfiApp, am.efiApp)),
|
||||||
}
|
}
|
||||||
param_bytes := bytes.Join(params, commaByte)
|
param_bytes := bytes.Join(params, commaByte)
|
||||||
return bytes.Join([][]byte{action, param_bytes}, spaceByte), nil
|
return bytes.Join([][]byte{action, param_bytes}, spaceByte), nil
|
||||||
|
|
|
@ -55,7 +55,6 @@ type jsonConf struct {
|
||||||
Iface string `json:"interface"`
|
Iface string `json:"interface"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
McastGroup string `json:"multicast_group"`
|
McastGroup string `json:"multicast_group"`
|
||||||
SrcAddr string `json:"src_addr"`
|
|
||||||
} `json:"boot_provider"`
|
} `json:"boot_provider"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +68,6 @@ type AppConfig struct {
|
||||||
UPDMcastGroup string
|
UPDMcastGroup string
|
||||||
UDPPort int
|
UDPPort int
|
||||||
UDPIface string
|
UDPIface string
|
||||||
UDPSrcAddr string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLevel(lvlStr string) logrus.Level {
|
func parseLevel(lvlStr string) logrus.Level {
|
||||||
|
@ -99,7 +97,6 @@ func (ac *AppConfig) UnmarshalJSON(data []byte) error {
|
||||||
ac.UPDMcastGroup = jsonConf.BootProvider.McastGroup
|
ac.UPDMcastGroup = jsonConf.BootProvider.McastGroup
|
||||||
ac.UDPIface = jsonConf.BootProvider.Iface
|
ac.UDPIface = jsonConf.BootProvider.Iface
|
||||||
ac.UDPPort = jsonConf.BootProvider.Port
|
ac.UDPPort = jsonConf.BootProvider.Port
|
||||||
ac.UDPSrcAddr = jsonConf.BootProvider.SrcAddr
|
|
||||||
ac.DataFilepath = jsonConf.Storage.Path
|
ac.DataFilepath = jsonConf.Storage.Path
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,110 +1,85 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
// import (
|
||||||
"encoding/json"
|
// "encoding/json"
|
||||||
"errors"
|
// "fmt"
|
||||||
"fmt"
|
// "io"
|
||||||
"io"
|
// "net"
|
||||||
"net/http"
|
// "net/http"
|
||||||
|
|
||||||
"git.faercol.me/faercol/http-boot-server/bootserver/helpers"
|
// "git.faercol.me/faercol/http-boot-server/bootserver/helpers"
|
||||||
"git.faercol.me/faercol/http-boot-server/bootserver/services"
|
// "git.faercol.me/faercol/http-boot-server/bootserver/services"
|
||||||
"github.com/google/uuid"
|
// "github.com/sirupsen/logrus"
|
||||||
"github.com/sirupsen/logrus"
|
// )
|
||||||
)
|
|
||||||
|
|
||||||
const SetBootRoute = "/config/boot"
|
// const BootRoute = "/boot"
|
||||||
|
|
||||||
type setBootOptionPayload struct {
|
// type BootController struct {
|
||||||
ClientID string `json:"client_id"`
|
// clientService *services.ClientHandlerService
|
||||||
OptionID string `json:"option_id"`
|
// l *logrus.Logger
|
||||||
}
|
// }
|
||||||
|
|
||||||
type BootController struct {
|
// func NewBootController(logger *logrus.Logger, service *services.ClientHandlerService) *BootController {
|
||||||
clientService *services.ClientHandlerService
|
// return &BootController{
|
||||||
l *logrus.Logger
|
// clientService: service,
|
||||||
}
|
// l: logger,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
func NewBootController(logger *logrus.Logger, service *services.ClientHandlerService) *BootController {
|
// func (bc *BootController) getBootOption(clientIP string, w http.ResponseWriter, r *http.Request) (int, []byte, error) {
|
||||||
return &BootController{
|
// bootOption, err := bc.clientService.GetClientSelectedBootOption(clientIP)
|
||||||
clientService: service,
|
// if err != nil {
|
||||||
l: logger,
|
// return http.StatusInternalServerError, nil, fmt.Errorf("failed to get boot option: %w", err)
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *BootController) setBootOption(w http.ResponseWriter, r *http.Request) (int, []byte, error) {
|
// dat, err := json.Marshal(bootOption)
|
||||||
dat, err := io.ReadAll(r.Body)
|
// if err != nil {
|
||||||
if err != nil {
|
// return http.StatusInternalServerError, nil, fmt.Errorf("failed to serialize body")
|
||||||
return http.StatusInternalServerError, nil, fmt.Errorf("failed to read body: %w", err)
|
// }
|
||||||
}
|
|
||||||
var payload setBootOptionPayload
|
|
||||||
if err := json.Unmarshal(dat, &payload); err != nil {
|
|
||||||
return http.StatusBadRequest, nil, fmt.Errorf("failed to parse body: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
clientID, err := uuid.Parse(payload.ClientID)
|
// w.Header().Add("Content-Type", "application/json")
|
||||||
if err != nil {
|
// return http.StatusOK, dat, nil
|
||||||
return http.StatusBadRequest, []byte("bad client ID"), fmt.Errorf("invalid format for client ID: %w", err)
|
// }
|
||||||
}
|
|
||||||
optionID, err := uuid.Parse(payload.OptionID)
|
|
||||||
if err != nil {
|
|
||||||
return http.StatusBadRequest, []byte("bad option ID"), fmt.Errorf("invalid format for option ID: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bc.clientService.SetClientBootOption(clientID, optionID.String()); err != nil {
|
// func (bc *BootController) setBootOption(clientIP string, w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
if errors.Is(err, services.ErrUnknownClient) {
|
// dat, err := io.ReadAll(r.Body)
|
||||||
return http.StatusNotFound, []byte("unknown client"), err
|
// if err != nil {
|
||||||
}
|
// return http.StatusInternalServerError, fmt.Errorf("failed to read body: %w", err)
|
||||||
if errors.Is(err, services.ErrUnknownBootOption) {
|
// }
|
||||||
return http.StatusNotFound, []byte("unknown boot option"), err
|
// var option string
|
||||||
}
|
// if err := json.Unmarshal(dat, &option); err != nil {
|
||||||
return http.StatusInternalServerError, nil, fmt.Errorf("failed to set boot option for client: %w", err)
|
// return http.StatusInternalServerError, fmt.Errorf("failed to parse body: %w", err)
|
||||||
}
|
// }
|
||||||
|
|
||||||
return http.StatusAccepted, nil, nil
|
// if err := bc.clientService.SetClientBootOption(clientIP, option); err != nil {
|
||||||
}
|
// return http.StatusInternalServerError, fmt.Errorf("failed to set boot option for client: %w", err)
|
||||||
|
// }
|
||||||
|
|
||||||
func (bc *BootController) deleteClient(w http.ResponseWriter, r *http.Request) (int, []byte, error) {
|
// return http.StatusAccepted, nil
|
||||||
dat, err := io.ReadAll(r.Body)
|
// }
|
||||||
if err != nil {
|
|
||||||
return http.StatusInternalServerError, nil, fmt.Errorf("failed to read body: %w", err)
|
|
||||||
}
|
|
||||||
var payload setBootOptionPayload
|
|
||||||
if err := json.Unmarshal(dat, &payload); err != nil {
|
|
||||||
return http.StatusBadRequest, nil, fmt.Errorf("failed to parse body: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
clientID, err := uuid.Parse(payload.ClientID)
|
// func (bc *BootController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
// clientIP, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||||
return http.StatusBadRequest, []byte("bad client ID"), fmt.Errorf("invalid format for client ID: %w", err)
|
// if err != nil {
|
||||||
}
|
// bc.l.Errorf("Failed to read remote IP: %s", err.Error())
|
||||||
if err := bc.clientService.DeleteClient(clientID); err != nil {
|
// helpers.HandleResponse(w, r, http.StatusInternalServerError, nil, bc.l)
|
||||||
return http.StatusInternalServerError, []byte("failed to delete client"), fmt.Errorf("failed to delete client: %w", err)
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
return http.StatusOK, nil, nil
|
// var returncode int
|
||||||
}
|
// var content []byte
|
||||||
|
|
||||||
func (bc *BootController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
// switch r.Method {
|
||||||
var returncode int
|
// case http.MethodGet:
|
||||||
var content []byte
|
// returncode, content, err = bc.getBootOption(clientIP, w, r)
|
||||||
var err error
|
// case http.MethodPut:
|
||||||
|
// returncode, err = bc.setBootOption(clientIP, w, r)
|
||||||
|
// default:
|
||||||
|
// returncode = http.StatusMethodNotAllowed
|
||||||
|
// }
|
||||||
|
|
||||||
switch r.Method {
|
// if err != nil {
|
||||||
case http.MethodPut:
|
// bc.l.Errorf("An error occured while handling boot request: %q", err.Error())
|
||||||
returncode, content, err = bc.setBootOption(w, r)
|
// }
|
||||||
if err != nil {
|
// helpers.HandleResponse(w, r, returncode, content, bc.l)
|
||||||
bc.l.Errorf("Error setting boot option for client: %s", err.Error())
|
// }
|
||||||
}
|
|
||||||
case http.MethodDelete:
|
|
||||||
returncode, content, err = bc.deleteClient(w, r)
|
|
||||||
if err != nil {
|
|
||||||
bc.l.Errorf("Error setting boot option for client: %s", err.Error())
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
helpers.HandleResponse(w, r, http.StatusMethodNotAllowed, nil, bc.l)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
helpers.HandleResponse(w, r, returncode, content, bc.l)
|
|
||||||
}
|
|
||||||
|
|
|
@ -16,24 +16,17 @@ const EnrollRoute = "/enroll"
|
||||||
|
|
||||||
type newClientPayload struct {
|
type newClientPayload struct {
|
||||||
ID string `json:"ID"`
|
ID string `json:"ID"`
|
||||||
MulticastGroup string `json:"multicast_group"`
|
|
||||||
MulticastPort int `json:"multicast_port"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EnrollController struct {
|
type EnrollController struct {
|
||||||
clientService *services.ClientHandlerService
|
clientService *services.ClientHandlerService
|
||||||
l *logrus.Logger
|
l *logrus.Logger
|
||||||
multicastPort int
|
|
||||||
multicastGroup string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEnrollController(l *logrus.Logger, service *services.ClientHandlerService, mcastPort int, mcastGroup string) *EnrollController {
|
func NewEnrollController(l *logrus.Logger, service *services.ClientHandlerService) *EnrollController {
|
||||||
return &EnrollController{
|
return &EnrollController{
|
||||||
|
|
||||||
clientService: service,
|
clientService: service,
|
||||||
l: l,
|
l: l,
|
||||||
multicastPort: mcastPort,
|
|
||||||
multicastGroup: mcastGroup,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,13 +50,12 @@ func (ec *EnrollController) enrollMachine(w http.ResponseWriter, r *http.Request
|
||||||
return http.StatusInternalServerError, nil, fmt.Errorf("failed to create client %w", err)
|
return http.StatusInternalServerError, nil, fmt.Errorf("failed to create client %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
payload, err := json.Marshal(newClientPayload{ID: cltID.String(), MulticastGroup: ec.multicastGroup, MulticastPort: ec.multicastPort})
|
payload, err := json.Marshal(newClientPayload{ID: cltID.String()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, nil, fmt.Errorf("failed to serialize payload: %w", err)
|
return http.StatusInternalServerError, nil, fmt.Errorf("failed to serialize payload: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ec.l.Infof("Added client")
|
ec.l.Infof("Added client")
|
||||||
w.Header().Add("Content-Type", "application/json")
|
|
||||||
return http.StatusOK, payload, nil
|
return http.StatusOK, payload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
|
||||||
|
|
||||||
"git.faercol.me/faercol/http-boot-server/bootserver/helpers"
|
"git.faercol.me/faercol/http-boot-server/bootserver/helpers"
|
||||||
"git.faercol.me/faercol/http-boot-server/bootserver/services"
|
"git.faercol.me/faercol/http-boot-server/bootserver/services"
|
||||||
|
@ -64,13 +63,10 @@ func (uc *UIController) serveUI(w http.ResponseWriter, r *http.Request) (int, in
|
||||||
for id, bo := range clt.Options {
|
for id, bo := range clt.Options {
|
||||||
tplBO = append(tplBO, templateBootOption{
|
tplBO = append(tplBO, templateBootOption{
|
||||||
Name: bo.Name,
|
Name: bo.Name,
|
||||||
Path: bo.DevicePath,
|
Path: bo.Path,
|
||||||
ID: id,
|
ID: id,
|
||||||
Selected: id == clt.SelectedOption,
|
Selected: id == clt.SelectedOption,
|
||||||
})
|
})
|
||||||
sort.Slice(tplBO, func(i, j int) bool {
|
|
||||||
return tplBO[i].ID < tplBO[j].ID
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
dat.Clients = append(dat.Clients, templateClient{
|
dat.Clients = append(dat.Clients, templateClient{
|
||||||
ID: clt.ID.String(),
|
ID: clt.ID.String(),
|
||||||
|
@ -91,16 +87,10 @@ func (uc *UIController) serveUI(w http.ResponseWriter, r *http.Request) (int, in
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uc *UIController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (uc *UIController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.RequestURI != "/" {
|
|
||||||
uc.l.Errorf("Unhandled route %q", r.RequestURI)
|
|
||||||
helpers.HandleResponse(w, r, http.StatusNotFound, nil, uc.l)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
returncode, contentLength, err := uc.serveUI(w, r)
|
returncode, contentLength, err := uc.serveUI(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
uc.l.Errorf("Error serving UI: %s", err.Error())
|
uc.l.Errorf("Error serving UI: %s", err.Error())
|
||||||
helpers.HandleResponse(w, r, returncode, nil, uc.l)
|
helpers.HandleResponse(w, r, returncode, nil, uc.l)
|
||||||
} else {
|
|
||||||
helpers.AddToContext(r, returncode, contentLength)
|
|
||||||
}
|
}
|
||||||
|
helpers.AddToContext(r, returncode, contentLength)
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,8 @@ func New(appConf *config.AppConfig, logger *logrus.Logger) (*Server, error) {
|
||||||
}
|
}
|
||||||
service := services.NewClientHandlerService(appConf.DataFilepath, logger)
|
service := services.NewClientHandlerService(appConf.DataFilepath, logger)
|
||||||
controllers := map[string]http.Handler{
|
controllers := map[string]http.Handler{
|
||||||
client.EnrollRoute: middlewares.WithLogger(client.NewEnrollController(logger, service, appConf.UDPPort, appConf.UPDMcastGroup), logger),
|
client.EnrollRoute: middlewares.WithLogger(client.NewEnrollController(logger, service), logger),
|
||||||
client.ConfigRoute: middlewares.WithLogger(client.NewGetConfigController(logger, service, appConf), logger),
|
client.ConfigRoute: middlewares.WithLogger(client.NewGetConfigController(logger, service, appConf), logger),
|
||||||
client.SetBootRoute: middlewares.WithLogger(client.NewBootController(logger, service), logger),
|
|
||||||
ui.StaticRoute: &ui.StaticController{},
|
ui.StaticRoute: &ui.StaticController{},
|
||||||
ui.UIRoute: middlewares.WithLogger(ui.NewUIController(logger, service), logger),
|
ui.UIRoute: middlewares.WithLogger(ui.NewUIController(logger, service), logger),
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.faercol.me/faercol/http-boot-server/bootserver/bootoption"
|
"git.faercol.me/faercol/http-boot-server/bootserver/bootoption"
|
||||||
|
@ -112,9 +111,6 @@ func (chs *ClientHandlerService) GetAllClientConfig() ([]*bootoption.Client, err
|
||||||
clt.ID = id
|
clt.ID = id
|
||||||
clientList = append(clientList, clt)
|
clientList = append(clientList, clt)
|
||||||
}
|
}
|
||||||
sort.Slice(clientList, func(i, j int) bool {
|
|
||||||
return clientList[i].ID.String() < clientList[j].ID.String()
|
|
||||||
})
|
|
||||||
return clientList, nil
|
return clientList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,20 +152,6 @@ func (chs *ClientHandlerService) GetClientSelectedBootOption(client uuid.UUID) (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (chs *ClientHandlerService) DeleteClient(client uuid.UUID) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
clients, err := chs.load()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load current config: %w", err)
|
|
||||||
}
|
|
||||||
delete(clients, client)
|
|
||||||
if err := chs.unload(clients); err != nil {
|
|
||||||
return fmt.Errorf("failed to save current config: %w", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (chs *ClientHandlerService) SetClientBootOption(client uuid.UUID, option string) error {
|
func (chs *ClientHandlerService) SetClientBootOption(client uuid.UUID, option string) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
function selectBootOption(clientID, bootID) {
|
|
||||||
const Http = new XMLHttpRequest;
|
|
||||||
var host = window.location.protocol + "//" + window.location.host;
|
|
||||||
const url = host + "/config/boot"
|
|
||||||
console.debug(`Sending request to ${url}`);
|
|
||||||
Http.open("PUT", url);
|
|
||||||
Http.setRequestHeader("Content-Type", "application/json");
|
|
||||||
const body = JSON.stringify({
|
|
||||||
client_id: clientID,
|
|
||||||
option_id: bootID,
|
|
||||||
});
|
|
||||||
Http.onload = () => {
|
|
||||||
if (Http.readyState === 4 && Http.status === 202) {
|
|
||||||
location.reload();
|
|
||||||
} else {
|
|
||||||
console.error(`Unexpected returncode ${Http.status}`)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Http.send(body);
|
|
||||||
}
|
|
|
@ -1,48 +1,24 @@
|
||||||
:root {
|
|
||||||
--page-background: #000000;
|
|
||||||
--background: #121212;
|
|
||||||
--surface: #181818;
|
|
||||||
--surface-active: #303030;
|
|
||||||
--surface-hover: #aaaaaa;
|
|
||||||
--primary: #3b80c9;
|
|
||||||
--primary-variant: #c9953b;
|
|
||||||
--secondary: #c94e3b;
|
|
||||||
--text-main: #ffffff;
|
|
||||||
--text-variant: #9B9B9B;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
background-color: var(--page-background);
|
background-color: black;
|
||||||
color: var(--text-main);
|
color: white;
|
||||||
}
|
|
||||||
|
|
||||||
.page-content {
|
|
||||||
width: 90%;
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
border-radius: 5px;
|
|
||||||
background-color: var(--surface);
|
|
||||||
padding: 5px;
|
|
||||||
border-radius: 5px 5px;
|
|
||||||
margin: 5px auto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.main-container {
|
.main-container {
|
||||||
|
border-radius: 5px;
|
||||||
|
background-color: #121212;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title-container {
|
.title-container {
|
||||||
background-color: var(--primary);
|
border-radius: 5px 5px 0px 0px;
|
||||||
|
padding: 5px;
|
||||||
|
background-color: #1A3A5D;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-list-container {
|
.client-list-container {
|
||||||
border-radius: 0px 0px 5px 5px;
|
border-radius: 0px 0px 5px 5px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
background-color: var(--surface);
|
background-color: #232323;
|
||||||
}
|
}
|
||||||
|
|
||||||
.client-container {
|
.client-container {
|
||||||
|
@ -60,7 +36,7 @@ body {
|
||||||
|
|
||||||
.client-uuid {
|
.client-uuid {
|
||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
color: var(--text-variant);
|
color: #9B9B9B;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,16 +48,9 @@ body {
|
||||||
.client-boot-option {
|
.client-boot-option {
|
||||||
margin: 3px auto;
|
margin: 3px auto;
|
||||||
padding: 8px 8px;
|
padding: 8px 8px;
|
||||||
cursor: pointer;
|
|
||||||
|
|
||||||
&.selected {
|
&.selected {
|
||||||
background-color: var(--surface-active);
|
background-color: #3E4042;
|
||||||
cursor: default;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
background-color: var(--surface-hover);
|
|
||||||
--text-variant: #000000;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +61,7 @@ body {
|
||||||
|
|
||||||
.boot-option-uuid {
|
.boot-option-uuid {
|
||||||
font-size: smaller;
|
font-size: smaller;
|
||||||
color: var(--text-variant);
|
color: #9B9B9B;
|
||||||
}
|
}
|
||||||
|
|
||||||
.boot-option-path {
|
.boot-option-path {
|
||||||
|
|
|
@ -5,19 +5,17 @@
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>HTTP boot server</title>
|
<title>HTTP boot server</title>
|
||||||
<link rel="stylesheet" href="/static/stylesheets/main.css">
|
<link rel="stylesheet" href="/static/stylesheets/main.css">
|
||||||
<script src="/static/scripts/index.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="page-content">
|
<div class="main-container">
|
||||||
|
|
||||||
<div class="title-container container">
|
<div class="title-container">
|
||||||
<h1>HTTP boot server admin page</h1>
|
<h1>HTTP boot server admin page</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="main-container container">
|
<div class="client-list-container">
|
||||||
<div class="client-list">
|
<h2>Currently enrolled clients</h2>
|
||||||
<h2>{{len .Clients}} enrolled clients</h2>
|
|
||||||
|
|
||||||
{{range .Clients}}
|
{{range .Clients}}
|
||||||
<div class="client-container">
|
<div class="client-container">
|
||||||
|
@ -27,9 +25,8 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="client-content">
|
<div class="client-content">
|
||||||
<div class="client-boot-options">
|
<div class="client-boot-options">
|
||||||
{{$cid := .ID}}{{range .BootOptions}}
|
{{range .BootOptions}}
|
||||||
<div class="client-boot-option{{if .Selected}} selected{{end}}"
|
<div class="client-boot-option{{if .Selected}} selected{{end}}">
|
||||||
onclick="selectBootOption('{{$cid}}', '{{.ID}}')">
|
|
||||||
<div>
|
<div>
|
||||||
<span class="boot-option-name">{{.Name}}</span>
|
<span class="boot-option-name">{{.Name}}</span>
|
||||||
<span class="boot-option-uuid">{{.ID}}</span>
|
<span class="boot-option-uuid">{{.ID}}</span>
|
||||||
|
@ -46,7 +43,6 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
|
@ -22,7 +22,6 @@ type udpMessage struct {
|
||||||
|
|
||||||
type UDPListener struct {
|
type UDPListener struct {
|
||||||
addr *net.UDPAddr
|
addr *net.UDPAddr
|
||||||
laddr *net.UDPAddr
|
|
||||||
iface *net.Interface
|
iface *net.Interface
|
||||||
l *net.UDPConn
|
l *net.UDPConn
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
|
@ -42,15 +41,9 @@ func New(conf *config.AppConfig, log *logrus.Logger) (*UDPListener, error) {
|
||||||
return nil, fmt.Errorf("failed to resolve interface name %s: %w", conf.UDPIface, err)
|
return nil, fmt.Errorf("failed to resolve interface name %s: %w", conf.UDPIface, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
laddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("[%s%%%s]:0", conf.UDPSrcAddr, conf.UDPIface))
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to resolve UDP source address: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &UDPListener{
|
return &UDPListener{
|
||||||
addr: addr,
|
addr: addr,
|
||||||
iface: iface,
|
iface: iface,
|
||||||
laddr: laddr,
|
|
||||||
ctx: context.TODO(),
|
ctx: context.TODO(),
|
||||||
service: services.NewClientHandlerService(conf.DataFilepath, log),
|
service: services.NewClientHandlerService(conf.DataFilepath, log),
|
||||||
log: log,
|
log: log,
|
||||||
|
@ -85,7 +78,7 @@ func (l *UDPListener) handleBootRequest(msg bootprotocol.Message, subLogger logr
|
||||||
requestLogger.Errorf("Failed to get config for client: %s", err.Error())
|
requestLogger.Errorf("Failed to get config for client: %s", err.Error())
|
||||||
return bootprotocol.Deny(msg.ID(), "unknown server error")
|
return bootprotocol.Deny(msg.ID(), "unknown server error")
|
||||||
}
|
}
|
||||||
return bootprotocol.Accept(msg.ID(), bootOption.DevicePath)
|
return bootprotocol.Accept(msg.ID(), bootOption.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UDPListener) handleClient(msg *udpMessage) error {
|
func (l *UDPListener) handleClient(msg *udpMessage) error {
|
||||||
|
@ -95,7 +88,7 @@ func (l *UDPListener) handleClient(msg *udpMessage) error {
|
||||||
response := l.handleBootRequest(msg.message, clientLogger)
|
response := l.handleBootRequest(msg.message, clientLogger)
|
||||||
|
|
||||||
clientLogger.Debug("Dialing client for answer")
|
clientLogger.Debug("Dialing client for answer")
|
||||||
con, err := net.DialUDP("udp", l.laddr, msg.sourceAddr)
|
con, err := net.DialUDP("udp", nil, msg.sourceAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to dialed client: %w", err)
|
return fmt.Errorf("failed to dialed client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue