Commit c677aa39 authored by Jérome Perrin's avatar Jérome Perrin

make sure we have been provided a good ip:port node reference before adding it

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6338 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 961793b1
...@@ -46,6 +46,7 @@ import sys ...@@ -46,6 +46,7 @@ import sys
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from types import TupleType, StringType from types import TupleType, StringType
import re
from zLOG import LOG, INFO, WARNING from zLOG import LOG, INFO, WARNING
...@@ -55,6 +56,9 @@ except ImportError: ...@@ -55,6 +56,9 @@ except ImportError:
def getTimerService(self): def getTimerService(self):
pass pass
# minimal IP:Port regexp
NODE_RE = re.compile('\d+\.\d+\.\d+\.\d:\d+')
# Using a RAM property (not a property of an instance) allows # Using a RAM property (not a property of an instance) allows
# to prevent from storing a state in the ZODB (and allows to restart...) # to prevent from storing a state in the ZODB (and allows to restart...)
active_threads = 0 active_threads = 0
...@@ -372,24 +376,44 @@ class ActivityTool (Folder, UniqueObject): ...@@ -372,24 +376,44 @@ class ActivityTool (Folder, UniqueObject):
""" Return the distributingNode """ """ Return the distributingNode """
return self.distributingNode return self.distributingNode
security.declarePublic('getNodeList') security.declarePublic('getNodeList getNodes')
def getNodes(self): def getNodes(self):
""" Return all nodes """ """ Return all nodes """
return self._nodes return self._nodes
getNodeList = getNodes
def _isValidNodeName(self, node_name) :
"""Check we have been provided a good node name"""
return isinstance(node_name, str) and NODE_RE.match(node_name)
security.declarePublic('manage_setDistributingNode') security.declarePublic('manage_setDistributingNode')
def manage_setDistributingNode(self, distributingNode, REQUEST=None): def manage_setDistributingNode(self, distributingNode, REQUEST=None):
""" set the distributing node """ """ set the distributing node """
if self._isValidNodeName(distributingNode):
self.distributingNode = distributingNode self.distributingNode = distributingNode
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect( REQUEST.RESPONSE.redirect(
REQUEST.URL1 + REQUEST.URL1 +
'/manageLoadBalancing?manage_tabs_message=' + '/manageLoadBalancing?manage_tabs_message=' +
urllib.quote("Distributing Node successfully changed.")) urllib.quote("Distributing Node successfully changed."))
else :
if REQUEST is not None:
REQUEST.RESPONSE.redirect(
REQUEST.URL1 +
'/manageLoadBalancing?manage_tabs_message=' +
urllib.quote("Malformed Distributing Node."))
security.declarePublic('manage_addNode') security.declarePublic('manage_addNode')
def manage_addNode(self, node, REQUEST=None): def manage_addNode(self, node, REQUEST=None):
""" add a node """ """ add a node """
if not self._isValidNodeName(node) :
if REQUEST is not None:
REQUEST.RESPONSE.redirect(
REQUEST.URL1 +
'/manageLoadBalancing?manage_tabs_message=' +
urllib.quote("Malformed node."))
return
if node in self._nodes: if node in self._nodes:
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect( REQUEST.RESPONSE.redirect(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment