mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Added config var for convert usernames to lowercase...
This commit is contained in:
parent
f773cb5ecc
commit
22a7e2336e
@ -33,7 +33,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from uds import ui
|
||||
from uds import browser
|
||||
from uds.rest import RestRequest
|
||||
from uds.rest import RestRequest, RetryException
|
||||
from uds.forward import forward
|
||||
from uds import VERSION
|
||||
from uds.log import logger # @UnresolvedImport
|
||||
@ -78,6 +78,16 @@ def approveHost(host):
|
||||
return approved
|
||||
|
||||
|
||||
def getWithRetry(rest, url):
|
||||
while True:
|
||||
try:
|
||||
res = rest.get(url)
|
||||
return res
|
||||
except RetryException as e:
|
||||
if ui.question('Service not available', '{}\nPlease, wait a minute and press "OK" to retry, or CANCEL to abort') is True:
|
||||
continue
|
||||
raise Exception('Cancelled by user')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logger.debug('Initializing connector')
|
||||
@ -113,16 +123,18 @@ if __name__ == "__main__":
|
||||
# Main requests part
|
||||
# First, get version
|
||||
try:
|
||||
res = rest.get('')['result']
|
||||
res = getWithRetry(rest, '')
|
||||
|
||||
if res['requiredVersion'] > VERSION:
|
||||
ui.message("New UDS Client available", "A new uds version is needed in order to access this version of UDS. A browser will be openend for this download.")
|
||||
webbrowser.open(res['downloadUrl'])
|
||||
sys.exit(1)
|
||||
|
||||
# Now get ticket
|
||||
res = rest.get('/{}/{}'.format(ticket, scrambler), params={'hostname': tools.getHostName(), 'version': VERSION})
|
||||
res = getWithRetry(rest, '/{}/{}'.format(ticket, scrambler), params={'hostname': tools.getHostName(), 'version': VERSION})
|
||||
|
||||
except KeyError as e:
|
||||
logger.error('Got an exception access RESULT: {}'.format(e))
|
||||
except Exception as e:
|
||||
logger.error('Got an unexpected exception: {}'.format(e))
|
||||
error = 'ERROR: {}'.format(e)
|
||||
logger.error(error)
|
||||
ui.message('Error', error)
|
||||
sys.exit(2)
|
||||
|
@ -39,8 +39,13 @@ import json
|
||||
import six
|
||||
import urllib
|
||||
|
||||
|
||||
from .log import logger
|
||||
|
||||
class RetryException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class RestRequest(object):
|
||||
|
||||
restApiUrl = ''
|
||||
@ -54,19 +59,24 @@ class RestRequest(object):
|
||||
if params is not None:
|
||||
url += '?' + '&'.join('{}={}'.format(k, urllib.quote(six.text_type(v).encode('utf8'))) for k, v in params.iteritems())
|
||||
|
||||
try:
|
||||
logger.debug('Requesting {}'.format(url))
|
||||
try:
|
||||
r = requests.get(url, headers={'Content-type': 'application/json'})
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
raise Exception('Error connecting to UDS Server at {}'.format(self.restApiUrl[0:-11]))
|
||||
|
||||
if r.ok:
|
||||
logger.debug('Request was OK. {}'.format(r.text))
|
||||
data = json.loads(r.text)
|
||||
if not 'error' in data:
|
||||
return data['result']
|
||||
# Has error
|
||||
if data.get('retryable', '0') == '1':
|
||||
raise RetryException(data['error'])
|
||||
|
||||
raise Exception(data['error'])
|
||||
else:
|
||||
logger.error('Error requesting {}: {}, {}'.format(url, r.code. r.text))
|
||||
raise Exception('Error {}: {}'.format(r.code, r.text))
|
||||
except Exception as e:
|
||||
data = {
|
||||
'result': None,
|
||||
'error': six.text_type(e)
|
||||
}
|
||||
|
||||
return data
|
||||
|
@ -321,6 +321,9 @@ class GlobalConfig(object):
|
||||
# Custom message for error when limiting by calendar
|
||||
LIMITED_BY_CALENDAR_TEXT = Config.section(GLOBAL_SECTION).value('Calendar access denied text', '', type=Config.TEXT_FIELD) # Defaults to Nothing
|
||||
|
||||
# This is used so templates can change "styles" from admin interface
|
||||
LOWERCASE_USERNAME = Config.section(SECURITY_SECTION).value('Convert username to lowercase', '1', type=Config.BOOLEAN_FIELD)
|
||||
|
||||
initDone = False
|
||||
|
||||
@staticmethod
|
||||
|
@ -50,7 +50,7 @@ import uds.web.errors as errors
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
__updated__ = '2017-04-19'
|
||||
__updated__ = '2017-06-01'
|
||||
|
||||
# Allow cross-domain login
|
||||
# @csrf_exempt
|
||||
@ -93,6 +93,8 @@ def login(request, tag=None):
|
||||
except Exception:
|
||||
authenticator = Authenticator()
|
||||
userName = form.cleaned_data['user']
|
||||
if GlobalConfig.LOWERCASE_USERNAME.getBool(True) is True:
|
||||
userName = userName.lower()
|
||||
|
||||
cache = Cache('auth')
|
||||
cacheKey = str(authenticator.id) + userName
|
||||
|
Loading…
Reference in New Issue
Block a user