From ef091a427d85fd4ecc8b7359c78fd863414c29eb Mon Sep 17 00:00:00 2001 From: chrys Date: Fri, 7 Sep 2018 21:55:40 +0200 Subject: [PATCH] add permission propertys --- config/settings/espeak.settings.conf | 2 +- config/settings/settings.conf | 2 +- config/settings/settings.conf.example | 2 +- config/settings/settings.conf.storm | 2 +- config/settings/speech-dispatcher.settings.conf | 2 +- src/fenrirscreenreader/core/remoteManager.py | 16 +++++++++++++--- src/fenrirscreenreader/core/settingsData.py | 2 +- src/fenrirscreenreader/core/settingsManager.py | 10 +++++++++- 8 files changed, 28 insertions(+), 10 deletions(-) diff --git a/config/settings/espeak.settings.conf b/config/settings/espeak.settings.conf index 3137a660..2ee038c1 100644 --- a/config/settings/espeak.settings.conf +++ b/config/settings/espeak.settings.conf @@ -204,7 +204,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf b/config/settings/settings.conf index ab2d8f90..54550c55 100644 --- a/config/settings/settings.conf +++ b/config/settings/settings.conf @@ -214,7 +214,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf.example b/config/settings/settings.conf.example index a9e893e8..64d71a66 100644 --- a/config/settings/settings.conf.example +++ b/config/settings/settings.conf.example @@ -215,7 +215,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/settings.conf.storm b/config/settings/settings.conf.storm index 2969e76a..7e808e86 100644 --- a/config/settings/settings.conf.storm +++ b/config/settings/settings.conf.storm @@ -160,7 +160,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/config/settings/speech-dispatcher.settings.conf b/config/settings/speech-dispatcher.settings.conf index 4bfe3c0c..8dbbc242 100644 --- a/config/settings/speech-dispatcher.settings.conf +++ b/config/settings/speech-dispatcher.settings.conf @@ -214,7 +214,7 @@ allowSettings=barrier#enabled # allow commands to be executed enableCommandRemote=True # permitted commands -allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight +allowCommands=say,interrupt,window,resetwindow [barrier] enabled=True diff --git a/src/fenrirscreenreader/core/remoteManager.py b/src/fenrirscreenreader/core/remoteManager.py index 89a7b77f..0fa4947e 100644 --- a/src/fenrirscreenreader/core/remoteManager.py +++ b/src/fenrirscreenreader/core/remoteManager.py @@ -48,9 +48,9 @@ class remoteManager(): self.env = environment if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): - if self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'unix': + if self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'UNIX': self.env['runtime']['processManager'].addCustomEventThread(self.unixSocketWatchDog, multiprocess=True) - elif self.env['runtime']['settingsManager'].getSetting('remote', 'method') == 'tcp': + elif self.env['runtime']['settingsManager'].getSetting('remote', 'method').upper() == 'TCP': self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True) def shutdown(self): if self.sock: @@ -126,6 +126,7 @@ class remoteManager(): def handleSettingsChange(self, settingsText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): return + upperSettingsText = settingsText.upper() # set setting if upperSettingsText.startswith(self.setSettingConst): @@ -137,7 +138,14 @@ class remoteManager(): def handleCommandExecution(self, commandText): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): return + allowCommands = self.env['runtime']['settingsManager'].getSetting('remote', 'allowCommands').upper().split(',') upperCommandText = commandText.upper() + allowed = False + for a in allowCommands: + if upperCommandText.startswith(a): + allowed = True + if not allowed: + return # say if upperCommandText.startswith(self.sayConst): parameterText = commandText[len(self.sayConst):] @@ -176,7 +184,9 @@ class remoteManager(): def resetSettings(self): self.env['runtime']['settingsManager'].resetSettingArgDict() def setSettings(self, settingsArgs): - self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs) + allowSettings = self.env['runtime']['settingsManager'].getSetting('remote', 'allowSettings').upper().split(',') + + self.env['runtime']['settingsManager'].parseSettingArgs(settingsArgs, allowSettings) def handleRemoteIncomming(self, eventData): if not eventData: return diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index b0cb535f..60b34e50 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -89,7 +89,7 @@ settingsData = { 'enableSettingsRemote': True, 'allowSettings': 'barrier#enabled', 'enableCommandRemote': True, - 'allowCommands': 'Say,defineWindow,resetSettings,resetWindow,toggleHighlight', + 'allowCommands': 'say,interrupt,window,resetwindow', }, 'barrier':{ 'enabled': True, diff --git a/src/fenrirscreenreader/core/settingsManager.py b/src/fenrirscreenreader/core/settingsManager.py index 07faf7ad..bd609070 100644 --- a/src/fenrirscreenreader/core/settingsManager.py +++ b/src/fenrirscreenreader/core/settingsManager.py @@ -186,12 +186,20 @@ class settingsManager(): self.settingArgDict[section] = {} self.settingArgDict[section][option] = str(value) - def parseSettingArgs(self, settingArgs): + def parseSettingArgs(self, settingArgs, allowSettings): for optionElem in settingArgs.split(';'): if len(optionElem.split('#',1)) != 2: continue if len(optionElem.split('#',1)[1].split('=',1)) != 2: continue + allowed = False + if allowSettings: + for a in allowSettings: + if a in optionElem: + allowed = True + if not allowed: + continue + section = str(optionElem.split('#',1)[0]).lower() option = str(optionElem.split('#',1)[1].split('=',1)[0]).lower() value = optionElem.split('#',1)[1].split('=',1)[1]