forked from shaba/openuds
added actor configuration for unmanaged actors
This commit is contained in:
parent
efe7bb2a53
commit
b0d4be83a4
@ -51,7 +51,7 @@ logger = logging.getLogger('actor')
|
||||
class UDSConfigDialog(QDialog):
|
||||
_host: str = ''
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
QDialog.__init__(self, None)
|
||||
# Get local config config
|
||||
config: udsactor.types.ActorConfigurationType = udsactor.platform.store.readConfig()
|
||||
@ -104,22 +104,22 @@ class UDSConfigDialog(QDialog):
|
||||
# Last, add "admin" authenticator (for uds root user)
|
||||
self.ui.authenticators.addItem('Administration', userData=udsactor.types.AuthenticatorType('admin', 'admin', 'admin', 'admin', 1, False))
|
||||
|
||||
def textChanged(self):
|
||||
def textChanged(self) -> None:
|
||||
enableButtons = bool(self.ui.host.text() and self.ui.username.text() and self.ui.password.text() and self.ui.authenticators.currentText())
|
||||
self.ui.registerButton.setEnabled(enableButtons)
|
||||
self.ui.testButton.setEnabled(False) # Only registered information can be checked
|
||||
|
||||
def finish(self):
|
||||
def finish(self) -> None:
|
||||
self.close()
|
||||
|
||||
def testUDSServer(self):
|
||||
def testUDSServer(self) -> None:
|
||||
config: udsactor.types.ActorConfigurationType = udsactor.platform.store.readConfig()
|
||||
if not config.master_token:
|
||||
if not config.master_token or not config.host:
|
||||
self.ui.testButton.setEnabled(False)
|
||||
return
|
||||
try:
|
||||
api = udsactor.rest.UDSServerApi(config.host, config.validateCertificate)
|
||||
if not api.test(config.master_token):
|
||||
if not api.test(config.master_token, udsactor.types.MANAGED):
|
||||
QMessageBox.information(
|
||||
self,
|
||||
'UDS Test',
|
||||
@ -141,7 +141,7 @@ class UDSConfigDialog(QDialog):
|
||||
QMessageBox.Ok
|
||||
)
|
||||
|
||||
def registerWithUDS(self):
|
||||
def registerWithUDS(self) -> None:
|
||||
# Get network card. Will fail if no network card is available, but don't mind (not contempled)
|
||||
data: udsactor.types.InterfaceInfoType = next(udsactor.platform.operations.getNetworkInfo())
|
||||
try:
|
||||
@ -160,6 +160,7 @@ class UDSConfigDialog(QDialog):
|
||||
# Store parameters on register for later use, notify user of registration
|
||||
udsactor.platform.store.writeConfig(
|
||||
udsactor.types.ActorConfigurationType(
|
||||
actorType=udsactor.types.MANAGED,
|
||||
host=self.ui.host.text(),
|
||||
validateCertificate=self.ui.validateCertificate.currentIndex() == 1,
|
||||
master_token=token,
|
||||
|
152
actor/src/actor_config_unmanaged.py
Normal file → Executable file
152
actor/src/actor_config_unmanaged.py
Normal file → Executable file
@ -32,15 +32,16 @@
|
||||
# pylint: disable=invalid-name
|
||||
import sys
|
||||
import os
|
||||
import pickle
|
||||
import logging
|
||||
import typing
|
||||
|
||||
import PyQt5 # pylint: disable=unused-import
|
||||
from PyQt5.QtWidgets import QApplication, QDialog, QFileDialog, QMessageBox
|
||||
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox
|
||||
|
||||
import udsactor
|
||||
|
||||
from ui.setup_dialog_ui import Ui_UdsActorSetupDialog
|
||||
from ui.setup_dialog_unmanaged_ui import Ui_UdsActorSetupDialog
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
@ -50,132 +51,74 @@ logger = logging.getLogger('actor')
|
||||
|
||||
class UDSConfigDialog(QDialog):
|
||||
_host: str = ''
|
||||
_config: udsactor.types.ActorConfigurationType
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
QDialog.__init__(self, None)
|
||||
# Get local config config
|
||||
config: udsactor.types.ActorConfigurationType = udsactor.platform.store.readConfig()
|
||||
self._config = udsactor.platform.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)
|
||||
self.ui.host.setText(self._config.host)
|
||||
self.ui.validateCertificate.setCurrentIndex(1 if self._config.validateCertificate else 0)
|
||||
self.ui.logLevelComboBox.setCurrentIndex(self._config.log_level)
|
||||
self.ui.serviceToken.setText(self._config.master_token)
|
||||
|
||||
if config.host:
|
||||
self.updateAuthenticators()
|
||||
|
||||
self.ui.username.setText('')
|
||||
self.ui.password.setText('')
|
||||
|
||||
self.ui.testButton.setEnabled(bool(config.master_token and config.host))
|
||||
self.ui.testButton.setEnabled(bool(self._config.master_token and self._config.host))
|
||||
|
||||
@property
|
||||
def api(self) -> udsactor.rest.UDSServerApi:
|
||||
return udsactor.rest.UDSServerApi(self.ui.host.text(), self.ui.validateCertificate.currentIndex() == 1)
|
||||
|
||||
def browse(self, lineEdit: 'QLineEdit', caption: str) -> None:
|
||||
name = QFileDialog.getOpenFileName(parent=self, caption=caption, directory=os.path.dirname(lineEdit.text()))[0]
|
||||
if name:
|
||||
if ' ' in name:
|
||||
name = '"' + name + '"'
|
||||
lineEdit.setText(os.path.normpath(name))
|
||||
|
||||
def browsePreconnect(self) -> None:
|
||||
self.browse(self.ui.preCommand, 'Select Preconnect command')
|
||||
|
||||
def browseRunOnce(self) -> None:
|
||||
self.browse(self.ui.runonceCommand, 'Select Runonce command')
|
||||
|
||||
def browsePostConfig(self) -> None:
|
||||
self.browse(self.ui.postConfigCommand, 'Select Postconfig command')
|
||||
|
||||
def updateAuthenticators(self) -> None:
|
||||
if self.ui.host.text() != self._host:
|
||||
self._host = self.ui.host.text()
|
||||
self.ui.authenticators.clear()
|
||||
auth: udsactor.types.AuthenticatorType
|
||||
auths = list(self.api.enumerateAuthenticators())
|
||||
if auths:
|
||||
for auth in auths:
|
||||
self.ui.authenticators.addItem(auth.auth, userData=auth)
|
||||
# Last, add "admin" authenticator (for uds root user)
|
||||
self.ui.authenticators.addItem('Administration', userData=udsactor.types.AuthenticatorType('admin', 'admin', 'admin', 'admin', 1, False))
|
||||
|
||||
def textChanged(self):
|
||||
enableButtons = bool(self.ui.host.text() and self.ui.username.text() and self.ui.password.text() and self.ui.authenticators.currentText())
|
||||
self.ui.registerButton.setEnabled(enableButtons)
|
||||
self.ui.testButton.setEnabled(False) # Only registered information can be checked
|
||||
|
||||
def finish(self):
|
||||
def finish(self) -> None:
|
||||
self.close()
|
||||
|
||||
def testUDSServer(self):
|
||||
config: udsactor.types.ActorConfigurationType = udsactor.platform.store.readConfig()
|
||||
if not config.master_token:
|
||||
def configChanged(self, text: str) -> None:
|
||||
self.ui.testButton.setEnabled(self.ui.host.text() == self._config.host and self.ui.serviceToken.text() == self._config.master_token)
|
||||
|
||||
def testUDSServer(self) -> None:
|
||||
if not self._config.master_token or not self._config.host:
|
||||
self.ui.testButton.setEnabled(False)
|
||||
return
|
||||
try:
|
||||
api = udsactor.rest.UDSServerApi(config.host, config.validateCertificate)
|
||||
if not api.test(config.master_token):
|
||||
api = udsactor.rest.UDSServerApi(self._config.host, self._config.validateCertificate)
|
||||
if not api.test(self._config.master_token, udsactor.types.UNMANAGED):
|
||||
QMessageBox.information(
|
||||
self,
|
||||
'UDS Test',
|
||||
'Current configured token seems to be invalid for {}. Please, request a new one.'.format(config.host),
|
||||
'Service token seems to be invalid . Please, check token validity.',
|
||||
QMessageBox.Ok
|
||||
)
|
||||
else:
|
||||
QMessageBox.information(
|
||||
self,
|
||||
'UDS Test',
|
||||
'Configuration for {} seems to be correct.'.format(config.host),
|
||||
'Configuration for {} seems to be correct.'.format(self._config.host),
|
||||
QMessageBox.Ok
|
||||
)
|
||||
except Exception:
|
||||
QMessageBox.information(
|
||||
self,
|
||||
'UDS Test',
|
||||
'Configured host {} seems to be inaccesible.'.format(config.host),
|
||||
'Configured host {} seems to be inaccesible.'.format(self._config.host),
|
||||
QMessageBox.Ok
|
||||
)
|
||||
|
||||
def registerWithUDS(self):
|
||||
# Get network card. Will fail if no network card is available, but don't mind (not contempled)
|
||||
data: udsactor.types.InterfaceInfoType = next(udsactor.platform.operations.getNetworkInfo())
|
||||
try:
|
||||
token = self.api.register(
|
||||
self.ui.authenticators.currentData().auth,
|
||||
self.ui.username.text(),
|
||||
self.ui.password.text(),
|
||||
udsactor.platform.operations.getComputerName(),
|
||||
data.ip or '', # IP
|
||||
data.mac or '', # MAC
|
||||
self.ui.preCommand.text(),
|
||||
self.ui.runonceCommand.text(),
|
||||
self.ui.postConfigCommand.text(),
|
||||
self.ui.logLevelComboBox.currentIndex() # Loglevel
|
||||
)
|
||||
# Store parameters on register for later use, notify user of registration
|
||||
udsactor.platform.store.writeConfig(
|
||||
udsactor.types.ActorConfigurationType(
|
||||
host=self.ui.host.text(),
|
||||
validateCertificate=self.ui.validateCertificate.currentIndex() == 1,
|
||||
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()
|
||||
)
|
||||
)
|
||||
# Enables test button
|
||||
self.ui.testButton.setEnabled(True)
|
||||
# Informs the user
|
||||
QMessageBox.information(self, 'UDS Registration', 'Registration with UDS completed.', QMessageBox.Ok)
|
||||
except udsactor.rest.RESTError as e:
|
||||
self.ui.testButton.setEnabled(False)
|
||||
QMessageBox.critical(self, 'UDS Registration', 'UDS Registration error: {}'.format(e), QMessageBox.Ok)
|
||||
def saveConfig(self) -> None:
|
||||
# Store parameters on register for later use, notify user of registration
|
||||
self._config = udsactor.types.ActorConfigurationType(
|
||||
actorType=udsactor.types.UNMANAGED,
|
||||
host=self.ui.host.text(),
|
||||
validateCertificate=self.ui.validateCertificate.currentIndex() == 1,
|
||||
master_token=self.ui.serviceToken.text(),
|
||||
log_level=self.ui.logLevelComboBox.currentIndex()
|
||||
)
|
||||
|
||||
udsactor.platform.store.writeConfig(self._config)
|
||||
# Enables test button
|
||||
self.ui.testButton.setEnabled(True)
|
||||
# Informs the user
|
||||
QMessageBox.information(self, 'UDS Configuration', 'Configuration saved.', QMessageBox.Ok)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@ -184,11 +127,30 @@ if __name__ == "__main__":
|
||||
os.environ['QT_X11_NO_MITSHM'] = '1'
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
|
||||
if udsactor.platform.operations.checkPermissions() is False:
|
||||
QMessageBox.critical(None, 'UDS Actor', 'This Program must be executed as administrator', QMessageBox.Ok)
|
||||
sys.exit(1)
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
if sys.argv[1] == 'export':
|
||||
try:
|
||||
with open(sys.argv[2], 'wb') as f:
|
||||
pickle.dump(udsactor.platform.store.readConfig(), f, protocol=3)
|
||||
except Exception as e:
|
||||
print('Error exporting configuration file: {}'.format(e))
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
if sys.argv[1] == 'import':
|
||||
try:
|
||||
with open(sys.argv[2], 'rb') as f:
|
||||
config = pickle.load(f)
|
||||
udsactor.platform.store.writeConfig(config)
|
||||
except Exception as e:
|
||||
print('Error importing configuration file: {}'.format(e))
|
||||
sys.exit(1)
|
||||
sys.exit(0)
|
||||
|
||||
myapp = UDSConfigDialog()
|
||||
myapp.show()
|
||||
sys.exit(app.exec_())
|
||||
|
363
actor/src/designer/setup-dialog-unmanaged.ui
Normal file
363
actor/src/designer/setup-dialog-unmanaged.ui
Normal file
@ -0,0 +1,363 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<author>Adolfo Gómez</author>
|
||||
<class>UdsActorSetupDialog</class>
|
||||
<widget class="QDialog" name="UdsActorSetupDialog">
|
||||
<property name="windowModality">
|
||||
<enum>Qt::WindowModal</enum>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>595</width>
|
||||
<height>220</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Verdana</family>
|
||||
<pointsize>9</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>UDS Actor Configuration Tool</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="uds.qrc">
|
||||
<normaloff>:/img/img/uds-icon.png</normaloff>:/img/img/uds-icon.png</iconset>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="locale">
|
||||
<locale language="English" country="UnitedStates"/>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QPushButton" name="saveButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>180</y>
|
||||
<width>181</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>181</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::DefaultContextMenu</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to register Actor with UDS Broker</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Click on this button to register Actor with UDS Broker.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save Configuration</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="closeButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>410</x>
|
||||
<y>180</y>
|
||||
<width>171</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>171</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Closes UDS Actor Configuration (discard pending changes if any)</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Exits the UDS Actor Configuration Tool</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="testButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>210</x>
|
||||
<y>180</y>
|
||||
<width>181</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>181</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Click to test existing configuration (disabled if no config found)</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Click on this button to test the server host and assigned toen.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Test configuration</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>571</width>
|
||||
<height>161</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetDefaultConstraint</enum>
|
||||
</property>
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>16</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_security">
|
||||
<property name="text">
|
||||
<string>SSL Validation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="validateCertificate">
|
||||
<property name="toolTip">
|
||||
<string>Select communication security with broker</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Select the security for communications with UDS Broker.</p><p>The recommended method of communication is <span style=" font-weight:600;">Use SSL</span>, but selection needs to be acording to your broker configuration.</p></body></html></string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Ignore certificate</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Verify certificate</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_host">
|
||||
<property name="text">
|
||||
<string>UDS Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="host">
|
||||
<property name="acceptDrops">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Uds Broker Server Addres. Use IP or FQDN</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string>Enter here the UDS Broker Addres using either its IP address or its FQDN address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_serviceToken">
|
||||
<property name="text">
|
||||
<string>Service Token</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="serviceToken">
|
||||
<property name="toolTip">
|
||||
<string>UDS user with administration rights (Will not be stored on template)</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_loglevel">
|
||||
<property name="text">
|
||||
<string>Log Level</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="logLevelComboBox">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="frame">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">DEBUG</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">INFO</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">ERROR</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">FATAL</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>label_host</zorder>
|
||||
<zorder>host</zorder>
|
||||
<zorder>label_serviceToken</zorder>
|
||||
<zorder>serviceToken</zorder>
|
||||
<zorder>validateCertificate</zorder>
|
||||
<zorder>label_security</zorder>
|
||||
<zorder>label_loglevel</zorder>
|
||||
<zorder>logLevelComboBox</zorder>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="uds.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>closeButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>UdsActorSetupDialog</receiver>
|
||||
<slot>finish()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>315</x>
|
||||
<y>165</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>231</x>
|
||||
<y>161</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>testButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>UdsActorSetupDialog</receiver>
|
||||
<slot>testUDSServer()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>300</x>
|
||||
<y>281</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>294</x>
|
||||
<y>153</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>saveButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>UdsActorSetupDialog</receiver>
|
||||
<slot>saveConfig()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>100</x>
|
||||
<y>191</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>297</x>
|
||||
<y>109</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>host</sender>
|
||||
<signal>textChanged(QString)</signal>
|
||||
<receiver>UdsActorSetupDialog</receiver>
|
||||
<slot>configChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>341</x>
|
||||
<y>61</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>297</x>
|
||||
<y>109</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>serviceToken</sender>
|
||||
<signal>textChanged(QString)</signal>
|
||||
<receiver>UdsActorSetupDialog</receiver>
|
||||
<slot>configChanged()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>341</x>
|
||||
<y>100</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>297</x>
|
||||
<y>109</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>finish()</slot>
|
||||
<slot>saveConfig()</slot>
|
||||
<slot>testUDSServer()</slot>
|
||||
<slot>configChanged()</slot>
|
||||
</slots>
|
||||
</ui>
|
@ -5,6 +5,7 @@ function process {
|
||||
# pyuic4 about-dialog.ui -o about_dialog_ui.py -x
|
||||
# pyuic4 message-dialog.ui -o message_dialog_ui.py
|
||||
pyuic5 setup-dialog.ui -o ../ui/setup_dialog_ui.py --import-from=ui
|
||||
pyuic5 setup-dialog-unmanaged.ui -o ../ui/setup_dialog_unmanaged_ui.py --import-from=ui
|
||||
}
|
||||
|
||||
pyrcc5 uds.qrc -o ../ui/uds_rc.py
|
||||
|
@ -275,8 +275,9 @@ class UDSServerApi(UDSApi):
|
||||
}
|
||||
self._doPost('log', payLoad) # Ignores result...
|
||||
|
||||
def test(self, master_token: str) -> bool:
|
||||
def test(self, master_token: str, actorType: typing.Optional[str]) -> bool:
|
||||
payLoad = {
|
||||
'type': actorType or types.MANAGED,
|
||||
'token': master_token,
|
||||
}
|
||||
return self._doPost('test', payLoad) == 'ok'
|
||||
|
142
actor/src/ui/setup_dialog_unmanaged_ui.py
Normal file
142
actor/src/ui/setup_dialog_unmanaged_ui.py
Normal file
@ -0,0 +1,142 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Form implementation generated from reading ui file 'setup-dialog-unmanaged.ui'
|
||||
#
|
||||
# Created by: PyQt5 UI code generator 5.13.2
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
|
||||
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_UdsActorSetupDialog(object):
|
||||
def setupUi(self, UdsActorSetupDialog):
|
||||
UdsActorSetupDialog.setObjectName("UdsActorSetupDialog")
|
||||
UdsActorSetupDialog.setWindowModality(QtCore.Qt.WindowModal)
|
||||
UdsActorSetupDialog.resize(595, 220)
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(UdsActorSetupDialog.sizePolicy().hasHeightForWidth())
|
||||
UdsActorSetupDialog.setSizePolicy(sizePolicy)
|
||||
font = QtGui.QFont()
|
||||
font.setFamily("Verdana")
|
||||
font.setPointSize(9)
|
||||
UdsActorSetupDialog.setFont(font)
|
||||
UdsActorSetupDialog.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(":/img/img/uds-icon.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
UdsActorSetupDialog.setWindowIcon(icon)
|
||||
UdsActorSetupDialog.setAutoFillBackground(False)
|
||||
UdsActorSetupDialog.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedStates))
|
||||
UdsActorSetupDialog.setSizeGripEnabled(False)
|
||||
UdsActorSetupDialog.setModal(True)
|
||||
self.saveButton = QtWidgets.QPushButton(UdsActorSetupDialog)
|
||||
self.saveButton.setEnabled(True)
|
||||
self.saveButton.setGeometry(QtCore.QRect(10, 180, 181, 23))
|
||||
self.saveButton.setMinimumSize(QtCore.QSize(181, 0))
|
||||
self.saveButton.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
|
||||
self.saveButton.setObjectName("saveButton")
|
||||
self.closeButton = QtWidgets.QPushButton(UdsActorSetupDialog)
|
||||
self.closeButton.setGeometry(QtCore.QRect(410, 180, 171, 23))
|
||||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(0)
|
||||
sizePolicy.setVerticalStretch(0)
|
||||
sizePolicy.setHeightForWidth(self.closeButton.sizePolicy().hasHeightForWidth())
|
||||
self.closeButton.setSizePolicy(sizePolicy)
|
||||
self.closeButton.setMinimumSize(QtCore.QSize(171, 0))
|
||||
self.closeButton.setObjectName("closeButton")
|
||||
self.testButton = QtWidgets.QPushButton(UdsActorSetupDialog)
|
||||
self.testButton.setEnabled(False)
|
||||
self.testButton.setGeometry(QtCore.QRect(210, 180, 181, 23))
|
||||
self.testButton.setMinimumSize(QtCore.QSize(181, 0))
|
||||
self.testButton.setObjectName("testButton")
|
||||
self.layoutWidget = QtWidgets.QWidget(UdsActorSetupDialog)
|
||||
self.layoutWidget.setGeometry(QtCore.QRect(10, 10, 571, 161))
|
||||
self.layoutWidget.setObjectName("layoutWidget")
|
||||
self.formLayout = QtWidgets.QFormLayout(self.layoutWidget)
|
||||
self.formLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
|
||||
self.formLayout.setFieldGrowthPolicy(QtWidgets.QFormLayout.AllNonFixedFieldsGrow)
|
||||
self.formLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.formLayout.setVerticalSpacing(16)
|
||||
self.formLayout.setObjectName("formLayout")
|
||||
self.label_security = QtWidgets.QLabel(self.layoutWidget)
|
||||
self.label_security.setObjectName("label_security")
|
||||
self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_security)
|
||||
self.validateCertificate = QtWidgets.QComboBox(self.layoutWidget)
|
||||
self.validateCertificate.setObjectName("validateCertificate")
|
||||
self.validateCertificate.addItem("")
|
||||
self.validateCertificate.addItem("")
|
||||
self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.validateCertificate)
|
||||
self.label_host = QtWidgets.QLabel(self.layoutWidget)
|
||||
self.label_host.setObjectName("label_host")
|
||||
self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_host)
|
||||
self.host = QtWidgets.QLineEdit(self.layoutWidget)
|
||||
self.host.setAcceptDrops(False)
|
||||
self.host.setObjectName("host")
|
||||
self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.host)
|
||||
self.label_serviceToken = QtWidgets.QLabel(self.layoutWidget)
|
||||
self.label_serviceToken.setObjectName("label_serviceToken")
|
||||
self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_serviceToken)
|
||||
self.serviceToken = QtWidgets.QLineEdit(self.layoutWidget)
|
||||
self.serviceToken.setObjectName("serviceToken")
|
||||
self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.serviceToken)
|
||||
self.label_loglevel = QtWidgets.QLabel(self.layoutWidget)
|
||||
self.label_loglevel.setObjectName("label_loglevel")
|
||||
self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_loglevel)
|
||||
self.logLevelComboBox = QtWidgets.QComboBox(self.layoutWidget)
|
||||
self.logLevelComboBox.setFrame(True)
|
||||
self.logLevelComboBox.setObjectName("logLevelComboBox")
|
||||
self.logLevelComboBox.addItem("")
|
||||
self.logLevelComboBox.setItemText(0, "DEBUG")
|
||||
self.logLevelComboBox.addItem("")
|
||||
self.logLevelComboBox.setItemText(1, "INFO")
|
||||
self.logLevelComboBox.addItem("")
|
||||
self.logLevelComboBox.setItemText(2, "ERROR")
|
||||
self.logLevelComboBox.addItem("")
|
||||
self.logLevelComboBox.setItemText(3, "FATAL")
|
||||
self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.logLevelComboBox)
|
||||
self.label_host.raise_()
|
||||
self.host.raise_()
|
||||
self.label_serviceToken.raise_()
|
||||
self.serviceToken.raise_()
|
||||
self.validateCertificate.raise_()
|
||||
self.label_security.raise_()
|
||||
self.label_loglevel.raise_()
|
||||
self.logLevelComboBox.raise_()
|
||||
|
||||
self.retranslateUi(UdsActorSetupDialog)
|
||||
self.logLevelComboBox.setCurrentIndex(1)
|
||||
self.closeButton.clicked.connect(UdsActorSetupDialog.finish)
|
||||
self.testButton.clicked.connect(UdsActorSetupDialog.testUDSServer)
|
||||
self.saveButton.clicked.connect(UdsActorSetupDialog.saveConfig)
|
||||
self.host.textChanged['QString'].connect(UdsActorSetupDialog.configChanged)
|
||||
self.serviceToken.textChanged['QString'].connect(UdsActorSetupDialog.configChanged)
|
||||
QtCore.QMetaObject.connectSlotsByName(UdsActorSetupDialog)
|
||||
|
||||
def retranslateUi(self, UdsActorSetupDialog):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
UdsActorSetupDialog.setWindowTitle(_translate("UdsActorSetupDialog", "UDS Actor Configuration Tool"))
|
||||
self.saveButton.setToolTip(_translate("UdsActorSetupDialog", "Click to register Actor with UDS Broker"))
|
||||
self.saveButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Click on this button to register Actor with UDS Broker.</p></body></html>"))
|
||||
self.saveButton.setText(_translate("UdsActorSetupDialog", "Save Configuration"))
|
||||
self.closeButton.setToolTip(_translate("UdsActorSetupDialog", "Closes UDS Actor Configuration (discard pending changes if any)"))
|
||||
self.closeButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Exits the UDS Actor Configuration Tool</p></body></html>"))
|
||||
self.closeButton.setText(_translate("UdsActorSetupDialog", "Close"))
|
||||
self.testButton.setToolTip(_translate("UdsActorSetupDialog", "Click to test existing configuration (disabled if no config found)"))
|
||||
self.testButton.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Click on this button to test the server host and assigned toen.</p></body></html>"))
|
||||
self.testButton.setText(_translate("UdsActorSetupDialog", "Test configuration"))
|
||||
self.label_security.setText(_translate("UdsActorSetupDialog", "SSL Validation"))
|
||||
self.validateCertificate.setToolTip(_translate("UdsActorSetupDialog", "Select communication security with broker"))
|
||||
self.validateCertificate.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Select the security for communications with UDS Broker.</p><p>The recommended method of communication is <span style=\" font-weight:600;\">Use SSL</span>, but selection needs to be acording to your broker configuration.</p></body></html>"))
|
||||
self.validateCertificate.setItemText(0, _translate("UdsActorSetupDialog", "Ignore certificate"))
|
||||
self.validateCertificate.setItemText(1, _translate("UdsActorSetupDialog", "Verify certificate"))
|
||||
self.label_host.setText(_translate("UdsActorSetupDialog", "UDS Server"))
|
||||
self.host.setToolTip(_translate("UdsActorSetupDialog", "Uds Broker Server Addres. Use IP or FQDN"))
|
||||
self.host.setWhatsThis(_translate("UdsActorSetupDialog", "Enter here the UDS Broker Addres using either its IP address or its FQDN address"))
|
||||
self.label_serviceToken.setText(_translate("UdsActorSetupDialog", "Service Token"))
|
||||
self.serviceToken.setToolTip(_translate("UdsActorSetupDialog", "UDS user with administration rights (Will not be stored on template)"))
|
||||
self.serviceToken.setWhatsThis(_translate("UdsActorSetupDialog", "<html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.</p></body></html>"))
|
||||
self.label_loglevel.setText(_translate("UdsActorSetupDialog", "Log Level"))
|
||||
from ui import uds_rc
|
@ -40,7 +40,6 @@ from uds.models import (
|
||||
UserService,
|
||||
Service,
|
||||
TicketStore,
|
||||
|
||||
)
|
||||
|
||||
#from uds.core import VERSION
|
||||
@ -59,6 +58,7 @@ from ..handlers import Handler, AccessDenied, RequestError
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
ALLOWED_FAILS = 5
|
||||
UNMANAGED = 'unmanaged' # matches the definition of UDS Actors OFC
|
||||
|
||||
class BlockAccess(Exception):
|
||||
pass
|
||||
@ -125,8 +125,12 @@ class test(ActorV3Action):
|
||||
name = 'test'
|
||||
|
||||
def post(self) -> typing.MutableMapping[str, typing.Any]:
|
||||
# First, try to locate an user service providing this token.
|
||||
try:
|
||||
ActorToken.objects.get(token=self._params['token']) # Not assigned, because only needs check
|
||||
if self._params['type'] == UNMANAGED:
|
||||
Service.objects.get(token=self._params['token'])
|
||||
else:
|
||||
ActorToken.objects.get(token=self._params['token']) # Not assigned, because only needs check
|
||||
except Exception:
|
||||
return ActorV3Action.actorResult('invalid token')
|
||||
|
||||
@ -182,11 +186,13 @@ class Initiialize(ActorV3Action):
|
||||
def action(self) -> typing.MutableMapping[str, typing.Any]:
|
||||
"""
|
||||
Initialize method expect a json POST with this fields:
|
||||
* type: Actor type. (Currently "managed" or "unmanaged")
|
||||
* version: str -> Actor version
|
||||
* token: str -> Valid Actor Token (if invalid, will return an error)
|
||||
* id: List[dict] -> List of dictionary containing ip and mac:
|
||||
Example:
|
||||
{
|
||||
'type': 'managed,
|
||||
'version': '3.0',
|
||||
'token': 'asbdasdf',
|
||||
'id': [
|
||||
@ -213,16 +219,14 @@ class Initiialize(ActorV3Action):
|
||||
logger.debug('Args: %s, Params: %s', self._args, self._params)
|
||||
try:
|
||||
# First, try to locate an user service providing this token.
|
||||
# User service has precedence over ActorToken
|
||||
|
||||
try:
|
||||
if self._params['type'] == UNMANAGED:
|
||||
# If unmanaged, use Service locator
|
||||
service: Service = Service.objects.get(token=self._params['token'])
|
||||
# Locate an userService that belongs to this service and which
|
||||
# Build the possible ids and make initial filter to match service
|
||||
idsList = [x['ip'] for x in self._params['id']] + [x['mac'] for x in self._params['id']][:10]
|
||||
dbFilter = UserService.objects.filter(deployed_service__service=service)
|
||||
|
||||
except Service.DoesNotExist:
|
||||
else:
|
||||
# If not service provided token, use actor tokens
|
||||
ActorToken.objects.get(token=self._params['token']) # Not assigned, because only needs check
|
||||
# Build the possible ids and make initial filter to match ANY userservice with provided MAC
|
||||
@ -259,7 +263,7 @@ class Initiialize(ActorV3Action):
|
||||
'unique_id': userService.unique_id,
|
||||
'os': osData
|
||||
})
|
||||
except ActorToken.DoesNotExist:
|
||||
except (ActorToken.DoesNotExist, Service.DoesNotExist):
|
||||
raise BlockAccess()
|
||||
|
||||
class ChangeIp(ActorV3Action):
|
||||
|
Loading…
Reference in New Issue
Block a user