GmailTrust commited on
Commit
b0f0c9e
·
verified ·
1 Parent(s): c78753a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -40
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
- # Tải danh sách key từ nhiều biến môi trường
17
- VALID_KEYS = set()
18
- for i in range(1, 11): # Giả sử chia thành 10 phần, mỗi phần 1,000 key
19
- key_part = os.getenv(f"ZGM_VALID_KEYS_{i}")
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
- # Danh sách dịch vụ cố định
29
- SERVICES = [
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 xác thực và xóa key (chỉ xóa khi thuê thành công)
 
 
 
 
 
 
 
 
 
 
85
  def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
86
- if len(VALID_KEYS) == 0:
87
- return False, "Hết key! Vui lòng liên hệ quản trị viên để tạo thêm key."
88
-
89
- if access_key not in VALID_KEYS:
 
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 khi API trả về code 200 và có dữ liệu hợp lệ
93
  if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
94
- VALID_KEYS.remove(access_key)
95
- # Cập nhật lại các biến môi trường (chia nhỏ để tránh vượt giới hạn)
96
- keys_list = list(VALID_KEYS)
97
- chunk_size = 1000 # Mỗi phần 1,000 key
98
- for i in range(1, 11):
99
- start = (i - 1) * chunk_size
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()