Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,103 +1,22 @@
|
|
| 1 |
-
import sys
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
-
import
|
| 5 |
-
import shutil
|
| 6 |
-
import random
|
| 7 |
-
import stat
|
| 8 |
-
import gc
|
| 9 |
-
import threading
|
| 10 |
-
import time
|
| 11 |
-
from urllib.request import Request, urlopen
|
| 12 |
-
|
| 13 |
-
# ααααΆααΆαααΆααααααααΆααα psutil αααααΆααααΆαααα·αααααααααΆαααΈα
|
| 14 |
-
try:
|
| 15 |
-
import psutil
|
| 16 |
-
except ImportError:
|
| 17 |
-
psutil = None
|
| 18 |
-
|
| 19 |
-
# =========================================================
|
| 20 |
-
# α‘. ααααΎααααΆαααα Flags ααΎαααααΌααααα’αααααααΆααααα·αααΆα α‘α α %
|
| 21 |
-
# =========================================================
|
| 22 |
-
os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = (
|
| 23 |
-
"--disable-features=FFmpegAllowLists "
|
| 24 |
-
"--disable-web-security "
|
| 25 |
-
"--allow-running-insecure-content "
|
| 26 |
-
"--no-sandbox "
|
| 27 |
-
"--ignore-certificate-errors "
|
| 28 |
-
"--disable-gpu "
|
| 29 |
-
"--disable-gpu-sandbox"
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
from PyQt6.QtCore import QUrl, Qt, QSize, QThread, pyqtSignal, QTimer, QRect, QObject
|
| 33 |
-
from PyQt6.QtGui import QColor, QFont, QIcon, QAction, QPainter
|
| 34 |
-
from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QFrame, QLabel, QPushButton, QLineEdit
|
| 35 |
-
from PyQt6.QtWebEngineWidgets import QWebEngineView
|
| 36 |
-
from PyQt6.QtWebEngineCore import QWebEngineProfile, QWebEnginePage, QWebEngineScript
|
| 37 |
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
|
|
|
|
| 38 |
|
| 39 |
-
# α―αααΆα Database
|
| 40 |
DB_PATH = "./data/instances.json"
|
| 41 |
STORES_PATH = "./data/stores.json"
|
| 42 |
URLS_PATH = "./data/urls.json"
|
| 43 |
CONFIG_PATH = "./data/config.json"
|
| 44 |
DEFAULT_URL = "https://www.facebook.com"
|
| 45 |
-
PORT = 8000
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
"width": 360, "height": 500,
|
| 50 |
-
"ua": "Mozilla/5.0 (Linux; Android 13; SM-S911B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36"
|
| 51 |
-
},
|
| 52 |
-
"Samsung Galaxy S23 (360x780)": {
|
| 53 |
-
"width": 360, "height": 780,
|
| 54 |
-
"ua": "Mozilla/5.0 (Linux; Android 13; SM-S911B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36"
|
| 55 |
-
},
|
| 56 |
-
"Google Pixel 8 (412x892)": {
|
| 57 |
-
"width": 412, "height": 892,
|
| 58 |
-
"ua": "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36"
|
| 59 |
-
},
|
| 60 |
-
"iPhone 15 Pro (393x852)": {
|
| 61 |
-
"width": 393, "height": 852,
|
| 62 |
-
"ua": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
|
| 63 |
-
},
|
| 64 |
-
"iPad Pro 12.9 (1024x1366)": {
|
| 65 |
-
"width": 1024, "height": 1366,
|
| 66 |
-
"ua": "Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1"
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
|
| 70 |
-
|
| 71 |
-
running_windows = {}
|
| 72 |
-
instance_statuses = {}
|
| 73 |
-
calculated_sizes = {}
|
| 74 |
-
|
| 75 |
-
# --- Helper Functions ---
|
| 76 |
-
def get_dir_size(path):
|
| 77 |
-
total_size = 0
|
| 78 |
-
if not os.path.exists(path):
|
| 79 |
-
return 0
|
| 80 |
-
try:
|
| 81 |
-
for dirpath, dirnames, filenames in os.walk(path):
|
| 82 |
-
for f in filenames:
|
| 83 |
-
fp = os.path.join(dirpath, f)
|
| 84 |
-
if not os.path.islink(fp):
|
| 85 |
-
total_size += os.path.getsize(fp)
|
| 86 |
-
except Exception:
|
| 87 |
-
pass
|
| 88 |
-
return total_size
|
| 89 |
-
|
| 90 |
-
def format_size(bytes_size):
|
| 91 |
-
if bytes_size <= 0: return "0 KB"
|
| 92 |
-
kb_size = bytes_size / 1024
|
| 93 |
-
if kb_size < 1024: return f"{kb_size:.1f} KB"
|
| 94 |
-
mb_size = kb_size / 1024
|
| 95 |
-
if mb_size < 1024: return f"{mb_size:.1f} MB"
|
| 96 |
-
return f"{mb_size/1024:.1f} GB"
|
| 97 |
|
| 98 |
def load_json(path, default):
|
| 99 |
if not os.path.exists(path):
|
| 100 |
-
os.makedirs(os.path.dirname(path), exist_ok=True)
|
| 101 |
with open(path, "w", encoding="utf-8") as f:
|
| 102 |
json.dump(default, f, ensure_ascii=False, indent=4)
|
| 103 |
return default
|
|
@@ -111,400 +30,41 @@ def save_json(path, data):
|
|
| 111 |
with open(path, "w", encoding="utf-8") as f:
|
| 112 |
json.dump(data, f, ensure_ascii=False, indent=4)
|
| 113 |
|
| 114 |
-
# αααα»ααα·ααααααααααΌα
|
| 115 |
instances = load_json(DB_PATH, [{"id": 1, "name": "ααααΈ #1", "device": "Compact Mobile (360x500)", "url": DEFAULT_URL, "scale": 0.50, "ip": "", "city": "", "note": "", "store": "ααΌαα
(Default)"}])
|
| 116 |
stores = load_json(STORES_PATH, ["ααΌαα
(Default)"])
|
| 117 |
urls_db = load_json(URLS_PATH, [DEFAULT_URL, "https://www.youtube.com", "https://www.google.com", "https://www.tiktok.com"])
|
| 118 |
app_config = load_json(CONFIG_PATH, {"chk_auto_scroll": True, "delay_spin": 3, "auto_close_spin": 0, "arrange_type_idx": 0, "cols_spin": 3, "preset_speed": 2, "preset_mode_idx": 1})
|
| 119 |
|
| 120 |
-
|
| 121 |
-
profile_name = f"instance_{instance_id}"
|
| 122 |
-
if profile_name in GLOBAL_PROFILES_CACHE:
|
| 123 |
-
return GLOBAL_PROFILES_CACHE[profile_name]
|
| 124 |
-
data_dir = os.path.abspath("./data")
|
| 125 |
-
profile = QWebEngineProfile(profile_name, parent_widget)
|
| 126 |
-
profile.setPersistentStoragePath(os.path.join(data_dir, profile_name, "storage"))
|
| 127 |
-
profile.setCachePath(os.path.join(data_dir, profile_name, "cache"))
|
| 128 |
-
profile.setPersistentCookiesPolicy(QWebEngineProfile.PersistentCookiesPolicy.ForcePersistentCookies)
|
| 129 |
-
GLOBAL_PROFILES_CACHE[profile_name] = profile
|
| 130 |
-
return profile
|
| 131 |
-
|
| 132 |
-
# =========================================================
|
| 133 |
-
# α’. ααααααααααααα IP αα·ααααααααααΈααΆαα (Background Thread)
|
| 134 |
-
# =========================================================
|
| 135 |
-
class IpFetcher(QThread):
|
| 136 |
-
ip_fetched = pyqtSignal(str, str)
|
| 137 |
-
|
| 138 |
-
def run(self):
|
| 139 |
-
import urllib.request
|
| 140 |
-
opener = urllib.request.build_opener()
|
| 141 |
-
try:
|
| 142 |
-
req = Request("https://ipapi.co/json/", headers={'User-Agent': 'Mozilla/5.0'})
|
| 143 |
-
with opener.open(req, timeout=6) as response:
|
| 144 |
-
data = json.loads(response.read().decode())
|
| 145 |
-
self.ip_fetched.emit(data.get("ip", "Unknown IP"), data.get("city", "Unknown City"))
|
| 146 |
-
return
|
| 147 |
-
except Exception: pass
|
| 148 |
-
try:
|
| 149 |
-
req = Request("https://freeipapi.com/api/json", headers={'User-Agent': 'Mozilla/5.0'})
|
| 150 |
-
with opener.open(req, timeout=6) as response:
|
| 151 |
-
data = json.loads(response.read().decode())
|
| 152 |
-
self.ip_fetched.emit(data.get("ipAddress", "Unknown IP"), data.get("cityName", "Unknown City"))
|
| 153 |
-
return
|
| 154 |
-
except Exception:
|
| 155 |
-
self.ip_fetched.emit("127.0.0.1", "Local Connection")
|
| 156 |
-
|
| 157 |
-
class CustomWebEnginePage(QWebEnginePage):
|
| 158 |
-
console_message_signal = pyqtSignal(int, str, int, str)
|
| 159 |
-
def javaScriptConsoleMessage(self, level, message, lineNumber, sourceID):
|
| 160 |
-
self.console_message_signal.emit(level, message, lineNumber, sourceID)
|
| 161 |
-
super().javaScriptConsoleMessage(level, message, lineNumber, sourceID)
|
| 162 |
-
|
| 163 |
-
# =========================================================
|
| 164 |
-
# α£. ααααΆαααααααΎαααααΆααααΌααααα (Preserved PyQt6 Mobile Frame)
|
| 165 |
-
# =========================================================
|
| 166 |
-
class MobileSimulator(QMainWindow):
|
| 167 |
-
def __init__(self, instance_id=1, device_name=None, initial_url=DEFAULT_URL, scale_factor=0.75):
|
| 168 |
-
super().__init__()
|
| 169 |
-
self.instance_id = instance_id
|
| 170 |
-
self.current_device_name = device_name if device_name in DEVICES else list(DEVICES.keys())[0]
|
| 171 |
-
self.home_url = initial_url if initial_url else DEFAULT_URL
|
| 172 |
-
self.scale_factor = scale_factor if scale_factor else 0.75
|
| 173 |
-
self.is_landscape = False
|
| 174 |
-
self.is_auto_scrolling = False
|
| 175 |
-
self.auto_close_on_finish = False
|
| 176 |
-
self.is_loading_started = False
|
| 177 |
-
|
| 178 |
-
# αααααα±αα PyQt6 αααααα
αα·ααααααα Memory αααα Window αααααααΆαααα
αααα
α»α
αα·α (Close)
|
| 179 |
-
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)
|
| 180 |
-
|
| 181 |
-
self.remaining_seconds = 0
|
| 182 |
-
self.countdown_timer = QTimer(self)
|
| 183 |
-
self.countdown_timer.timeout.connect(self.update_countdown)
|
| 184 |
-
|
| 185 |
-
self.setWindowTitle(f"ααΌαααααααααα - ααααΈ #{self.instance_id}")
|
| 186 |
-
self.setStyleSheet("background-color: #0f1115;")
|
| 187 |
-
|
| 188 |
-
self.profile = get_or_create_profile(self.instance_id, self)
|
| 189 |
-
self.webpage = CustomWebEnginePage(self.profile, self)
|
| 190 |
-
self.webpage.setBackgroundColor(QColor("white"))
|
| 191 |
-
|
| 192 |
-
self.browser = QWebEngineView()
|
| 193 |
-
self.browser.setPage(self.webpage)
|
| 194 |
-
self.browser.setStyleSheet("border: none; background-color: white; border-radius: 0px 0px 18px 18px;")
|
| 195 |
-
|
| 196 |
-
self.browser.loadStarted.connect(self.on_load_started)
|
| 197 |
-
self.browser.loadFinished.connect(self.on_load_finished)
|
| 198 |
-
self.browser.urlChanged.connect(self.update_url_bar)
|
| 199 |
-
|
| 200 |
-
main_widget = QWidget()
|
| 201 |
-
self.setCentralWidget(main_widget)
|
| 202 |
-
self.main_layout = QVBoxLayout(main_widget)
|
| 203 |
-
self.main_layout.setContentsMargins(10, 10, 10, 10)
|
| 204 |
-
self.main_layout.setSpacing(5)
|
| 205 |
-
|
| 206 |
-
self.phone_frame = QFrame()
|
| 207 |
-
self.phone_frame.setStyleSheet("QFrame { background-color: #020617; border: 8px solid #1e293b; border-radius: 32px; }")
|
| 208 |
-
self.phone_inner_layout = QVBoxLayout(self.phone_frame)
|
| 209 |
-
self.phone_inner_layout.setContentsMargins(6, 6, 6, 6)
|
| 210 |
-
self.phone_inner_layout.setSpacing(6)
|
| 211 |
-
|
| 212 |
-
self.notch_frame = QFrame()
|
| 213 |
-
self.notch_frame.setFixedHeight(22)
|
| 214 |
-
self.notch_frame.setStyleSheet("background-color: transparent; border: none;")
|
| 215 |
-
notch_layout = QHBoxLayout(self.notch_frame)
|
| 216 |
-
notch_layout.setContentsMargins(0, 0, 0, 0)
|
| 217 |
-
self.notch_element = QFrame()
|
| 218 |
-
self.notch_element.setFixedSize(90, 14)
|
| 219 |
-
self.notch_element.setStyleSheet("background-color: #000000; border-radius: 7px; border: none;")
|
| 220 |
-
notch_layout.addWidget(self.notch_element, alignment=Qt.AlignmentFlag.AlignCenter)
|
| 221 |
-
self.phone_inner_layout.addWidget(self.notch_frame)
|
| 222 |
-
|
| 223 |
-
browser_bar = QHBoxLayout()
|
| 224 |
-
browser_bar.setContentsMargins(4, 0, 4, 0)
|
| 225 |
-
browser_bar.setSpacing(6)
|
| 226 |
-
|
| 227 |
-
self.btn_back = QPushButton("β")
|
| 228 |
-
self.btn_back.setStyleSheet(self.get_icon_style())
|
| 229 |
-
self.btn_back.clicked.connect(self.browser.back)
|
| 230 |
-
browser_bar.addWidget(self.btn_back)
|
| 231 |
-
|
| 232 |
-
self.btn_forward = QPushButton("βΆ")
|
| 233 |
-
self.btn_forward.setStyleSheet(self.get_icon_style())
|
| 234 |
-
self.btn_forward.clicked.connect(self.browser.forward)
|
| 235 |
-
browser_bar.addWidget(self.btn_forward)
|
| 236 |
-
|
| 237 |
-
self.btn_home = QPushButton("π ")
|
| 238 |
-
self.btn_home.setStyleSheet(self.get_icon_style())
|
| 239 |
-
self.btn_home.clicked.connect(self.go_home)
|
| 240 |
-
browser_bar.addWidget(self.btn_home)
|
| 241 |
-
|
| 242 |
-
self.url_input = QLineEdit()
|
| 243 |
-
self.url_input.setText(self.home_url)
|
| 244 |
-
self.url_input.setStyleSheet("QLineEdit { background-color: #0f172a; color: #f8fafc; border: 1px solid #334155; border-radius: 12px; padding: 4px 10px; font-size: 11px; } QLineEdit:focus { border-color: #38bdf8; }")
|
| 245 |
-
self.url_input.returnPressed.connect(self.load_url)
|
| 246 |
-
browser_bar.addWidget(self.url_input)
|
| 247 |
-
|
| 248 |
-
self.btn_scroll = QPushButton("π")
|
| 249 |
-
self.btn_scroll.setStyleSheet(self.get_icon_style())
|
| 250 |
-
self.btn_scroll.clicked.connect(lambda: self.toggle_auto_scroll())
|
| 251 |
-
browser_bar.addWidget(self.btn_scroll)
|
| 252 |
-
|
| 253 |
-
self.btn_rotate = QPushButton("π")
|
| 254 |
-
self.btn_rotate.setStyleSheet(self.get_icon_style())
|
| 255 |
-
self.btn_rotate.clicked.connect(self.toggle_rotation)
|
| 256 |
-
browser_bar.addWidget(self.btn_rotate)
|
| 257 |
-
|
| 258 |
-
self.phone_inner_layout.addLayout(browser_bar)
|
| 259 |
-
self.phone_inner_layout.addWidget(self.browser, 1)
|
| 260 |
-
|
| 261 |
-
self.home_bar = QFrame()
|
| 262 |
-
self.home_bar.setFixedHeight(12)
|
| 263 |
-
self.home_bar.setStyleSheet("background-color: transparent; border: none;")
|
| 264 |
-
home_bar_layout = QHBoxLayout(self.home_bar)
|
| 265 |
-
indicator = QFrame()
|
| 266 |
-
indicator.setFixedSize(110, 4)
|
| 267 |
-
indicator.setStyleSheet("background-color: #475569; border-radius: 2px;")
|
| 268 |
-
home_bar_layout.addWidget(indicator, alignment=Qt.AlignmentFlag.AlignCenter)
|
| 269 |
-
self.phone_inner_layout.addWidget(self.home_bar)
|
| 270 |
-
|
| 271 |
-
self.main_layout.addWidget(self.phone_frame, alignment=Qt.AlignmentFlag.AlignCenter)
|
| 272 |
-
|
| 273 |
-
self.scroll_timer = QTimer(self)
|
| 274 |
-
self.scroll_timer.timeout.connect(self.scroll_page)
|
| 275 |
-
|
| 276 |
-
self.apply_device_settings()
|
| 277 |
-
self.load_url()
|
| 278 |
-
|
| 279 |
-
self.ip_fetcher = IpFetcher(self)
|
| 280 |
-
self.ip_fetcher.ip_fetched.connect(self.on_ip_fetched)
|
| 281 |
-
self.ip_fetcher.start()
|
| 282 |
-
|
| 283 |
-
def get_icon_style(self):
|
| 284 |
-
return "QPushButton { background-color: #1e293b; color: #f8fafc; border: 1px solid #334155; border-radius: 13px; min-width: 26px; min-height: 26px; max-width: 26px; max-height: 26px; font-size: 10px; } QPushButton:hover { background-color: #38bdf8; color: #0f1115; }"
|
| 285 |
-
|
| 286 |
-
def on_load_started(self):
|
| 287 |
-
self.is_loading_started = True
|
| 288 |
-
self.update_status("β³ αααα»ααααα»α...")
|
| 289 |
-
|
| 290 |
-
def on_load_finished(self, ok):
|
| 291 |
-
self.is_loading_started = False
|
| 292 |
-
self.update_status("π’ Online")
|
| 293 |
-
|
| 294 |
-
def on_ip_fetched(self, ip, city):
|
| 295 |
-
global instances
|
| 296 |
-
for inst in instances:
|
| 297 |
-
if inst["id"] == self.instance_id:
|
| 298 |
-
inst["ip"] = ip
|
| 299 |
-
inst["city"] = city
|
| 300 |
-
break
|
| 301 |
-
save_json(DB_PATH, instances)
|
| 302 |
-
|
| 303 |
-
def update_status(self, text):
|
| 304 |
-
instance_statuses[self.instance_id] = text
|
| 305 |
-
|
| 306 |
-
def start_countdown(self, duration_min, auto_close=True):
|
| 307 |
-
if duration_min > 0:
|
| 308 |
-
self.remaining_seconds = duration_min * 60
|
| 309 |
-
self.auto_close_on_finish = auto_close
|
| 310 |
-
self.countdown_timer.start(1000)
|
| 311 |
-
|
| 312 |
-
def update_countdown(self):
|
| 313 |
-
if self.remaining_seconds > 0:
|
| 314 |
-
self.remaining_seconds -= 1
|
| 315 |
-
mins = self.remaining_seconds // 60
|
| 316 |
-
secs = self.remaining_seconds % 60
|
| 317 |
-
self.update_status(f"π ααααΌα ({mins:02d}:{secs:02d})")
|
| 318 |
-
else:
|
| 319 |
-
self.countdown_timer.stop()
|
| 320 |
-
if self.auto_close_on_finish:
|
| 321 |
-
self.close()
|
| 322 |
-
|
| 323 |
-
def toggle_auto_scroll(self, force_state=None, speed=2, duration_min=0, random_mode=True, auto_close=None):
|
| 324 |
-
if force_state is not None:
|
| 325 |
-
self.is_auto_scrolling = force_state
|
| 326 |
-
else:
|
| 327 |
-
self.is_auto_scrolling = not self.is_auto_scrolling
|
| 328 |
-
|
| 329 |
-
if auto_close is not None:
|
| 330 |
-
self.auto_close_on_finish = auto_close
|
| 331 |
-
|
| 332 |
-
if self.is_auto_scrolling:
|
| 333 |
-
self.scroll_speed_base = speed
|
| 334 |
-
self.scroll_speed = max(1, speed + random.randint(-1, 1))
|
| 335 |
-
self.scroll_direction = 1
|
| 336 |
-
self.random_mode = random_mode
|
| 337 |
-
self.ticks_since_dir_change = 0
|
| 338 |
-
self.next_dir_change_ticks = random.randint(100, 300)
|
| 339 |
-
self.scroll_timer.start(random.randint(35, 55))
|
| 340 |
-
|
| 341 |
-
if duration_min > 0:
|
| 342 |
-
self.start_countdown(duration_min, auto_close)
|
| 343 |
-
else:
|
| 344 |
-
self.update_status("π αααα»αααααΌα...")
|
| 345 |
-
else:
|
| 346 |
-
self.scroll_timer.stop()
|
| 347 |
-
self.countdown_timer.stop()
|
| 348 |
-
self.update_status("π’ Online")
|
| 349 |
-
|
| 350 |
-
def scroll_page(self):
|
| 351 |
-
if not hasattr(self, 'browser') or self.browser is None:
|
| 352 |
-
self.scroll_timer.stop()
|
| 353 |
-
return
|
| 354 |
-
try:
|
| 355 |
-
if self.random_mode:
|
| 356 |
-
self.ticks_since_dir_change += 1
|
| 357 |
-
if self.ticks_since_dir_change >= self.next_dir_change_ticks:
|
| 358 |
-
self.ticks_since_dir_change = 0
|
| 359 |
-
self.next_dir_change_ticks = random.randint(100, 300)
|
| 360 |
-
self.scroll_direction = -1 if random.random() < 0.20 else 1
|
| 361 |
-
self.scroll_speed = max(1, self.scroll_speed_base + random.randint(-1, 1))
|
| 362 |
-
self.browser.page().runJavaScript(f"window.scrollBy(0, {self.scroll_direction * self.scroll_speed});")
|
| 363 |
-
except Exception:
|
| 364 |
-
self.scroll_timer.stop()
|
| 365 |
-
|
| 366 |
-
def load_url(self):
|
| 367 |
-
url = self.url_input.text().strip()
|
| 368 |
-
if not url: return
|
| 369 |
-
if not url.startswith("http://") and not url.startswith("https://"):
|
| 370 |
-
url = "https://" + url
|
| 371 |
-
self.browser.setUrl(QUrl(url))
|
| 372 |
-
|
| 373 |
-
def update_url_bar(self, qurl):
|
| 374 |
-
self.url_input.setText(qurl.toString())
|
| 375 |
-
|
| 376 |
-
def go_home(self):
|
| 377 |
-
self.browser.setUrl(QUrl(self.home_url))
|
| 378 |
-
|
| 379 |
-
def toggle_rotation(self):
|
| 380 |
-
self.is_landscape = not self.is_landscape
|
| 381 |
-
self.apply_device_settings()
|
| 382 |
-
|
| 383 |
-
def apply_device_settings(self):
|
| 384 |
-
device = DEVICES[self.current_device_name]
|
| 385 |
-
w, h, ua = device["width"], device["height"], device["ua"]
|
| 386 |
-
self.profile.setHttpUserAgent(ua)
|
| 387 |
-
self.profile.scripts().clear()
|
| 388 |
-
|
| 389 |
-
js_code = ""
|
| 390 |
-
if "Android" in ua:
|
| 391 |
-
js_code = "Object.defineProperty(navigator, 'platform', { get: () => 'Linux armv8l' });"
|
| 392 |
-
elif "iPhone" in ua:
|
| 393 |
-
js_code = "Object.defineProperty(navigator, 'platform', { get: () => 'iPhone' });"
|
| 394 |
-
|
| 395 |
-
if js_code:
|
| 396 |
-
script = QWebEngineScript()
|
| 397 |
-
script.setSourceCode(js_code)
|
| 398 |
-
script.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentCreation)
|
| 399 |
-
self.profile.scripts().insert(script)
|
| 400 |
-
|
| 401 |
-
if self.is_landscape:
|
| 402 |
-
w, h = h, w
|
| 403 |
-
self.notch_frame.hide()
|
| 404 |
-
else:
|
| 405 |
-
self.notch_frame.show()
|
| 406 |
-
|
| 407 |
-
w_scaled = int(w * self.scale_factor)
|
| 408 |
-
h_scaled = int(h * self.scale_factor)
|
| 409 |
-
self.phone_frame.setFixedSize(w_scaled + 24, h_scaled + (60 if self.is_landscape else 85))
|
| 410 |
-
self.setFixedSize(w_scaled + 44, h_scaled + (80 if self.is_landscape else 105))
|
| 411 |
-
self.browser.setZoomFactor(self.scale_factor)
|
| 412 |
-
|
| 413 |
-
def closeEvent(self, event):
|
| 414 |
-
self.scroll_timer.stop()
|
| 415 |
-
self.countdown_timer.stop()
|
| 416 |
-
|
| 417 |
-
# αααααα αα·ααααα’αΆα WebEngine ααΆα
αααΆα ααΎααααΈαααααα (Unlock) αα·αααααα Profile ααααααααΈ
|
| 418 |
-
if hasattr(self, 'browser') and self.browser is not None:
|
| 419 |
-
self.browser.setPage(None)
|
| 420 |
-
self.webpage.deleteLater()
|
| 421 |
-
self.browser.deleteLater()
|
| 422 |
-
self.browser = None
|
| 423 |
-
|
| 424 |
-
if self.instance_id in running_windows:
|
| 425 |
-
del running_windows[self.instance_id]
|
| 426 |
-
instance_statuses[self.instance_id] = "π΄ Offline"
|
| 427 |
-
event.accept()
|
| 428 |
-
|
| 429 |
-
# =========================================================
|
| 430 |
-
# α€. Web App Control Panel (ααααααααααΆαααα‘α·α
ααααΈ - Zero Selection Loss)
|
| 431 |
-
# =========================================================
|
| 432 |
HTML_PANEL = """<!DOCTYPE html>
|
| 433 |
<html lang="km">
|
| 434 |
<head>
|
| 435 |
<meta charset="UTF-8">
|
| 436 |
<title>αααααααααααααααααααααΈ - Web Control Panel</title>
|
| 437 |
<style>
|
| 438 |
-
body {
|
| 439 |
-
|
| 440 |
-
color: #e2e8f0;
|
| 441 |
-
font-family: 'Segoe UI', 'Kantumruuy Pro', sans-serif;
|
| 442 |
-
font-size: 12px;
|
| 443 |
-
margin: 0;
|
| 444 |
-
padding: 15px;
|
| 445 |
-
}
|
| 446 |
-
.top-bar {
|
| 447 |
-
display: flex;
|
| 448 |
-
align-items: center;
|
| 449 |
-
gap: 12px;
|
| 450 |
-
margin-bottom: 15px;
|
| 451 |
-
}
|
| 452 |
.lbl-total { font-weight: bold; color: #38bdf8; font-size: 13px; }
|
| 453 |
.main-body { display: flex; gap: 15px; }
|
| 454 |
-
.table-container {
|
| 455 |
-
flex: 1;
|
| 456 |
-
background-color: #161920;
|
| 457 |
-
border: 1px solid #1e293b;
|
| 458 |
-
border-radius: 8px;
|
| 459 |
-
padding: 12px;
|
| 460 |
-
}
|
| 461 |
table { width: 100%; border-collapse: collapse; }
|
| 462 |
th, td { padding: 8px; text-align: left; border-bottom: 1px solid #1d212a; }
|
| 463 |
th { background-color: #0f172a; color: #94a3b8; font-weight: bold; }
|
| 464 |
-
|
| 465 |
-
.sidebar {
|
| 466 |
-
width: 240px;
|
| 467 |
-
background-color: #161920;
|
| 468 |
-
border: 1px solid #1e293b;
|
| 469 |
-
border-radius: 8px;
|
| 470 |
-
padding: 12px;
|
| 471 |
-
display: flex;
|
| 472 |
-
flex-direction: column;
|
| 473 |
-
gap: 12px;
|
| 474 |
-
}
|
| 475 |
.group-box { border: 1px solid #1e293b; border-radius: 6px; padding: 10px; }
|
| 476 |
.group-title { font-weight: bold; color: #38bdf8; font-size: 11px; margin-bottom: 6px; }
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
background-color: #0f1115; color: #f8fafc; border: 1px solid #2d3343;
|
| 480 |
-
border-radius: 6px; padding: 5px 8px; width: 100%; box-sizing: border-box;
|
| 481 |
-
}
|
| 482 |
-
button {
|
| 483 |
-
background-color: #1e293b; color: #f8fafc; border: 1px solid #334155;
|
| 484 |
-
border-radius: 6px; padding: 6px 12px; font-weight: bold; cursor: pointer;
|
| 485 |
-
}
|
| 486 |
button:hover { background-color: #38bdf8; color: #0f1115; }
|
| 487 |
.btn-success { background-color: #10b981; color: white; border: none; }
|
| 488 |
.btn-success:hover { background-color: #059669; }
|
| 489 |
.btn-danger { background-color: #ef4444; color: white; border: none; }
|
| 490 |
.btn-danger:hover { background-color: #dc2626; }
|
| 491 |
-
|
| 492 |
.digital-timer { font-size: 24px; font-weight: bold; color: #f97316; font-family: monospace; margin-left: auto; }
|
| 493 |
-
.status-badge { font-weight: bold; }
|
| 494 |
.footer-bar { margin-top: 15px; display: flex; justify-content: space-between; color: #64748b; font-size: 11px; }
|
| 495 |
-
|
| 496 |
-
.modal {
|
| 497 |
-
display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
|
| 498 |
-
background: rgba(0,0,0,0.6); justify-content: center; align-items: center;
|
| 499 |
-
}
|
| 500 |
-
.modal-content {
|
| 501 |
-
background-color: #111317; border: 1px solid #2d3343; border-radius: 12px;
|
| 502 |
-
padding: 20px; width: 350px; display: flex; flex-direction: column; gap: 12px;
|
| 503 |
-
}
|
| 504 |
</style>
|
| 505 |
</head>
|
| 506 |
<body>
|
| 507 |
-
|
| 508 |
<div class="top-bar">
|
| 509 |
<div class="lbl-total" id="lbl-total">ααααΈααα»α (Total Profiles): 0</div>
|
| 510 |
<button onclick="addInstance()">οΌ ααααααααααΈ</button>
|
|
@@ -513,7 +73,6 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 513 |
<button class="btn-danger" onclick="stopSelected()">βΉ ααααααααα (STOP)</button>
|
| 514 |
<div class="digital-timer" id="stopwatch">00:00:00</div>
|
| 515 |
<input type="text" id="search" placeholder="ααααααα..." style="width: 150px;" oninput="filterRows()">
|
| 516 |
-
<button onclick="document.getElementById('search').value=''; filterRows();">αααα’αΆα</button>
|
| 517 |
</div>
|
| 518 |
|
| 519 |
<div class="main-body">
|
|
@@ -545,7 +104,6 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 545 |
<button style="flex:1;" onclick="deleteStore()">ποΈ αα»α</button>
|
| 546 |
</div>
|
| 547 |
</div>
|
| 548 |
-
|
| 549 |
<div class="group-box">
|
| 550 |
<div class="group-title">αααααααααααΈα/αα·αααΆα (URLS)</div>
|
| 551 |
<select id="url-select" style="margin-bottom: 6px;"></select>
|
|
@@ -554,79 +112,17 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 554 |
<button style="flex:1;" onclick="deleteUrl()">ποΈ αα»α</button>
|
| 555 |
</div>
|
| 556 |
</div>
|
| 557 |
-
|
| 558 |
-
<div class="group-box">
|
| 559 |
-
<div class="group-title">ααΆαααααααααααααα (SYSTEM CONFIG)</div>
|
| 560 |
-
<label style="display:flex; align-items:center; gap:6px; margin-bottom: 6px;">
|
| 561 |
-
<input type="checkbox" id="cfg-auto-scroll" onchange="toggleScrollOption(this)"> ααααΌαα’αΌααΌαααααΎα
|
| 562 |
-
</label>
|
| 563 |
-
<div style="margin-bottom:6px;">
|
| 564 |
-
<span>α
ααααααααααΎα (αα·ααΆααΈ):</span>
|
| 565 |
-
<input type="number" id="cfg-delay" onchange="saveConfig()">
|
| 566 |
-
</div>
|
| 567 |
-
<div style="margin-bottom:6px;">
|
| 568 |
-
<span>αααααααΆααΈααα (0=β):</span>
|
| 569 |
-
<input type="number" id="cfg-duration" onchange="saveConfig()">
|
| 570 |
-
</div>
|
| 571 |
-
<div style="margin-bottom:6px;">
|
| 572 |
-
<span>αααααααα
α:</span>
|
| 573 |
-
<select id="cfg-arrange-type" onchange="saveConfig()">
|
| 574 |
-
<option value="0">αααααΆαα½ααα (Columns)</option>
|
| 575 |
-
<option value="1">αααααΆαα½αααα (Rows)</option>
|
| 576 |
-
</select>
|
| 577 |
-
</div>
|
| 578 |
-
<div style="margin-bottom:6px;">
|
| 579 |
-
<span>α
ααα½ααα½α (Grid Count):</span>
|
| 580 |
-
<input type="number" id="cfg-cols" onchange="saveConfig()">
|
| 581 |
-
</div>
|
| 582 |
-
<button style="width:100%;" class="btn-success" onclick="arrangeWindows()">π αααα
αα’αααααααααααααααααα</button>
|
| 583 |
-
</div>
|
| 584 |
</div>
|
| 585 |
</div>
|
| 586 |
|
| 587 |
<div class="footer-bar">
|
| 588 |
<span id="lbl-status">ααααααααα½ααα½α
ααΆαα (Ready)</span>
|
| 589 |
-
<span id="lbl-resources">π₯οΈ
|
| 590 |
-
</div>
|
| 591 |
-
|
| 592 |
-
<!-- Active Scroll Setup Modal -->
|
| 593 |
-
<div class="modal" id="scroll-modal">
|
| 594 |
-
<div class="modal-content">
|
| 595 |
-
<h3 style="color:#38bdf8; margin:0;">ααΆααααααααΆαααααΌααααααααααααα</h3>
|
| 596 |
-
<label>ααααΏαααααΌα (1-10):</label>
|
| 597 |
-
<input type="number" id="scroll-speed" min="1" max="10" value="2">
|
| 598 |
-
<label>ααααααααΌαα’αααααα:</label>
|
| 599 |
-
<select id="scroll-behavior">
|
| 600 |
-
<option value="0">ααααΌαα
α»αααααα (Standard Down)</option>
|
| 601 |
-
<option value="1" selected>ααααααΉααααααα»ααα (Human-Like β
)</option>
|
| 602 |
-
</select>
|
| 603 |
-
<div style="display:flex; gap:10px; margin-top:10px;">
|
| 604 |
-
<button class="btn-success" style="flex:1;" onclick="applyScrollSettings()">αααααΆαα»α</button>
|
| 605 |
-
<button class="btn-danger" style="flex:1;" onclick="closeScrollModal()">αααααα</button>
|
| 606 |
-
</div>
|
| 607 |
-
</div>
|
| 608 |
</div>
|
| 609 |
|
| 610 |
<script>
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
function startStopwatch() {
|
| 615 |
-
if(stopwatchInterval) clearInterval(stopwatchInterval);
|
| 616 |
-
timerVal = 0;
|
| 617 |
-
stopwatchInterval = setInterval(() => {
|
| 618 |
-
timerVal++;
|
| 619 |
-
let h = String(Math.floor(timerVal/3600)).padStart(2,'0');
|
| 620 |
-
let m = String(Math.floor((timerVal%3600)/60)).padStart(2,'0');
|
| 621 |
-
let s = String(timerVal%60).padStart(2,'0');
|
| 622 |
-
document.getElementById("stopwatch").innerText = `${h}:${m}:${s}`;
|
| 623 |
-
}, 1000);
|
| 624 |
-
}
|
| 625 |
-
|
| 626 |
-
function stopStopwatch() {
|
| 627 |
-
clearInterval(stopwatchInterval);
|
| 628 |
-
document.getElementById("stopwatch").innerText = "00:00:00";
|
| 629 |
-
}
|
| 630 |
|
| 631 |
async function loadUI() {
|
| 632 |
let resStores = await fetch('/api/get_stores');
|
|
@@ -641,20 +137,20 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 641 |
urlSelect.innerHTML = '';
|
| 642 |
listUrls.forEach(u => urlSelect.innerHTML += `<option value="${u}">${u}</option>`);
|
| 643 |
|
| 644 |
-
let resConfig = await fetch('/api/get_config');
|
| 645 |
-
let cfg = await resConfig.json();
|
| 646 |
-
document.getElementById("cfg-auto-scroll").checked = cfg.chk_auto_scroll;
|
| 647 |
-
document.getElementById("cfg-delay").value = cfg.delay_spin;
|
| 648 |
-
document.getElementById("cfg-duration").value = cfg.auto_close_spin;
|
| 649 |
-
document.getElementById("cfg-arrange-type").value = cfg.arrange_type_idx;
|
| 650 |
-
document.getElementById("cfg-cols").value = cfg.cols_spin;
|
| 651 |
-
|
| 652 |
await loadTable();
|
| 653 |
}
|
| 654 |
|
| 655 |
async function loadTable() {
|
| 656 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 657 |
|
|
|
|
| 658 |
let resInst = await fetch('/api/get_instances');
|
| 659 |
let data = await resInst.json();
|
| 660 |
document.getElementById("lbl-total").innerText = `ααααΈααα»α (Total Profiles): ${data.length}`;
|
|
@@ -662,17 +158,18 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 662 |
let tbody = document.getElementById("table-body");
|
| 663 |
tbody.innerHTML = "";
|
| 664 |
data.forEach(inst => {
|
|
|
|
| 665 |
let statusColor = "color: #ef4444;";
|
| 666 |
-
if(
|
| 667 |
-
else if(
|
| 668 |
-
else if(
|
| 669 |
|
| 670 |
let isChecked = checkedIds.includes(inst.id) ? "checked" : "";
|
| 671 |
|
| 672 |
tbody.innerHTML += `
|
| 673 |
<tr class="profile-row" data-id="${inst.id}" data-name="${inst.name.toLowerCase()}" data-store="${inst.store}">
|
| 674 |
<td><input type="checkbox" class="row-check" value="${inst.id}" ${isChecked}></td>
|
| 675 |
-
<td style="${statusColor} font-weight:bold;">${
|
| 676 |
<td><input type="text" value="${inst.name}" onchange="updateField(${inst.id}, 'name', this.value)"></td>
|
| 677 |
<td>
|
| 678 |
<select onchange="updateField(${inst.id}, 'store', this.value)">
|
|
@@ -681,16 +178,16 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 681 |
.map(o => `<option value="${o.value}" ${inst.store === o.value ? 'selected':''}>${o.value}</option>`).join('')}
|
| 682 |
</select>
|
| 683 |
</td>
|
| 684 |
-
<td>${inst.device}
|
| 685 |
-
<td>${inst.size}</td>
|
| 686 |
-
<td><input type="text" value="${inst.ip_display}" onchange="updateField(${inst.id}, 'ip', this.value)" placeholder="IP/ααΈαααα»α"></td>
|
| 687 |
<td>
|
| 688 |
<select onchange="updateField(${inst.id}, 'url', this.value)">
|
| 689 |
${Array.from(document.getElementById("url-select").options)
|
| 690 |
.map(o => `<option value="${o.value}" ${inst.url === o.value ? 'selected':''}>${o.value}</option>`).join('')}
|
| 691 |
</select>
|
| 692 |
</td>
|
| 693 |
-
<td><input type="text" value="${inst.note}" onchange="updateField(${inst.id}, 'note', this.value)" placeholder="α
αααΆα..."></td>
|
| 694 |
</tr>
|
| 695 |
`;
|
| 696 |
});
|
|
@@ -703,7 +200,6 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 703 |
headers: {'Content-Type': 'application/json'},
|
| 704 |
body: JSON.stringify({id, field, value})
|
| 705 |
});
|
| 706 |
-
document.getElementById("lbl-status").innerText = "ααΆααααααΆαα»ααα·ααααααα";
|
| 707 |
}
|
| 708 |
|
| 709 |
function selectAll(master) {
|
|
@@ -744,69 +240,37 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 744 |
}
|
| 745 |
}
|
| 746 |
|
|
|
|
| 747 |
async function startSelected() {
|
| 748 |
let ids = getSelected();
|
| 749 |
if(!ids.length) return alert("ααΌαααααΎαααΎαααααΈ!");
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 757 |
}
|
| 758 |
|
| 759 |
async function stopSelected() {
|
| 760 |
let ids = getSelected();
|
| 761 |
if(!ids.length) return alert("ααΌαααααΎαααΎαααααΈ!");
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
}
|
| 770 |
-
|
| 771 |
-
function toggleScrollOption(chk) {
|
| 772 |
-
if(chk.checked) {
|
| 773 |
-
document.getElementById("scroll-modal").style.display = "flex";
|
| 774 |
-
} else {
|
| 775 |
-
saveConfig();
|
| 776 |
-
}
|
| 777 |
-
}
|
| 778 |
-
|
| 779 |
-
function closeScrollModal() {
|
| 780 |
-
document.getElementById("cfg-auto-scroll").checked = false;
|
| 781 |
-
document.getElementById("scroll-modal").style.display = "none";
|
| 782 |
-
saveConfig();
|
| 783 |
-
}
|
| 784 |
-
|
| 785 |
-
async function applyScrollSettings() {
|
| 786 |
-
let speed = parseInt(document.getElementById("scroll-speed").value);
|
| 787 |
-
let behavior = parseInt(document.getElementById("scroll-behavior").value);
|
| 788 |
-
await fetch('/api/save_scroll_preset', {
|
| 789 |
-
method: 'POST',
|
| 790 |
-
headers: {'Content-Type': 'application/json'},
|
| 791 |
-
body: JSON.stringify({speed, behavior})
|
| 792 |
-
});
|
| 793 |
-
document.getElementById("scroll-modal").style.display = "none";
|
| 794 |
-
saveConfig();
|
| 795 |
-
}
|
| 796 |
-
|
| 797 |
-
async function saveConfig() {
|
| 798 |
-
let cfg = {
|
| 799 |
-
chk_auto_scroll: document.getElementById("cfg-auto-scroll").checked,
|
| 800 |
-
delay_spin: parseInt(document.getElementById("cfg-delay").value),
|
| 801 |
-
auto_close_spin: parseInt(document.getElementById("cfg-duration").value),
|
| 802 |
-
arrange_type_idx: parseInt(document.getElementById("cfg-arrange-type").value),
|
| 803 |
-
cols_spin: parseInt(document.getElementById("cfg-cols").value)
|
| 804 |
-
};
|
| 805 |
-
await fetch('/api/save_config', {
|
| 806 |
-
method: 'POST',
|
| 807 |
-
headers: {'Content-Type': 'application/json'},
|
| 808 |
-
body: JSON.stringify(cfg)
|
| 809 |
-
});
|
| 810 |
}
|
| 811 |
|
| 812 |
async function addStore() {
|
|
@@ -859,97 +323,14 @@ HTML_PANEL = """<!DOCTYPE html>
|
|
| 859 |
}
|
| 860 |
}
|
| 861 |
|
| 862 |
-
async function arrangeWindows() {
|
| 863 |
-
await fetch('/api/arrange_windows', { method: 'POST' });
|
| 864 |
-
}
|
| 865 |
-
|
| 866 |
-
async function updateResources() {
|
| 867 |
-
try {
|
| 868 |
-
let res = await fetch('/api/get_resources');
|
| 869 |
-
let data = await res.json();
|
| 870 |
-
document.getElementById("lbl-resources").innerText = `π₯οΈ CPU: ${data.cpu}% | πΎ RAM: ${data.ram}%`;
|
| 871 |
-
} catch {}
|
| 872 |
-
}
|
| 873 |
-
|
| 874 |
loadUI();
|
| 875 |
-
setInterval(updateResources, 2000);
|
| 876 |
setInterval(loadTable, 3000);
|
| 877 |
</script>
|
| 878 |
</body>
|
| 879 |
</html>
|
| 880 |
"""
|
| 881 |
|
| 882 |
-
|
| 883 |
-
# α₯. ααααααααααααΆαααααααααΆα Web UI αα·α PyQt6 Threading (Coordinator)
|
| 884 |
-
# =========================================================
|
| 885 |
-
class Coordinator(QObject):
|
| 886 |
-
start_signal = pyqtSignal(int)
|
| 887 |
-
stop_signal = pyqtSignal(int)
|
| 888 |
-
arrange_signal = pyqtSignal()
|
| 889 |
-
|
| 890 |
-
def __init__(self):
|
| 891 |
-
super().__init__()
|
| 892 |
-
self.start_signal.connect(self.on_start)
|
| 893 |
-
self.stop_signal.connect(self.on_stop)
|
| 894 |
-
self.arrange_signal.connect(self.on_arrange)
|
| 895 |
-
|
| 896 |
-
def on_start(self, inst_id):
|
| 897 |
-
if inst_id not in running_windows:
|
| 898 |
-
inst_data = next((x for x in instances if x["id"] == inst_id), None)
|
| 899 |
-
if inst_data:
|
| 900 |
-
win = MobileSimulator(
|
| 901 |
-
instance_id=inst_id,
|
| 902 |
-
device_name=inst_data["device"],
|
| 903 |
-
initial_url=inst_data["url"],
|
| 904 |
-
scale_factor=inst_data.get("scale", 0.75)
|
| 905 |
-
)
|
| 906 |
-
win.show()
|
| 907 |
-
running_windows[inst_id] = win
|
| 908 |
-
|
| 909 |
-
if app_config.get("chk_auto_scroll", True):
|
| 910 |
-
win.toggle_auto_scroll(
|
| 911 |
-
force_state=True,
|
| 912 |
-
speed=app_config.get("preset_speed", 2),
|
| 913 |
-
duration_min=app_config.get("auto_close_spin", 0),
|
| 914 |
-
random_mode=(app_config.get("preset_mode_idx", 1) == 1),
|
| 915 |
-
auto_close=(app_config.get("auto_close_spin", 0) > 0)
|
| 916 |
-
)
|
| 917 |
-
|
| 918 |
-
def on_stop(self, inst_id):
|
| 919 |
-
if inst_id in running_windows:
|
| 920 |
-
running_windows[inst_id].close()
|
| 921 |
-
|
| 922 |
-
def on_arrange(self):
|
| 923 |
-
if not running_windows: return
|
| 924 |
-
arrange_type = "Columns" if app_config.get("arrange_type_idx", 0) == 0 else "Rows"
|
| 925 |
-
count_limit = app_config.get("cols_spin", 3)
|
| 926 |
-
margin_x, margin_y, spacing = 20, 50, 15
|
| 927 |
-
current_col, current_row = 0, 0
|
| 928 |
-
sorted_keys = sorted(running_windows.keys())
|
| 929 |
-
|
| 930 |
-
for idx in sorted_keys:
|
| 931 |
-
win = running_windows[idx]
|
| 932 |
-
x = margin_x + current_col * (win.width() + spacing)
|
| 933 |
-
y = margin_y + current_row * (win.height() + spacing)
|
| 934 |
-
win.move(x, y)
|
| 935 |
-
|
| 936 |
-
if "Columns" in arrange_type:
|
| 937 |
-
current_col += 1
|
| 938 |
-
if current_col >= count_limit:
|
| 939 |
-
current_col = 0
|
| 940 |
-
current_row += 1
|
| 941 |
-
else:
|
| 942 |
-
current_row += 1
|
| 943 |
-
if current_row >= count_limit:
|
| 944 |
-
current_row = 0
|
| 945 |
-
current_col += 1
|
| 946 |
-
|
| 947 |
-
coordinator = None
|
| 948 |
-
|
| 949 |
-
# =========================================================
|
| 950 |
-
# α¦. Web App API Server Handler
|
| 951 |
-
# =========================================================
|
| 952 |
-
class WebUIRequestHandler(BaseHTTPRequestHandler):
|
| 953 |
def log_message(self, format, *args): return
|
| 954 |
|
| 955 |
def do_GET(self):
|
|
@@ -965,42 +346,13 @@ class WebUIRequestHandler(BaseHTTPRequestHandler):
|
|
| 965 |
self.send_json(urls_db)
|
| 966 |
elif self.path == "/api/get_config":
|
| 967 |
self.send_json(app_config)
|
| 968 |
-
elif self.path == "/api/get_resources":
|
| 969 |
-
cpu, ram = 0, 0
|
| 970 |
-
if psutil:
|
| 971 |
-
try:
|
| 972 |
-
cpu = psutil.cpu_percent()
|
| 973 |
-
ram = psutil.virtual_memory().percent
|
| 974 |
-
except Exception: pass
|
| 975 |
-
self.send_json({"cpu": cpu, "ram": ram})
|
| 976 |
elif self.path == "/api/get_instances":
|
| 977 |
-
|
| 978 |
-
for inst in instances:
|
| 979 |
-
iid = inst["id"]
|
| 980 |
-
status = instance_statuses.get(iid, "π΄ Offline")
|
| 981 |
-
size = calculated_sizes.get(iid, "Calculating...")
|
| 982 |
-
ip_city = inst.get("ip", "")
|
| 983 |
-
if ip_city and inst.get("city", ""):
|
| 984 |
-
ip_city = f"{inst['ip']} ({inst['city']})"
|
| 985 |
-
|
| 986 |
-
res.append({
|
| 987 |
-
"id": iid,
|
| 988 |
-
"name": inst.get("name", ""),
|
| 989 |
-
"store": inst.get("store", "ααΌαα
(Default)"),
|
| 990 |
-
"device": inst.get("device", ""),
|
| 991 |
-
"scale": inst.get("scale", 0.75),
|
| 992 |
-
"size": size,
|
| 993 |
-
"ip_display": ip_city,
|
| 994 |
-
"url": inst.get("url", DEFAULT_URL),
|
| 995 |
-
"note": inst.get("note", ""),
|
| 996 |
-
"status": status
|
| 997 |
-
})
|
| 998 |
-
self.send_json(res)
|
| 999 |
else:
|
| 1000 |
self.send_error(404)
|
| 1001 |
|
| 1002 |
def do_POST(self):
|
| 1003 |
-
global instances, stores, urls_db, app_config
|
| 1004 |
content_length = int(self.headers.get('Content-Length', 0))
|
| 1005 |
post_data = self.rfile.read(content_length) if content_length > 0 else b""
|
| 1006 |
req = json.loads(post_data.decode("utf-8")) if post_data else {}
|
|
@@ -1009,10 +361,7 @@ class WebUIRequestHandler(BaseHTTPRequestHandler):
|
|
| 1009 |
iid, field, value = req["id"], req["field"], req["value"]
|
| 1010 |
for inst in instances:
|
| 1011 |
if inst["id"] == iid:
|
| 1012 |
-
|
| 1013 |
-
inst["ip"] = value
|
| 1014 |
-
else:
|
| 1015 |
-
inst[field] = value
|
| 1016 |
break
|
| 1017 |
save_json(DB_PATH, instances)
|
| 1018 |
self.send_success()
|
|
@@ -1028,21 +377,8 @@ class WebUIRequestHandler(BaseHTTPRequestHandler):
|
|
| 1028 |
|
| 1029 |
elif self.path == "/api/delete_instances":
|
| 1030 |
ids = req["ids"]
|
| 1031 |
-
def handle_remove_readonly(func, path, exc):
|
| 1032 |
-
try:
|
| 1033 |
-
os.chmod(path, stat.S_IWRITE)
|
| 1034 |
-
func(path)
|
| 1035 |
-
except Exception: pass
|
| 1036 |
-
|
| 1037 |
-
for iid in ids:
|
| 1038 |
-
coordinator.stop_signal.emit(iid)
|
| 1039 |
-
inst_dir = os.path.abspath(f"./data/instance_{iid}")
|
| 1040 |
-
if os.path.exists(inst_dir):
|
| 1041 |
-
shutil.rmtree(inst_dir, onerror=handle_remove_readonly)
|
| 1042 |
-
|
| 1043 |
instances = [x for x in instances if x["id"] not in ids]
|
| 1044 |
save_json(DB_PATH, instances)
|
| 1045 |
-
gc.collect()
|
| 1046 |
self.send_success()
|
| 1047 |
|
| 1048 |
elif self.path == "/api/add_store":
|
|
@@ -1055,7 +391,8 @@ class WebUIRequestHandler(BaseHTTPRequestHandler):
|
|
| 1055 |
if name in stores:
|
| 1056 |
stores.remove(name)
|
| 1057 |
for inst in instances:
|
| 1058 |
-
if inst.get("store") == name:
|
|
|
|
| 1059 |
save_json(STORES_PATH, stores)
|
| 1060 |
save_json(DB_PATH, instances)
|
| 1061 |
self.send_success()
|
|
@@ -1073,41 +410,6 @@ class WebUIRequestHandler(BaseHTTPRequestHandler):
|
|
| 1073 |
urls_db.remove(req["url"])
|
| 1074 |
save_json(URLS_PATH, urls_db)
|
| 1075 |
self.send_success()
|
| 1076 |
-
|
| 1077 |
-
elif self.path == "/api/save_scroll_preset":
|
| 1078 |
-
app_config["preset_speed"] = req["speed"]
|
| 1079 |
-
app_config["preset_mode_idx"] = req["behavior"]
|
| 1080 |
-
save_json(CONFIG_PATH, app_config)
|
| 1081 |
-
self.send_success()
|
| 1082 |
-
|
| 1083 |
-
elif self.path == "/api/save_config":
|
| 1084 |
-
app_config.update(req)
|
| 1085 |
-
save_json(CONFIG_PATH, app_config)
|
| 1086 |
-
self.send_success()
|
| 1087 |
-
|
| 1088 |
-
elif self.path == "/api/arrange_windows":
|
| 1089 |
-
coordinator.arrange_signal.emit()
|
| 1090 |
-
self.send_success()
|
| 1091 |
-
|
| 1092 |
-
elif self.path == "/api/start_profiles":
|
| 1093 |
-
ids = req["ids"]
|
| 1094 |
-
delay = app_config.get("delay_spin", 3)
|
| 1095 |
-
|
| 1096 |
-
def run_queue():
|
| 1097 |
-
for idx, iid in enumerate(ids):
|
| 1098 |
-
if idx > 0 and delay > 0:
|
| 1099 |
-
time.sleep(delay)
|
| 1100 |
-
coordinator.start_signal.emit(iid)
|
| 1101 |
-
time.sleep(1)
|
| 1102 |
-
coordinator.arrange_signal.emit()
|
| 1103 |
-
|
| 1104 |
-
threading.Thread(target=run_queue, daemon=True).start()
|
| 1105 |
-
self.send_success()
|
| 1106 |
-
|
| 1107 |
-
elif self.path == "/api/stop_profiles":
|
| 1108 |
-
for iid in req["ids"]:
|
| 1109 |
-
coordinator.stop_signal.emit(iid)
|
| 1110 |
-
self.send_success()
|
| 1111 |
else:
|
| 1112 |
self.send_error(404)
|
| 1113 |
|
|
@@ -1120,37 +422,8 @@ class WebUIRequestHandler(BaseHTTPRequestHandler):
|
|
| 1120 |
def send_success(self):
|
| 1121 |
self.send_json({"status": "success"})
|
| 1122 |
|
| 1123 |
-
def run_web_server():
|
| 1124 |
-
server = ThreadingHTTPServer(("127.0.0.1", PORT), WebUIRequestHandler)
|
| 1125 |
-
server.serve_forever()
|
| 1126 |
-
|
| 1127 |
-
# =========================================================
|
| 1128 |
-
# α§. ααααΆααααααΆααα α Folder αα
ααΆαααααα (Background Thread)
|
| 1129 |
-
# =========================================================
|
| 1130 |
-
class SizeWorker(QThread):
|
| 1131 |
-
def run(self):
|
| 1132 |
-
while True:
|
| 1133 |
-
for inst in instances:
|
| 1134 |
-
iid = inst["id"]
|
| 1135 |
-
path = os.path.abspath(f"./data/instance_{iid}")
|
| 1136 |
-
calculated_sizes[iid] = format_size(get_dir_size(path))
|
| 1137 |
-
time.sleep(5)
|
| 1138 |
-
|
| 1139 |
-
# =========================================================
|
| 1140 |
-
# α¨. α
ααα»α
α
αΆααααααΎααααααα·ααΈ (Main Application Entry)
|
| 1141 |
-
# =========================================================
|
| 1142 |
if __name__ == "__main__":
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
-
|
| 1147 |
-
web_thread = threading.Thread(target=run_web_server, daemon=True)
|
| 1148 |
-
web_thread.start()
|
| 1149 |
-
|
| 1150 |
-
size_worker = SizeWorker()
|
| 1151 |
-
size_worker.start()
|
| 1152 |
-
|
| 1153 |
-
webbrowser = __import__("webbrowser")
|
| 1154 |
-
webbrowser.open(f"http://127.0.0.1:{PORT}")
|
| 1155 |
-
|
| 1156 |
-
sys.exit(app.exec())
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
+
import gc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
|
| 5 |
+
import urllib.parse
|
| 6 |
|
|
|
|
| 7 |
DB_PATH = "./data/instances.json"
|
| 8 |
STORES_PATH = "./data/stores.json"
|
| 9 |
URLS_PATH = "./data/urls.json"
|
| 10 |
CONFIG_PATH = "./data/config.json"
|
| 11 |
DEFAULT_URL = "https://www.facebook.com"
|
|
|
|
| 12 |
|
| 13 |
+
# Hugging Face αααααΌαα±αααααααΎ Port 7860 ααΆα
αααΆα
|
| 14 |
+
PORT = 7860
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
os.makedirs("./data", exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def load_json(path, default):
|
| 19 |
if not os.path.exists(path):
|
|
|
|
| 20 |
with open(path, "w", encoding="utf-8") as f:
|
| 21 |
json.dump(default, f, ensure_ascii=False, indent=4)
|
| 22 |
return default
|
|
|
|
| 30 |
with open(path, "w", encoding="utf-8") as f:
|
| 31 |
json.dump(data, f, ensure_ascii=False, indent=4)
|
| 32 |
|
|
|
|
| 33 |
instances = load_json(DB_PATH, [{"id": 1, "name": "ααααΈ #1", "device": "Compact Mobile (360x500)", "url": DEFAULT_URL, "scale": 0.50, "ip": "", "city": "", "note": "", "store": "ααΌαα
(Default)"}])
|
| 34 |
stores = load_json(STORES_PATH, ["ααΌαα
(Default)"])
|
| 35 |
urls_db = load_json(URLS_PATH, [DEFAULT_URL, "https://www.youtube.com", "https://www.google.com", "https://www.tiktok.com"])
|
| 36 |
app_config = load_json(CONFIG_PATH, {"chk_auto_scroll": True, "delay_spin": 3, "auto_close_spin": 0, "arrange_type_idx": 0, "cols_spin": 3, "preset_speed": 2, "preset_mode_idx": 1})
|
| 37 |
|
| 38 |
+
# ααααΆαα Web UI αααααΆαα
ααΆαα Local Agent ααΎαα»αααααΌαααααααΆαααααα½αααααα’αααααααΎααααΆαα (Port 4848)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
HTML_PANEL = """<!DOCTYPE html>
|
| 40 |
<html lang="km">
|
| 41 |
<head>
|
| 42 |
<meta charset="UTF-8">
|
| 43 |
<title>αααααααααααααααααααααΈ - Web Control Panel</title>
|
| 44 |
<style>
|
| 45 |
+
body { background-color: #0f1115; color: #e2e8f0; font-family: sans-serif; font-size: 12px; margin: 0; padding: 15px; }
|
| 46 |
+
.top-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 15px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
.lbl-total { font-weight: bold; color: #38bdf8; font-size: 13px; }
|
| 48 |
.main-body { display: flex; gap: 15px; }
|
| 49 |
+
.table-container { flex: 1; background-color: #161920; border: 1px solid #1e293b; border-radius: 8px; padding: 12px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
table { width: 100%; border-collapse: collapse; }
|
| 51 |
th, td { padding: 8px; text-align: left; border-bottom: 1px solid #1d212a; }
|
| 52 |
th { background-color: #0f172a; color: #94a3b8; font-weight: bold; }
|
| 53 |
+
.sidebar { width: 240px; background-color: #161920; border: 1px solid #1e293b; border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
.group-box { border: 1px solid #1e293b; border-radius: 6px; padding: 10px; }
|
| 55 |
.group-title { font-weight: bold; color: #38bdf8; font-size: 11px; margin-bottom: 6px; }
|
| 56 |
+
input[type="text"], select, input[type="number"] { background-color: #0f1115; color: #f8fafc; border: 1px solid #2d3343; border-radius: 6px; padding: 5px 8px; width: 100%; box-sizing: border-box; }
|
| 57 |
+
button { background-color: #1e293b; color: #f8fafc; border: 1px solid #334155; border-radius: 6px; padding: 6px 12px; font-weight: bold; cursor: pointer; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
button:hover { background-color: #38bdf8; color: #0f1115; }
|
| 59 |
.btn-success { background-color: #10b981; color: white; border: none; }
|
| 60 |
.btn-success:hover { background-color: #059669; }
|
| 61 |
.btn-danger { background-color: #ef4444; color: white; border: none; }
|
| 62 |
.btn-danger:hover { background-color: #dc2626; }
|
|
|
|
| 63 |
.digital-timer { font-size: 24px; font-weight: bold; color: #f97316; font-family: monospace; margin-left: auto; }
|
|
|
|
| 64 |
.footer-bar { margin-top: 15px; display: flex; justify-content: space-between; color: #64748b; font-size: 11px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
</style>
|
| 66 |
</head>
|
| 67 |
<body>
|
|
|
|
| 68 |
<div class="top-bar">
|
| 69 |
<div class="lbl-total" id="lbl-total">ααααΈααα»α (Total Profiles): 0</div>
|
| 70 |
<button onclick="addInstance()">οΌ ααααααααααΈ</button>
|
|
|
|
| 73 |
<button class="btn-danger" onclick="stopSelected()">βΉ ααααααααα (STOP)</button>
|
| 74 |
<div class="digital-timer" id="stopwatch">00:00:00</div>
|
| 75 |
<input type="text" id="search" placeholder="ααααααα..." style="width: 150px;" oninput="filterRows()">
|
|
|
|
| 76 |
</div>
|
| 77 |
|
| 78 |
<div class="main-body">
|
|
|
|
| 104 |
<button style="flex:1;" onclick="deleteStore()">ποΈ αα»α</button>
|
| 105 |
</div>
|
| 106 |
</div>
|
|
|
|
| 107 |
<div class="group-box">
|
| 108 |
<div class="group-title">αααααααααααΈα/αα·αααΆα (URLS)</div>
|
| 109 |
<select id="url-select" style="margin-bottom: 6px;"></select>
|
|
|
|
| 112 |
<button style="flex:1;" onclick="deleteUrl()">ποΈ αα»α</button>
|
| 113 |
</div>
|
| 114 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
</div>
|
| 116 |
</div>
|
| 117 |
|
| 118 |
<div class="footer-bar">
|
| 119 |
<span id="lbl-status">ααααααααα½ααα½α
ααΆαα (Ready)</span>
|
| 120 |
+
<span id="lbl-resources">π₯οΈ Cloud Server ααααΎαααΆαααααααΆ</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
</div>
|
| 122 |
|
| 123 |
<script>
|
| 124 |
+
// ααααΆαααααααΆααΈ Cloud αα
ααΆαα Local Agent αα
ααΎαααΆαααΈαααααΆαααααα½αααααα’αααααααΎααααΆαα
|
| 125 |
+
const LOCAL_AGENT_URL = "http://127.0.0.1:4848";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
async function loadUI() {
|
| 128 |
let resStores = await fetch('/api/get_stores');
|
|
|
|
| 137 |
urlSelect.innerHTML = '';
|
| 138 |
listUrls.forEach(u => urlSelect.innerHTML += `<option value="${u}">${u}</option>`);
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
await loadTable();
|
| 141 |
}
|
| 142 |
|
| 143 |
async function loadTable() {
|
| 144 |
+
// ααΆαααααααΆαααΆαααΌααααααα·αααα·αααΈ Local Agent
|
| 145 |
+
let activeLocalStatuses = {};
|
| 146 |
+
try {
|
| 147 |
+
let localRes = await fetch(`${LOCAL_AGENT_URL}/api/get_instances_status`);
|
| 148 |
+
activeLocalStatuses = await localRes.json();
|
| 149 |
+
} catch(e) {
|
| 150 |
+
document.getElementById("lbl-status").innerText = "β οΈ ααΌαααΎααααααα·ααΈ Local Agent ααΎαα»αααααΌαααααααα’ααααα·α!";
|
| 151 |
+
}
|
| 152 |
|
| 153 |
+
let checkedIds = Array.from(document.querySelectorAll(".row-check:checked")).map(cb => parseInt(cb.value));
|
| 154 |
let resInst = await fetch('/api/get_instances');
|
| 155 |
let data = await resInst.json();
|
| 156 |
document.getElementById("lbl-total").innerText = `ααααΈααα»α (Total Profiles): ${data.length}`;
|
|
|
|
| 158 |
let tbody = document.getElementById("table-body");
|
| 159 |
tbody.innerHTML = "";
|
| 160 |
data.forEach(inst => {
|
| 161 |
+
let status = activeLocalStatuses[inst.id] || "π΄ Offline";
|
| 162 |
let statusColor = "color: #ef4444;";
|
| 163 |
+
if(status.includes("ααααΌα")) statusColor = "color: #a855f7;";
|
| 164 |
+
else if(status.includes("αααα»α")) statusColor = "color: #eab308;";
|
| 165 |
+
else if(status.includes("Online")) statusColor = "color: #10b981;";
|
| 166 |
|
| 167 |
let isChecked = checkedIds.includes(inst.id) ? "checked" : "";
|
| 168 |
|
| 169 |
tbody.innerHTML += `
|
| 170 |
<tr class="profile-row" data-id="${inst.id}" data-name="${inst.name.toLowerCase()}" data-store="${inst.store}">
|
| 171 |
<td><input type="checkbox" class="row-check" value="${inst.id}" ${isChecked}></td>
|
| 172 |
+
<td style="${statusColor} font-weight:bold;">${status}</td>
|
| 173 |
<td><input type="text" value="${inst.name}" onchange="updateField(${inst.id}, 'name', this.value)"></td>
|
| 174 |
<td>
|
| 175 |
<select onchange="updateField(${inst.id}, 'store', this.value)">
|
|
|
|
| 178 |
.map(o => `<option value="${o.value}" ${inst.store === o.value ? 'selected':''}>${o.value}</option>`).join('')}
|
| 179 |
</select>
|
| 180 |
</td>
|
| 181 |
+
<td>${inst.device}</td>
|
| 182 |
+
<td>${inst.size || '0 KB'}</td>
|
| 183 |
+
<td><input type="text" value="${inst.ip_display || ''}" onchange="updateField(${inst.id}, 'ip', this.value)" placeholder="IP/ααΈαααα»α"></td>
|
| 184 |
<td>
|
| 185 |
<select onchange="updateField(${inst.id}, 'url', this.value)">
|
| 186 |
${Array.from(document.getElementById("url-select").options)
|
| 187 |
.map(o => `<option value="${o.value}" ${inst.url === o.value ? 'selected':''}>${o.value}</option>`).join('')}
|
| 188 |
</select>
|
| 189 |
</td>
|
| 190 |
+
<td><input type="text" value="${inst.note || ''}" onchange="updateField(${inst.id}, 'note', this.value)" placeholder="α
αααΆα..."></td>
|
| 191 |
</tr>
|
| 192 |
`;
|
| 193 |
});
|
|
|
|
| 200 |
headers: {'Content-Type': 'application/json'},
|
| 201 |
body: JSON.stringify({id, field, value})
|
| 202 |
});
|
|
|
|
| 203 |
}
|
| 204 |
|
| 205 |
function selectAll(master) {
|
|
|
|
| 240 |
}
|
| 241 |
}
|
| 242 |
|
| 243 |
+
// ααααΎαααααΆααααΆαααα
ααΆαα Local Agent ααΎαααΆαααΈααααα½αα―α
|
| 244 |
async function startSelected() {
|
| 245 |
let ids = getSelected();
|
| 246 |
if(!ids.length) return alert("ααΌαααααΎαααΎαααααΈ!");
|
| 247 |
+
|
| 248 |
+
// ααΆααααα·αααααααααα’α·αααααααΈαααααααΌαααΎα
|
| 249 |
+
let res = await fetch('/api/get_instances');
|
| 250 |
+
let allInstances = await res.json();
|
| 251 |
+
let selectedData = allInstances.filter(x => ids.includes(x.id));
|
| 252 |
+
|
| 253 |
+
try {
|
| 254 |
+
await fetch(`${LOCAL_AGENT_URL}/api/start_profiles`, {
|
| 255 |
+
method: 'POST',
|
| 256 |
+
headers: {'Content-Type': 'application/json'},
|
| 257 |
+
body: JSON.stringify({profiles: selectedData})
|
| 258 |
+
});
|
| 259 |
+
} catch(e) {
|
| 260 |
+
alert("αα·αα’αΆα
αααααΆαα
ααΆαα Local Agent ααΆααα! ααΌαααααΆααααΆααΆαααΎα Agent αα½α
ααΆααα");
|
| 261 |
+
}
|
| 262 |
}
|
| 263 |
|
| 264 |
async function stopSelected() {
|
| 265 |
let ids = getSelected();
|
| 266 |
if(!ids.length) return alert("ααΌαααααΎαααΎαααααΈ!");
|
| 267 |
+
try {
|
| 268 |
+
await fetch(`${LOCAL_AGENT_URL}/api/stop_profiles`, {
|
| 269 |
+
method: 'POST',
|
| 270 |
+
headers: {'Content-Type': 'application/json'},
|
| 271 |
+
body: JSON.stringify({ids})
|
| 272 |
+
});
|
| 273 |
+
} catch(e) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
}
|
| 275 |
|
| 276 |
async function addStore() {
|
|
|
|
| 323 |
}
|
| 324 |
}
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
loadUI();
|
|
|
|
| 327 |
setInterval(loadTable, 3000);
|
| 328 |
</script>
|
| 329 |
</body>
|
| 330 |
</html>
|
| 331 |
"""
|
| 332 |
|
| 333 |
+
class CloudRequestHandler(BaseHTTPRequestHandler):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
def log_message(self, format, *args): return
|
| 335 |
|
| 336 |
def do_GET(self):
|
|
|
|
| 346 |
self.send_json(urls_db)
|
| 347 |
elif self.path == "/api/get_config":
|
| 348 |
self.send_json(app_config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
elif self.path == "/api/get_instances":
|
| 350 |
+
self.send_json(instances)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
else:
|
| 352 |
self.send_error(404)
|
| 353 |
|
| 354 |
def do_POST(self):
|
| 355 |
+
global instances, stores, urls_db, app_config
|
| 356 |
content_length = int(self.headers.get('Content-Length', 0))
|
| 357 |
post_data = self.rfile.read(content_length) if content_length > 0 else b""
|
| 358 |
req = json.loads(post_data.decode("utf-8")) if post_data else {}
|
|
|
|
| 361 |
iid, field, value = req["id"], req["field"], req["value"]
|
| 362 |
for inst in instances:
|
| 363 |
if inst["id"] == iid:
|
| 364 |
+
inst[field] = value
|
|
|
|
|
|
|
|
|
|
| 365 |
break
|
| 366 |
save_json(DB_PATH, instances)
|
| 367 |
self.send_success()
|
|
|
|
| 377 |
|
| 378 |
elif self.path == "/api/delete_instances":
|
| 379 |
ids = req["ids"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
instances = [x for x in instances if x["id"] not in ids]
|
| 381 |
save_json(DB_PATH, instances)
|
|
|
|
| 382 |
self.send_success()
|
| 383 |
|
| 384 |
elif self.path == "/api/add_store":
|
|
|
|
| 391 |
if name in stores:
|
| 392 |
stores.remove(name)
|
| 393 |
for inst in instances:
|
| 394 |
+
if inst.get("store") == name:
|
| 395 |
+
inst["store"] = "ααΌαα
(Default)"
|
| 396 |
save_json(STORES_PATH, stores)
|
| 397 |
save_json(DB_PATH, instances)
|
| 398 |
self.send_success()
|
|
|
|
| 410 |
urls_db.remove(req["url"])
|
| 411 |
save_json(URLS_PATH, urls_db)
|
| 412 |
self.send_success()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
else:
|
| 414 |
self.send_error(404)
|
| 415 |
|
|
|
|
| 422 |
def send_success(self):
|
| 423 |
self.send_json({"status": "success"})
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
if __name__ == "__main__":
|
| 426 |
+
# ααΎαααααΎαααΆα Web Server ααΎ Port 7860 αααααΆαα Cloud
|
| 427 |
+
server = ThreadingHTTPServer(("0.0.0.0", PORT), CloudRequestHandler)
|
| 428 |
+
print(f"Cloud Server running on port {PORT}...")
|
| 429 |
+
server.serve_forever()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|