fix loopback check

This commit is contained in:
hardy 2023-06-09 20:23:24 +08:00
parent a29e969eed
commit 9df2cf7bfe
No known key found for this signature in database
GPG Key ID: D1ED7F7A9ED520C3
1 changed files with 38 additions and 40 deletions

View File

@ -7,6 +7,11 @@ package api
import (
"context"
"fmt"
"net"
"net/http"
"strconv"
"time"
log "github.com/cihub/seelog"
"infini.sh/console/modules/agent/client"
common2 "infini.sh/console/modules/agent/common"
@ -21,10 +26,6 @@ import (
"infini.sh/framework/core/util"
elastic2 "infini.sh/framework/modules/elastic"
"infini.sh/framework/modules/elastic/common"
"net"
"net/http"
"strconv"
"time"
)
type APIHandler struct {
@ -122,7 +123,6 @@ func (h *APIHandler) createInstance(w http.ResponseWriter, req *http.Request, ps
}
func (h *APIHandler) getInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
id := ps.MustGetParameter("instance_id")
@ -342,7 +342,6 @@ func (h *APIHandler) updateInstance(w http.ResponseWriter, req *http.Request, ps
}, 200)
}
func (h *APIHandler) searchInstance(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
var (
@ -498,7 +497,7 @@ func (h *APIHandler) authESNode(w http.ResponseWriter, req *http.Request, ps htt
h.WriteError(w, err.Error(), http.StatusInternalServerError)
return
}
if !util.StringInArray(inst.IPS, host) {
if !util.StringInArray(inst.IPS, host) && !net.ParseIP(host).IsLoopback() {
h.WriteError(w, fmt.Sprintf("got node host %s not match any ip of %v", host, inst.IPS), http.StatusInternalServerError)
return
}
@ -731,7 +730,6 @@ func getNodesInfoFromES(agentID string) (map[int]*agent.ESNodeInfo, error){
},
},
},
}
q := orm.Query{
RawQuery: util.MustToJSONBytes(query),