From 2a8d7b8926760045ae1120fdeacfb8dc3087b87f Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 19 Nov 2023 20:48:25 +0000 Subject: [PATCH] core: add commands that will not be forwarded to connected mobile (#3398) * core: add commands that will not be forwarded to connected mobile * fail if command that must be executed locally sent to remote host --- src/Simplex/Chat.hs | 4 +++- src/Simplex/Chat/Controller.hs | 15 ++++++++++++++- src/Simplex/Chat/Terminal/Input.hs | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Simplex/Chat.hs b/src/Simplex/Chat.hs index 5c8e812a2b..a6d5576133 100644 --- a/src/Simplex/Chat.hs +++ b/src/Simplex/Chat.hs @@ -400,7 +400,9 @@ execChatCommand rh s = do case parseChatCommand s of Left e -> pure $ chatCmdError u e Right cmd -> case rh of - Just remoteHostId | allowRemoteCommand cmd -> execRemoteCommand u remoteHostId cmd s + Just rhId + | allowRemoteCommand cmd -> execRemoteCommand u rhId cmd s + | otherwise -> pure $ CRChatCmdError u $ ChatErrorRemoteHost (RHId rhId) $ RHELocalCommand _ -> execChatCommand_ u cmd execChatCommand' :: ChatMonad' m => ChatCommand -> m ChatResponse diff --git a/src/Simplex/Chat/Controller.hs b/src/Simplex/Chat/Controller.hs index dcfa9b431c..3a97d2c32c 100644 --- a/src/Simplex/Chat/Controller.hs +++ b/src/Simplex/Chat/Controller.hs @@ -452,8 +452,20 @@ allowRemoteCommand = \case APIStopChat -> False APIActivateChat -> False APISuspendChat _ -> False - SetTempFolder _ -> False QuitChat -> False + SetTempFolder _ -> False + SetFilesFolder _ -> False + SetRemoteHostsFolder _ -> False + APISetXFTPConfig _ -> False + APISetEncryptLocalFiles _ -> False + APIExportArchive _ -> False + APIImportArchive _ -> False + ExportArchive -> False + APIDeleteStorage -> False + APIStorageEncryption _ -> False + APISetNetworkConfig _ -> False + APIGetNetworkConfig -> False + SetLocalDeviceName _ -> False ListRemoteHosts -> False StartRemoteHost _ -> False SwitchRemoteHost {} -> False @@ -1052,6 +1064,7 @@ data RemoteHostError | RHETimeout | RHEBadState -- ^ Illegal state transition | RHEBadVersion {appVersion :: AppVersion} + | RHELocalCommand -- ^ Command not allowed for remote execution | RHEDisconnected {reason :: Text} -- TODO should be sent when disconnected? | RHEProtocolError RemoteProtocolError deriving (Show, Exception) diff --git a/src/Simplex/Chat/Terminal/Input.hs b/src/Simplex/Chat/Terminal/Input.hs index 090f06c7b3..ecf1255999 100644 --- a/src/Simplex/Chat/Terminal/Input.hs +++ b/src/Simplex/Chat/Terminal/Input.hs @@ -56,8 +56,9 @@ runInputLoop ct@ChatTerminal {termState, liveMessageState} cc = forever $ do rh <- readTVarIO $ currentRemoteHost cc let bs = encodeUtf8 $ T.pack s cmd = parseChatCommand bs + rh' = if either (const False) allowRemoteCommand cmd then rh else Nothing unless (isMessage cmd) $ echo s - r <- runReaderT (execChatCommand rh bs) cc + r <- runReaderT (execChatCommand rh' bs) cc processResp s cmd r printRespToTerminal ct cc False rh r startLiveMessage cmd r