forked from shaba/openuds
Updated to client for python 3
This commit is contained in:
parent
2fbdef1739
commit
a648f5686e
@ -30,9 +30,6 @@
|
|||||||
'''
|
'''
|
||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
# pylint: disable=c-extension-no-member
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import json
|
import json
|
||||||
@ -118,7 +115,6 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
def cancelPushed(self):
|
def cancelPushed(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
@QtCore.pyqtSlot()
|
|
||||||
def updateAnim(self):
|
def updateAnim(self):
|
||||||
self.anim += 2
|
self.anim += 2
|
||||||
if self.anim > 99:
|
if self.anim > 99:
|
||||||
@ -139,12 +135,10 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
self.ui.progressBar.invertedAppearance = False
|
self.ui.progressBar.invertedAppearance = False
|
||||||
self.animTimer.stop()
|
self.animTimer.stop()
|
||||||
|
|
||||||
@QtCore.pyqtSlot()
|
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
self.req = RestRequest('', self, self.version)
|
self.req = RestRequest('', self, self.version)
|
||||||
self.req.get()
|
self.req.get()
|
||||||
|
|
||||||
@QtCore.pyqtSlot(dict)
|
|
||||||
def version(self, data):
|
def version(self, data):
|
||||||
try:
|
try:
|
||||||
self.processError(data)
|
self.processError(data)
|
||||||
@ -160,14 +154,12 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
self.getTransportData()
|
self.getTransportData()
|
||||||
|
|
||||||
except RetryException as e:
|
except RetryException as e:
|
||||||
self.ui.info.setText(six.text_type(e))
|
self.ui.info.setText(str(e))
|
||||||
QtCore.QTimer.singleShot(1000, self.getVersion)
|
QtCore.QTimer.singleShot(1000, self.getVersion)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.showError(e)
|
self.showError(e)
|
||||||
|
|
||||||
|
|
||||||
@QtCore.pyqtSlot()
|
|
||||||
def getTransportData(self):
|
def getTransportData(self):
|
||||||
try:
|
try:
|
||||||
self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION})
|
self.req = RestRequest('/{}/{}'.format(self.ticket, self.scrambler), self, self.transportDataReceived, params={'hostname': tools.getHostName(), 'version': VERSION})
|
||||||
@ -176,8 +168,6 @@ class UDSClient(QtWidgets.QMainWindow):
|
|||||||
logger.exception('Got exception on getTransportData')
|
logger.exception('Got exception on getTransportData')
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
@QtCore.pyqtSlot(dict)
|
|
||||||
def transportDataReceived(self, data):
|
def transportDataReceived(self, data):
|
||||||
logger.debug('Transport data received')
|
logger.debug('Transport data received')
|
||||||
try:
|
try:
|
||||||
@ -274,6 +264,7 @@ def approveHost(hostName, parentWindow=None):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logger.debug('Initializing connector')
|
logger.debug('Initializing connector')
|
||||||
|
|
||||||
# Initialize app
|
# Initialize app
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
|
|
||||||
|
@ -31,13 +31,10 @@
|
|||||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
'''
|
'''
|
||||||
# pylint: disable=c-extension-no-member,no-name-in-module
|
# pylint: disable=c-extension-no-member,no-name-in-module
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
from PyQt5.QtCore import pyqtSignal, pyqtSlot
|
||||||
from PyQt5.QtCore import QObject, QUrl, QSettings
|
from PyQt5.QtCore import QObject, QUrl, QSettings
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
@ -60,8 +57,16 @@ class RestRequest(QObject):
|
|||||||
super(RestRequest, self).__init__()
|
super(RestRequest, self).__init__()
|
||||||
# private
|
# private
|
||||||
self._manager = QNetworkAccessManager()
|
self._manager = QNetworkAccessManager()
|
||||||
|
try:
|
||||||
|
if os.path.exists('/etc/ssl/certs/ca-certificates.crt'):
|
||||||
|
pass
|
||||||
|
# os.environ['REQUESTS_CA_BUNDLE'] = '/etc/ssl/certs/ca-certificates.crt'
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if params is not None:
|
if params is not None:
|
||||||
url += '?' + '&'.join('{}={}'.format(k, urllib.parse.quote(six.text_type(v).encode('utf8'))) for k, v in params.items())
|
url += '?' + '&'.join('{}={}'.format(k, urllib.parse.quote(str(v).encode('utf8'))) for k, v in params.items())
|
||||||
|
|
||||||
self.url = QUrl(RestRequest.restApiUrl + url)
|
self.url = QUrl(RestRequest.restApiUrl + url)
|
||||||
|
|
||||||
@ -79,14 +84,12 @@ class RestRequest(QObject):
|
|||||||
try:
|
try:
|
||||||
if reply.error() != QNetworkReply.NoError:
|
if reply.error() != QNetworkReply.NoError:
|
||||||
raise Exception(reply.errorString())
|
raise Exception(reply.errorString())
|
||||||
#data = six.text_type(reply.readAll())
|
|
||||||
data = bytes(reply.readAll())
|
data = bytes(reply.readAll())
|
||||||
#data = data.encode("utf-8")
|
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
data = {
|
data = {
|
||||||
'result': None,
|
'result': None,
|
||||||
'error': six.text_type(e)
|
'error': str(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.done.emit(data)
|
self.done.emit(data)
|
||||||
@ -97,7 +100,7 @@ class RestRequest(QObject):
|
|||||||
settings = QSettings()
|
settings = QSettings()
|
||||||
settings.beginGroup('ssl')
|
settings.beginGroup('ssl')
|
||||||
cert = errors[0].certificate()
|
cert = errors[0].certificate()
|
||||||
digest = six.text_type(cert.digest().toHex())
|
digest = str(cert.digest().toHex())
|
||||||
|
|
||||||
approved = settings.value(digest, False)
|
approved = settings.value(digest, False)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user