Refactorized uds.core.ui and several fixes

This commit is contained in:
Adolfo Gómez García 2019-08-15 12:11:47 +02:00
parent c980d42b1e
commit 104eeac53c
47 changed files with 60 additions and 58 deletions

View File

@ -32,7 +32,7 @@
"""
import logging
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.REST import Handler, RequestError, NotFound

View File

@ -34,7 +34,7 @@ import logging
from django.utils.translation import ugettext_lazy as _, ugettext
from uds.models import Image
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.REST.model import ModelHandler

View File

@ -41,7 +41,7 @@ from uds.core.util import log
from uds.core.util import permissions
from uds.REST.model import ModelHandler
from uds.REST import RequestError, ResponseError
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.REST.methods.op_calendars import AccessCalendars
from .user_services import Groups

View File

@ -37,7 +37,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext
from uds.models import Network
from uds.core.util import net
from uds.core.util import permissions
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.REST.model import ModelHandler, SaveException

View File

@ -34,7 +34,7 @@ import logging
from django.utils.translation import ugettext_lazy as _, ugettext
from uds.models import Proxy
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util import permissions
from uds.REST.model import ModelHandler

View File

@ -43,7 +43,7 @@ from uds.core.util import permissions
from uds.core.util.model import processUuid
from uds.core.environment import Environment
from uds.core.ui.images import DEFAULT_THUMB_BASE64
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util.State import State
from uds.REST.model import DetailHandler

View File

@ -35,7 +35,7 @@ import logging
from django.utils.translation import ugettext_lazy as _, ugettext
from uds.models import ServicePoolGroup, Image
from uds.core.util.model import processUuid
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.ui.images import DEFAULT_THUMB_BASE64
from uds.REST.model import ModelHandler

View File

@ -52,7 +52,7 @@ from uds.core.util.State import State
from uds.core.util.model import processUuid
from uds.core.util import log
from uds.core.util import permissions
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.REST.model import ModelHandler
from uds.REST import RequestError, ResponseError

View File

@ -70,7 +70,7 @@ def getServicesPoolsCounters(servicePool, counter_type):
for x in counters.getCounters(us, counter_type, since=since, to=to, limit=POINTS, use_max=USE_MAX, all=complete):
val.append({'stamp': x[0], 'value': int(x[1])})
if len(val) > 2:
cache.put(cacheKey, encoders.encode(pickle.dumps(val), 'zip') , 600)
cache.put(cacheKey, encoders.encode(pickle.dumps(val), 'zip'), 600)
else:
val = [{'stamp': since, 'value': 0}, {'stamp': to, 'value': 0}]
else:
@ -94,7 +94,7 @@ class System(Handler):
service_pools = ServicePool.objects.count()
meta_pools = MetaPool.objects.count()
user_services = UserService.objects.exclude(state__in=(State.REMOVED, State.ERROR)).count()
restrained_services_pools = len(ServicePool.getRestraineds())
restrained_services_pools = ServicePool.getRestrainedsQuerySet().count()
return {
'users': users,
'groups': groups,

View File

@ -41,7 +41,7 @@ import logging
from django.utils.translation import ugettext as _
from django.db import IntegrityError, models
from uds.core.ui.UserInterface import gui as uiGui
from uds.core.ui import gui as uiGui
from uds.core.util import log
from uds.core.util import permissions
from uds.core.util.model import processUuid

View File

@ -38,7 +38,7 @@ from uds.core.auths import Authenticator
from uds.core.auths.GroupsManager import GroupsManager
from uds.core.util import net
from uds.core.util.request import getRequest
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
logger = logging.getLogger(__name__)

View File

@ -37,7 +37,7 @@ import logging
import ldap
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core import auths
from uds.core.auths.Exceptions import AuthenticatorException
from uds.core.util import ldaputil

View File

@ -31,7 +31,7 @@
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
"""
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core import auths
import logging

View File

@ -36,7 +36,7 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.auths import Authenticator
from uds.core.auths.Exceptions import AuthenticatorException
from uds.core.util import ldaputil

View File

@ -37,7 +37,7 @@ import typing
from django import forms
from django.utils.translation import ugettext as _, ugettext_lazy
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
if typing.TYPE_CHECKING:
from uds.models import User

View File

@ -38,7 +38,7 @@ import logging
from django.utils.translation import ugettext as _
from uds.core.ui.UserInterface import UserInterface
from uds.core.ui import UserInterface
from uds.core.util import encoders
from .serializable import Serializable
@ -89,7 +89,7 @@ class Module(UserInterface, Environmentable, Serializable):
Anyway, if you override this method, you must also override previous one
* UserInterface Methods:
* :py:meth:`uds.core.ui.UserInterface.UserInterface.valuesDict`
* :py:meth:`from from uds.core.ui.valuesDict`
This method, by default, provides the values contained in the form fields. If you don't override the marshal and
unmarshal, this method should be fine as is for you also.

View File

@ -66,7 +66,7 @@ class OSManager(Module):
# : Type of services for which this OS Manager is designed
# : Defaults to all. (list or tuple)
servicesType = serviceTypes.ALL
servicesType: typing.Tuple[str, ...] = serviceTypes.ALL
def __init__(self, environment: 'Environment', values: Module.ValuesType):
super().__init__(environment, values)

View File

@ -39,7 +39,7 @@ from weasyprint import HTML, CSS, default_url_fetcher
from django.utils.translation import ugettext, ugettext_noop as _
from django.template import loader
from uds.core.ui.UserInterface import UserInterface, gui
from uds.core.ui import UserInterface, gui
from uds.core.util import encoders
from . import stock

View File

@ -37,7 +37,7 @@ from uds.core import Module
from uds.core.environment import Environment
from uds.core.util.Config import GlobalConfig
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
logger = logging.getLogger(__name__)

View File

@ -5,4 +5,4 @@ This module contains the definition of UserInterface, needed to describe the int
between an UDS module and the administration interface
"""
from .UserInterface import gui
from .user_interface import gui, UserInterface

View File

@ -2,7 +2,7 @@
from __future__ import unicode_literals
from django.db import migrations
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util import encoders
from uds.transports.RDP.RDPTransport import RDPTransport
from uds.transports.RDP.TRDPTransport import TRDPTransport

View File

@ -36,7 +36,7 @@ import pickle
from datetime import datetime, timedelta
from django.db import models, transaction
from django.db.models import signals
from django.db.models import signals, QuerySet
from uds.core.environment import Environment
from uds.core.util import log
@ -154,7 +154,7 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
return [username, password]
@staticmethod
def getRestraineds() -> typing.Iterable['ServicePool']:
def getRestrainedsQuerySet() -> QuerySet:
from uds.models.user_service import UserService # pylint: disable=redefined-outer-name
from uds.core.util.Config import GlobalConfig
from django.db.models import Count
@ -171,7 +171,11 @@ class ServicePool(UUIDModel, TaggingMixin): # type: ignore
).values('deployed_service').annotate(how_many=Count('deployed_service')).order_by('deployed_service'):
if v['how_many'] >= min_:
res.append(v['deployed_service'])
return ServicePool.objects.filter(pk__in=res).iterator()
return ServicePool.objects.filter(pk__in=res)
@staticmethod
def getRestraineds() -> typing.Iterable['ServicePool']:
return ServicePool.getRestrainedsQuerySet().iterator()
@property
def is_meta(self) -> bool:

View File

@ -30,17 +30,16 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
from __future__ import unicode_literals
import os.path
import sys
from django.utils.translation import ugettext_noop as _
from uds.core.osmanagers.osmfactory import OSManagersFactory
from uds.core.managers.DownloadsManager import DownloadsManager
from uds.core import VERSION
from .LinuxOsManager import LinuxOsManager
from .LinuxRandomPassOsManager import LinuxRandomPassManager
import os.path
import sys
from .linux_osmanager import LinuxOsManager
from .linux_randompass_osmanager import LinuxRandomPassManager
OSManagersFactory.factory().insert(LinuxOsManager)
OSManagersFactory.factory().insert(LinuxRandomPassManager)

View File

@ -35,7 +35,7 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext_noop as _, ugettext_lazy
from django.conf import settings
from uds.core.services import types as serviceTypes
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core import osmanagers
from uds.core.util.State import State
from uds.core.util import log

View File

@ -30,16 +30,15 @@
"""
@author: Adolfo Gómez, dkmaster at dkmon dot com
"""
from __future__ import unicode_literals
import logging
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core import osmanagers
from uds.osmanagers.LinuxOsManager import LinuxOsManager
from uds.core.util import log
from uds.core.util import encoders
import logging
from .linux_osmanager import LinuxOsManager
logger = logging.getLogger(__name__)

View File

@ -14,7 +14,7 @@ import dns.resolver
import ldap
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.managers import cryptoManager
from uds.core import osmanagers
from uds.core.util import log

View File

@ -11,7 +11,7 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.managers import cryptoManager
from uds.core import osmanagers
from .WindowsOsManager import WindowsOsManager

View File

@ -10,7 +10,7 @@
"""
from django.utils.translation import ugettext_noop as _, ugettext_lazy
from uds.core.services import types as serviceTypes
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core import osmanagers
from uds.core.managers.UserServiceManager import UserServiceManager
from uds.core.util.State import State

View File

@ -33,7 +33,7 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext, ugettext_lazy as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.models import Authenticator
import six

View File

@ -34,7 +34,7 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext, ugettext_lazy as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util.stats import events
import io

View File

@ -39,7 +39,7 @@ from django.utils.translation import ugettext, ugettext_lazy as _
from django.db.models import Count
import django.template.defaultfilters as filters
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util.stats import events
from uds.core.reports import graphs

View File

@ -32,7 +32,7 @@
"""
from django.utils.translation import ugettext, ugettext_lazy as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util.stats import counters
import csv

View File

@ -34,7 +34,7 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext, ugettext_lazy as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util.stats import events
import six

View File

@ -38,7 +38,7 @@ import logging
from django.utils.translation import ugettext, ugettext_lazy as _
import django.template.defaultfilters as filters
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.util.stats import events
from uds.core.reports import graphs

View File

@ -34,7 +34,7 @@
from django.utils.translation import ugettext_lazy as _
from uds.core import services
from uds.core.services import types as serviceTypes
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from .IPMachineDeployed import IPMachineDeployed
import logging
import pickle

View File

@ -34,7 +34,7 @@
from django.utils.translation import ugettext_lazy as _
from uds.core import services
from uds.core.services import types as serviceTypes
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from .IPMachineDeployed import IPMachineDeployed
import logging

View File

@ -34,7 +34,7 @@
from django.utils.translation import ugettext_lazy as _
from uds.core import services
from uds.core.services import types as serviceTypes
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from .IPMachineDeployed import IPMachineDeployed
import logging
import pickle

View File

@ -37,7 +37,7 @@ from django.utils.translation import ugettext_noop as _
from django.urls import reverse
from django.http import HttpResponseRedirect
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports.BaseTransport import Transport
from uds.core.transports.BaseTransport import TUNNELED_GROUP

View File

@ -34,7 +34,7 @@ Created on Jul 29, 2011
"""
from django.utils.translation import ugettext_noop as _
from uds.core.managers.UserPrefsManager import CommonPrefs
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports import protocols
from uds.core.util import OsDetector
from .BaseNXTransport import BaseNXTransport

View File

@ -34,7 +34,7 @@ Created on Jul 29, 2011
"""
from django.utils.translation import ugettext_noop as _
from uds.core.managers.UserPrefsManager import CommonPrefs
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports.BaseTransport import Transport
from uds.core.transports.BaseTransport import TUNNELED_GROUP
from uds.core.transports import protocols
@ -204,7 +204,7 @@ class TSNXTransport(BaseNXTransport):
}.get(os['OS'])
if os is None:
return super(self.__class__, self).getUDSTransportScript(userService, transport, ip, os, user, password, request)
return super().getUDSTransportScript(userService, transport, ip, os, user, password, request)
sp = {
'ip': ip,

View File

@ -32,7 +32,7 @@
"""
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports.BaseTransport import Transport
from uds.core.transports import protocols
from typing import Tuple

View File

@ -33,7 +33,7 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext_noop as _
from uds.core.managers.UserPrefsManager import CommonPrefs
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports.BaseTransport import Transport
from uds.core.transports.BaseTransport import TUNNELED_GROUP
from uds.core.transports import protocols

View File

@ -33,7 +33,7 @@
from django.utils.translation import ugettext_noop as _
from uds.core.managers.UserPrefsManager import CommonPrefs
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports.BaseTransport import Transport
from uds.core.transports import protocols
from uds.core.util import connection

View File

@ -32,7 +32,7 @@
"""
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports.BaseTransport import Transport
from uds.core.transports.BaseTransport import TUNNELED_GROUP
from uds.core.transports import protocols

View File

@ -34,7 +34,7 @@
from django.utils.translation import ugettext_noop as _
from uds.core.managers.UserPrefsManager import CommonPrefs
from uds.core.managers import userServiceManager
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.transports.BaseTransport import Transport
from uds.core.transports import protocols
from uds.core.util import OsDetector

View File

@ -32,7 +32,7 @@
"""
from django.utils.translation import ugettext_noop as _
from uds.core.ui.UserInterface import gui
from uds.core.ui import gui
from uds.core.managers.UserPrefsManager import CommonPrefs
from uds.core.util import OsDetector
from uds.core.util import tools