THEZYZSTUDIO commited on
Commit
d4ace36
ยท
verified ยท
1 Parent(s): de06120

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -33
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
- elif action == "start_stream":
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, start_stream, stop_stream"
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