mirror of
https://github.com/dkmstr/openuds.git
synced 2025-10-07 15:33:51 +03:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b5926dec6f | ||
|
bd70a6290e | ||
|
813764a100 | ||
|
09f329db62 | ||
|
6b5f9d266d |
@@ -57,7 +57,7 @@ def _getMacAddr(ifname):
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
info = bytearray(fcntl.ioctl(s.fileno(), 0x8927, struct.pack(str('256s'), ifname[:15])))
|
||||
return six.text_type(''.join(['%02x:' % char for char in info[18:24]])[:-1])
|
||||
return six.text_type(''.join(['%02x:' % char for char in info[18:24]])[:-1]).upper()
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
@@ -137,8 +137,12 @@ class UDSClient(QtGui.QMainWindow):
|
||||
|
||||
@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()
|
||||
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)
|
||||
@@ -232,7 +236,7 @@ if __name__ == "__main__":
|
||||
|
||||
except Exception:
|
||||
logger.debug('Detected execution without valid URI, exiting')
|
||||
QtGui.QMessageBox.critical(None, 'Notice', 'This program is designed to be used by UDS', QtGui.QMessageBox.Ok)
|
||||
QtGui.QMessageBox.critical(None, 'Notice', 'UDS Client Version {}'.format(VERSION), QtGui.QMessageBox.Ok)
|
||||
sys.exit(1)
|
||||
|
||||
# Setup REST api endpoint
|
||||
|
@@ -34,7 +34,7 @@ from __future__ import unicode_literals
|
||||
# On centos, old six release does not includes byte2int, nor six.PY2
|
||||
import six
|
||||
|
||||
VERSION = '1.9.0'
|
||||
VERSION = '1.9.1'
|
||||
|
||||
__title__ = 'udclient'
|
||||
__version__ = VERSION
|
||||
|
@@ -56,7 +56,7 @@ class RestRequest(QObject):
|
||||
# private
|
||||
self._manager = QNetworkAccessManager()
|
||||
if params is not None:
|
||||
url += '?' + '&'.join('{}={}'.format(k, urllib.quote(six.text_type(v))) for k, v in params.iteritems())
|
||||
url += '?' + '&'.join('{}={}'.format(k, urllib.quote(six.text_type(v).encode('utf8'))) for k, v in params.iteritems())
|
||||
|
||||
self.url = QUrl(RestRequest.restApiUrl + url)
|
||||
|
||||
|
@@ -41,27 +41,36 @@ import stat
|
||||
import six
|
||||
import sys
|
||||
|
||||
from log import logger
|
||||
|
||||
_unlinkFiles = []
|
||||
_tasksToWait = []
|
||||
_execBeforeExit = []
|
||||
|
||||
|
||||
sys_fs_enc = sys.getfilesystemencoding() or 'mbcs'
|
||||
|
||||
def saveTempFile(content, filename=None):
|
||||
if filename is None:
|
||||
filename = ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(16))
|
||||
filename = b''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(16))
|
||||
filename = filename + '.uds'
|
||||
|
||||
if 'win32' in sys.platform:
|
||||
filename = filename.encode('utf-8')
|
||||
logger.info('Fixing for win32')
|
||||
filename = filename.encode(sys_fs_enc)
|
||||
|
||||
filename = os.path.join(tempfile.gettempdir(), filename)
|
||||
|
||||
with open(filename, 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
logger.info('Returning filename')
|
||||
return filename
|
||||
|
||||
|
||||
def findApp(appName, extraPath=None):
|
||||
if 'win32' in sys.platform and isinstance(appName, six.text_type):
|
||||
appName = six.binary_type(appName)
|
||||
appName = appName.encode(sys_fs_enc)
|
||||
searchPath = os.environ['PATH'].split(os.pathsep)
|
||||
if extraPath is not None:
|
||||
searchPath += list(extraPath)
|
||||
@@ -78,7 +87,13 @@ def getHostName():
|
||||
Returns current host name
|
||||
In fact, it's a wrapper for socket.gethostname()
|
||||
'''
|
||||
return six.text_type(socket.gethostname())
|
||||
hostname = socket.gethostname()
|
||||
if 'win32' in sys.platform:
|
||||
hostname = hostname.decode(sys_fs_enc)
|
||||
|
||||
hostname = six.text_type(hostname)
|
||||
logger.info('Hostname: {}'.format(hostname))
|
||||
return hostname
|
||||
|
||||
# Queing operations (to be executed before exit)
|
||||
|
||||
|
@@ -111,7 +111,7 @@ class Actor(Handler):
|
||||
logger.debug('Getting User services from ids: {}'.format(self._params.get('id')))
|
||||
|
||||
try:
|
||||
clientIds = self._params.get('id').split(',')[:5]
|
||||
clientIds = [i.upper() for i in self._params.get('id').split(',')[:5]]
|
||||
except Exception:
|
||||
raise RequestError('Invalid request: (no id found)')
|
||||
|
||||
|
@@ -282,6 +282,9 @@ class GlobalConfig(object):
|
||||
# Allow clients to notify their own ip (if set), or use always the request extracted IP
|
||||
HONOR_CLIENT_IP_NOTIFY = Config.section(SECURITY_SECTION).value('honorClientNotifyIP', '0', type=Config.BOOLEAN_FIELD)
|
||||
|
||||
# If there is a proxy in front of us
|
||||
BEHIND_PROXY = Config.section(SECURITY_SECTION).value('Behind a proxy', '0', type=Config.BOOLEAN_FIELD)
|
||||
|
||||
# Clusters related vars
|
||||
|
||||
# Maximum desired CPU Load. If cpu is over this value, a migration of a service is "desirable"
|
||||
|
@@ -32,13 +32,14 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from uds.core.util import OsDetector
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
from uds.core.auths.auth import ROOT_ID, USER_KEY, getRootUser
|
||||
from uds.models import User
|
||||
|
||||
import threading
|
||||
import logging
|
||||
|
||||
__updated__ = '2015-05-10'
|
||||
__updated__ = '2016-04-22'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -90,6 +91,7 @@ class GlobalRequestMiddleware(object):
|
||||
|
||||
Returns the obtained IP, that is always be a valid ip address.
|
||||
'''
|
||||
behind_proxy = GlobalConfig.BEHIND_PROXY.getBool(False)
|
||||
try:
|
||||
request.ip = request.META['REMOTE_ADDR']
|
||||
except:
|
||||
@@ -98,6 +100,11 @@ class GlobalRequestMiddleware(object):
|
||||
|
||||
try:
|
||||
request.ip_proxy = request.META['HTTP_X_FORWARDED_FOR'].split(",")[0]
|
||||
|
||||
if behind_proxy is True:
|
||||
request.ip = request.ip_proxy
|
||||
request.ip_proxy = request.META['HTTP_X_FORWARDED_FOR'].split(",")[1] # Try to get next proxy
|
||||
|
||||
request.is_proxy = True
|
||||
except:
|
||||
request.ip_proxy = request.ip
|
||||
|
Reference in New Issue
Block a user