allow to ask for remote host profiles and save token on first connection for later use
This commit is contained in:
@@ -17,8 +17,10 @@ def _handle(command, args=None, profile=None):
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def _handle_multi(command, args=None, profile=None):
|
||||
def _handle_multi(command, args=None, profile=None, remote=None, token=None):
|
||||
try:
|
||||
if remote:
|
||||
return send_command(command, args or {}, profile=profile, remote=remote, token=token)
|
||||
return send_command(command, args or {}, profile=profile)
|
||||
except (BrowserNotConnected, RuntimeError):
|
||||
return None
|
||||
@@ -29,7 +31,7 @@ def _multi_browser_targets():
|
||||
if root.obj.get("browser_explicit"):
|
||||
return []
|
||||
targets = active_browser_targets()
|
||||
if len(targets) <= 1:
|
||||
if len(targets) <= 1 and not any(target.remote for target in targets):
|
||||
return []
|
||||
return targets
|
||||
|
||||
@@ -71,7 +73,7 @@ def group_list():
|
||||
if targets:
|
||||
groups = []
|
||||
for target in targets:
|
||||
result = _handle_multi("group.list", profile=target.profile)
|
||||
result = _handle_multi("group.list", profile=target.profile, remote=target.remote, token=target.token)
|
||||
if result is None:
|
||||
continue
|
||||
groups.extend({**group, "browser": target.display_name} for group in result)
|
||||
@@ -104,7 +106,7 @@ def group_count():
|
||||
total = 0
|
||||
rows = 0
|
||||
for target in targets:
|
||||
count = _handle_multi("group.count", profile=target.profile)
|
||||
count = _handle_multi("group.count", profile=target.profile, remote=target.remote, token=target.token)
|
||||
if count is None:
|
||||
continue
|
||||
count = int(count or 0)
|
||||
|
||||
@@ -56,6 +56,17 @@ def _proxy_request(client_sock:socket.socket, addr:tuple, profile:str|None, serv
|
||||
_log(addr, command, None, "DENIED", "bad token")
|
||||
return
|
||||
|
||||
if command == "browser-cli.targets":
|
||||
from browser_cli.client import active_browser_targets
|
||||
targets = [
|
||||
{"profile": target.profile, "displayName": target.display_name}
|
||||
for target in active_browser_targets(include_remotes=False)
|
||||
]
|
||||
data = json.dumps({"id": msg_id, "success": True, "data": targets}).encode()
|
||||
client_sock.sendall(struct.pack("<I", len(data)) + data)
|
||||
_log(addr, command, None, "OK")
|
||||
return
|
||||
|
||||
resolved_profile = msg.get("_route") or profile
|
||||
|
||||
strip = {"token", "_route"}
|
||||
|
||||
@@ -16,8 +16,10 @@ def _handle(command, args=None, profile=None):
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def _handle_multi(command, args=None, profile=None):
|
||||
def _handle_multi(command, args=None, profile=None, remote=None, token=None):
|
||||
try:
|
||||
if remote:
|
||||
return send_command(command, args or {}, profile=profile, remote=remote, token=token)
|
||||
return send_command(command, args or {}, profile=profile)
|
||||
except (BrowserNotConnected, RuntimeError):
|
||||
return None
|
||||
@@ -28,7 +30,7 @@ def _multi_browser_targets():
|
||||
if root.obj.get("browser_explicit"):
|
||||
return []
|
||||
targets = active_browser_targets()
|
||||
if len(targets) <= 1:
|
||||
if len(targets) <= 1 and not any(target.remote for target in targets):
|
||||
return []
|
||||
return targets
|
||||
|
||||
@@ -92,7 +94,7 @@ def session_list():
|
||||
if targets:
|
||||
sessions = []
|
||||
for target in targets:
|
||||
result = _handle_multi("session.list", profile=target.profile)
|
||||
result = _handle_multi("session.list", profile=target.profile, remote=target.remote, token=target.token)
|
||||
if result is None:
|
||||
continue
|
||||
sessions.extend({**session, "browser": target.display_name} for session in result)
|
||||
|
||||
@@ -18,8 +18,10 @@ def _handle(command, args=None, profile=None):
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def _handle_multi(command, args=None, profile=None):
|
||||
def _handle_multi(command, args=None, profile=None, remote=None, token=None):
|
||||
try:
|
||||
if remote:
|
||||
return send_command(command, args or {}, profile=profile, remote=remote, token=token)
|
||||
return send_command(command, args or {}, profile=profile)
|
||||
except (BrowserNotConnected, RuntimeError):
|
||||
return None
|
||||
@@ -30,7 +32,7 @@ def _multi_browser_targets():
|
||||
if root.obj.get("browser_explicit"):
|
||||
return []
|
||||
targets = active_browser_targets()
|
||||
if len(targets) <= 1:
|
||||
if len(targets) <= 1 and not any(target.remote for target in targets):
|
||||
return []
|
||||
return targets
|
||||
|
||||
@@ -76,7 +78,7 @@ def tabs_list():
|
||||
if targets:
|
||||
tabs = []
|
||||
for target in targets:
|
||||
result = _handle_multi("tabs.list", profile=target.profile)
|
||||
result = _handle_multi("tabs.list", profile=target.profile, remote=target.remote, token=target.token)
|
||||
if result is None:
|
||||
continue
|
||||
tabs.extend({**tab, "browser": target.display_name} for tab in result)
|
||||
@@ -163,7 +165,7 @@ def tabs_count(pattern):
|
||||
total = 0
|
||||
rows = 0
|
||||
for target in targets:
|
||||
count = _handle_multi("tabs.count", {"pattern": pattern}, profile=target.profile)
|
||||
count = _handle_multi("tabs.count", {"pattern": pattern}, profile=target.profile, remote=target.remote, token=target.token)
|
||||
if count is None:
|
||||
continue
|
||||
count = int(count or 0)
|
||||
|
||||
@@ -17,8 +17,10 @@ def _handle(command, args=None, profile=None):
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def _handle_multi(command, args=None, profile=None):
|
||||
def _handle_multi(command, args=None, profile=None, remote=None, token=None):
|
||||
try:
|
||||
if remote:
|
||||
return send_command(command, args or {}, profile=profile, remote=remote, token=token)
|
||||
return send_command(command, args or {}, profile=profile)
|
||||
except (BrowserNotConnected, RuntimeError):
|
||||
return None
|
||||
@@ -29,7 +31,7 @@ def _multi_browser_targets():
|
||||
if root.obj.get("browser_explicit"):
|
||||
return []
|
||||
targets = active_browser_targets()
|
||||
if len(targets) <= 1:
|
||||
if len(targets) <= 1 and not any(target.remote for target in targets):
|
||||
return []
|
||||
return targets
|
||||
|
||||
@@ -69,7 +71,7 @@ def windows_list():
|
||||
if targets:
|
||||
windows = []
|
||||
for target in targets:
|
||||
result = _handle_multi("windows.list", profile=target.profile)
|
||||
result = _handle_multi("windows.list", profile=target.profile, remote=target.remote, token=target.token)
|
||||
if result is None:
|
||||
continue
|
||||
windows.extend({**window, "browser": target.display_name} for window in result)
|
||||
|
||||
Reference in New Issue
Block a user