|
@@ -31,6 +31,7 @@ func hostHandlers(r *mux.Router) {
|
|
|
r.HandleFunc("/api/hosts/adm/authenticate", authenticateHost).Methods(http.MethodPost)
|
|
|
r.HandleFunc("/api/v1/host", Authorize(true, false, "host", http.HandlerFunc(pull))).Methods(http.MethodGet)
|
|
|
r.HandleFunc("/api/v1/host/{hostid}/signalpeer", Authorize(true, false, "host", http.HandlerFunc(signalPeer))).Methods(http.MethodPost)
|
|
|
+ r.HandleFunc("/api/v1/fallback/host/{hostid}", Authorize(true, false, "host", http.HandlerFunc(hostUpdateFallback))).Methods(http.MethodPut)
|
|
|
r.HandleFunc("/api/v1/auth-register/host", socketHandler)
|
|
|
}
|
|
|
|
|
@@ -141,6 +142,8 @@ func pull(w http.ResponseWriter, r *http.Request) {
|
|
|
Peers: hPU.Peers,
|
|
|
PeerIDs: hPU.PeerIDs,
|
|
|
HostNetworkInfo: hPU.HostNetworkInfo,
|
|
|
+ EgressRoutes: hPU.EgressRoutes,
|
|
|
+ FwUpdate: hPU.FwUpdate,
|
|
|
}
|
|
|
|
|
|
logger.Log(1, hostID, "completed a pull")
|
|
@@ -208,6 +211,51 @@ func updateHost(w http.ResponseWriter, r *http.Request) {
|
|
|
json.NewEncoder(w).Encode(apiHostData)
|
|
|
}
|
|
|
|
|
|
+// swagger:route PUT /api/v1/fallback/host/{hostid} hosts hostUpdateFallback
|
|
|
+//
|
|
|
+// Updates a Netclient host on Netmaker server.
|
|
|
+//
|
|
|
+// Schemes: https
|
|
|
+//
|
|
|
+// Security:
|
|
|
+// oauth
|
|
|
+//
|
|
|
+// Responses:
|
|
|
+// 200: apiHostResponse
|
|
|
+func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
|
|
|
+ var params = mux.Vars(r)
|
|
|
+ hostid := params["hostid"]
|
|
|
+ currentHost, err := logic.GetHost(hostid)
|
|
|
+ if err != nil {
|
|
|
+ slog.Error("error getting host", "id", hostid, "error", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var hostUpdate models.HostUpdate
|
|
|
+ err = json.NewDecoder(r.Body).Decode(&hostUpdate)
|
|
|
+ if err != nil {
|
|
|
+ logger.Log(0, r.Header.Get("user"), "failed to update a host:", err.Error())
|
|
|
+ logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ slog.Info("recieved host update", "name", hostUpdate.Host.Name, "id", hostUpdate.Host.ID)
|
|
|
+ switch hostUpdate.Action {
|
|
|
+ case models.CheckIn:
|
|
|
+ _ = mq.HandleHostCheckin(&hostUpdate.Host, currentHost)
|
|
|
+
|
|
|
+ case models.UpdateHost:
|
|
|
+
|
|
|
+ _ = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
|
|
|
+ err := logic.UpsertHost(currentHost)
|
|
|
+ if err != nil {
|
|
|
+ slog.Error("failed to update host", "id", currentHost.ID, "error", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
// swagger:route DELETE /api/hosts/{hostid} hosts deleteHost
|
|
|
//
|
|
|
// Deletes a Netclient host from Netmaker server.
|
|
@@ -497,7 +545,7 @@ func authenticateHost(response http.ResponseWriter, request *http.Request) {
|
|
|
|
|
|
// Create EMQX creds and ACLs if not found
|
|
|
if servercfg.GetBrokerType() == servercfg.EmqxBrokerType {
|
|
|
- if err := mq.CreateEmqxUser(host.ID.String(), host.HostPass, false); err != nil {
|
|
|
+ if err := mq.CreateEmqxUser(host.ID.String(), authRequest.Password, false); err != nil {
|
|
|
slog.Error("failed to create host credentials for EMQX: ", err.Error())
|
|
|
} else {
|
|
|
if err := mq.CreateHostACL(host.ID.String(), servercfg.GetServerInfo().Server); err != nil {
|