From c075ae5a9cb1da6c1757f03432277d26a5e8b99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Sun, 22 Feb 2015 09:31:56 +0100 Subject: [PATCH] * Updated notification so, by default, is broker which "deduces" the client IP and not the client who notifies it (this is left just for "trusted" environments) --- server/src/uds/core/util/Config.py | 3 +++ server/src/uds/web/views/service.py | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/server/src/uds/core/util/Config.py b/server/src/uds/core/util/Config.py index d22ff8635..c181aee87 100644 --- a/server/src/uds/core/util/Config.py +++ b/server/src/uds/core/util/Config.py @@ -279,6 +279,9 @@ class GlobalConfig(object): # Allowed "trusted sources" for request TRUSTED_SOURCES = Config.section(SECURITY_SECTION).value('Trusted Hosts', '*', type=Config.TEXT_FIELD) + # Allow clients to notify their own ip (if set), or use always the request extracted IP + HONOR_CLIENT_IP_NOTIFY = Config.section(SECURITY_SECTION).value('honorClientNotifyIP', '0', type=Config.BOOLEAN_FIELD) + # Clusters related vars # Maximum desired CPU Load. If cpu is over this value, a migration of a service is "desirable" diff --git a/server/src/uds/web/views/service.py b/server/src/uds/web/views/service.py index 1a26b0a40..d3e868ba4 100644 --- a/server/src/uds/web/views/service.py +++ b/server/src/uds/web/views/service.py @@ -37,13 +37,14 @@ from django.views.decorators.cache import cache_page from uds.core.auths.auth import webLoginRequired, webPassword from uds.core.services.Exceptions import ServiceInMaintenanceMode -from uds.models import DeployedService, Transport, UserService, Image -from uds.core.ui.images import DEFAULT_IMAGE from uds.core.managers.UserServiceManager import UserServiceManager +from uds.core.ui.images import DEFAULT_IMAGE +from uds.core.ui import theme +from uds.core.util.Config import GlobalConfig +from uds.core.util.stats import events from uds.core.util import log from uds.core.util import OsDetector -from uds.core.util.stats import events -from uds.core.ui import theme +from uds.models import DeployedService, Transport, UserService, Image import uds.web.errors as errors @@ -51,7 +52,7 @@ import logging logger = logging.getLogger(__name__) -__updated__ = '2015-02-18' +__updated__ = '2015-02-22' @webLoginRequired @@ -121,8 +122,12 @@ def transcomp(request, idTransport, componentId): def sernotify(request, idUserService, notification): try: if notification == 'hostname': - hostname = request.GET.get('hostname', None) - ip = request.GET.get('ip', None) + hostname = request.GET.get('hostname', None)[:64] # Cuts host name to 64 chars + ip = request.ip + + if GlobalConfig.HONOR_CLIENT_IP_NOTIFY.getBool(True) is True: + ip = request.GET.get('ip', ip) + if ip is not None and hostname is not None: us = UserService.objects.get(uuid=idUserService) us.setConnectionSource(ip, hostname)