mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-13 13:17:54 +03:00
Added support for name resolutions on service_multi && fixed max page limit from 50 to 100
This commit is contained in:
parent
0a0b4cb740
commit
3f881b3e17
@ -34,7 +34,10 @@ import requests
|
|||||||
import logging
|
import logging
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
from uds.core import services
|
from uds.core import services
|
||||||
|
from uds.core.util import net
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -45,7 +48,18 @@ class IPServiceBase(services.Service):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getIp(ipData: str) -> str:
|
def getIp(ipData: str) -> str:
|
||||||
return ipData.split('~')[0].split(';')[0]
|
ip = ipData.split('~')[0].split(';')[0]
|
||||||
|
# If ip is in fact a hostname...
|
||||||
|
if not net.ipToLong(ip):
|
||||||
|
# Try to resolve name...
|
||||||
|
try:
|
||||||
|
res = dns.resolver.resolve(ip)
|
||||||
|
ip = res[0].address
|
||||||
|
except Exception:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
return ip
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getMac(ipData: str) -> typing.Optional[str]:
|
def getMac(ipData: str) -> typing.Optional[str]:
|
||||||
|
@ -197,6 +197,18 @@ class IPMachinesService(IPServiceBase):
|
|||||||
consideredFreeTime = now - config.GlobalConfig.SESSION_EXPIRE_TIME.getInt(force=False) * 3600
|
consideredFreeTime = now - config.GlobalConfig.SESSION_EXPIRE_TIME.getInt(force=False) * 3600
|
||||||
for ip in self._ips:
|
for ip in self._ips:
|
||||||
theIP = IPServiceBase.getIp(ip)
|
theIP = IPServiceBase.getIp(ip)
|
||||||
|
if not theIP:
|
||||||
|
self.parent().doLog(
|
||||||
|
log.WARN,
|
||||||
|
'Hostname in {} could not be resolved. Skipped.'.format(
|
||||||
|
ip
|
||||||
|
),
|
||||||
|
)
|
||||||
|
logger.warning(
|
||||||
|
'Hostname in %s could not be resolved. Skipped.', ip
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
theMAC = IPServiceBase.getMac(ip)
|
theMAC = IPServiceBase.getMac(ip)
|
||||||
locked = self.storage.getPickle(theIP)
|
locked = self.storage.getPickle(theIP)
|
||||||
if not locked or locked < consideredFreeTime:
|
if not locked or locked < consideredFreeTime:
|
||||||
@ -265,6 +277,9 @@ class IPMachinesService(IPServiceBase):
|
|||||||
IPMachineDeployed, userDeployment
|
IPMachineDeployed, userDeployment
|
||||||
)
|
)
|
||||||
theIP = IPServiceBase.getIp(assignableId)
|
theIP = IPServiceBase.getIp(assignableId)
|
||||||
|
if not theIP:
|
||||||
|
return userServiceInstance.error('Hostname could not be resolved')
|
||||||
|
|
||||||
if self.storage.readData(theIP) is None:
|
if self.storage.readData(theIP) is None:
|
||||||
self.storage.saveData(theIP, theIP)
|
self.storage.saveData(theIP, theIP)
|
||||||
return userServiceInstance.assign(theIP)
|
return userServiceInstance.assign(theIP)
|
||||||
|
@ -50,6 +50,7 @@ from uds.models import Authenticator, Image, Network, Transport
|
|||||||
# Not imported at runtime, just for type checking
|
# Not imported at runtime, just for type checking
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
from django.http import HttpRequest # pylint: disable=ungrouped-imports
|
||||||
|
from uds.core.util.request import ExtendedHttpRequest
|
||||||
from uds.models import User
|
from uds.models import User
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -60,7 +61,7 @@ CSRF_FIELD = 'csrfmiddlewaretoken'
|
|||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def udsJs(request: 'HttpRequest') -> str:
|
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
|
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'
|
role: str = 'user'
|
||||||
@ -214,7 +215,7 @@ def udsJs(request: 'HttpRequest') -> str:
|
|||||||
# Admin config
|
# Admin config
|
||||||
page_size = GlobalConfig.ADMIN_PAGESIZE.getInt(True)
|
page_size = GlobalConfig.ADMIN_PAGESIZE.getInt(True)
|
||||||
# Fix page size to razonable usable values
|
# Fix page size to razonable usable values
|
||||||
page_size = 10 if page_size < 10 else 50 if page_size > 50 else page_size
|
page_size = 10 if page_size < 10 else 100 if page_size > 100 else page_size
|
||||||
config['admin'] = {
|
config['admin'] = {
|
||||||
'page_size': page_size,
|
'page_size': page_size,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user