generated from nationalarchives/django-application-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,045 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
import json | ||
from typing import Optional | ||
from app.lib.api import BaseAPI | ||
from django.conf import settings | ||
from typing import Optional | ||
|
||
class DeliveryOptionsAPI(BaseAPI): | ||
def __init__(self): | ||
super().__init__(settings.DELIVERY_OPTIONS_CLIENT_BASE_URL) | ||
|
||
|
||
def get_delivery_option(iaid: Optional[str] = None): | ||
do_api = DeliveryOptionsAPI() | ||
|
||
do_api.add_parameter("iaid", iaid) | ||
do_api.api_path = "" | ||
|
||
return do_api.get_results() | ||
return do_api.get_results() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import ipaddress | ||
from typing import List | ||
|
||
from django.http import HttpRequest | ||
|
||
IP_STAFFIN_RANGES = [ | ||
{"Address": "172.31.8.0/22", "Description": "Front-end Web servers"}, | ||
{ | ||
"Address": "10.96.0.0/13", | ||
"Description": "UPTOS servers- all NA- servers", | ||
}, | ||
{ | ||
"Address": "10.104.0.0/13", | ||
"Description": "Staff Edge User Access", | ||
}, | ||
{ | ||
"Address": "10.95.48.0/24", | ||
"Description": "TNA WVD", | ||
}, | ||
{ | ||
"Address": "172.31.0.0/21", | ||
"Description": "BIA Excluding web servers and load balanced services", | ||
}, | ||
{ | ||
"Address": "10.252.16.0/21", | ||
"Description": "Staff Remote Access", | ||
}, | ||
{ | ||
"Address": "10.252.21.0/24", | ||
"Description": "F5 VPN Staff Remote Access", | ||
}, | ||
{ | ||
"Address": "10.114.1.0/24", | ||
"Description": "F5 BIG-IP", | ||
}, | ||
] | ||
|
||
IP_ONSITE_RANGES = [ | ||
{ | ||
"Address": "10.136.0.0/19", | ||
"Description": "Public reading rooms device (Thin clients and PCs) VLAN", | ||
}, | ||
{ | ||
"Address": "167.98.93.94/32", | ||
"Description": "Public Wi-Fi", | ||
}, | ||
{ | ||
"Address": "10.120.0.0/13", | ||
"Description": "Public Edge User Access", | ||
}, | ||
{ | ||
"Address": "10.112.0.0/13", | ||
"Description": "Untrusted servers- all WB- servers ( including reading rooms thin client pcs incl staff and public wifi)", | ||
}, | ||
] | ||
|
||
|
||
def get_client_ip(request: HttpRequest) -> str: | ||
x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR") | ||
if x_forwarded_for: | ||
ip = x_forwarded_for.split(",")[0] | ||
else: | ||
ip = request.META.get("REMOTE_ADDR") | ||
return ip | ||
|
||
|
||
def is_ip_in_cidr(ip: str, cidr: list[dict]) -> bool: | ||
try: | ||
# Parse the IP address | ||
ip_obj = ipaddress.ip_address(ip) | ||
|
||
# Parse the CIDR range | ||
for cidr_obj in cidr: | ||
network = ipaddress.ip_network(cidr_obj["Address"], strict=False) | ||
|
||
if ip_obj in network: | ||
return True | ||
|
||
# Check if the IP address is in the network | ||
return False | ||
except ValueError as e: | ||
raise ValueError(f"Invalid IP or CIDR: {e}") |
Oops, something went wrong.