Spaces:
Configuration error
Configuration error
Update app.py
Browse files
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 |
-
# --- ααΆαααααα
|
| 17 |
-
CONFIG_FILE = "
|
| 18 |
-
active_drivers = {} #
|
| 19 |
|
| 20 |
def load_config():
|
| 21 |
if not os.path.exists(CONFIG_FILE):
|
| 22 |
default = {
|
| 23 |
-
"profile_path": os.path.join(os.
|
| 24 |
-
"max_threads": 2,
|
| 25 |
"device_presets": [
|
| 26 |
-
{"name": "
|
| 27 |
-
{"name": "
|
|
|
|
| 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 |
-
# --- αα»αααΆα
|
| 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 |
-
"""
|
|
|
|
| 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 "ααααα
|
| 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
|
|
|
|
|
|
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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://
|
| 115 |
-
return f"ααΆαααΎα
|
| 116 |
except Exception as e:
|
| 117 |
-
return f"ααα α»α: {str(e)}"
|
| 118 |
|
| 119 |
def close_chrome(name):
|
| 120 |
if name in active_drivers:
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
| 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"ααΆααα»α
|
| 132 |
-
return "αααα·αααΎα Profile!", get_profile_list()
|
| 133 |
|
| 134 |
# --- Gradio UI Layout ---
|
| 135 |
|
| 136 |
-
with gr.Blocks(title="
|
| 137 |
-
gr.Markdown("#
|
| 138 |
|
| 139 |
with gr.Tabs():
|
| 140 |
# TAB 1: αααααΈ Profile
|
| 141 |
-
with gr.TabItem("π
|
| 142 |
with gr.Row():
|
| 143 |
-
refresh_btn = gr.Button("π Refresh
|
| 144 |
-
open_btn = gr.Button("π’
|
| 145 |
-
close_btn = gr.Button("π΄
|
| 146 |
-
del_btn = gr.Button("ποΈ
|
| 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="
|
| 151 |
|
| 152 |
-
#
|
| 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("β
|
| 164 |
with gr.Row():
|
| 165 |
-
name_in = gr.Textbox(label="
|
| 166 |
-
uid_in = gr.Textbox(label="UID
|
| 167 |
with gr.Row():
|
| 168 |
-
note_in = gr.Textbox(label="
|
| 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="
|
| 178 |
)
|
| 179 |
-
lat_in = gr.Textbox(label="Latitude (
|
| 180 |
-
lon_in = gr.Textbox(label="Longitude (
|
| 181 |
|
| 182 |
-
create_btn = gr.Button("
|
| 183 |
-
create_msg = gr.Textbox(label="
|
| 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,
|