Skip to content

Commit

Permalink
fixed crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Foroxon committed Dec 17, 2024
1 parent 04a7c17 commit 91ccded
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions deploy/websocket_server/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def bin_sort(bin):


async def alerts_data(websocket, client, shared_data, alert_version):
client_ip = websocket.request_headers["CF-Connecting-IP"] or websocket.remote_address[0]
client_ip = websocket.request_headers.get("CF-Connecting-IP", websocket.remote_address[0])
while True:
if client["firmware"] == "unknown":
await asyncio.sleep(0.1)
Expand Down Expand Up @@ -197,30 +197,30 @@ def send_google_stat(tracker, event):
async def echo(websocket, path):
client_port = websocket.remote_address[1]
# get real header from websocket
client_ip = websocket.request_headers["CF-Connecting-IP"] or websocket.remote_address[0]
client_ip = websocket.request_headers.get("CF-Connecting-IP", websocket.remote_address[0])
logger.info(f"{client_ip}:{client_port} >>> new client")

if client_ip in shared_data.blocked_ips:
logger.warning(f"{client_ip}:{client_port} !!! BLOCKED")
return

country = websocket.request_headers["cf-ipcountry"]
region = websocket.request_headers["cf-region"]
city = websocket.request_headers["cf-ipcity"]
timezone = websocket.request_headers["cf-timezone"]
country = websocket.request_headers.get("cf-ipcountry", None)
region = websocket.request_headers.get("cf-region", None)
city = websocket.request_headers.get("cf-ipcity", None)
timezone = websocket.request_headers.get("cf-timezone", None)

if not country or not region or not city or not timezone:
try:
response = geo.city(client_ip)
city = response.city.name or "not-in-db"
region = response.subdivisions.most_specific.name or "not-in-db"
country = response.country.iso_code or "not-in-db"
timezone = response.location.time_zone or "not-in-db"
city = city or response.city.name or "not-in-db"
region = region or response.subdivisions.most_specific.name or "not-in-db"
country = country or response.country.iso_code or "not-in-db"
timezone = timezone or response.location.time_zone or "not-in-db"
except errors.AddressNotFoundError:
city = "not-found"
region = "not-found"
country = "not-found"
timezone = "not-found"
city = city or "not-found"
region = region or "not-found"
country = country or "not-found"
timezone = timezone or "not-found"

# if response.country.iso_code != 'UA' and response.continent.code != 'EU':
# shared_data.blocked_ips.append(client_ip)
Expand Down

0 comments on commit 91ccded

Please sign in to comment.