add permission propertys

This commit is contained in:
chrys 2018-09-07 21:55:40 +02:00
parent 6b8c24831c
commit ef091a427d
8 changed files with 28 additions and 10 deletions

View File

@ -204,7 +204,7 @@ allowSettings=barrier#enabled
# allow commands to be executed # allow commands to be executed
enableCommandRemote=True enableCommandRemote=True
# permitted commands # permitted commands
allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight allowCommands=say,interrupt,window,resetwindow
[barrier] [barrier]
enabled=True enabled=True

View File

@ -214,7 +214,7 @@ allowSettings=barrier#enabled
# allow commands to be executed # allow commands to be executed
enableCommandRemote=True enableCommandRemote=True
# permitted commands # permitted commands
allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight allowCommands=say,interrupt,window,resetwindow
[barrier] [barrier]
enabled=True enabled=True

View File

@ -215,7 +215,7 @@ allowSettings=barrier#enabled
# allow commands to be executed # allow commands to be executed
enableCommandRemote=True enableCommandRemote=True
# permitted commands # permitted commands
allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight allowCommands=say,interrupt,window,resetwindow
[barrier] [barrier]
enabled=True enabled=True

View File

@ -160,7 +160,7 @@ allowSettings=barrier#enabled
# allow commands to be executed # allow commands to be executed
enableCommandRemote=True enableCommandRemote=True
# permitted commands # permitted commands
allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight allowCommands=say,interrupt,window,resetwindow
[barrier] [barrier]
enabled=True enabled=True

View File

@ -214,7 +214,7 @@ allowSettings=barrier#enabled
# allow commands to be executed # allow commands to be executed
enableCommandRemote=True enableCommandRemote=True
# permitted commands # permitted commands
allowCommands=Say,defineWindow,resetSettings,resetWindow,toggleHighlight allowCommands=say,interrupt,window,resetwindow
[barrier] [barrier]
enabled=True enabled=True

View File

@ -48,9 +48,9 @@ class remoteManager():
self.env = environment self.env = environment
if self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enabled'): 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) 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) self.env['runtime']['processManager'].addCustomEventThread(self.tcpWatchDog, multiprocess=True)
def shutdown(self): def shutdown(self):
if self.sock: if self.sock:
@ -126,6 +126,7 @@ class remoteManager():
def handleSettingsChange(self, settingsText): def handleSettingsChange(self, settingsText):
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableSettingsRemote'):
return return
upperSettingsText = settingsText.upper() upperSettingsText = settingsText.upper()
# set setting # set setting
if upperSettingsText.startswith(self.setSettingConst): if upperSettingsText.startswith(self.setSettingConst):
@ -137,7 +138,14 @@ class remoteManager():
def handleCommandExecution(self, commandText): def handleCommandExecution(self, commandText):
if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'): if not self.env['runtime']['settingsManager'].getSettingAsBool('remote', 'enableCommandRemote'):
return return
allowCommands = self.env['runtime']['settingsManager'].getSetting('remote', 'allowCommands').upper().split(',')
upperCommandText = commandText.upper() upperCommandText = commandText.upper()
allowed = False
for a in allowCommands:
if upperCommandText.startswith(a):
allowed = True
if not allowed:
return
# say # say
if upperCommandText.startswith(self.sayConst): if upperCommandText.startswith(self.sayConst):
parameterText = commandText[len(self.sayConst):] parameterText = commandText[len(self.sayConst):]
@ -176,7 +184,9 @@ class remoteManager():
def resetSettings(self): def resetSettings(self):
self.env['runtime']['settingsManager'].resetSettingArgDict() self.env['runtime']['settingsManager'].resetSettingArgDict()
def setSettings(self, settingsArgs): 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): def handleRemoteIncomming(self, eventData):
if not eventData: if not eventData:
return return

View File

@ -89,7 +89,7 @@ settingsData = {
'enableSettingsRemote': True, 'enableSettingsRemote': True,
'allowSettings': 'barrier#enabled', 'allowSettings': 'barrier#enabled',
'enableCommandRemote': True, 'enableCommandRemote': True,
'allowCommands': 'Say,defineWindow,resetSettings,resetWindow,toggleHighlight', 'allowCommands': 'say,interrupt,window,resetwindow',
}, },
'barrier':{ 'barrier':{
'enabled': True, 'enabled': True,

View File

@ -186,12 +186,20 @@ class settingsManager():
self.settingArgDict[section] = {} self.settingArgDict[section] = {}
self.settingArgDict[section][option] = str(value) self.settingArgDict[section][option] = str(value)
def parseSettingArgs(self, settingArgs): def parseSettingArgs(self, settingArgs, allowSettings):
for optionElem in settingArgs.split(';'): for optionElem in settingArgs.split(';'):
if len(optionElem.split('#',1)) != 2: if len(optionElem.split('#',1)) != 2:
continue continue
if len(optionElem.split('#',1)[1].split('=',1)) != 2: if len(optionElem.split('#',1)[1].split('=',1)) != 2:
continue 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() section = str(optionElem.split('#',1)[0]).lower()
option = str(optionElem.split('#',1)[1].split('=',1)[0]).lower() option = str(optionElem.split('#',1)[1].split('=',1)[0]).lower()
value = optionElem.split('#',1)[1].split('=',1)[1] value = optionElem.split('#',1)[1].split('=',1)[1]