forked from shaba/openuds
Added actor tokens
This commit is contained in:
parent
f47b208c33
commit
cef382a1df
94
server/src/uds/REST/methods/actor_token.py
Normal file
94
server/src/uds/REST/methods/actor_token.py
Normal file
@ -0,0 +1,94 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2020 Virtual Cable S.L.U.
|
||||
# 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
|
||||
"""
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from uds.models import ActorToken
|
||||
from uds.REST.handlers import RequestError, NotFound
|
||||
from uds.REST.model import ModelHandler, OK
|
||||
from uds.core.util import permissions
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Enclosed methods under /osm path
|
||||
|
||||
|
||||
class ActorTokens(ModelHandler):
|
||||
model = ActorToken
|
||||
|
||||
table_title = _('Actor tokens')
|
||||
table_fields = [
|
||||
# {'token': {'title': _('Token')}},
|
||||
{'stamp': {'title': _('Date'), 'type': 'datetime'}},
|
||||
{'username': {'title': _('Issued by')}},
|
||||
{'host': {'title': _('Origin')}},
|
||||
{'hostname': {'title': _('Hostname')}},
|
||||
{'pre_command': {'title': _('Pre-connect')}},
|
||||
{'post_command': {'title': _('Post-Configure')}},
|
||||
{'runonce_command': {'title': _('Run Once')}},
|
||||
{'log_level': {'title': _('Log level')}},
|
||||
]
|
||||
|
||||
def item_as_dict(self, item: ActorToken) -> typing.Dict[str, typing.Any]:
|
||||
return {
|
||||
'id': item.token,
|
||||
'name': _('Token isued by {} from {}').format(item.username, item.hostname or item.ip),
|
||||
'stamp': item.stamp,
|
||||
'username': item.username,
|
||||
'ip': item.ip,
|
||||
'host': '{} - {}'.format(item.ip, item.mac),
|
||||
'hostname': item.hostname,
|
||||
'pre_command': item.pre_command,
|
||||
'post_command': item.post_command,
|
||||
'runonce_command': item.runonce_command,
|
||||
'log_level': ['DEBUG', 'INFO', 'ERROR', 'FATAL'][item.log_level%4]
|
||||
}
|
||||
|
||||
# Rewrite, this is an special case where no "uuid" is no table
|
||||
def delete(self) -> str:
|
||||
"""
|
||||
Processes a DELETE request
|
||||
"""
|
||||
if len(self._args) != 1:
|
||||
raise RequestError('Delete need one and only one argument')
|
||||
|
||||
self.ensureAccess(self.model(), permissions.PERMISSION_ALL, root=True) # Must have write permissions to delete
|
||||
|
||||
try:
|
||||
self.model.objects.get(token=self._args[0]).delete()
|
||||
except self.model.DoesNotExist:
|
||||
raise NotFound('Element do not exists')
|
||||
|
||||
return OK
|
@ -156,7 +156,7 @@ class Register(ActorV3Action):
|
||||
actorToken.save()
|
||||
except Exception:
|
||||
actorToken = ActorToken.objects.create(
|
||||
username=self._params['username'],
|
||||
username=self._user.pretty_name,
|
||||
ip_from=self._request.ip,
|
||||
ip=self._params['ip'],
|
||||
hostname=self._params['hostname'],
|
||||
|
@ -57,7 +57,7 @@ class User(UUIDModel):
|
||||
"""
|
||||
This class represents a single user, associated with one authenticator
|
||||
"""
|
||||
# pylint: disable=model-missing-unicode, maybe-no-member
|
||||
# pylint: disable=maybe-no-member
|
||||
manager = UnsavedForeignKey(Authenticator, on_delete=models.CASCADE, related_name='users')
|
||||
name = models.CharField(max_length=128, db_index=True)
|
||||
real_name = models.CharField(max_length=128)
|
||||
|
File diff suppressed because one or more lines are too long
@ -88,11 +88,12 @@ gettext("Error");
|
||||
gettext("Please, provide a name and a image");
|
||||
gettext("Successfully saved");
|
||||
gettext("dismiss");
|
||||
gettext("Delete actor token - USE WITH EXTREME CAUTION!!!");
|
||||
gettext("Configuration saved");
|
||||
gettext("dismiss");
|
||||
gettext("New Authenticator");
|
||||
gettext("Edit Authenticator");
|
||||
gettext("Delete authencitator");
|
||||
gettext("New OS Manager");
|
||||
gettext("Edit OS Manager");
|
||||
gettext("Delete OS Manager");
|
||||
gettext("#USR_NUMBER# users, #GRP_NUMBER# groups");
|
||||
gettext("#POOLS_NUMBER# service pools");
|
||||
gettext("#SERVICES_NUMBER# user services");
|
||||
@ -316,6 +317,7 @@ gettext("Tools");
|
||||
gettext("Gallery");
|
||||
gettext("Reports");
|
||||
gettext("Configuration");
|
||||
gettext("Actor tokens");
|
||||
gettext("Flush Cache");
|
||||
gettext("Image name");
|
||||
gettext("Image (click to change)");
|
||||
|
@ -92,6 +92,6 @@
|
||||
</svg>
|
||||
</div>
|
||||
</uds-root>
|
||||
<script src="/uds/res/admin/runtime.js?stamp=1580127342" defer></script><script src="/uds/res/admin/polyfills-es5.js?stamp=1580127342" nomodule defer></script><script src="/uds/res/admin/polyfills.js?stamp=1580127342" defer></script><script src="/uds/res/admin/main.js?stamp=1580127342" defer></script></body>
|
||||
<script src="/uds/res/admin/runtime.js?stamp=1580734508" defer></script><script src="/uds/res/admin/polyfills-es5.js?stamp=1580734508" nomodule defer></script><script src="/uds/res/admin/polyfills.js?stamp=1580734508" defer></script><script src="/uds/res/admin/main.js?stamp=1580734508" defer></script></body>
|
||||
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user