mirror of
https://github.com/dkmstr/openuds.git
synced 2025-02-09 09:57:36 +03:00
* Added ticket keep on debug mode for servers
This commit is contained in:
parent
0df92bc3cd
commit
73eb15fd13
@ -31,10 +31,12 @@ Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from uds import models
|
||||
from uds.core import consts, osmanagers, types
|
||||
from uds.core.util import log
|
||||
from uds.core.util.model import getSqlDatetime, getSqlStamp
|
||||
from uds.core.util.model import getSqlDatetime
|
||||
from uds.REST.utils import rest_result
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -78,7 +80,8 @@ def process_login(server: 'models.Server', data: typing.Dict[str, typing.Any]) -
|
||||
"""
|
||||
ticket: typing.Any = None
|
||||
if 'ticket' in data:
|
||||
ticket = models.TicketStore.get(data['ticket'], invalidate=True)
|
||||
# Do not invalidate tickets on debug mode, the will last for 1000 hours (41 days and 16 hours)
|
||||
ticket = models.TicketStore.get(data['ticket'], invalidate=not getattr(settings, 'DEBUG', False))
|
||||
# If ticket is included, user_service can be inside ticket or in data
|
||||
data['userservice_uuid'] = data.get('userservice_uuid', ticket['userservice_uuid'])
|
||||
|
||||
|
@ -100,6 +100,14 @@ def service_exporter(service: models.Service) -> typing.Dict[str, typing.Any]:
|
||||
return s
|
||||
|
||||
|
||||
def mfa_exporter(mfa: models.MFA) -> typing.Dict[str, typing.Any]:
|
||||
"""
|
||||
Exports a mfa to a dict
|
||||
"""
|
||||
m = managed_object_exporter(mfa)
|
||||
return m
|
||||
|
||||
|
||||
def authenticator_exporter(
|
||||
authenticator: models.Authenticator,
|
||||
) -> typing.Dict[str, typing.Any]:
|
||||
@ -252,6 +260,7 @@ class Command(BaseCommand):
|
||||
'authenticators': self.export_authenticators,
|
||||
'users': self.export_users,
|
||||
'groups': self.export_groups,
|
||||
'mfa': self.export_mfa,
|
||||
'networks': self.export_networks,
|
||||
'transports': self.export_transports,
|
||||
'osmanagers': self.export_osmanagers,
|
||||
@ -272,7 +281,7 @@ class Command(BaseCommand):
|
||||
'--output',
|
||||
action='store',
|
||||
dest='output',
|
||||
default='/tmp/export.yaml', # nosec: This is a default value
|
||||
default='/tmp/export.yaml',
|
||||
help='Output file name. Defaults to /tmp/export.yaml',
|
||||
)
|
||||
|
||||
@ -329,7 +338,7 @@ class Command(BaseCommand):
|
||||
if self.verbose:
|
||||
self.stderr.write(f'Exported to {options["output"]}')
|
||||
|
||||
def apply_filter(self, model: typing.Type[ModelType]) -> typing.Iterable[ModelType]:
|
||||
def apply_filter(self, model: typing.Type[ModelType]) -> typing.Iterator[ModelType]:
|
||||
"""
|
||||
Applies a filter to a model
|
||||
"""
|
||||
@ -340,14 +349,13 @@ class Command(BaseCommand):
|
||||
self.stderr.write("\n ".join(values))
|
||||
# Generate "OR" filter with all kwargs
|
||||
if self.filter_args:
|
||||
return model.objects.filter(
|
||||
reduce(operator.or_, (Q(**{k: v}) for k, v in self.filter_args))
|
||||
return typing.cast(
|
||||
'typing.Iterator[ModelType]',
|
||||
model.objects.filter(reduce(operator.or_, (Q(**{k: v}) for k, v in self.filter_args))),
|
||||
)
|
||||
return model.objects.all()
|
||||
return typing.cast('typing.Iterator[ModelType]', model.objects.all().iterator())
|
||||
|
||||
def output_count(
|
||||
self, message: str, iterable: typing.Iterable[T]
|
||||
) -> typing.Iterable[T]:
|
||||
def output_count(self, message: str, iterable: typing.Iterable[T]) -> typing.Iterable[T]:
|
||||
"""
|
||||
Outputs the count of an iterable
|
||||
"""
|
||||
@ -394,6 +402,19 @@ class Command(BaseCommand):
|
||||
+ yaml.safe_dump(providers)
|
||||
+ '# Services\n'
|
||||
+ yaml.safe_dump(services)
|
||||
|
||||
def export_mfa(self) -> str:
|
||||
"""
|
||||
Exports all mfa to a list of dicts
|
||||
"""
|
||||
return '# MFA\n' + yaml.safe_dump(
|
||||
[
|
||||
mfa_exporter(m)
|
||||
for m in self.output_count(
|
||||
'Saving mfa',
|
||||
self.apply_filter(models.MFA),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
def export_authenticators(self) -> str:
|
||||
|
Loading…
x
Reference in New Issue
Block a user