diff --git a/.env.example b/.env.example index 9c74d34..44c4f72 100644 --- a/.env.example +++ b/.env.example @@ -2,7 +2,6 @@ MONGO_URI=mongodb://127.0.0.1:27017 MONGO_DB=meowerserver REDIS_URI=redis://127.0.0.1:6379/0 REAL_IP_HEADER= -IPHUB_KEY= CL3_HOST="0.0.0.0" CL3_PORT=3000 API_HOST="0.0.0.0" diff --git a/rest_api/v0/emojis.py b/rest_api/v0/emojis.py index d7ac037..da0bd97 100644 --- a/rest_api/v0/emojis.py +++ b/rest_api/v0/emojis.py @@ -16,6 +16,6 @@ @emojis_bp.get("/") async def get_default_emojis(lang: str): if lang in DEFAULT_EMOJIS: - return DEFAULT_EMOJIS[lang], 200 + return {"error": False, "groups": DEFAULT_EMOJIS[lang]}, 200 else: abort(404) diff --git a/security.py b/security.py index 6f5db22..e6799c5 100644 --- a/security.py +++ b/security.py @@ -423,7 +423,7 @@ def delete_account(username, purge=False): def get_netinfo(ip_address): """ - Get IP info from IPHub. + Get IP info from IP-API. Returns: ```json @@ -441,21 +441,23 @@ def get_netinfo(ip_address): # Get IP hash ip_hash = sha256(ip_address.encode()).hexdigest() - # Get from database or IPHub if not cached + # Get from database or IP-API if not cached netinfo = db.netinfo.find_one({"_id": ip_hash}) if not netinfo: - iphub_key = os.getenv("IPHUB_KEY") - if iphub_key: - iphub_info = requests.get(f"http://v2.api.iphub.info/ip/{ip_address}", headers={ - "X-Key": iphub_key - }).json() + resp = requests.get(f"http://ip-api.com/json/{ip_address}?fields=25349915") + if resp.ok: + resp_json = resp.json() netinfo = { "_id": ip_hash, - "country_code": iphub_info["countryCode"], - "country_name": iphub_info["countryName"], - "asn": iphub_info["asn"], - "isp": iphub_info["isp"], - "vpn": (iphub_info["block"] == 1), + "country_code": resp_json["countryCode"], + "country_name": resp_json["country"], + "region": resp_json["regionName"], + "city": resp_json["city"], + "timezone": resp_json["timezone"], + "currency": resp_json["currency"], + "as": resp_json["as"], + "isp": resp_json["isp"], + "vpn": (resp_json.get("hosting") or resp_json.get("proxy")), "last_refreshed": int(time.time()) } db.netinfo.update_one({"_id": ip_hash}, {"$set": netinfo}, upsert=True) @@ -464,7 +466,11 @@ def get_netinfo(ip_address): "_id": ip_hash, "country_code": "Unknown", "country_name": "Unknown", - "asn": "Unknown", + "region": "Unknown", + "city": "Unknown", + "timezone": "Unknown", + "currency": "Unknown", + "as": "Unknown", "isp": "Unknown", "vpn": False, "last_refreshed": int(time.time())