def getTransportData(self): try: self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) self.req.get() except Exception as e: logger.exception('Got exception on getTransportData') raise e
def getTransportData(self): try: self.req = RestRequest( "/{}/{}".format(self.ticket, self.scrambler), self, self.transportDataReceived, params={"hostname": tools.getHostName(), "version": VERSION}, ) self.req.get() except Exception as e: logger.exception("Got exception on getTransportData") raise e
def getTransportData(self): try: self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) self.req.get() except Exception as e: logger.exception('Got exception: {}'.format(e)) raise e
def version(self, data): try: self.ui.progressBar.setValue(50) self.processError(data) self.ui.info.setText('Processing...') if data['result']['requiredVersion'] > VERSION: QtGui.QMessageBox.critical(self, 'Upgrade required', 'A newer connector version is required.\nA browser will be opened to download it.', QtGui.QMessageBox.Ok) webbrowser.open(data['result']['downloadUrl']) self.closeWindow() return self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived) self.req.get() except Exception as e: self.showError(e)
class UDSClient(QtWidgets.QMainWindow): ticket = None scrambler = None withError = False animTimer = None anim = 0 animInverted = False serverVersion = 'X.Y.Z' # Will be overwriten on getVersion req = None def __init__(self): QtWidgets.QMainWindow.__init__(self) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.progressBar.setValue(0) self.ui.cancelButton.clicked.connect(self.cancelPushed) self.ui.info.setText('Initializing...') screen = QtWidgets.QDesktopWidget().screenGeometry() mysize = self.geometry() hpos = (screen.width() - mysize.width()) // 2 vpos = (screen.height() - mysize.height() - mysize.height()) // 2 self.move(hpos, vpos) self.animTimer = QtCore.QTimer() self.animTimer.timeout.connect(self.updateAnim) # QtCore.QObject.connect(self.animTimer, QtCore.SIGNAL('timeout()'), self.updateAnim) self.activateWindow() self.startAnim() def closeWindow(self): self.close() def processError(self, data): if 'error' in data: # QtWidgets.QMessageBox.critical(self, 'Request error {}'.format(data.get('retryable', '0')), data['error'], QtWidgets.QMessageBox.Ok) if data.get('retryable', '0') == '1': raise RetryException(data['error']) raise Exception(data['error']) # QtWidgets.QMessageBox.critical(self, 'Request error', rest.data['error'], QtWidgets.QMessageBox.Ok) # self.closeWindow() # return def showError(self, error): logger.error('got error: %s', error) self.stopAnim() self.ui.info.setText('UDS Plugin Error') # In fact, main window is hidden, so this is not visible... :) self.closeWindow() QtWidgets.QMessageBox.critical(None, 'UDS Plugin Error', '{}'.format(error), QtWidgets.QMessageBox.Ok) self.withError = True def cancelPushed(self): self.close() def updateAnim(self): self.anim += 2 if self.anim > 99: self.animInverted = not self.animInverted self.ui.progressBar.setInvertedAppearance(self.animInverted) self.anim = 0 self.ui.progressBar.setValue(self.anim) def startAnim(self): self.ui.progressBar.invertedAppearance = False self.anim = 0 self.animInverted = False self.ui.progressBar.setInvertedAppearance(self.animInverted) self.animTimer.start(40) def stopAnim(self): self.ui.progressBar.invertedAppearance = False self.animTimer.stop() def getVersion(self): self.req = RestRequest('', self, self.version) self.req.get() def version(self, data): try: self.processError(data) self.ui.info.setText('Processing...') if data['result']['requiredVersion'] > VERSION: QtWidgets.QMessageBox.critical(self, 'Upgrade required', 'A newer connector version is required.\nA browser will be opened to download it.', QtWidgets.QMessageBox.Ok) webbrowser.open(data['result']['downloadUrl']) self.closeWindow() return self.serverVersion = data['result']['requiredVersion'] self.getTransportData() except RetryException as e: self.ui.info.setText(str(e)) QtCore.QTimer.singleShot(1000, self.getVersion) except Exception as e: self.showError(e) def getTransportData(self): try: self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) self.req.get() except Exception as e: logger.exception('Got exception on getTransportData') raise e def transportDataReceived(self, data): logger.debug('Transport data received') try: self.processError(data) params = None if self.serverVersion <= OLD_METHOD_VERSION: script = bz2.decompress(base64.b64decode(data['result'])) # This fixes uds 2.2 "write" string on binary streams on some transport script = script.replace(b'stdin.write("', b'stdin.write(b"') script = script.replace(b'version)', b'version.decode("utf-8"))') else: res = data['result'] # We have three elements on result: # * Script # * Signature # * Script data # We test that the Script has correct signature, and them execute it with the parameters #script, signature, params = res['script'].decode('base64').decode('bz2'), res['signature'], json.loads(res['params'].decode('base64').decode('bz2')) script, signature, params = bz2.decompress(base64.b64decode(res['script'])), res['signature'], json.loads(bz2.decompress(base64.b64decode(res['params']))) if tools.verifySignature(script, signature) is False: logger.error('Signature is invalid') raise Exception('Invalid UDS code signature. Please, report to administrator') self.stopAnim() if 'darwin' in sys.platform: self.showMinimized() QtCore.QTimer.singleShot(3000, self.endScript) self.hide() six.exec_(script.decode("utf-8"), globals(), {'parent': self, 'sp': params}) except RetryException as e: self.ui.info.setText(six.text_type(e) + ', retrying access...') # Retry operation in ten seconds QtCore.QTimer.singleShot(10000, self.getTransportData) except Exception as e: #logger.exception('Got exception executing script:') self.showError(e) def endScript(self): # After running script, wait for stuff try: tools.waitForTasks() except Exception: pass try: tools.unlinkFiles() except Exception: pass try: tools.execBeforeExit() except Exception: pass self.closeWindow() def start(self): ''' Starts proccess by requesting version info ''' self.ui.info.setText('Initializing...') QtCore.QTimer.singleShot(100, self.getVersion)
def getVersion(self): self.req = RestRequest('', self, self.version) self.req.get()
logger.debug('URI: %s', uri) if uri[:6] != 'uds://' and uri[:7] != 'udss://': raise Exception() ssl = uri[3] == 's' host, ticket, scrambler = uri.split('//')[1].split('/') logger.debug('ssl: %s, host:%s, ticket:%s, scrambler:%s', ssl, host, ticket, scrambler) except Exception: logger.debug('Detected execution without valid URI, exiting') ui.message('UDS Client', 'UDS Client Version {}'.format(VERSION)) sys.exit(1) rest = RestRequest(host, ssl) logger.debug('Setting request URL to %s', rest.restApiUrl) # Main requests part # First, get version try: res = getWithRetry(rest, '') logger.debug('Got information %s', res) requiredVersion = res['requiredVersion'] if requiredVersion > VERSION: ui.message( "New UDS Client available", "A new uds version is needed in order to access this version of UDS.\nPlease, download and install it" )
class UDSClient(QtGui.QMainWindow): ticket = None scrambler = None withError = False def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.progressBar.setValue(0) self.ui.cancelButton.clicked.connect(self.cancelPushed) self.ui.info.setText('Initializing...') screen = QtGui.QDesktopWidget().screenGeometry() mysize = self.geometry() hpos = (screen.width() - mysize.width()) / 2 vpos = (screen.height() - mysize.height() - mysize.height()) / 2 self.move(hpos, vpos) self.activateWindow() def closeWindow(self): self.close() def processError(self, data): if 'error' in data: # QtGui.QMessageBox.critical(self, 'Request error {}'.format(data.get('retryable', '0')), data['error'], QtGui.QMessageBox.Ok) if data.get('retryable', '0') == '1': raise RetryException(data['error']) raise Exception(data['error']) # QtGui.QMessageBox.critical(self, 'Request error', rest.data['error'], QtGui.QMessageBox.Ok) # self.closeWindow() # return def showError(self, e): self.ui.progressBar.setValue(100) self.ui.info.setText('Error') QtGui.QMessageBox.critical(self, 'Error', six.text_type(e), QtGui.QMessageBox.Ok) self.closeWindow() self.withError = True def cancelPushed(self): self.close() def _updateProgressBar(self, increment, maximum=100): val = self.ui.progressBar.value() val += increment if val > maximum: val = maximum self.ui.progressBar.setValue(val) @QtCore.pyqtSlot() def getVersion(self): self.req = RestRequest('', self, self.version) self.req.get() @QtCore.pyqtSlot(dict) def version(self, data): try: self.ui.progressBar.setValue(20) self.processError(data) self.ui.info.setText('Processing...') if data['result']['requiredVersion'] > VERSION: QtGui.QMessageBox.critical(self, 'Upgrade required', 'A newer connector version is required.\nA browser will be opened to download it.', QtGui.QMessageBox.Ok) webbrowser.open(data['result']['downloadUrl']) self.closeWindow() return self.getTransportData() except RetryException as e: self._updateProgressBar(5, 80) self.ui.info.setText(six.text_type(e)) QtCore.QTimer.singleShot(1000, self.getVersion) except Exception as e: self.showError(e) @QtCore.pyqtSlot() def getTransportData(self): self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) self.req.get() @QtCore.pyqtSlot(dict) def transportDataReceived(self, data): try: self.processError(data) self.ui.progressBar.setValue(80) script = data['result'].decode('base64').decode('bz2') self.ui.progressBar.setValue(100) # self.showMinimized() QtCore.QTimer.singleShot(3000, self.endScript) self.hide() six.exec_(script, globals(), {'parent': self}) except RetryException as e: self._updateProgressBar(5, 80) self.ui.info.setText(six.text_type(e) + ', retrying access...') # Retry operation in ten seconds QtCore.QTimer.singleShot(10000, self.getTransportData) except Exception as e: self.showError(e) def endScript(self): # After running script, wait for stuff try: tools.waitForTasks() except Exception: pass try: tools.unlinkFiles() except Exception: pass try: tools.execBeforeExit() except Exception: pass self.closeWindow() def start(self): ''' Starts proccess by requesting version info ''' self.ui.info.setText('Initializing...') QtCore.QTimer.singleShot(100, self.getVersion)
def getTransportData(self): self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) self.req.get()
class UDSClient(QtGui.QMainWindow): ticket = None scrambler = None withError = False def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.progressBar.setValue(0) self.ui.cancelButton.clicked.connect(self.cancelPushed) self.ui.info.setText('Initializing...') screen = QtGui.QDesktopWidget().screenGeometry() mysize = self.geometry() hpos = (screen.width() - mysize.width()) / 2 vpos = (screen.height() - mysize.height() - mysize.height()) / 2 self.move(hpos, vpos) self.activateWindow() def closeWindow(self): self.close() def processError(self, data): if 'error' in data: raise Exception(data['error']) # QtGui.QMessageBox.critical(self, 'Request error', rest.data['error'], QtGui.QMessageBox.Ok) # self.closeWindow() # return def showError(self, e): self.ui.progressBar.setValue(100) self.ui.info.setText('Error') QtGui.QMessageBox.critical(self, 'Error', six.text_type(e), QtGui.QMessageBox.Ok) self.closeWindow() self.withError = True def cancelPushed(self): self.close() @QtCore.pyqtSlot() def getVersion(self): self.req = RestRequest('', self, self.version) self.req.get() @QtCore.pyqtSlot(dict) def version(self, data): try: self.ui.progressBar.setValue(50) self.processError(data) self.ui.info.setText('Processing...') if data['result']['requiredVersion'] > VERSION: QtGui.QMessageBox.critical(self, 'Upgrade required', 'A newer connector version is required.\nA browser will be opened to download it.', QtGui.QMessageBox.Ok) webbrowser.open(data['result']['downloadUrl']) self.closeWindow() return self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived) self.req.get() except Exception as e: self.showError(e) @QtCore.pyqtSlot(dict) def transportDataReceived(self, data): try: self.ui.progressBar.setValue(80) self.processError(data) script = data['result'].decode('base64').decode('bz2') six.exec_(script, globals(), {'parent': self}) self.ui.progressBar.setValue(100) self.showMinimized() QtCore.QTimer.singleShot(3000, self.endScript) except Exception as e: self.showError(e) def endScript(self): # After running script, wait for stuff try: tools.waitForTasks() except Exception: pass try: tools.unlinkFiles() except Exception: pass try: tools.execBeforeExit() except Exception: pass self.closeWindow() def start(self): ''' Starts proccess by requesting version info ''' self.ui.info.setText('Initializing...') QtCore.QTimer.singleShot(100, self.getVersion)
class UDSClient(QtGui.QMainWindow): ticket = None scrambler = None withError = False animTimer = None anim = 0 animInverted = False serverVersion = 'X.Y.Z' # Will be overwriten on getVersion def __init__(self): QtGui.QMainWindow.__init__(self) self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowStaysOnTopHint) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.progressBar.setValue(0) self.ui.cancelButton.clicked.connect(self.cancelPushed) self.ui.info.setText('Initializing...') screen = QtGui.QDesktopWidget().screenGeometry() mysize = self.geometry() hpos = (screen.width() - mysize.width()) / 2 vpos = (screen.height() - mysize.height() - mysize.height()) / 2 self.move(hpos, vpos) self.animTimer = QtCore.QTimer() QtCore.QObject.connect(self.animTimer, QtCore.SIGNAL('timeout()'), self.updateAnim) self.activateWindow() self.startAnim() def closeWindow(self): self.close() def processError(self, data): if 'error' in data: # QtGui.QMessageBox.critical(self, 'Request error {}'.format(data.get('retryable', '0')), data['error'], QtGui.QMessageBox.Ok) if data.get('retryable', '0') == '1': raise RetryException(data['error']) raise Exception(data['error']) # QtGui.QMessageBox.critical(self, 'Request error', rest.data['error'], QtGui.QMessageBox.Ok) # self.closeWindow() # return def showError(self, e): logger.error('got error: {}'.format(e)) self.stopAnim() self.ui.info.setText('UDS Plugin Error') # In fact, main window is hidden, so this is not visible... :) self.closeWindow() QtGui.QMessageBox.critical(None, 'UDS Plugin Error', '{}'.format(e), QtGui.QMessageBox.Ok) self.withError = True def cancelPushed(self): self.close() @QtCore.pyqtSlot() def updateAnim(self): self.anim += 2 if self.anim > 99: self.animInverted = not self.animInverted self.ui.progressBar.setInvertedAppearance(self.animInverted) self.anim = 0 self.ui.progressBar.setValue(self.anim) def startAnim(self): self.ui.progressBar.invertedAppearance = False self.anim = 0 self.animInverted = False self.ui.progressBar.setInvertedAppearance(self.animInverted) self.animTimer.start(40) def stopAnim(self): self.ui.progressBar.invertedAppearance = False self.animTimer.stop() @QtCore.pyqtSlot() def getVersion(self): self.req = RestRequest('', self, self.version) self.req.get() @QtCore.pyqtSlot(dict) def version(self, data): try: self.processError(data) self.ui.info.setText('Processing...') if data['result']['requiredVersion'] > VERSION: QtGui.QMessageBox.critical(self, 'Upgrade required', 'A newer connector version is required.\nA browser will be opened to download it.', QtGui.QMessageBox.Ok) webbrowser.open(data['result']['downloadUrl']) self.closeWindow() return self.serverVersion = data['result']['requiredVersion'] self.getTransportData() except RetryException as e: self.ui.info.setText(six.text_type(e)) QtCore.QTimer.singleShot(1000, self.getVersion) except Exception as e: self.showError(e) @QtCore.pyqtSlot() def getTransportData(self): try: self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION}) self.req.get() except Exception as e: logger.exception('Got exception: {}'.format(e)) raise e @QtCore.pyqtSlot(dict) def transportDataReceived(self, data): logger.debug('Transport data received') try: self.processError(data) params = None if self.serverVersion <= OLD_METHOD_VERSION: script = data['result'].decode('base64').decode('bz2') else: res = data['result'] # We have three elements on result: # * Script # * Signature # * Script data # We test that the Script has correct signature, and them execute it with the parameters script, signature, params = res['script'].decode('base64').decode('bz2'), res['signature'], json.loads(res['params'].decode('base64').decode('bz2')) if tools.verifySignature(script, signature) is False: logger.error('Signature is invalid') raise Exception('Invalid UDS code signature. Please, report to administrator') self.stopAnim() if 'darwin' in sys.platform: self.showMinimized() QtCore.QTimer.singleShot(3000, self.endScript) self.hide() # if self.serverVersion <= OLD_METHOD_VERSION: # errorString = '<p>The server <b>{}</b> runs an old version of UDS:</p>'.format(host) # errorString += '<p>To avoid security issues, you must approve old UDS Version access.</p>' # # if QtGui.QMessageBox.warning(None, 'ACCESS Warning', errorString, QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) == QtGui.QMessageBox.No: # raise Exception('Server not approved. Access denied.') six.exec_(script, globals(), {'parent': self, 'sp': params}) except RetryException as e: self.ui.info.setText(six.text_type(e) + ', retrying access...') # Retry operation in ten seconds QtCore.QTimer.singleShot(10000, self.getTransportData) except Exception as e: #logger.exception('Got exception executing script:') self.showError(e) def endScript(self): # After running script, wait for stuff try: tools.waitForTasks() except Exception: pass try: tools.unlinkFiles() except Exception: pass try: tools.execBeforeExit() except Exception: pass self.closeWindow() def start(self): ''' Starts proccess by requesting version info ''' self.ui.info.setText('Initializing...') QtCore.QTimer.singleShot(100, self.getVersion)