1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Working on next-gen user id

This commit is contained in:
Adolfo Gómez García 2018-05-18 09:44:29 +02:00
parent df17aa8687
commit 2ed4bf07cd
18 changed files with 3008 additions and 73 deletions

View File

@ -54,7 +54,7 @@ from uds.models import User
import logging
import six
__updated__ = '2018-02-26'
__updated__ = '2018-05-18'
logger = logging.getLogger(__name__)
authLogger = logging.getLogger('authLog')
@ -64,43 +64,6 @@ PASS_KEY = 'pk'
ROOT_ID = -20091204 # Any negative number will do the trick
def getUDSCookie(request, response=None, force=False):
"""
Generates a random cookie for uds, used, for example, to encript things
"""
if 'uds' not in request.COOKIES:
import random
import string
cookie = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32)) # @UndefinedVariable
if response is not None:
response.set_cookie('uds', cookie)
request.COOKIES['uds'] = cookie
else:
cookie = request.COOKIES['uds']
if response is not None and force is True:
response.set_cookie('uds', cookie)
return cookie
def getRootUser():
# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
from uds.models import Authenticator
u = User(id=ROOT_ID, name=GlobalConfig.SUPER_USER_LOGIN.get(True), real_name=_('System Administrator'), state=State.ACTIVE, staff_member=True, is_admin=True)
u.manager = Authenticator()
u.getGroups = lambda: []
u.updateLastAccess = lambda: None
u.logout = lambda: None
return u
@deprecated
def getIp(request):
logger.info('Deprecated IP')
return request.ip
# Decorator to make easier protect pages that needs to be logged in
def webLoginRequired(admin=False):
"""
@ -153,6 +116,43 @@ def trustedSourceRequired(view_func):
return _wrapped_view
def getUDSCookie(request, response=None, force=False):
"""
Generates a random cookie for uds, used, for example, to encript things
"""
if 'uds' not in request.COOKIES:
import random
import string
cookie = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32)) # @UndefinedVariable
if response is not None:
response.set_cookie('uds', cookie)
request.COOKIES['uds'] = cookie
else:
cookie = request.COOKIES['uds']
if response is not None and force is True:
response.set_cookie('uds', cookie)
return cookie
def getRootUser():
# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
from uds.models import Authenticator
u = User(id=ROOT_ID, name=GlobalConfig.SUPER_USER_LOGIN.get(True), real_name=_('System Administrator'), state=State.ACTIVE, staff_member=True, is_admin=True)
u.manager = Authenticator()
u.getGroups = lambda: []
u.updateLastAccess = lambda: None
u.logout = lambda: None
return u
@deprecated
def getIp(request):
logger.info('Deprecated IP')
return request.ip
def __registerUser(authenticator, authInstance, username):
"""
Check if this user already exists on database with this authenticator, if don't, create it with defaults

View File

@ -0,0 +1,188 @@
cache-loader@1.2.2
MIT
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@angular-devkit/build-optimizer@0.3.2
MIT
The MIT License
Copyright (c) 2017 Google, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
webpack@3.11.0
MIT
Copyright JS Foundation and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@angular/core@5.2.10
MIT
MIT
@angular/platform-browser@5.2.10
MIT
MIT
@angular/common@5.2.10
MIT
MIT
@ng-bootstrap/ng-bootstrap@2.0.0
MIT
The MIT License (MIT)
Copyright (c) 2015-2018 Angular ng-bootstrap team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@angular/router@5.2.10
MIT
MIT
@angular/forms@5.2.10
MIT
MIT
@angular/platform-browser-dynamic@5.2.10
MIT
MIT
core-js@2.5.5
MIT
Copyright (c) 2014-2018 Denis Pushkarev
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
zone.js@0.8.26
MIT
The MIT License
Copyright (c) 2016-2018 Google, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
bootstrap@4.1.1
MIT
The MIT License (MIT)
Copyright (c) 2011-2018 Twitter, Inc.
Copyright (c) 2011-2018 The Bootstrap Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Binary file not shown.

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 434 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1 @@
!function(r){var n=window.webpackJsonp;window.webpackJsonp=function(t,c,u){for(var f,i,p,a=0,l=[];a<t.length;a++)e[i=t[a]]&&l.push(e[i][0]),e[i]=0;for(f in c)Object.prototype.hasOwnProperty.call(c,f)&&(r[f]=c[f]);for(n&&n(t,c,u);l.length;)l.shift()();if(u)for(a=0;a<u.length;a++)p=o(o.s=u[a]);return p};var t={},e={3:0};function o(n){if(t[n])return t[n].exports;var e=t[n]={i:n,l:!1,exports:{}};return r[n].call(e.exports,e,e.exports,o),e.l=!0,e.exports}o.m=r,o.c=t,o.d=function(r,n,t){o.o(r,n)||Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:t})},o.n=function(r){var n=r&&r.__esModule?function(){return r.default}:function(){return r};return o.d(n,"a",n),n},o.o=function(r,n){return Object.prototype.hasOwnProperty.call(r,n)},o.p="/static/modern/",o.oe=function(r){throw console.error(r),r}}([]);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,5 @@
// "Fake" javascript file for translations
gettext("About");
gettext("UDS Plugin");
gettext("Download uds plugin for your platform");
gettext("Download");

View File

@ -4,7 +4,6 @@
{% block title %}{% trans 'Welcome to UDS' %}{% endblock %}
{% block js %}
{% javascript_auths authenticators %}
<script type="text/javascript">
function chkNonStandardAuth(val, nonStandard) {

View File

@ -0,0 +1,2 @@
{% load i18n uds %}
{% udsJs %}

View File

@ -0,0 +1 @@
{% load uds i18n %}{% get_current_language as LANGUAGE_CODE %}<!doctype html><html lang="{{ LANGUAGE_CODE }}"><head><meta charset="utf-8"><title>Uds</title><base href="/modern"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><script type="text/javascript" src="{% url 'uds.web.views.jsCatalog' LANGUAGE_CODE %}"></script><script type="text/javascript" src="{% url 'uds.js' %}"></script><link href="/static/modern/styles.bundle.css" rel="stylesheet"/></head><body><uds-root></uds-root><script type="text/javascript" src="/static/modern/inline.bundle.js"></script><script type="text/javascript" src="/static/modern/polyfills.bundle.js"></script><script type="text/javascript" src="/static/modern/main.bundle.js"></script></body></html>

View File

@ -38,54 +38,73 @@ from django import template
from django.conf import settings
from django.utils.translation import gettext, get_language
from django.utils.html import mark_safe
from django.urls import reverse
from django.templatetags.static import static
from uds.REST.methods.client import CLIENT_VERSION
from uds.core.managers import downloadsManager
logger = logging.getLogger(__name__)
register = template.Library()
@register.simple_tag
def javascript_auths(authenticators):
res = []
for a in authenticators:
theType = a.getType()
res.append({
'authId': a.uuid,
'authSmallName': str(a.small_name),
'auth': a.name,
'type': theType.typeType,
'priority': a.priority,
'isCustom': theType.isCustom()
})
return mark_safe('<script type="text/javascript">\nvar authenticators = ' + json.dumps(res, indent=4) + ';\n</script>')
CSRF_FIELD = 'csrfmiddlewaretoken'
@register.simple_tag
def udsJs(request):
udsConfig = {
@register.simple_tag(takes_context=True)
def udsJs(context):
request = context['request']
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)
config = {
'language': get_language(),
'available_languages': [{'id': k, 'name': gettext(v)} for k, v in settings.LANGUAGES],
'os': request.os['OS'],
'csrf_field': CSRF_FIELD,
'csrf': csrf_token,
'urls': {
'lang': reverse('set_language'),
'logout': reverse('uds.web.views.logout')
}
}
packages = (
('clients/UDSClientSetup-{version}.exe'.format(version=CLIENT_VERSION), gettext('Debian based Linux') + ' ' + gettext('(requires Python-2.7)'), 'Linux'),
('udsclient_{version}_all.deb'.format(version=CLIENT_VERSION), gettext('Debian based Linux') + ' ' + gettext('(requires Python-2.7)'), 'Linux'),
('udsclient-{version}-1.noarch.rpm'.format(version=CLIENT_VERSION), gettext('Red Hat based Linux (RH, Fedora, Centos, ...)') + ' ' + gettext('(requires Python-2.7)'), 'Linux'),
('udsclient-opensuse-{version}-1.noarch.rpm'.format(version=CLIENT_VERSION), gettext('Suse based Linux') + ' ' + gettext('(requires Python-2.7)'), 'Linux'),
('udsclient-{version}.tar.gz'.format(version=CLIENT_VERSION), gettext('Generic .tar.gz Linux') + ' ' + gettext('(requires Python-2.7)'), 'Linux')
)
udsPlugins = [
plugins = [
{
'url': static(url),
'url': static(url.format(version=CLIENT_VERSION)),
'description': description,
'os': os
} for url, description, os in packages
'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')
)
]
javascript = 'var udsConfig = ' + json.dumps(udsConfig) + ';\n';
javascript += 'var plugins = ';
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);

View File

@ -31,7 +31,6 @@
from __future__ import unicode_literals
from django.shortcuts import render
from django.template import RequestContext
from django.utils.translation import ugettext as _
from uds.core.auths.auth import webLoginRequired
@ -42,7 +41,7 @@ import logging
logger = logging.getLogger(__name__)
__updated__ = '2016-08-26'
__updated__ = '2018-05-18'
@webLoginRequired(admin=True)

View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2018 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
from django.shortcuts import render
def index(request):
return render(request, 'uds/modern/index.html', {})
def js(request):
return render(request, 'uds/js.js', content_type='text/javascript')