diff --git a/server/src/uds/core/util/html.py b/server/src/uds/core/util/html.py index 7e6ae75e7..fc5d464f6 100644 --- a/server/src/uds/core/util/html.py +++ b/server/src/uds/core/util/html.py @@ -32,6 +32,7 @@ ''' from __future__ import unicode_literals +import re import logging logger = logging.getLogger(__name__) @@ -73,39 +74,80 @@ def extractKey(dictionary, key, **kwargs): value = default return value +# Regular expressions for User Agents +# These both are for Internet Explorer +_msie = re.compile('MSIE ([0-9]+)\.([0-9]+)') +_trident = re.compile('Trident/.*rv:([0-9]+)\.([0-9]+)') +# Opera +_opera = re.compile('OPR/([0-9]+)\.([0-9]+)') +# Firefox +_firefox = re.compile('Firefox/([0-9]+)\.([0-9]+)') +# Chrome +_chrome = re.compile('Chrome/([0-9]+)\.([0-9]+)') +# Webkit in general +_webkit = re.compile('AppleWebKit/([0-9]+)\.([0-9]+)') + +_browsers = { + 'ie' : [_trident, _msie], + 'opera': [_opera], + 'firefox': [_firefox], + 'chrome': [_chrome], + 'webkit': [_webkit], +} + def checkBrowser(user_agent, browser): ''' Known browsers right now: ie[version] ie<[version] ''' - import re # Split brwosers we look for - needs_msie = False - needs_version = 6 - needs = '=' + needs_browser = None + needs_version = 0 + needs = '' - if browser[:2] == 'ie': - needs_msie = True - if browser[2] == '<' or browser[2] == '>' or browser[2] == '=': - needs = browser[2] - needs_version = int(browser[3:]) - else: - needs_version = int(browser[2:]) + regexs = None - try: - if needs_msie: - msie = re.compile('MSIE ([0-9]+)\.([0-9]+)') - matches = msie.search(user_agent) - if matches is None: - return False - version = int(matches.groups()[0]) - if needs == '<': - return version < needs_version - elif needs == '>': - return version > needs_version + for b, res in _browsers.iteritems(): + if browser.startswith(b): + logger.debug('Found: {0}'.format(b)) + regexs = res + browser = browser[len(b):] + + if regexs is None: + return False + + browser += ' ' # So we ensure we have at least beowser 0 + + if browser[0] == '<' or browser[0] == '>' or browser[0] == '=': + needs = browser[0] + needs_version = int(browser[1:]) + else: + try: + needs = '=' + needs_version = int(browser) + except: + needs = '' + needs_version = 0 + try: + matches = None + for r in regexs: + matches = r.search(user_agent) + if matches is not None: + break + if matches is None: + return False + + version = int(matches.groups()[0]) + if needs == '<': + return version < needs_version + elif needs == '>': + return version > needs_version + elif needs == '=': return version == needs_version + + return True except: return False diff --git a/server/src/uds/templates/uds/html5/index.html b/server/src/uds/templates/uds/html5/index.html index 4d6b328df..cb37c0df9 100644 --- a/server/src/uds/templates/uds/html5/index.html +++ b/server/src/uds/templates/uds/html5/index.html @@ -29,12 +29,14 @@ width: 48px; height: 48px; } - - {% ifbrowser ie<9 %} + + /* We need to write under button */ .btn-group { max-width: 114px; } + {% ifbrowser firefox %} + {% else %} .btn .caret { margin-left: -4px; } @@ -60,6 +62,9 @@ {% endblock %} {% block body %} + {% ifbrowser webkit %} + webkit!!! + {% endifbrowser %}

{% trans "Services" %}

{% for ser in services %} @@ -121,7 +126,8 @@

{% trans "Ip" %}: {{ ip }}

{% trans "Networks" %}: {{ nets }}

{% trans "Transports" %}: {{ transports }}

- +

{% trans "User Agent" %}: {{ request.META.HTTP_USER_AGENT }}

+

{% trans "OS" %}: {{ request.session.OS.OS }}

{% endif %} diff --git a/server/src/uds/web/views.py b/server/src/uds/web/views.py index 20d311365..38d7240ce 100644 --- a/server/src/uds/web/views.py +++ b/server/src/uds/web/views.py @@ -431,4 +431,4 @@ def download(request, idDownload): last_modified_date = timezone.now() @last_modified(lambda req, **kw: last_modified_date) def jsCatalog(request, lang, domain='djangojs', packages=None): - return javascript_catalog(request, domain, packages) \ No newline at end of file + return javascript_catalog(request, domain, packages)