MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / check

Method check

core/api_views.py:162–203  ·  view source on GitHub ↗
(self, request, *args, **kwargs)

Source from the content-addressed store, hash-verified

160 return response
161 @action(detail=False, methods=["post"], url_path="check")
162 def check(self, request, *args, **kwargs):
163 data = request.data
164
165 if data.get("key") == NETWORK_ACCESS_KEY:
166 client_ip = ipaddress.ip_address(get_client_ip(request))
167
168 in_network = {}
169 invalid = []
170
171 value = data.get("value", {})
172 for key, val in value.items():
173 in_network[key] = []
174 cidrs = val.split(",")
175 for cidr in cidrs:
176 try:
177 network = ipaddress.ip_network(cidr)
178
179 if client_ip in network:
180 in_network[key] = []
181 break
182
183 in_network[key].append(cidr)
184 except:
185 invalid.append(cidr)
186
187 if len(invalid) > 0:
188 return Response(
189 {
190 "error": True,
191 "message": "Invalid CIDR(s)",
192 "data": invalid,
193 },
194 status=status.HTTP_200_OK,
195 )
196
197 response_data = {
198 **in_network,
199 "client_ip": str(client_ip)
200 }
201 return Response(response_data, status=status.HTTP_200_OK)
202
203 return Response({}, status=status.HTTP_200_OK)
204
205class ProxySettingsViewSet(viewsets.ViewSet):
206 """

Callers

nothing calls this directly

Calls 2

get_client_ipFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected