Pull request 2208: AG-27492-client-persistent-list
Squashed commit of the following: commit 1b1a21b07baa15499e5e4963d35bfd2e542533ed Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed May 8 17:32:38 2024 +0300 client: imp tests commit 7e6d17158a254aa29bf4033fb68171d4209bb954 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed May 8 17:27:00 2024 +0300 client: imp tests commit 5e4cd2b3ca9557929b9b79a0610151ce09c792f9 Merge: 7faddd8aa1a62ce471Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed May 8 15:57:33 2024 +0300 Merge branch 'master' into AG-27492-client-persistent-list commit 7faddd8aade2b1b791beec694b88513b0a2a520e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 6 20:55:43 2024 +0300 client: imp code commit 54212e975b700f792a53fc3bfe1c2970778e05ea Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 6 20:24:18 2024 +0300 all: imp code commit 3f23c9af470036c2166e20c8d0b5d84810b35b6e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 6 17:07:40 2024 +0300 home: imp tests commit 39b99fc050047cebadc51ae64e220ec1cb873d83 Merge: 76469ac5917c4eeb64Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 6 16:39:56 2024 +0300 Merge branch 'master' into AG-27492-client-persistent-list commit 76469ac59400aae2f7563750a981138b8cbf3aa1 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon May 6 14:36:22 2024 +0300 home: imp naming commit 4e4aa5802c9aafc67c52b8a290d8046531f8a1c8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu May 2 19:50:45 2024 +0300 client: imp docs commit bf5c23a72c93e58c8bc7e0ca896b2ea28519cf54 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu May 2 19:40:53 2024 +0300 home: add tests commit c6cdba7a8d0dfce22634f88258f61abb09ecca5a Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Apr 24 14:21:44 2024 +0300 all: add tests commit 1fc43cb45efbd428abaae9eba030f9bea818dfe3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 19 19:19:48 2024 +0300 all: add tests commit ccc423b296d9037f0aa23a125a5ad3af95b8c9f3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 19 15:37:15 2024 +0300 all: client persistent list
This commit is contained in:
@@ -96,10 +96,12 @@ func (clients *clientsContainer) handleGetClients(w http.ResponseWriter, r *http
|
||||
clients.lock.Lock()
|
||||
defer clients.lock.Unlock()
|
||||
|
||||
for _, c := range clients.list {
|
||||
clients.clientIndex.Range(func(c *client.Persistent) (cont bool) {
|
||||
cj := clientToJSON(c)
|
||||
data.Clients = append(data.Clients, cj)
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
clients.runtimeIndex.Range(func(rc *client.Runtime) (cont bool) {
|
||||
src, host := rc.Info()
|
||||
@@ -334,20 +336,16 @@ func (clients *clientsContainer) handleAddClient(w http.ResponseWriter, r *http.
|
||||
return
|
||||
}
|
||||
|
||||
ok, err := clients.add(c)
|
||||
err = clients.add(c)
|
||||
if err != nil {
|
||||
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if !ok {
|
||||
aghhttp.Error(r, w, http.StatusBadRequest, "Client already exists")
|
||||
|
||||
return
|
||||
if !clients.testing {
|
||||
onConfigModified()
|
||||
}
|
||||
|
||||
onConfigModified()
|
||||
}
|
||||
|
||||
// handleDelClient is the handler for POST /control/clients/delete HTTP API.
|
||||
@@ -372,7 +370,9 @@ func (clients *clientsContainer) handleDelClient(w http.ResponseWriter, r *http.
|
||||
return
|
||||
}
|
||||
|
||||
onConfigModified()
|
||||
if !clients.testing {
|
||||
onConfigModified()
|
||||
}
|
||||
}
|
||||
|
||||
// updateJSON contains the name and data of the updated persistent client.
|
||||
@@ -406,7 +406,7 @@ func (clients *clientsContainer) handleUpdateClient(w http.ResponseWriter, r *ht
|
||||
clients.lock.Lock()
|
||||
defer clients.lock.Unlock()
|
||||
|
||||
prev, ok = clients.list[dj.Name]
|
||||
prev, ok = clients.clientIndex.FindByName(dj.Name)
|
||||
}()
|
||||
|
||||
if !ok {
|
||||
@@ -429,7 +429,9 @@ func (clients *clientsContainer) handleUpdateClient(w http.ResponseWriter, r *ht
|
||||
return
|
||||
}
|
||||
|
||||
onConfigModified()
|
||||
if !clients.testing {
|
||||
onConfigModified()
|
||||
}
|
||||
}
|
||||
|
||||
// handleFindClient is the handler for GET /control/clients/find HTTP API.
|
||||
@@ -449,7 +451,7 @@ func (clients *clientsContainer) handleFindClient(w http.ResponseWriter, r *http
|
||||
cj = clients.findRuntime(ip, idStr)
|
||||
} else {
|
||||
cj = clientToJSON(c)
|
||||
disallowed, rule := clients.dnsServer.IsBlockedClient(ip, idStr)
|
||||
disallowed, rule := clients.clientChecker.IsBlockedClient(ip, idStr)
|
||||
cj.Disallowed, cj.DisallowedRule = &disallowed, &rule
|
||||
}
|
||||
|
||||
@@ -472,7 +474,7 @@ func (clients *clientsContainer) findRuntime(ip netip.Addr, idStr string) (cj *c
|
||||
// blocked IP list.
|
||||
//
|
||||
// See https://github.com/AdguardTeam/AdGuardHome/issues/2428.
|
||||
disallowed, rule := clients.dnsServer.IsBlockedClient(ip, idStr)
|
||||
disallowed, rule := clients.clientChecker.IsBlockedClient(ip, idStr)
|
||||
cj = &clientJSON{
|
||||
IDs: []string{idStr},
|
||||
Disallowed: &disallowed,
|
||||
@@ -490,7 +492,7 @@ func (clients *clientsContainer) findRuntime(ip netip.Addr, idStr string) (cj *c
|
||||
WHOIS: whoisOrEmpty(rc),
|
||||
}
|
||||
|
||||
disallowed, rule := clients.dnsServer.IsBlockedClient(ip, idStr)
|
||||
disallowed, rule := clients.clientChecker.IsBlockedClient(ip, idStr)
|
||||
cj.Disallowed, cj.DisallowedRule = &disallowed, &rule
|
||||
|
||||
return cj
|
||||
|
||||
Reference in New Issue
Block a user