2022-08-14 03:12:19 +08:00
|
|
|
package headscale
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"tailscale.com/tailcfg"
|
2022-08-19 22:29:04 +08:00
|
|
|
"tailscale.com/types/key"
|
2022-08-14 03:12:19 +08:00
|
|
|
)
|
|
|
|
|
2022-08-14 18:00:43 +08:00
|
|
|
// // NoiseRegistrationHandler handles the actual registration process of a machine.
|
2022-08-14 03:12:19 +08:00
|
|
|
func (h *Headscale) NoiseRegistrationHandler(
|
|
|
|
writer http.ResponseWriter,
|
|
|
|
req *http.Request,
|
|
|
|
) {
|
|
|
|
log.Trace().Caller().Msgf("Noise registration handler for client %s", req.RemoteAddr)
|
|
|
|
if req.Method != http.MethodPost {
|
|
|
|
http.Error(writer, "Wrong method", http.StatusMethodNotAllowed)
|
2022-08-14 18:40:22 +08:00
|
|
|
|
2022-08-14 03:12:19 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
body, _ := io.ReadAll(req.Body)
|
|
|
|
registerRequest := tailcfg.RegisterRequest{}
|
|
|
|
if err := json.Unmarshal(body, ®isterRequest); err != nil {
|
|
|
|
log.Error().
|
|
|
|
Caller().
|
|
|
|
Err(err).
|
|
|
|
Msg("Cannot parse RegisterRequest")
|
|
|
|
machineRegistrations.WithLabelValues("unknown", "web", "error", "unknown").Inc()
|
|
|
|
http.Error(writer, "Internal error", http.StatusInternalServerError)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-19 22:29:04 +08:00
|
|
|
h.handleRegisterCommon(writer, req, registerRequest, key.MachinePublic{})
|
2022-08-14 03:12:19 +08:00
|
|
|
}
|