From bef9776a6bda81a41be589093a8a25d3114cf825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Fri, 22 Nov 2019 09:36:16 +0100 Subject: [PATCH] Updated udsacotr config tool --- actor/src/UDSActorConfig.py | 21 +++++++++++++++------ actor/src/udsactor/linux/store.py | 19 ++++++++++++++----- actor/src/udsactor/rest.py | 21 --------------------- actor/src/udsactor/types.py | 6 +++++- server/src/uds/REST/methods/actor_v2.py | 2 +- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/actor/src/UDSActorConfig.py b/actor/src/UDSActorConfig.py index d5ce3e5f..af6a8a50 100644 --- a/actor/src/UDSActorConfig.py +++ b/actor/src/UDSActorConfig.py @@ -55,15 +55,20 @@ class UDSConfigDialog(QDialog): QDialog.__init__(self, None) # Get local config config config: udsactor.types.ActorConfigurationType = udsactor.store.readConfig() - self.ui = Ui_UdsActorSetupDialog() self.ui.setupUi(self) self.ui.host.setText(config.host) + self.ui.validateCertificate.setCurrentIndex(1 if config.validateCertificate else 0) + self.ui.postConfigCommand.setText(config.post_command or '') + self.ui.preCommand.setText(config.pre_command or '') + self.ui.runonceCommand.setText(config.runonce_command or '') + self.ui.logLevelComboBox.setCurrentIndex(config.log_level) + + if config.host: + self.updateAuthenticators() + self.ui.username.setText('') self.ui.password.setText('') - self.ui.postConfigCommand.setText('') - self.ui.preCommand.setText('') - self.ui.runonceCommand.setText(r'c:\windows\runonce.bat') @property def api(self) -> udsactor.rest.REST: @@ -115,14 +120,18 @@ class UDSConfigDialog(QDialog): self.ui.preCommand.text(), self.ui.runonceCommand.text(), self.ui.postConfigCommand.text(), - (self.ui.logLevelComboBox.currentIndex() + 1) * 10000 # Loglevel + self.ui.logLevelComboBox.currentIndex() # Loglevel ) # Store parameters on register for later use, notify user of registration udsactor.store.writeConfig( udsactor.types.ActorConfigurationType( host=self.ui.host.text(), validateCertificate=self.ui.validateCertificate.currentIndex() == 1, - master_token=token + master_token=token, + pre_command=self.ui.preCommand.text(), + post_command=self.ui.postConfigCommand.text(), + runonce_command=self.ui.runonceCommand.text(), + log_level=self.ui.logLevelComboBox.currentIndex() ) ) # Inform the user diff --git a/actor/src/udsactor/linux/store.py b/actor/src/udsactor/linux/store.py index 4e6b339c..3f01dc97 100644 --- a/actor/src/udsactor/linux/store.py +++ b/actor/src/udsactor/linux/store.py @@ -55,6 +55,10 @@ def readConfig() -> types.ActorConfigurationType: validateCertificate=uds.getboolean('validate', fallback=False), master_token=uds.get('master_token', None), own_token=uds.get('own_token', None), + pre_command=uds.get('pre_command', None), + runonce_command=uds.get('runonce_command', None), + post_command=uds.get('post_command', None), + log_level=int(uds.get('log_level', '1')), data=data ) except Exception: @@ -67,11 +71,16 @@ def writeConfig(config: types.ActorConfigurationType) -> None: uds: configparser.SectionProxy = cfg['uds'] uds['host'] = config.host uds['validate'] = 'yes' if config.validateCertificate else 'no' - if config.master_token: - uds['master_token'] = config.master_token - if config.own_token: - uds['own_token'] = config.own_token - if config.data: + def writeIfValue(val, name): + if val: + uds[name] = val + writeIfValue(config.master_token, 'master_token') + writeIfValue(config.own_token, 'own_token') + writeIfValue(config.pre_command, 'pre_command') + writeIfValue(config.post_command, 'post_command') + writeIfValue(config.runonce_command, 'runonce_command') + uds['log_level'] = str(config.log_level) + if config.data: # Special case, encoded & dumped uds['data'] = base64.b64encode(pickle.dumps(config.data)).decode() # Ensures exists destination folder diff --git a/actor/src/udsactor/rest.py b/actor/src/udsactor/rest.py index 24896fab..89314978 100644 --- a/actor/src/udsactor/rest.py +++ b/actor/src/udsactor/rest.py @@ -175,24 +175,3 @@ class REST: pass raise RESTError(result.content) - - def readConfig( - self, - auth: str, - username: str, - password: str, - mac: str, - config: typing.Optional[types.ActorConfigurationType] = None - ) -> typing.Optional[typing.MutableMapping[str, typing.Any]]: - try: - res = None - headers = self._login(auth, username, password) - result = requests.post(self.url + 'actor/v2/config', data=json.dumps(mac), headers=headers, verify=self.validateCert) - if result.ok: - res = result.json()['result'] - except Exception: - pass - - if config: - config - return None diff --git a/actor/src/udsactor/types.py b/actor/src/udsactor/types.py index 2bd810c4..00d384ea 100644 --- a/actor/src/udsactor/types.py +++ b/actor/src/udsactor/types.py @@ -18,7 +18,11 @@ class ActorConfigurationType(typing.NamedTuple): validateCertificate: bool master_token: typing.Optional[str] = None own_token: typing.Optional[str] = None + pre_command: typing.Optional[str] = None - run_once_command: typing.Optional[str] = None + runonce_command: typing.Optional[str] = None post_command: typing.Optional[str] = None + + log_level: int = 0 + data: typing.Optional[typing.Dict[str, str]] = None diff --git a/server/src/uds/REST/methods/actor_v2.py b/server/src/uds/REST/methods/actor_v2.py index 513e1da6..4cb24d5f 100644 --- a/server/src/uds/REST/methods/actor_v2.py +++ b/server/src/uds/REST/methods/actor_v2.py @@ -37,7 +37,7 @@ import typing from uds.models import getSqlDatetimeAsUnix, getSqlDatetime, ActorToken from uds.core import VERSION -from ..handlers import Handler +from ..handlers import Handler, NotFound logger = logging.getLogger(__name__)