Skip to content

Commit

Permalink
feat: empty array in whitelist allows anyone use it since now
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhaillav committed Nov 11, 2023
1 parent ea4db4d commit c16d658
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/api/apiServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func Setup(paramConfig *conf.Config, users *sync.Map) error {
}

log.Printf("Starting api server on %v.", config.ApiServerAddress)

if len(config.ApiWhitelist) == 0 {
log.Print("Api whitelist is empty, so anyone could use it. Disable api server by setting Use_api_server to false in config.toml if you don't need it.")
}

serv := &ApiServer{
Users: users,
Expand All @@ -49,7 +53,7 @@ func Setup(paramConfig *conf.Config, users *sync.Map) error {
}

func (s *ApiServer) online(w http.ResponseWriter, r *http.Request) {
if !isAllowed(addrStringToArray(r.RemoteAddr)[0]) {
if !isAllowed(addrStringToArray(r.RemoteAddr)[0]){
w.WriteHeader(http.StatusForbidden)
return
}
Expand Down Expand Up @@ -129,7 +133,7 @@ func (s *ApiServer) port2ip(w http.ResponseWriter, r *http.Request) {
}

func isAllowed(address string) bool {
return slices.Contains(config.ApiWhitelist, address)
return slices.Contains(config.ApiWhitelist, address) || len(config.ApiWhitelist) == 0
}

func addrStringToArray(str string) []string {
Expand Down

0 comments on commit c16d658

Please sign in to comment.