Spaces:
Sleeping
Sleeping
Fix encryption: support direct RSA-OAEP and hybrid RSA+AES-GCM modes
Browse files- app.py +22 -0
- models.py +2 -0
- templates/index.html +4 -2
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import logging
|
|
| 8 |
from contextlib import asynccontextmanager
|
| 9 |
from typing import Optional, Tuple
|
| 10 |
|
|
|
|
| 11 |
import httpx
|
| 12 |
from fastapi import FastAPI, Query, Request, Depends, HTTPException, status
|
| 13 |
from fastapi.middleware.cors import CORSMiddleware
|
|
@@ -158,6 +159,8 @@ async def get_data(
|
|
| 158 |
"user_id": item.user_id,
|
| 159 |
"refer_url": item.refer_url,
|
| 160 |
"ip_address": item.ip_address,
|
|
|
|
|
|
|
| 161 |
"country": item.country,
|
| 162 |
"region": item.region,
|
| 163 |
"json_data": item.json_data,
|
|
@@ -242,6 +245,21 @@ async def blink(
|
|
| 242 |
# Get geolocation from IP address
|
| 243 |
country, region = await get_geolocation(ip_address)
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
# Store each decrypted result as separate records
|
| 246 |
records_created = 0
|
| 247 |
for json_data in decrypted_results:
|
|
@@ -249,6 +267,8 @@ async def blink(
|
|
| 249 |
user_id=user_id,
|
| 250 |
refer_url=refer_url,
|
| 251 |
ip_address=ip_address,
|
|
|
|
|
|
|
| 252 |
country=country,
|
| 253 |
region=region,
|
| 254 |
json_data=json_data
|
|
@@ -262,6 +282,8 @@ async def blink(
|
|
| 262 |
user_id=user_id,
|
| 263 |
refer_url=refer_url,
|
| 264 |
ip_address=ip_address,
|
|
|
|
|
|
|
| 265 |
country=country,
|
| 266 |
region=region,
|
| 267 |
json_data={"encrypted_length": len(encrypted_data)}
|
|
|
|
| 8 |
from contextlib import asynccontextmanager
|
| 9 |
from typing import Optional, Tuple
|
| 10 |
|
| 11 |
+
import ipaddress
|
| 12 |
import httpx
|
| 13 |
from fastapi import FastAPI, Query, Request, Depends, HTTPException, status
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 159 |
"user_id": item.user_id,
|
| 160 |
"refer_url": item.refer_url,
|
| 161 |
"ip_address": item.ip_address,
|
| 162 |
+
"ipv4_address": item.ipv4_address,
|
| 163 |
+
"ipv6_address": item.ipv6_address,
|
| 164 |
"country": item.country,
|
| 165 |
"region": item.region,
|
| 166 |
"json_data": item.json_data,
|
|
|
|
| 245 |
# Get geolocation from IP address
|
| 246 |
country, region = await get_geolocation(ip_address)
|
| 247 |
|
| 248 |
+
# Determine IPv4 vs IPv6
|
| 249 |
+
ipv4_address = None
|
| 250 |
+
ipv6_address = None
|
| 251 |
+
|
| 252 |
+
if ip_address:
|
| 253 |
+
try:
|
| 254 |
+
ip_obj = ipaddress.ip_address(ip_address)
|
| 255 |
+
if isinstance(ip_obj, ipaddress.IPv4Address):
|
| 256 |
+
ipv4_address = ip_address
|
| 257 |
+
elif isinstance(ip_obj, ipaddress.IPv6Address):
|
| 258 |
+
ipv6_address = ip_address
|
| 259 |
+
except ValueError:
|
| 260 |
+
# Invalid IP address format, just keep it in ip_address
|
| 261 |
+
pass
|
| 262 |
+
|
| 263 |
# Store each decrypted result as separate records
|
| 264 |
records_created = 0
|
| 265 |
for json_data in decrypted_results:
|
|
|
|
| 267 |
user_id=user_id,
|
| 268 |
refer_url=refer_url,
|
| 269 |
ip_address=ip_address,
|
| 270 |
+
ipv4_address=ipv4_address,
|
| 271 |
+
ipv6_address=ipv6_address,
|
| 272 |
country=country,
|
| 273 |
region=region,
|
| 274 |
json_data=json_data
|
|
|
|
| 282 |
user_id=user_id,
|
| 283 |
refer_url=refer_url,
|
| 284 |
ip_address=ip_address,
|
| 285 |
+
ipv4_address=ipv4_address,
|
| 286 |
+
ipv6_address=ipv6_address,
|
| 287 |
country=country,
|
| 288 |
region=region,
|
| 289 |
json_data={"encrypted_length": len(encrypted_data)}
|
models.py
CHANGED
|
@@ -23,6 +23,8 @@ class BlinkData(Base):
|
|
| 23 |
user_id = Column(String(20), index=True, nullable=False)
|
| 24 |
refer_url = Column(Text, nullable=True)
|
| 25 |
ip_address = Column(String(45), nullable=True) # IPv6 can be up to 45 chars
|
|
|
|
|
|
|
| 26 |
country = Column(String(100), nullable=True) # Country from IP geolocation
|
| 27 |
region = Column(String(100), nullable=True) # Region/State from IP geolocation
|
| 28 |
json_data = Column(JSON, nullable=True)
|
|
|
|
| 23 |
user_id = Column(String(20), index=True, nullable=False)
|
| 24 |
refer_url = Column(Text, nullable=True)
|
| 25 |
ip_address = Column(String(45), nullable=True) # IPv6 can be up to 45 chars
|
| 26 |
+
ipv4_address = Column(String(15), nullable=True)
|
| 27 |
+
ipv6_address = Column(String(45), nullable=True)
|
| 28 |
country = Column(String(100), nullable=True) # Country from IP geolocation
|
| 29 |
region = Column(String(100), nullable=True) # Region/State from IP geolocation
|
| 30 |
json_data = Column(JSON, nullable=True)
|
templates/index.html
CHANGED
|
@@ -232,7 +232,8 @@
|
|
| 232 |
<th>ID</th>
|
| 233 |
<th>User ID</th>
|
| 234 |
<th>Refer URL</th>
|
| 235 |
-
<th>
|
|
|
|
| 236 |
<th>Country</th>
|
| 237 |
<th>Region</th>
|
| 238 |
<th>JSON Data</th>
|
|
@@ -298,7 +299,8 @@
|
|
| 298 |
<td>${item.id}</td>
|
| 299 |
<td class="user-id">${item.user_id}</td>
|
| 300 |
<td class="refer-url" title="${item.refer_url || ''}">${item.refer_url || '-'}</td>
|
| 301 |
-
<td class="ip-address">${item.
|
|
|
|
| 302 |
<td>${item.country || '-'}</td>
|
| 303 |
<td>${item.region || '-'}</td>
|
| 304 |
<td><pre class="json-data">${JSON.stringify(item.json_data, null, 2)}</pre></td>
|
|
|
|
| 232 |
<th>ID</th>
|
| 233 |
<th>User ID</th>
|
| 234 |
<th>Refer URL</th>
|
| 235 |
+
<th>IPv4</th>
|
| 236 |
+
<th>IPv6</th>
|
| 237 |
<th>Country</th>
|
| 238 |
<th>Region</th>
|
| 239 |
<th>JSON Data</th>
|
|
|
|
| 299 |
<td>${item.id}</td>
|
| 300 |
<td class="user-id">${item.user_id}</td>
|
| 301 |
<td class="refer-url" title="${item.refer_url || ''}">${item.refer_url || '-'}</td>
|
| 302 |
+
<td class="ip-address">${item.ipv4_address || '-'}</td>
|
| 303 |
+
<td class="ip-address">${item.ipv6_address || '-'}</td>
|
| 304 |
<td>${item.country || '-'}</td>
|
| 305 |
<td>${item.region || '-'}</td>
|
| 306 |
<td><pre class="json-data">${JSON.stringify(item.json_data, null, 2)}</pre></td>
|