chanraphone4 commited on
Commit
f19de2b
Β·
verified Β·
1 Parent(s): 9dd42af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -60
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import os
2
  import json
3
- import random
4
  import shutil
5
  import logging
6
  import requests
@@ -9,22 +8,21 @@ import gradio as gr
9
  from selenium import webdriver
10
  from selenium.webdriver.chrome.service import Service
11
  from selenium.webdriver.chrome.options import Options
12
- from webdriver_manager.chrome import ChromeDriverManager
13
  from fake_useragent import UserAgent
14
  from selenium.webdriver.common.by import By
15
 
16
- # --- αž€αžΆαžšαž€αŸ†αžŽαžαŸ‹αž˜αžΌαž›αžŠαŸ’αž‹αžΆαž“ (Configurations) ---
17
- CONFIG_FILE = "CONFIG.JSON"
18
- active_drivers = {} # αžšαž€αŸ’αžŸαžΆαž‘αž»αž€ Chrome αžŠαŸ‚αž›αž€αŸ†αž–αž»αž„αž”αžΎαž€
19
 
20
  def load_config():
21
  if not os.path.exists(CONFIG_FILE):
22
  default = {
23
- "profile_path": os.path.join(os.path.expanduser("~"), "Documents", "Chrome_Profiles"),
24
- "max_threads": 2,
25
  "device_presets": [
26
- {"name": "Samsung Galaxy S21", "ua": "Mozilla/5.0 (Linux; Android 12; SM-G998B)...", "size": "360,800"},
27
- {"name": "Desktop Windows", "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)...", "size": "1920,1080"}
 
28
  ]
29
  }
30
  with open(CONFIG_FILE, "w") as f: json.dump(default, f, indent=4)
@@ -35,16 +33,11 @@ config = load_config()
35
  PROFILE_PATH = config["profile_path"]
36
  if not os.path.exists(PROFILE_PATH): os.makedirs(PROFILE_PATH)
37
 
38
- # --- αž˜αž»αžαž„αžΆαžšαž‡αŸ†αž“αž½αž™ (Helper Functions) ---
39
-
40
- def get_location_from_ip(ip):
41
- try:
42
- response = requests.get(f"https://freegeoip.app/json/{ip}", timeout=5)
43
- return response.json()
44
- except: return None
45
 
46
  def get_profile_list():
47
- """ αž‘αžΆαž‰αž™αž€αž”αž‰αŸ’αž‡αžΈ Profile αžŠαžΎαž˜αŸ’αž”αžΈαž”αž„αŸ’αž αžΆαž‰αž€αŸ’αž“αž»αž„αžαžΆαžšαžΆαž„ """
 
48
  profiles = [d for d in os.listdir(PROFILE_PATH) if os.path.isdir(os.path.join(PROFILE_PATH, d))]
49
  rows = []
50
  for p in profiles:
@@ -60,12 +53,10 @@ def get_profile_list():
60
  rows.append([status, p, uid, device, note])
61
  return pd.DataFrame(rows, columns=["Status", "Name", "UID", "Device", "Note"])
62
 
63
- # --- αž˜αž»αžαž„αžΆαžšαž…αž˜αŸ’αž”αž„ (Main Logic) ---
64
-
65
  def create_profile(name, uid, note, pwd, tfa, email, device_idx, lat, lon):
66
- if not name: return "αžˆαŸ’αž˜αŸ„αŸ‡αž˜αž·αž“αž’αžΆαž…αž‘αž‘αŸαž”αžΆαž“αž‘αŸ!", get_profile_list()
67
  path = os.path.join(PROFILE_PATH, name)
68
- if os.path.exists(path): return "αžˆαŸ’αž˜αŸ„αŸ‡αž“αŸαŸ‡αž˜αžΆαž“αžšαž½αž…αž αžΎαž™!", get_profile_list()
69
 
70
  os.makedirs(path)
71
  preset = config["device_presets"][device_idx]
@@ -82,105 +73,121 @@ def create_profile(name, uid, note, pwd, tfa, email, device_idx, lat, lon):
82
  with open(os.path.join(path, "profile_config.json"), "w") as f:
83
  json.dump(data, f, indent=4)
84
 
85
- return f"αž”αžΆαž“αž”αž„αŸ’αž€αžΎαž Profile '{name}'!", get_profile_list()
86
 
87
  def open_chrome(name):
88
- if name in active_drivers: return "Chrome αž€αŸ†αž–αž»αž„αž”αžΎαž€αžšαž½αž…αž αžΎαž™!"
 
 
89
  path = os.path.join(PROFILE_PATH, name)
90
  conf_path = os.path.join(path, "profile_config.json")
91
 
92
- if not os.path.exists(conf_path): return "αžšαž€αž˜αž·αž“αžƒαžΎαž‰ Config!"
93
 
94
  with open(conf_path, "r") as f: conf = json.load(f)
95
 
96
  options = Options()
 
 
 
 
 
 
 
97
  options.add_argument(f"user-agent={conf['device_user_agent']}")
98
  options.add_argument(f"--window-size={conf['device_window_size']}")
99
  options.add_argument(f"--user-data-dir={path}")
100
-
101
- # αž”αžΎαž…αž„αŸ‹αž±αŸ’αž™αžŠαžΎαžšαž›αžΎ Server αžαŸ’αžšαžΌαžœαžŠαŸ„αŸ‡ comment αžαžΆαž„αž€αŸ’αžšαŸ„αž˜
102
- # options.add_argument("--headless")
103
 
104
  try:
105
- driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
106
-
107
- # Fake Location
 
 
 
 
 
 
 
108
  if conf.get("latitude") and conf.get("longitude"):
109
  driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
110
  "latitude": conf["latitude"], "longitude": conf["longitude"], "accuracy": 100
111
  })
112
 
113
  active_drivers[name] = driver
114
- driver.get("https://www.google.com")
115
- return f"αž”αžΆαž“αž”αžΎαž€ Profile: {name}"
116
  except Exception as e:
117
- return f"αž€αŸ†αž αž»αžŸ: {str(e)}"
118
 
119
  def close_chrome(name):
120
  if name in active_drivers:
121
- active_drivers[name].quit()
122
- del active_drivers[name]
123
- return f"αž”αžΆαž“αž”αž·αž‘ Profile: {name}"
124
- return "Profile αž“αŸαŸ‡αž˜αž·αž“αž‘αžΆαž“αŸ‹αž”αžΆαž“αž”αžΎαž€αž‘αŸαŸ”"
 
 
125
 
126
  def delete_profile(name):
127
- if name in active_drivers: return "αžŸαžΌαž˜αž”αž·αž‘ Chrome αž‡αžΆαž˜αž»αž“αžŸαž·αž“!"
128
  path = os.path.join(PROFILE_PATH, name)
129
  if os.path.exists(path):
130
  shutil.rmtree(path)
131
- return f"αž”αžΆαž“αž›αž»αž” Profile: {name}", get_profile_list()
132
- return "αžšαž€αž˜αž·αž“αžƒαžΎαž‰ Profile!", get_profile_list()
133
 
134
  # --- Gradio UI Layout ---
135
 
136
- with gr.Blocks(title="Chrome Manager", theme=gr.themes.Default()) as demo:
137
- gr.Markdown("# πŸš€ Chrome Profile Manager (Gradio version)")
138
 
139
  with gr.Tabs():
140
  # TAB 1: αž”αž‰αŸ’αž‡αžΈ Profile
141
- with gr.TabItem("πŸ“‹ Profile List"):
142
  with gr.Row():
143
- refresh_btn = gr.Button("πŸ”„ Refresh Table")
144
- open_btn = gr.Button("🟒 Open Chrome", variant="primary")
145
- close_btn = gr.Button("πŸ”΄ Close Chrome", variant="stop")
146
- del_btn = gr.Button("πŸ—‘οΈ Delete Profile")
147
 
148
  output_log = gr.Textbox(label="Status Log")
149
  table = gr.Dataframe(value=get_profile_list(), interactive=False)
150
- selected_name = gr.Textbox(label="Selected Profile Name (Type or Click below)")
151
 
152
- # Interactions
153
  def on_select(evt: gr.SelectData):
154
  return evt.value if evt.index[1] == 1 else None
155
 
156
  table.select(on_select, None, selected_name)
 
157
  refresh_btn.click(get_profile_list, outputs=table)
158
  open_btn.click(open_chrome, inputs=selected_name, outputs=output_log).then(get_profile_list, outputs=table)
159
  close_btn.click(close_chrome, inputs=selected_name, outputs=output_log).then(get_profile_list, outputs=table)
160
  del_btn.click(delete_profile, inputs=selected_name, outputs=[output_log, table])
161
 
162
  # TAB 2: αž”αž„αŸ’αž€αžΎαž Profile αžαŸ’αž˜αžΈ
163
- with gr.TabItem("βž• Create Profile"):
164
  with gr.Row():
165
- name_in = gr.Textbox(label="Profile Name")
166
- uid_in = gr.Textbox(label="UID (Optional)")
167
  with gr.Row():
168
- note_in = gr.Textbox(label="Note")
169
- pwd_in = gr.Textbox(label="Password")
170
  with gr.Row():
171
  email_in = gr.Textbox(label="Email")
172
- tfa_in = gr.Textbox(label="2FA")
173
 
174
  with gr.Row():
175
  device_in = gr.Dropdown(
176
  choices=[d["name"] for d in config["device_presets"]],
177
- label="Select Device", type="index", value=0
178
  )
179
- lat_in = gr.Textbox(label="Latitude (Fake)")
180
- lon_in = gr.Textbox(label="Longitude (Fake)")
181
 
182
- create_btn = gr.Button("Create Now", variant="primary")
183
- create_msg = gr.Textbox(label="Result")
184
 
185
  create_btn.click(
186
  create_profile,
 
1
  import os
2
  import json
 
3
  import shutil
4
  import logging
5
  import requests
 
8
  from selenium import webdriver
9
  from selenium.webdriver.chrome.service import Service
10
  from selenium.webdriver.chrome.options import Options
 
11
  from fake_useragent import UserAgent
12
  from selenium.webdriver.common.by import By
13
 
14
+ # --- αž€αŸ†αžŽαžαŸ‹αž…αŸ†αžŽαžΆαŸ† αž“αž·αž„αž€αžΆαžšαž€αŸ†αžŽαžαŸ‹ (Setup) ---
15
+ CONFIG_FILE = "CONFIG_GRADIO.JSON"
16
+ active_drivers = {} # αžŸαž˜αŸ’αžšαžΆαž”αŸ‹αž•αŸ’αž‘αž»αž€ Driver αžŠαŸ‚αž›αž€αŸ†αž–αž»αž„αžŠαŸ†αžŽαžΎαžšαž€αžΆαžš
17
 
18
  def load_config():
19
  if not os.path.exists(CONFIG_FILE):
20
  default = {
21
+ "profile_path": os.path.join(os.getcwd(), "Chrome_Profiles"),
 
22
  "device_presets": [
23
+ {"name": "Desktop Windows", "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "size": "1920,1080"},
24
+ {"name": "Samsung Galaxy S21", "ua": "Mozilla/5.0 (Linux; Android 12; SM-G998B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36", "size": "360,800"},
25
+ {"name": "iPhone 14 Pro", "ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1", "size": "393,852"}
26
  ]
27
  }
28
  with open(CONFIG_FILE, "w") as f: json.dump(default, f, indent=4)
 
33
  PROFILE_PATH = config["profile_path"]
34
  if not os.path.exists(PROFILE_PATH): os.makedirs(PROFILE_PATH)
35
 
36
+ # --- αž˜αž»αžαž„αžΆαžš Logic ---
 
 
 
 
 
 
37
 
38
  def get_profile_list():
39
+ """ αž”αž„αŸ’αž αžΆαž‰αž”αž‰αŸ’αž‡αžΈ Profile αž€αŸ’αž“αž»αž„αžαžΆαžšαžΆαž„ """
40
+ if not os.path.exists(PROFILE_PATH): return pd.DataFrame(columns=["Status", "Name", "UID", "Device", "Note"])
41
  profiles = [d for d in os.listdir(PROFILE_PATH) if os.path.isdir(os.path.join(PROFILE_PATH, d))]
42
  rows = []
43
  for p in profiles:
 
53
  rows.append([status, p, uid, device, note])
54
  return pd.DataFrame(rows, columns=["Status", "Name", "UID", "Device", "Note"])
55
 
 
 
56
  def create_profile(name, uid, note, pwd, tfa, email, device_idx, lat, lon):
57
+ if not name: return "⚠️ αžŸαžΌαž˜αž”αž‰αŸ’αž…αžΌαž›αžˆαŸ’αž˜αŸ„αŸ‡!", get_profile_list()
58
  path = os.path.join(PROFILE_PATH, name)
59
+ if os.path.exists(path): return "⚠️ αžˆαŸ’αž˜αŸ„αŸ‡αž“αŸαŸ‡αž˜αžΆαž“αžšαž½αž…αž αžΎαž™!", get_profile_list()
60
 
61
  os.makedirs(path)
62
  preset = config["device_presets"][device_idx]
 
73
  with open(os.path.join(path, "profile_config.json"), "w") as f:
74
  json.dump(data, f, indent=4)
75
 
76
+ return f"βœ… αž”αžΆαž“αž”αž„αŸ’αž€αžΎαž Profile '{name}'!", get_profile_list()
77
 
78
  def open_chrome(name):
79
+ if not name: return "⚠️ αžŸαžΌαž˜αž‡αŸ’αžšαžΎαžŸαžšαžΎαžŸ Profile!"
80
+ if name in active_drivers: return "ℹ️ Profile αž“αŸαŸ‡αž€αŸ†αž–αž»αž„αž”αžΎαž€αžšαž½αž…αž αžΎαž™!"
81
+
82
  path = os.path.join(PROFILE_PATH, name)
83
  conf_path = os.path.join(path, "profile_config.json")
84
 
85
+ if not os.path.exists(conf_path): return "❌ αžšαž€αž˜αž·αž“αžƒαžΎαž‰ Config!"
86
 
87
  with open(conf_path, "r") as f: conf = json.load(f)
88
 
89
  options = Options()
90
+ # αž€αŸ†αžŽαžαŸ‹αž±αŸ’αž™αž”αŸ’αžšαžΎ Chromium αž›αžΎ Server
91
+ if os.path.exists("/usr/bin/chromium"):
92
+ options.binary_location = "/usr/bin/chromium"
93
+
94
+ options.add_argument("--headless") # αžαŸ’αžšαžΌαžœαžαŸ‚αž”αŸ’αžšαžΎαž›αžΎ Server
95
+ options.add_argument("--no-sandbox")
96
+ options.add_argument("--disable-dev-shm-usage")
97
  options.add_argument(f"user-agent={conf['device_user_agent']}")
98
  options.add_argument(f"--window-size={conf['device_window_size']}")
99
  options.add_argument(f"--user-data-dir={path}")
 
 
 
100
 
101
  try:
102
+ # αž”αŸ’αžšαžΎ chromedriver αžŠαŸ‚αž›αž˜αž€αž‡αžΆαž˜αž½αž™ packages.txt
103
+ service_path = "/usr/bin/chromedriver" if os.path.exists("/usr/bin/chromedriver") else None
104
+ if service_path:
105
+ service = Service(executable_path=service_path)
106
+ driver = webdriver.Chrome(service=service, options=options)
107
+ else:
108
+ from webdriver_manager.chrome import ChromeDriverManager
109
+ driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
110
+
111
+ # αž€αŸ’αž›αŸ‚αž„αž”αž“αŸ’αž›αŸ†αž‘αžΈαžαžΆαŸ†αž„ (Fake Location)
112
  if conf.get("latitude") and conf.get("longitude"):
113
  driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
114
  "latitude": conf["latitude"], "longitude": conf["longitude"], "accuracy": 100
115
  })
116
 
117
  active_drivers[name] = driver
118
+ driver.get("https://ifconfig.me") # αž”αžΎαž€αž‘αŸ…αžœαŸαž”αžŸαžΆαž™αž†αŸ‚αž€ IP
119
+ return f"βœ… αž”αžΆαž“αž”αžΎαž€ {name} (IP: {driver.find_element(By.TAG_NAME, 'body').text})"
120
  except Exception as e:
121
+ return f"❌ αž€αŸ†αž αž»αžŸ: {str(e)}"
122
 
123
  def close_chrome(name):
124
  if name in active_drivers:
125
+ try:
126
+ active_drivers[name].quit()
127
+ del active_drivers[name]
128
+ return f"βœ… αž”αžΆαž“αž”αž·αž‘ {name}"
129
+ except: return "❌ αž˜αž·αž“αž’αžΆαž…αž”αž·αž‘αž”αžΆαž“αž‘αŸ"
130
+ return "ℹ️ Profile αž“αŸαŸ‡αž˜αž·αž“αž‘αžΆαž“αŸ‹αž”αžΆαž“αž”αžΎαž€αž‘αŸαŸ”"
131
 
132
  def delete_profile(name):
133
+ if name in active_drivers: return "⚠️ αžŸαžΌαž˜αž”αž·αž‘ Chrome αž‡αžΆαž˜αž»αž“αžŸαž·αž“!", get_profile_list()
134
  path = os.path.join(PROFILE_PATH, name)
135
  if os.path.exists(path):
136
  shutil.rmtree(path)
137
+ return f"πŸ—‘οΈ αž”αžΆαž“αž›αž»αž” {name}", get_profile_list()
138
+ return "⚠️ αžšαž€αž˜αž·αž“αžƒαžΎαž‰ Profile!", get_profile_list()
139
 
140
  # --- Gradio UI Layout ---
141
 
142
+ with gr.Blocks(title="Chromium Manager", theme=gr.themes.Soft()) as demo:
143
+ gr.Markdown("# 🌐 Chromium Profile Manager (Cloud Ready)")
144
 
145
  with gr.Tabs():
146
  # TAB 1: αž”αž‰αŸ’αž‡αžΈ Profile
147
+ with gr.TabItem("πŸ“‹ αž”αž‰αŸ’αž‡αžΈ Profile"):
148
  with gr.Row():
149
+ refresh_btn = gr.Button("πŸ”„ Refresh")
150
+ open_btn = gr.Button("🟒 αž”αžΎαž€ Chrome (Headless)", variant="primary")
151
+ close_btn = gr.Button("πŸ”΄ αž”αž·αž‘ Chrome", variant="stop")
152
+ del_btn = gr.Button("πŸ—‘οΈ αž›αž»αž”αž…αŸ„αž›")
153
 
154
  output_log = gr.Textbox(label="Status Log")
155
  table = gr.Dataframe(value=get_profile_list(), interactive=False)
156
+ selected_name = gr.Textbox(label="Profile αžŠαŸ‚αž›αž”αžΆαž“αž‡αŸ’αžšαžΎαžŸαžšαžΎαžŸ")
157
 
158
+ # αž…αžΆαž”αŸ‹αž™αž€αžˆαŸ’αž˜αŸ„αŸ‡αž–αŸαž› Select αž€αŸ’αž“αž»αž„ Table
159
  def on_select(evt: gr.SelectData):
160
  return evt.value if evt.index[1] == 1 else None
161
 
162
  table.select(on_select, None, selected_name)
163
+
164
  refresh_btn.click(get_profile_list, outputs=table)
165
  open_btn.click(open_chrome, inputs=selected_name, outputs=output_log).then(get_profile_list, outputs=table)
166
  close_btn.click(close_chrome, inputs=selected_name, outputs=output_log).then(get_profile_list, outputs=table)
167
  del_btn.click(delete_profile, inputs=selected_name, outputs=[output_log, table])
168
 
169
  # TAB 2: αž”αž„αŸ’αž€αžΎαž Profile αžαŸ’αž˜αžΈ
170
+ with gr.TabItem("βž• αž”αž„αŸ’αž€αžΎαž Profile αžαŸ’αž˜αžΈ"):
171
  with gr.Row():
172
+ name_in = gr.Textbox(label="αžˆαŸ’αž˜αŸ„αŸ‡ Profile")
173
+ uid_in = gr.Textbox(label="UID")
174
  with gr.Row():
175
+ note_in = gr.Textbox(label="αž…αŸ†αžŽαžΆαŸ†")
176
+ pwd_in = gr.Textbox(label="αž›αŸαžαžŸαž˜αŸ’αž„αžΆαžαŸ‹ (Password)")
177
  with gr.Row():
178
  email_in = gr.Textbox(label="Email")
179
+ tfa_in = gr.Textbox(label="2FA Code/Secret")
180
 
181
  with gr.Row():
182
  device_in = gr.Dropdown(
183
  choices=[d["name"] for d in config["device_presets"]],
184
+ label="αž‡αŸ’αžšαžΎαžŸαžšαžΎαžŸαž”αŸ’αžšαž—αŸαž‘αž§αž”αž€αžšαžŽαŸ (Device)", type="index", value=0
185
  )
186
+ lat_in = gr.Textbox(label="Latitude (αž‘αžΈαžαžΆαŸ†αž„αž€αŸ’αž›αŸ‚αž„αž€αŸ’αž›αžΆαž™)")
187
+ lon_in = gr.Textbox(label="Longitude (αž‘αžΈαžαžΆαŸ†αž„αž€αŸ’αž›αŸ‚αž„αž€αŸ’αž›αžΆαž™)")
188
 
189
+ create_btn = gr.Button("βž• αž”αž„αŸ’αž€αžΎαž Profile αž₯αž‘αžΌαžœαž“αŸαŸ‡", variant="primary")
190
+ create_msg = gr.Textbox(label="αž›αž‘αŸ’αž’αž•αž›")
191
 
192
  create_btn.click(
193
  create_profile,