Example #1
0
def download(request: 'HttpRequest', idDownload: str) -> 'HttpResponse':
    """
    Downloadables management
    """
    if idDownload.strip() == '':
        return index(request)

    return downloadsManager().send(request, idDownload)
Example #2
0
def udsJs(request):
    auth_host = request.META.get('HTTP_HOST') or request.META.get(
        'SERVER_NAME'
    ) or 'auth_host'  # Last one is a placeholder in case we can't locate host name

    profile = {
        'user': None if request.user is None else request.user.name,
        'role':
        'staff' if request.user and request.user.staff_member else 'user',
    }

    # Gets csrf token
    csrf_token = csrf.get_token(request)
    if csrf_token is not None:
        csrf_token = str(csrf_token)

    if GlobalConfig.DISALLOW_GLOBAL_LOGIN.getBool(False) is True:
        try:
            authenticators = [Authenticator.objects.get(small_name=auth_host)]
        except Exception:
            try:
                authenticators = [
                    Authenticator.objects.order_by('priority')[0].small_name
                ]
            except Exception:  # There is no authenticators yet...
                authenticators = []
    else:
        authenticators = Authenticator.objects.all()

    # the auths for client
    def getAuth(auth):
        theType = auth.getType()
        return {
            'id': auth.uuid,
            'name': auth.name,
            'label': auth.small_name,
            'priority': auth.priority,
            'is_custom': theType.isCustom()
        }

    config = {
        'version':
        VERSION,
        'version_stamp':
        VERSION_STAMP,
        'language':
        get_language(),
        'available_languages': [{
            'id': k,
            'name': gettext(v)
        } for k, v in settings.LANGUAGES],
        'authenticators':
        [getAuth(auth) for auth in authenticators if auth.getType()],
        'os':
        request.os['OS'],
        'csrf_field':
        CSRF_FIELD,
        'csrf':
        csrf_token,
        'image_size':
        Image.MAX_IMAGE_SIZE,
        'reload_time':
        GlobalConfig.RELOAD_TIME.getInt(True),
        'messages': {
            # Calendar denied message
            'calendarDenied':
            GlobalConfig.LIMITED_BY_CALENDAR_TEXT.get().strip()
            or gettext("Access limited by calendar")
        },
        'urls': {
            'changeLang':
            reverse('set_language'),
            'login':
            reverse('page.login'),
            'logout':
            reverse('page.logout'),
            'user':
            reverse('page.index'),
            'customAuth':
            reverse('uds.web.views.customAuth', kwargs={'idAuth': ''}),
            'services':
            reverse('webapi.services'),
            'enabler':
            reverse('webapi.enabler',
                    kwargs={
                        'idService': 'param1',
                        'idTransport': 'param2'
                    }),
            'action':
            reverse('webapi.action',
                    kwargs={
                        'idService': 'param1',
                        'action': 'param2'
                    }),
            'galleryImage':
            reverse('webapi.galleryImage', kwargs={'idImage': 'param1'}),
            'transportIcon':
            reverse('webapi.transportIcon', kwargs={'idTrans': 'param1'}),
            'static':
            static(''),
            # Launcher URL if exists
            'launch':
            request.session.get('launch', ''),
        }
    }

    plugins = [{
        'url': static(url.format(version=CLIENT_VERSION)),
        'description': description,
        'name': name
    } for url, description, name in (
        ('clients/UDSClientSetup-{version}.exe', gettext('Windows client'),
         'Windows'), ('clients/UDSClient-{version}.pkg',
                      gettext('Mac OS X client'), 'MacOS'),
        ('udsclient_{version}_all.deb', gettext('Debian based Linux client') +
         ' ' + gettext('(requires Python-2.7)'), 'Linux'),
        ('udsclient-{version}-1.noarch.rpm',
         gettext('Red Hat based Linux client (RH, Fedora, Centos, ...)') +
         ' ' + gettext('(requires Python-2.7)'),
         'Linux'), ('udsclient-opensuse-{version}-1.noarch.rpm',
                    gettext('Suse based Linux client') + ' ' +
                    gettext('(requires Python-2.7)'),
                    'Linux'), ('udsclient-{version}.tar.gz',
                               gettext('Generic .tar.gz Linux client') + ' ' +
                               gettext('(requires Python-2.7)'), 'Linux'))]

    actors = []

    if profile['role'] == 'staff':  # Add staff things
        # If is admin (informational, REST api checks users privileges anyway...)
        profile['admin'] = True
        # REST auth
        config['auth_token'] = request.session.session_key
        config['auth_header'] = AUTH_TOKEN_HEADER
        # Actors
        actors = [{
            'url':
            reverse('utility.downloader', kwargs={'idDownload': key}),
            'name':
            val['name'],
            'description':
            gettext(val['comment'])
        } for key, val in downloadsManager().getDownloadables().items()]
        # URLS
        config['urls']['admin'] = reverse('uds.admin.views.index')
        config['urls']['rest'] = reverse('REST', kwargs={'arguments': ''})

    errors = []
    if 'errors' in request.session:
        errors = request.session['errors']
        del request.session['errors']

    uds = {
        'profile': profile,
        'config': config,
        'plugins': plugins,
        'actors': actors,
        'errors': errors,
        'data': request.session.get('data')
    }

    # Reset some 1 time values...
    request.session['launch'] = ''

    return 'var udsData = ' + json.dumps(uds) + ';\n'
Example #3
0
def udsJs(request):
    auth_host = request.META.get('HTTP_HOST') or request.META.get('SERVER_NAME') or 'auth_host'  # Last one is a placeholder in case we can't locate host name

    profile = {
        'user': None if request.user is None else request.user.name,
        'role': 'staff' if request.user and request.user.staff_member else 'user',
    }

    # Gets csrf token
    csrf_token = csrf.get_token(request)
    if csrf_token is not None:
        csrf_token = str(csrf_token)

    if GlobalConfig.DISALLOW_GLOBAL_LOGIN.getBool(False) is True:
        try:
            authenticators = [Authenticator.objects.get(small_name=auth_host)]
        except Exception:
            try:
                authenticators = [Authenticator.objects.order_by('priority')[0].small_name]
            except Exception:  # There is no authenticators yet...
                authenticators = []
    else:
        authenticators = Authenticator.objects.all()

    # the auths for client
    def getAuth(auth):
        theType = auth.getType()
        return {
            'id': auth.uuid,
            'name': auth.name,
            'label': auth.small_name,
            'priority': auth.priority,
            'is_custom': theType.isCustom()
        }

    config = {
        'version': VERSION,
        'version_stamp': VERSION_STAMP,
        'language': get_language(),
        'available_languages': [{'id': k, 'name': gettext(v)} for k, v in settings.LANGUAGES],
        'authenticators': [getAuth(auth) for auth in authenticators if auth.getType()],
        'os': request.os['OS'],
        'csrf_field': CSRF_FIELD,
        'csrf': csrf_token,
        'image_size': Image.MAX_IMAGE_SIZE,
        'reload_time': GlobalConfig.RELOAD_TIME.getInt(True),
        'messages': {
            # Calendar denied message
            'calendarDenied': GlobalConfig.LIMITED_BY_CALENDAR_TEXT.get().strip() or gettext("Access limited by calendar")
        },
        'urls': {
            'changeLang': reverse('set_language'),
            'login': reverse('page.login'),
            'logout': reverse('page.logout'),
            'user': reverse('page.index'),
            'customAuth': reverse('uds.web.views.customAuth', kwargs={'idAuth': ''}),
            'services': reverse('webapi.services'),
            'enabler': reverse('webapi.enabler', kwargs={ 'idService': 'param1', 'idTransport': 'param2' }),
            'action': reverse('webapi.action', kwargs={ 'idService': 'param1', 'action': 'param2' }),
            'galleryImage': reverse('webapi.galleryImage', kwargs={ 'idImage': 'param1' }),
            'transportIcon': reverse('webapi.transportIcon', kwargs={'idTrans': 'param1'}),
            'static': static(''),
            # Launcher URL if exists
            'launch': request.session.get('launch', ''),
        }
    }

    plugins = [
        {
            'url': static(url.format(version=CLIENT_VERSION)),
            'description': description,
            'name': name
        } for url, description, name in (
            ('clients/UDSClientSetup-{version}.exe', gettext('Windows client'), 'Windows'),
            ('clients/UDSClient-{version}.pkg', gettext('Mac OS X client'), 'MacOS'),
            ('udsclient_{version}_all.deb', gettext('Debian based Linux client') + ' ' + gettext('(requires Python-2.7)'), 'Linux'),
            ('udsclient-{version}-1.noarch.rpm', gettext('Red Hat based Linux client (RH, Fedora, Centos, ...)') + ' ' + gettext('(requires Python-2.7)'), 'Linux'),
            ('udsclient-opensuse-{version}-1.noarch.rpm', gettext('Suse based Linux client') + ' ' + gettext('(requires Python-2.7)'), 'Linux'),
            ('udsclient-{version}.tar.gz', gettext('Generic .tar.gz Linux client') + ' ' + gettext('(requires Python-2.7)'), 'Linux')
        )
    ]

    actors = []

    if profile['role'] == 'staff':  # Add staff things
        # If is admin (informational, REST api checks users privileges anyway...)
        profile['admin'] = True;
        # REST auth
        config['auth_token'] = request.session.session_key
        config['auth_header'] = AUTH_TOKEN_HEADER
        # Actors
        actors = [{'url': reverse('utility.downloader', kwargs={'idDownload': key}), 'name': val['name'], 'description': gettext(val['comment'])} for key, val in downloadsManager().getDownloadables().items()]
        # URLS
        config['urls']['admin'] = reverse('uds.admin.views.index')
        config['urls']['rest'] = reverse('REST', kwargs={'arguments': ''})

    errors = []
    if 'errors' in request.session:
        errors = request.session['errors']
        del request.session['errors']

    uds = {
        'profile': profile,
        'config': config,
        'plugins': plugins,
        'actors': actors,
        'errors': errors,
        'data': request.session.get('data')
    }

    # Reset some 1 time values...
    request.session['launch'] = '';

    return 'var udsData = ' + json.dumps(uds) + ';\n'
Example #4
0
import os.path
import sys

from django.utils.translation import ugettext_noop as _
from uds.core import osmanagers
from uds.core import managers
from uds.core import VERSION

from .windows import WindowsOsManager
from .windows_domain import WinDomainOsManager
from .windows_random import WinRandomPassManager

osmanagers.factory().insert(WindowsOsManager)
osmanagers.factory().insert(WinDomainOsManager)
osmanagers.factory().insert(WinRandomPassManager)

managers.downloadsManager().registerDownloadable(
    'UDSActorSetup-{version}.exe'.format(version=VERSION),
    _('UDS Actor for windows machines'),
    os.path.dirname(sys.modules[__package__].__file__) +
    '/files/UDSActorSetup-{version}.exe'.format(version=VERSION),
    'application/x-msdos-program')

managers.downloadsManager().registerDownloadable(
    'UDSActorUnmanagedSetup-{version}.exe'.format(version=VERSION),
    _('UDS Actor for Unmanaged windows machines. Used ONLY for static machines.'
      ),
    os.path.dirname(sys.modules[__package__].__file__) +
    '/files/UDSActorUnmanagedSetup-{version}.exe'.format(version=VERSION),
    'application/x-msdos-program')
Example #5
0
from django.utils.translation import ugettext_noop as _
from uds.core.osmanagers.osmfactory import OSManagersFactory
from uds.core.managers import downloadsManager
from uds.core import VERSION

from .linux_osmanager import LinuxOsManager
from .linux_randompass_osmanager import LinuxRandomPassManager

OSManagersFactory.factory().insert(LinuxOsManager)
OSManagersFactory.factory().insert(LinuxRandomPassManager)

downloadsManager().registerDownloadable(
    'udsactor_{version}_all.deb'.format(version=VERSION),
    _('UDS Actor for Debian, Ubuntu, ... Linux machines <b>(Requires python >= 3.5)</b>'
      ),
    os.path.dirname(sys.modules[__package__].__file__) +
    '/files/udsactor_{version}_all.deb'.format(version=VERSION),
    'application/x-debian-package')

downloadsManager().registerDownloadable(
    'udsactor-{version}-1.noarch.rpm'.format(version=VERSION),
    _('UDS Actor for Centos, Fedora, RH, ... Linux machines <b>(Requires python 2.7)</b>'
      ),
    os.path.dirname(sys.modules[__package__].__file__) +
    '/files/udsactor-{version}-1.noarch.rpm'.format(version=VERSION),
    'application/x-redhat-package-manager')

downloadsManager().registerDownloadable(
    'udsactor-opensuse-{version}-1.noarch.rpm'.format(version=VERSION),
    _('UDS Actor for openSUSE, ... Linux machines <b>(Requires python 2.7)</b>'
Example #6
0
def udsJs(request: 'HttpRequest') -> str:
    auth_host = request.META.get('HTTP_HOST') or request.META.get(
        'SERVER_NAME'
    ) or 'auth_host'  # Last one is a placeholder in case we can't locate host name

    profile = {
        'user': None if not request.user else request.user.name,
        'role':
        'staff' if request.user and request.user.staff_member else 'user',
    }

    # Gets csrf token
    csrf_token = csrf.get_token(request)
    if csrf_token is not None:
        csrf_token = str(csrf_token)

    tag = request.session.get('tag', None)

    if GlobalConfig.DISALLOW_GLOBAL_LOGIN.getBool(False) is True:
        try:
            authenticators = [Authenticator.objects.get(small_name=auth_host)]
        except Exception:
            try:
                authenticators = [
                    Authenticator.objects.order_by('priority')[0].small_name
                ]
            except Exception:  # There is no authenticators yet...
                authenticators = []
    else:
        authenticators = Authenticator.objects.all().exclude(visible=False)

    if tag:
        authenticators = [x for x in authenticators if x.small_name == tag]

    # the auths for client
    def getAuthInfo(auth: Authenticator):
        theType = auth.getType()
        return {
            'id': auth.uuid,
            'name': auth.name,
            'label': auth.small_name,
            'priority': auth.priority,
            'is_custom': theType.isCustom()
        }

    config = {
        'version':
        VERSION,
        'version_stamp':
        VERSION_STAMP,
        'language':
        get_language(),
        'available_languages': [{
            'id': k,
            'name': gettext(v)
        } for k, v in settings.LANGUAGES],
        'authenticators':
        [getAuthInfo(auth) for auth in authenticators if auth.getType()],
        'os':
        request.os['OS'],
        'csrf_field':
        CSRF_FIELD,
        'csrf':
        csrf_token,
        'image_size':
        Image.MAX_IMAGE_SIZE,
        'experimental_features':
        GlobalConfig.EXPERIMENTAL_FEATURES.getBool(),
        'reload_time':
        GlobalConfig.RELOAD_TIME.getInt(True),
        'site_name':
        GlobalConfig.SITE_NAME.get(),
        'site_copyright_info':
        GlobalConfig.SITE_COPYRIGHT.get(),
        'site_copyright_link':
        GlobalConfig.SITE_COPYRIGHT_LINK.get(),
        'site_logo_name':
        GlobalConfig.SITE_LOGO_NAME.get(),
        'messages': {
            # Calendar denied message
            'calendarDenied':
            GlobalConfig.LIMITED_BY_CALENDAR_TEXT.get().strip()
            or gettext('Access limited by calendar')
        },
        'urls': {
            'changeLang':
            reverse('set_language'),
            'login':
            reverse('page.login'),
            'logout':
            reverse('page.logout'),
            'user':
            reverse('page.index'),
            'customAuth':
            reverse('uds.web.views.customAuth', kwargs={'idAuth': ''}),
            'services':
            reverse('webapi.services'),
            'enabler':
            reverse('webapi.enabler',
                    kwargs={
                        'idService': 'param1',
                        'idTransport': 'param2'
                    }),
            'action':
            reverse('webapi.action',
                    kwargs={
                        'idService': 'param1',
                        'actionString': 'param2'
                    }),
            'galleryImage':
            reverse('webapi.galleryImage', kwargs={'idImage': 'param1'}),
            'transportIcon':
            reverse('webapi.transportIcon', kwargs={'idTrans': 'param1'}),
            'static':
            static(''),
            # Launcher URL if exists
            'launch':
            request.session.get('launch', ''),
        }
    }

    info: typing.Optional[typing.MutableMapping] = None
    if request.user and request.user.isStaff():
        info = {
            'networks': [n.name for n in Network.networksFor(request.ip)],
            'transports': [
                t.name for t in Transport.objects.all()
                if t.validForIp(request.ip)
            ],
            'ip':
            request.ip,
            'ip_proxy':
            request.ip_proxy
        }

    # all plugins are under url clients...
    plugins = [{
        'url': static('clients/' + url.format(version=CLIENT_VERSION)),
        'description': description,
        'name': name
    } for url, description, name in (
        ('UDSClientSetup-{version}.exe', gettext('Windows client'), 'Windows'),
        ('UDSClient-{version}.pkg', gettext('Mac OS X client'), 'MacOS'),
        ('udsclient3_{version}_all.deb', gettext('Debian based Linux client') +
         ' ' + gettext('(requires Python-3.6 or newer)'),
         'Linux'), ('udsclient_{version}_all.deb',
                    gettext('Debian based Python 2.7 Linux client (legacy)') +
                    ' ' + gettext('(requires Python-2.7)'), 'Linux'),
        ('udsclient-{version}-1.noarch.rpm',
         gettext('Red Hat based Linux client (RH, Fedora, Centos, ...)') +
         ' ' + gettext('(requires Python-2.7)'),
         'Linux'), ('udsclient-opensuse-{version}-1.noarch.rpm',
                    gettext('Suse based Linux client') + ' ' +
                    gettext('(requires Python-2.7)'),
                    'Linux'), ('udsclient-{version}.tar.gz',
                               gettext('Generic .tar.gz Linux client') + ' ' +
                               gettext('(requires Python-2.7)'), 'Linux'))]

    actors: typing.List[typing.Dict[str, str]] = []

    if profile['role'] == 'staff':  # Add staff things
        # If is admin (informational, REST api checks users privileges anyway...)
        profile['admin'] = True
        # REST auth
        config['auth_token'] = request.session.session_key
        config['auth_header'] = AUTH_TOKEN_HEADER
        # Actors
        actors = [{
            'url':
            reverse('utility.downloader', kwargs={'idDownload': key}),
            'name':
            val['name'],
            'description':
            gettext(val['comment'])
        } for key, val in downloadsManager().getDownloadables().items()]
        # URLS
        config['urls']['admin'] = reverse('uds.admin.views.index')
        config['urls']['rest'] = reverse('REST', kwargs={'arguments': ''})

    errors: typing.List = []
    if 'errors' in request.session:
        errors = request.session['errors']
        del request.session['errors']
        request.session.modified = True  # Ensure saves it

    uds = {
        'profile': profile,
        'config': config,
        'info': info,
        'plugins': plugins,
        'actors': actors,
        'errors': errors,
        'data': request.session.get('data')
    }

    # Reset some 1 time values...
    request.session['launch'] = ''

    return 'var udsData = ' + json.dumps(uds) + ';\n'
Example #7
0
def udsJs(request: 'ExtendedHttpRequest') -> str:
    auth_host = request.META.get('HTTP_HOST') or request.META.get(
        'SERVER_NAME'
    ) or 'auth_host'  # Last one is a placeholder in case we can't locate host name

    role: str = 'user'
    user: typing.Optional['User'] = request.user

    if user:
        role = 'staff' if user.isStaff(
        ) and not user.is_admin else 'admin' if user.is_admin else 'user'
        if request.session.get('restricted', False):
            role = 'restricted'

    profile: typing.Dict[str, typing.Any] = {
        'user': user.name if user else None,
        'role': role,
    }

    # Gets csrf token
    csrf_token = csrf.get_token(request)
    if csrf_token is not None:
        csrf_token = str(csrf_token)

    tag = request.session.get('tag', None)
    logger.debug('Tag config: %s', tag)
    if GlobalConfig.DISALLOW_GLOBAL_LOGIN.getBool():
        try:
            # Get authenticators with auth_host or tag. If tag is None, auth_host, if exists
            # tag, later will remove "auth_host"
            authenticators = Authenticator.objects.filter(
                small_name__in=[auth_host, tag])[:]
        except Exception as e:
            authenticators = []
    else:
        authenticators = Authenticator.objects.all().exclude(visible=False)

    # logger.debug('Authenticators PRE: %s', authenticators)

    if tag and authenticators:  # Refilter authenticators, visible and with this tag if required
        authenticators = [
            x for x in authenticators if x.small_name == tag or (
                tag == 'disabled' and x.getType().isCustom() is False)
        ]

    if not authenticators:
        try:
            authenticators = [Authenticator.objects.order_by('priority')[0]]
        except Exception:  # There is no authenticators yet...
            authenticators = []

    if not tag and authenticators:
        tag = authenticators[0].small_name

    # logger.debug('Authenticators: %s', authenticators)

    # the auths for client
    def getAuthInfo(auth: Authenticator):
        theType = auth.getType()
        return {
            'id': auth.uuid,
            'name': auth.name,
            'label': auth.small_name,
            'priority': auth.priority,
            'is_custom': theType.isCustom()
        }

    config = {
        'version':
        VERSION,
        'version_stamp':
        VERSION_STAMP,
        'language':
        get_language(),
        'available_languages': [{
            'id': k,
            'name': gettext(v)
        } for k, v in settings.LANGUAGES],
        'authenticators':
        [getAuthInfo(auth) for auth in authenticators if auth.getType()],
        'tag':
        tag,
        'os':
        request.os['OS'],
        'csrf_field':
        CSRF_FIELD,
        'csrf':
        csrf_token,
        'image_size':
        Image.MAX_IMAGE_SIZE,
        'experimental_features':
        GlobalConfig.EXPERIMENTAL_FEATURES.getBool(),
        'reload_time':
        GlobalConfig.RELOAD_TIME.getInt(True),
        'site_name':
        GlobalConfig.SITE_NAME.get(),
        'site_copyright_info':
        GlobalConfig.SITE_COPYRIGHT.get(),
        'site_copyright_link':
        GlobalConfig.SITE_COPYRIGHT_LINK.get(),
        'site_logo_name':
        GlobalConfig.SITE_LOGO_NAME.get(),
        'site_information':
        GlobalConfig.SITE_INFO.get(),
        'site_filter_on_top':
        GlobalConfig.SITE_FILTER_ONTOP.getBool(True),
        'launcher_wait_time':
        5000,
        'messages': {
            # Calendar denied message
            'calendarDenied':
            GlobalConfig.LIMITED_BY_CALENDAR_TEXT.get().strip()
            or gettext('Access limited by calendar')
        },
        'urls': {
            'changeLang':
            reverse('set_language'),
            'login':
            reverse('page.login'),
            'logout':
            reverse('page.logout'),
            'user':
            reverse('page.index'),
            'customAuth':
            reverse('uds.web.views.customAuth', kwargs={'idAuth': ''}),
            'services':
            reverse('webapi.services'),
            'enabler':
            reverse('webapi.enabler',
                    kwargs={
                        'idService': 'param1',
                        'idTransport': 'param2'
                    }),
            'action':
            reverse('webapi.action',
                    kwargs={
                        'idService': 'param1',
                        'actionString': 'param2'
                    }),
            'galleryImage':
            reverse('webapi.galleryImage', kwargs={'idImage': 'param1'}),
            'transportIcon':
            reverse('webapi.transportIcon', kwargs={'idTrans': 'param1'}),
            'static':
            static(''),
            # Launcher URL if exists
            'launch':
            request.session.get('launch', ''),
        }
    }

    info: typing.Optional[typing.MutableMapping] = None
    if user and user.isStaff():
        info = {
            'networks': [n.name for n in Network.networksFor(request.ip)],
            'transports': [
                t.name for t in Transport.objects.all()
                if t.validForIp(request.ip)
            ],
            'ip':
            request.ip,
            'ip_proxy':
            request.ip_proxy
        }

    # all plugins are under url clients...
    plugins = [{
        'url': static('clients/' + url.format(version=CLIENT_VERSION)),
        'description': description,
        'name': name,
        'legacy': legacy,
    } for url, description, name, legacy in (
        ('UDSClientSetup-{version}.exe', gettext('Windows client'), 'Windows',
         False),
        ('UDSClient-{version}.pkg', gettext('Mac OS X client'), 'MacOS',
         False),
        ('udsclient3_{version}_all.deb', gettext('Debian based Linux client') +
         ' ' + gettext('(requires Python-3.6 or newer)'), 'Linux', False),
        ('udsclient3-{version}-1.noarch.rpm',
         gettext('RPM based Linux client (Fedora, Suse, ...)') + ' ' +
         gettext('(requires Python-3.6 or newer)'), 'Linux', False),
        ('udsclient3-{version}.tar.gz',
         gettext('Generic .tar.gz Linux client') + ' ' +
         gettext('(requires Python-3.6 or newer)'), 'Linux', False),
        ('udsclient_{version}_all.deb',
         gettext('Legacy Debian based Python 2.7 Linux client') + ' ' +
         gettext('(requires outdated Python-2.7)'), 'Linux', True),
        ('udsclient-{version}-1.noarch.rpm',
         gettext('Legacy RH based Linux client (Fedora, Centos, Suse, ...)') +
         ' ' + gettext('(requires outdated Python-2.7)'), 'Linux', True),
        ('udsclient-opensuse-{version}-1.noarch.rpm',
         gettext('Legacy OpenSuse based Linux client)') + ' ' +
         gettext('(requires outdated Python-2.7)'), 'Linux', True),
    )]

    # We can add here custom downloads with something like this:
    # plugins.append({
    #     'url': 'http://www.google.com/coche.exe',
    #     'description': 'Cliente SPICE for download',  # Text that appears on download
    #     'name': 'Linux', # Can be 'Linux', 'Windows', o 'MacOS'. Sets the icon.
    #     'legacy': False  # True = Gray, False = White
    #})

    actors: typing.List[typing.Dict[str, str]] = []

    if user and user.isStaff():  # Add staff things
        # If is admin (informational, REST api checks users privileges anyway...)
        profile['admin'] = True
        # REST auth
        config['auth_token'] = request.session.session_key
        config['auth_header'] = AUTH_TOKEN_HEADER
        # Actors
        actors = [{
            'url':
            reverse('utility.downloader', kwargs={'idDownload': key}),
            'name':
            val['name'],
            'description':
            gettext(val['comment'])
        } for key, val in downloadsManager().getDownloadables().items()]
        # URLS
        config['urls']['admin'] = reverse('uds.admin.views.index')
        config['urls']['rest'] = reverse('REST', kwargs={'arguments': ''})
        # Admin config
        page_size = GlobalConfig.ADMIN_PAGESIZE.getInt(True)
        # Fix page size to razonable usable values
        page_size = 10 if page_size < 10 else 100 if page_size > 100 else page_size
        config['admin'] = {
            'page_size': page_size,
        }

    errors: typing.List = []
    if 'errors' in request.session:
        errors = request.session['errors']
        del request.session['errors']
        request.session.modified = True  # Ensure saves it

    uds = {
        'profile': profile,
        'config': config,
        'info': info,
        'plugins': plugins,
        'actors': actors,
        'errors': errors,
        'data': request.session.get('data')
    }

    # Reset some 1 time values...
    request.session['launch'] = ''

    return 'var udsData = ' + json.dumps(uds) + ';\n'
Example #8
0
def udsJs(context):
    request = context['request']
    auth_host = request.META.get('HTTP_HOST') or request.META.get(
        'SERVER_NAME'
    ) or 'auth_host'  # Last one is a placeholder in case we can't locate host name

    profile = {
        'user': None if request.user is None else request.user.name,
        'role':
        'staff' if request.user and request.user.staff_member else 'user',
    }

    # Gets csrf token
    csrf_token = context.get('csrf_token')
    if csrf_token is not None:
        csrf_token = str(csrf_token)

    if GlobalConfig.DISALLOW_GLOBAL_LOGIN.getBool(False) is True:
        try:
            authenticators = [Authenticator.objects.get(small_name=auth_host)]
        except Exception:
            try:
                authenticators = [
                    Authenticator.objects.order_by('priority')[0].small_name
                ]
            except Exception:  # There is no authenticators yet...
                authenticators = []
    else:
        authenticators = Authenticator.objects.all()

    # the auths for client
    def getAuth(auth):
        theType = auth.getType()
        return {
            'id': auth.uuid,
            'name': auth.name,
            'label': auth.small_name,
            'priority': auth.priority,
            'is_custom': theType.isCustom()
        }

    config = {
        'language':
        get_language(),
        'available_languages': [{
            'id': k,
            'name': gettext(v)
        } for k, v in settings.LANGUAGES],
        'authenticators': [getAuth(auth) for auth in authenticators],
        'os':
        request.os['OS'],
        'csrf_field':
        CSRF_FIELD,
        'csrf':
        csrf_token,
        'urls': {
            'changeLang': reverse('set_language'),
            'login': reverse('uds.web.views.login'),
            'logout': reverse('uds.web.views.logout')
        }
    }

    plugins = [{
        'url': static(url.format(version=CLIENT_VERSION)),
        'description': description,
        'name': name
    } for url, description, name in (
        ('clients/UDSClientSetup-{version}.exe', gettext('Windows plugin'),
         'Windows'), ('clients/UDSClient-{version}.pkg',
                      gettext('Mac OS X plugin'), 'MacOS'),
        ('udsclient_{version}_all.deb', gettext('Debian based Linux') + ' ' +
         gettext('(requires Python-2.7)'),
         'Linux'), ('udsclient-{version}-1.noarch.rpm',
                    gettext('Red Hat based Linux (RH, Fedora, Centos, ...)') +
                    ' ' + gettext('(requires Python-2.7)'), 'Linux'),
        ('udsclient-opensuse-{version}-1.noarch.rpm',
         gettext('Suse based Linux') + ' ' + gettext('(requires Python-2.7)'),
         'Linux'), ('udsclient-{version}.tar.gz',
                    gettext('Generic .tar.gz Linux') + ' ' +
                    gettext('(requires Python-2.7)'), 'Linux'))]

    actors = []

    if profile['role'] == 'staff':  # Add staff things
        actors = [{
            'url':
            reverse('uds.web.views.download', kwargs={'idDownload': key}),
            'name':
            val['name'],
            'description':
            gettext(val['comment'])
        } for key, val in downloadsManager().getDownloadables().items()]
        config['urls']['admin'] = reverse('uds.admin.views.index')

    uds = {
        'profile': profile,
        'config': config,
        'plugins': plugins,
        'actors': actors
    }

    javascript = 'var udsData = ' + json.dumps(uds) + ';\n'

    return mark_safe(javascript)