forked from shaba/openuds
Updated udsacotr config tool
This commit is contained in:
parent
07d337364d
commit
bef9776a6b
@ -55,15 +55,20 @@ class UDSConfigDialog(QDialog):
|
|||||||
QDialog.__init__(self, None)
|
QDialog.__init__(self, None)
|
||||||
# Get local config config
|
# Get local config config
|
||||||
config: udsactor.types.ActorConfigurationType = udsactor.store.readConfig()
|
config: udsactor.types.ActorConfigurationType = udsactor.store.readConfig()
|
||||||
|
|
||||||
self.ui = Ui_UdsActorSetupDialog()
|
self.ui = Ui_UdsActorSetupDialog()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
self.ui.host.setText(config.host)
|
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.username.setText('')
|
||||||
self.ui.password.setText('')
|
self.ui.password.setText('')
|
||||||
self.ui.postConfigCommand.setText('')
|
|
||||||
self.ui.preCommand.setText('')
|
|
||||||
self.ui.runonceCommand.setText(r'c:\windows\runonce.bat')
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def api(self) -> udsactor.rest.REST:
|
def api(self) -> udsactor.rest.REST:
|
||||||
@ -115,14 +120,18 @@ class UDSConfigDialog(QDialog):
|
|||||||
self.ui.preCommand.text(),
|
self.ui.preCommand.text(),
|
||||||
self.ui.runonceCommand.text(),
|
self.ui.runonceCommand.text(),
|
||||||
self.ui.postConfigCommand.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
|
# Store parameters on register for later use, notify user of registration
|
||||||
udsactor.store.writeConfig(
|
udsactor.store.writeConfig(
|
||||||
udsactor.types.ActorConfigurationType(
|
udsactor.types.ActorConfigurationType(
|
||||||
host=self.ui.host.text(),
|
host=self.ui.host.text(),
|
||||||
validateCertificate=self.ui.validateCertificate.currentIndex() == 1,
|
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
|
# Inform the user
|
||||||
|
@ -55,6 +55,10 @@ def readConfig() -> types.ActorConfigurationType:
|
|||||||
validateCertificate=uds.getboolean('validate', fallback=False),
|
validateCertificate=uds.getboolean('validate', fallback=False),
|
||||||
master_token=uds.get('master_token', None),
|
master_token=uds.get('master_token', None),
|
||||||
own_token=uds.get('own_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
|
data=data
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -67,11 +71,16 @@ def writeConfig(config: types.ActorConfigurationType) -> None:
|
|||||||
uds: configparser.SectionProxy = cfg['uds']
|
uds: configparser.SectionProxy = cfg['uds']
|
||||||
uds['host'] = config.host
|
uds['host'] = config.host
|
||||||
uds['validate'] = 'yes' if config.validateCertificate else 'no'
|
uds['validate'] = 'yes' if config.validateCertificate else 'no'
|
||||||
if config.master_token:
|
def writeIfValue(val, name):
|
||||||
uds['master_token'] = config.master_token
|
if val:
|
||||||
if config.own_token:
|
uds[name] = val
|
||||||
uds['own_token'] = config.own_token
|
writeIfValue(config.master_token, 'master_token')
|
||||||
if config.data:
|
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()
|
uds['data'] = base64.b64encode(pickle.dumps(config.data)).decode()
|
||||||
|
|
||||||
# Ensures exists destination folder
|
# Ensures exists destination folder
|
||||||
|
@ -175,24 +175,3 @@ class REST:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
raise RESTError(result.content)
|
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
|
|
||||||
|
@ -18,7 +18,11 @@ class ActorConfigurationType(typing.NamedTuple):
|
|||||||
validateCertificate: bool
|
validateCertificate: bool
|
||||||
master_token: typing.Optional[str] = None
|
master_token: typing.Optional[str] = None
|
||||||
own_token: typing.Optional[str] = None
|
own_token: typing.Optional[str] = None
|
||||||
|
|
||||||
pre_command: 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
|
post_command: typing.Optional[str] = None
|
||||||
|
|
||||||
|
log_level: int = 0
|
||||||
|
|
||||||
data: typing.Optional[typing.Dict[str, str]] = None
|
data: typing.Optional[typing.Dict[str, str]] = None
|
||||||
|
@ -37,7 +37,7 @@ import typing
|
|||||||
from uds.models import getSqlDatetimeAsUnix, getSqlDatetime, ActorToken
|
from uds.models import getSqlDatetimeAsUnix, getSqlDatetime, ActorToken
|
||||||
|
|
||||||
from uds.core import VERSION
|
from uds.core import VERSION
|
||||||
from ..handlers import Handler
|
from ..handlers import Handler, NotFound
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user