From 5916d82580ef11638665d23feea5760f800ec1a7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 10 Aug 2022 16:28:14 +0530 Subject: [PATCH] Send disallowed responses when permission for rc is denied --- kitty/boss.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index 85f345d05..76ceb75b9 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -465,10 +465,13 @@ class Boss: if q is None: if self.ask_if_remote_cmd_is_allowed(pcmd, window, peer_id): return AsyncResponse() + response = {'ok': False, 'error': 'Remote control is disabled. Add allow_remote_control to your kitty.conf'} + if q is False: + response['error'] = 'The user rejected this password or it is disallowed by remote_control_password in kitty.conf' no_response = pcmd.get('no_response') or False if no_response: return None - return {'ok': False, 'error': 'Remote control is disabled. Add allow_remote_control to your kitty.conf'} + return response def ask_if_remote_cmd_is_allowed(self, pcmd: Dict[str, Any], window: Optional[Window] = None, peer_id: int = 0) -> bool: from kittens.tui.operations import styled @@ -498,22 +501,26 @@ class Boss: from .remote_control import ( encode_response_for_peer, set_user_password_allowed ) + response: RCResponse = None + window = self.window_id_map.get(window_id) if choice in ('r', 'd'): if choice == 'd': set_user_password_allowed(pcmd['password'], False) + no_response = pcmd.get('no_response') or False + if not no_response: + response = {'ok': False, 'error': 'The user rejected this ' + ('request' if choice == 'r' else 'password')} elif choice in ('t', 'p'): if choice == 'p': set_user_password_allowed(pcmd['password'], True) - window = self.window_id_map.get(window_id) response = self._execute_remote_command(pcmd, window, peer_id) - if window is not None and response is not None and not isinstance(response, AsyncResponse): - window.send_cmd_response(response) - if peer_id > 0: - if response is None or isinstance(response, AsyncResponse): - data = b'' - else: - data = encode_response_for_peer(response) - send_data_to_peer(peer_id, data) + if window is not None and response is not None and not isinstance(response, AsyncResponse): + window.send_cmd_response(response) + if peer_id > 0: + if response is None or isinstance(response, AsyncResponse): + data = b'' + else: + data = encode_response_for_peer(response) + send_data_to_peer(peer_id, data) def _execute_remote_command(self, pcmd: Dict[str, Any], window: Optional[Window] = None, peer_id: int = 0) -> RCResponse: from .remote_control import handle_cmd