Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -100,10 +100,6 @@ h1{{color:#4a90d9;}} .ok{{color:#00ff88;}} .info{{color:#888;font-size:13px;}}</
|
|
| 100 |
</body></html>"""
|
| 101 |
|
| 102 |
active_connections: list[WebSocket] = []
|
| 103 |
-
stream_active = False
|
| 104 |
-
stream_fps = 3
|
| 105 |
-
stream_quality = 60
|
| 106 |
-
stream_scale = 0.5
|
| 107 |
|
| 108 |
# โโโ CURL HEADERS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 109 |
CURL_HEADERS = (
|
|
@@ -496,7 +492,25 @@ def capture_screen_with_grid(scale=0.65, quality=72,
|
|
| 496 |
|
| 497 |
# โโโ Command Runner โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
def run_raw_command(cmd: str, timeout: int = 60) -> dict:
|
|
|
|
| 500 |
env = {**os.environ, "DISPLAY": DISPLAY,
|
| 501 |
"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"}
|
| 502 |
try:
|
|
@@ -758,19 +772,6 @@ async def broadcast(msg: dict):
|
|
| 758 |
active_connections.remove(ws)
|
| 759 |
|
| 760 |
|
| 761 |
-
async def screen_stream_loop():
|
| 762 |
-
global stream_active
|
| 763 |
-
interval = 1.0 / max(1, stream_fps)
|
| 764 |
-
while stream_active and active_connections:
|
| 765 |
-
try:
|
| 766 |
-
frame = capture_screen(scale=stream_scale, quality=stream_quality)
|
| 767 |
-
if frame:
|
| 768 |
-
await broadcast({"type": "frame", "data": frame})
|
| 769 |
-
except: pass
|
| 770 |
-
await asyncio.sleep(interval)
|
| 771 |
-
stream_active = False
|
| 772 |
-
|
| 773 |
-
|
| 774 |
# โโโ Action Handler โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 775 |
|
| 776 |
async def handle_action(ws: WebSocket, msg: dict):
|
|
@@ -997,21 +998,8 @@ async def handle_action(ws: WebSocket, msg: dict):
|
|
| 997 |
# cursor ููุชูู ุนูุฏ x2,y2
|
| 998 |
await auto_shot_grid("ุจุนุฏ ุงูุณุญุจ", delay=0.4, force_mx=x2, force_my=y2)
|
| 999 |
|
| 1000 |
-
# โโ start_stream
|
| 1001 |
-
|
| 1002 |
-
global stream_active, stream_fps, stream_quality, stream_scale
|
| 1003 |
-
stream_fps = int(data.get("fps", 3))
|
| 1004 |
-
stream_quality = int(data.get("quality", 60))
|
| 1005 |
-
stream_scale = float(data.get("scale", 0.5))
|
| 1006 |
-
if not stream_active:
|
| 1007 |
-
stream_active = True
|
| 1008 |
-
asyncio.create_task(screen_stream_loop())
|
| 1009 |
-
await send({"type": "ack", "action": "start_stream"})
|
| 1010 |
-
|
| 1011 |
-
# โโ stop_stream โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1012 |
-
elif action == "stop_stream":
|
| 1013 |
-
stream_active = False
|
| 1014 |
-
await send({"type": "ack", "action": "stop_stream"})
|
| 1015 |
|
| 1016 |
# โโ screen_info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1017 |
elif action == "screen_info":
|
|
@@ -1045,7 +1033,7 @@ async def handle_action(ws: WebSocket, msg: dict):
|
|
| 1045 |
else:
|
| 1046 |
await send({
|
| 1047 |
"type": "error",
|
| 1048 |
-
"msg": f"Unknown action: '{action}'. Available: screenshot, terminal, mouse_move, mouse_click, mouse_drag, keyboard_type, keyboard_hotkey, keyboard_press, clipboard_write, clipboard_read, scroll, open_app, open_browser, paste, simple_command, screen_info
|
| 1049 |
})
|
| 1050 |
|
| 1051 |
|
|
|
|
| 100 |
</body></html>"""
|
| 101 |
|
| 102 |
active_connections: list[WebSocket] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# โโโ CURL HEADERS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 105 |
CURL_HEADERS = (
|
|
|
|
| 492 |
|
| 493 |
# โโโ Command Runner โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 494 |
|
| 495 |
+
_PKILL_SELF_MATCH_RE = re.compile(r"\b(pkill|killall)\s+(-9\s+)?-f\s+(['\"]?)([a-zA-Z0-9_./-]+)\3")
|
| 496 |
+
|
| 497 |
+
def _sanitize_pkill_self_match(cmd: str) -> str:
|
| 498 |
+
"""
|
| 499 |
+
ูุญููู ุฃูู
ุงุท pkill -f ุงูุฎุทูุฑุฉ (ู
ุซู: pkill -f firefox) ุฅูู ุตูุบุฉ ุขู
ูุฉ
|
| 500 |
+
ูุง ุชุทุงุจู ุณุทุฑ ุงูุฃู
ุฑ ุงูุฎุงุต ุจู pkill ููุณู โ ูุฃู pkill -f ูุจุญุซ ูู ูุงู
ู ุณุทุฑ
|
| 501 |
+
ุงูุฃู
ุฑ ููู ุงูุนู
ููุงุชุ ูููุทุงุจู ุณุทุฑู ุงูุฎุงุต ูููุชู ููุณูุ ูููุนูุฏ returncode=-15
|
| 502 |
+
ููุฃู ุงูุฃู
ุฑ "ูุดู" ุจููู
ุง ูู ูุนููุงู ูุฌุญ (ุฃู ูู
ููู ููุงู ุดูุก ููุชูู ู
ู ุงูุฃุณุงุณ).
|
| 503 |
+
"""
|
| 504 |
+
def _fix(m):
|
| 505 |
+
tool, dash9, _q, pattern = m.group(1), m.group(2) or "", m.group(3), m.group(4)
|
| 506 |
+
# ุงุณุชุจุนุฏ ุณุทุฑ ุฃู
ุฑ pkill/killall ููุณู ู
ู ุงูู
ุทุงุจูุฉ ุจุฅุถุงูุฉ [^k]
|
| 507 |
+
safe_pattern = f"[{pattern[0]}]{pattern[1:]}" if len(pattern) > 1 else pattern
|
| 508 |
+
return f"{tool} {dash9}-f '{safe_pattern}'"
|
| 509 |
+
return _PKILL_SELF_MATCH_RE.sub(_fix, cmd)
|
| 510 |
+
|
| 511 |
+
|
| 512 |
def run_raw_command(cmd: str, timeout: int = 60) -> dict:
|
| 513 |
+
cmd = _sanitize_pkill_self_match(cmd)
|
| 514 |
env = {**os.environ, "DISPLAY": DISPLAY,
|
| 515 |
"PYTHONIOENCODING": "utf-8", "LANG": "en_US.UTF-8"}
|
| 516 |
try:
|
|
|
|
| 772 |
active_connections.remove(ws)
|
| 773 |
|
| 774 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
# โโโ Action Handler โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 776 |
|
| 777 |
async def handle_action(ws: WebSocket, msg: dict):
|
|
|
|
| 998 |
# cursor ููุชูู ุนูุฏ x2,y2
|
| 999 |
await auto_shot_grid("ุจุนุฏ ุงูุณุญุจ", delay=0.4, force_mx=x2, force_my=y2)
|
| 1000 |
|
| 1001 |
+
# โโ start_stream / stop_stream: ุบูุฑ ู
ุณุชุฎุฏู
ุฉ ู
ู ุงููุงุฌูุฉ ุงูุญุงููุฉุ ุฃูุฒููุช ูู
ูุน
|
| 1002 |
+
# ุชุดุบูู ุญููุฉ ุชุตููุฑ ู
ุณุชู
ุฑุฉ ูู ุงูุฎูููุฉ ุจูุง ุฏุงุนู (ูุงูุช ุชุณุชููู ู
ูุงุฑุฏ ุญุชู ุจุนุฏ ุฅุบูุงู ุงูุงุชุตุงู) โโ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1003 |
|
| 1004 |
# โโ screen_info โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1005 |
elif action == "screen_info":
|
|
|
|
| 1033 |
else:
|
| 1034 |
await send({
|
| 1035 |
"type": "error",
|
| 1036 |
+
"msg": f"Unknown action: '{action}'. Available: screenshot, terminal, mouse_move, mouse_click, mouse_drag, keyboard_type, keyboard_hotkey, keyboard_press, clipboard_write, clipboard_read, scroll, open_app, open_browser, paste, simple_command, screen_info"
|
| 1037 |
})
|
| 1038 |
|
| 1039 |
|