Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,23 +13,13 @@ ZGM_API_TOKEN = os.getenv("ZGM_API_TOKEN")
|
|
| 13 |
if not ZGM_API_TOKEN:
|
| 14 |
raise ValueError("ZGM_API_TOKEN không được tìm thấy trong biến môi trường!")
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if key_part:
|
| 21 |
-
try:
|
| 22 |
-
VALID_KEYS.update(json.loads(key_part))
|
| 23 |
-
except json.JSONDecodeError:
|
| 24 |
-
raise ValueError(f"ZGM_VALID_KEYS_{i} không phải là chuỗi JSON hợp lệ!")
|
| 25 |
-
if not VALID_KEYS:
|
| 26 |
-
raise ValueError("Không tìm thấy key nào trong biến môi trường!")
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
"ICLOUD", "ZSK", "FACEBOOK", "TELEGRAM", "OTHERS",
|
| 31 |
-
"GGPLAY", "INSTAGRAM", "FMCPAY", "AMAZON"
|
| 32 |
-
]
|
| 33 |
|
| 34 |
class ZGMApiClient:
|
| 35 |
"""Lớp client để tương tác với ZGM API"""
|
|
@@ -81,33 +71,33 @@ class ZGMApiClient:
|
|
| 81 |
# Khởi tạo client
|
| 82 |
client = ZGMApiClient("https://gm.haivl.wtf", ZGM_API_TOKEN)
|
| 83 |
|
| 84 |
-
# Hàm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 90 |
return False, "Key không hợp lệ! Vui lòng nhập key hợp lệ để tiếp tục."
|
| 91 |
|
| 92 |
-
# Chỉ xóa key
|
| 93 |
if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
end = i * chunk_size
|
| 101 |
-
chunk = keys_list[start:end]
|
| 102 |
-
if chunk:
|
| 103 |
-
os.environ[f"ZGM_VALID_KEYS_{i}"] = json.dumps(chunk)
|
| 104 |
-
else:
|
| 105 |
-
os.environ.pop(f"ZGM_VALID_KEYS_{i}", None)
|
| 106 |
-
remaining_keys = len(VALID_KEYS)
|
| 107 |
-
warning = f"\nCòn lại {remaining_keys} key."
|
| 108 |
-
if remaining_keys < 100:
|
| 109 |
-
warning += " Số lượng key còn ít! Vui lòng tạo thêm key mới."
|
| 110 |
-
return True, warning
|
| 111 |
else:
|
| 112 |
return True, f"Lỗi: {result.get('message', 'Không thể thuê Gmail.')}\nKey không bị xóa."
|
| 113 |
|
|
@@ -219,6 +209,12 @@ def gradio_interface(access_key, action, service, order_id, rent_otp_log, get_ot
|
|
| 219 |
else:
|
| 220 |
return rent_otp_log, get_otp_log, "Hành động không hợp lệ!", order_id
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
# Tạo giao diện Gradio
|
| 223 |
with gr.Blocks() as demo:
|
| 224 |
gr.Markdown("## ZGM API Client - Nhập Key để Thuê OTP (Key chỉ cần thiết cho Thuê OTP, mỗi key dùng 1 lần)")
|
|
@@ -271,4 +267,4 @@ with gr.Blocks() as demo:
|
|
| 271 |
)
|
| 272 |
|
| 273 |
# Khởi chạy giao diện
|
| 274 |
-
demo.launch()
|
|
|
|
| 13 |
if not ZGM_API_TOKEN:
|
| 14 |
raise ValueError("ZGM_API_TOKEN không được tìm thấy trong biến môi trường!")
|
| 15 |
|
| 16 |
+
# Lấy địa chỉ IP của VPS từ Secrets
|
| 17 |
+
VPS_IP = os.getenv("VPS_IP")
|
| 18 |
+
if not VPS_IP:
|
| 19 |
+
raise ValueError("VPS_IP không được tìm thấy trong biến môi trường!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# URL của API trên VPS (dùng port 3000)
|
| 22 |
+
KEY_API_URL = f"http://{VPS_IP}:3000"
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
class ZGMApiClient:
|
| 25 |
"""Lớp client để tương tác với ZGM API"""
|
|
|
|
| 71 |
# Khởi tạo client
|
| 72 |
client = ZGMApiClient("https://gm.haivl.wtf", ZGM_API_TOKEN)
|
| 73 |
|
| 74 |
+
# Hàm lấy key từ API trên VPS
|
| 75 |
+
def get_key_from_api() -> tuple[Optional[str], str]:
|
| 76 |
+
try:
|
| 77 |
+
response = requests.get(f"{KEY_API_URL}/api/keys/get", timeout=5)
|
| 78 |
+
response.raise_for_status()
|
| 79 |
+
data = response.json()
|
| 80 |
+
return data["key"], f"Còn lại {data['remaining']} key."
|
| 81 |
+
except requests.exceptions.RequestException as e:
|
| 82 |
+
return None, f"Lỗi khi lấy key từ API: {str(e)}"
|
| 83 |
+
|
| 84 |
+
# Hàm xác thực và xóa key (gọi API trên VPS)
|
| 85 |
def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
|
| 86 |
+
# Kiểm tra key có hợp lệ không (gọi API để lấy key và so sánh)
|
| 87 |
+
key_from_api, message = get_key_from_api()
|
| 88 |
+
if not key_from_api:
|
| 89 |
+
return False, message
|
| 90 |
+
if access_key != key_from_api:
|
| 91 |
return False, "Key không hợp lệ! Vui lòng nhập key hợp lệ để tiếp tục."
|
| 92 |
|
| 93 |
+
# Chỉ xóa key trên VPS khi thuê thành công (đã gọi API xóa trong get_key_from_api)
|
| 94 |
if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
|
| 95 |
+
remaining_message = message
|
| 96 |
+
if "Còn lại" in message:
|
| 97 |
+
remaining_keys = int(message.split("Còn lại ")[1].split(" key")[0])
|
| 98 |
+
if remaining_keys < 100:
|
| 99 |
+
remaining_message += " Số lượng key còn ít! Vui lòng tạo thêm key mới."
|
| 100 |
+
return True, remaining_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
else:
|
| 102 |
return True, f"Lỗi: {result.get('message', 'Không thể thuê Gmail.')}\nKey không bị xóa."
|
| 103 |
|
|
|
|
| 209 |
else:
|
| 210 |
return rent_otp_log, get_otp_log, "Hành động không hợp lệ!", order_id
|
| 211 |
|
| 212 |
+
# Danh sách dịch vụ cố định
|
| 213 |
+
SERVICES = [
|
| 214 |
+
"ICLOUD", "ZSK", "FACEBOOK", "TELEGRAM", "OTHERS",
|
| 215 |
+
"GGPLAY", "INSTAGRAM", "FMCPAY", "AMAZON"
|
| 216 |
+
]
|
| 217 |
+
|
| 218 |
# Tạo giao diện Gradio
|
| 219 |
with gr.Blocks() as demo:
|
| 220 |
gr.Markdown("## ZGM API Client - Nhập Key để Thuê OTP (Key chỉ cần thiết cho Thuê OTP, mỗi key dùng 1 lần)")
|
|
|
|
| 267 |
)
|
| 268 |
|
| 269 |
# Khởi chạy giao diện
|
| 270 |
+
demo.launch()
|