core: added the security_limit to setParam

- params with a security greater than security_limit can not be modified
- special value: security_limit < 0 disable the check (all params can be modified)
This commit is contained in:
souliane 2013-09-07 02:03:17 +02:00
commit 2bf3694fd0
13 changed files with 56 additions and 37 deletions

View file

@ -199,8 +199,8 @@ class DBusBridgeFrontend(BridgeFrontend):
def sendMessage(self, to_jid, message, subject='', mess_type="auto", options={}, profile_key="@NONE@"):
return self.db_core_iface.sendMessage(to_jid, message, subject, mess_type, options, profile_key)
def setParam(self, name, value, category, profile_key="@DEFAULT@"):
return self.db_core_iface.setParam(name, value, category, profile_key)
def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
return self.db_core_iface.setParam(name, value, category, security_limit, profile_key)
def setPresence(self, to_jid='', show='', priority=0, statuses={}, profile_key="@DEFAULT@"):
return self.db_core_iface.setPresence(to_jid, show, priority, statuses, profile_key)

View file

@ -525,8 +525,7 @@ class PrimitivusApp(QuickApp):
self.addWindow(XMLUI(self,xml_data=params))
def failure(error):
self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters"), ok_cb=self.removePopUp))
security_limit = -1
self.bridge.getParamsUI(security_limit, self.profile, callback=success, errback=failure)
self.bridge.getParamsUI(profile_key=self.profile, callback=success, errback=failure)
def onExitRequest(self, menu):

View file

@ -141,10 +141,10 @@ class ProfileManager(urwid.WidgetWrap):
new_pass = self.pass_wid.get_edit_text()
if old_jid != new_jid:
self.host.bridge.setParam("JabberID", new_jid, "Connection", profile)
self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile)
self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile)
self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile_key=profile)
if old_pass != new_pass:
self.host.bridge.setParam("Password", new_pass, "Connection", profile)
self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile)
self.host.plug_profile(profile)
def getParamError(self, ignore):

View file

@ -34,6 +34,7 @@ def getText(node):
data.append(child.wholeText)
return u"".join(data)
class Pairs(urwid.WidgetWrap):
def __init__(self, weight_0='1', weight_1='1'):
@ -274,5 +275,6 @@ class XMLUI(urwid.WidgetWrap):
value = "true" if ctrl.get_state() else "false"
else:
value = ctrl.get_edit_text()
self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category, profile_key = self.host.profile)
self.host.bridge.setParam(ctrl._param_name, value, ctrl._param_category,
profile_key=self.host.profile)
self.host.removeWindow()

View file

@ -363,8 +363,7 @@ class MainWindow(wx.Frame, QuickApp):
def onParam(self, e):
debug(_("Param request"))
#security_limit = -1
#xmlui = self.bridge.getParamsUI(security_limit, profile_key=self.profile)
#xmlui = self.bridge.getParamsUI(profile_key=self.profile)
#XMLUI(self, xml_data = xmlui)
param=Param(self)

View file

@ -103,7 +103,6 @@ class Param(wx.Frame):
cat_dom.unlink()
self.host.bridge.getParamsForCategory(category,
security_limit=-1,
profile_key=self.host.profile,
callback=gotParams,
errback=errorGettingParams)
@ -137,7 +136,8 @@ class Param(wx.Frame):
def __save_parameters(self):
for param in self.modified:
self.host.bridge.setParam(param[0], self.modified[param], param[1], profile_key = self.host.profile)
self.host.bridge.setParam(param[0], self.modified[param], param[1],
profile_key=self.host.profile)
self.modified.clear()
def onClose(self, event):

View file

@ -145,11 +145,11 @@ class ProfileManager(wx.Panel):
new_pass = self.login_pass.GetValue()
if old_jid != new_jid:
debug(_('Saving new JID and server'))
self.host.bridge.setParam("JabberID", new_jid, "Connection", profile)
self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile)
self.host.bridge.setParam("JabberID", new_jid, "Connection", profile_key=profile)
self.host.bridge.setParam("Server", JID(new_jid).domain, "Connection", profile_key=profile)
if old_pass != new_pass:
debug(_('Saving new password'))
self.host.bridge.setParam("Password", new_pass, "Connection", profile)
self.host.bridge.setParam("Password", new_pass, "Connection", profile_key=profile)
self.host.plug_profile(profile)

View file

@ -391,10 +391,10 @@ class DbusObject(dbus.service.Object):
return self._callback("sendMessage", unicode(to_jid), unicode(message), unicode(subject), unicode(mess_type), options, unicode(profile_key))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ssss', out_signature='',
in_signature='sssis', out_signature='',
async_callbacks=None)
def setParam(self, name, value, category, profile_key="@DEFAULT@"):
return self._callback("setParam", unicode(name), unicode(value), unicode(category), unicode(profile_key))
def setParam(self, name, value, category, security_limit=-1, profile_key="@DEFAULT@"):
return self._callback("setParam", unicode(name), unicode(value), unicode(category), security_limit, unicode(profile_key))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ssia{ss}s', out_signature='',

View file

@ -398,14 +398,16 @@ doc_param_1=name: name of the option
[setParam]
type=method
category=core
sig_in=ssss
sig_in=sssis
sig_out=
param_3_default="@DEFAULT@"
param_3_default=-1
param_4_default="@DEFAULT@"
doc=Change a parameter
doc_param_0=name: Name of the parameter to change
doc_param_1=value: New Value of the parameter
doc_param_2=category: Category of the parameter to change
doc_param_3=%(doc_profile_key)s
doc_param_3=security_limit: -1 means no security then the higher the most secure
doc_param_4=%(doc_profile_key)s
[getParamA]
type=method

View file

@ -414,10 +414,10 @@ class SAT(service.Service):
## Client management ##
def setParam(self, name, value, category, profile_key):
def setParam(self, name, value, category, security_limit, profile_key):
"""set wanted paramater and notice observers"""
info(_("setting param: %(name)s=%(value)s in category %(category)s") % {'name': name, 'value': value, 'category': category})
self.memory.setParam(name, value, category, profile_key)
self.memory.setParam(name, value, category, security_limit, profile_key)
def isConnected(self, profile_key):
"""Return connection status of profile

View file

@ -392,12 +392,12 @@ class Params(object):
if security_limit < 0:
return False
if not node.hasAttribute('security'):
debug("filtered param: %s (no security set)"
% node.getAttribute("name"))
#debug("filtered param: %s (no security set)"
# % node.getAttribute("name"))
return True
if int(node.getAttribute('security')) > security_limit:
debug("filtered param: %s (security level > %i)"
% (node.getAttribute("name"), security_limit))
#debug("filtered param: %s (security level > %i)"
# % (node.getAttribute("name"), security_limit))
return True
return False
@ -545,7 +545,7 @@ class Params(object):
categories.append(cat.getAttribute("name"))
return categories
def setParam(self, name, value, category, profile_key='@NONE@'):
def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
"""Set a parameter, return None if the parameter is not in param xml"""
#TODO: use different behaviour depending of the data type (e.g. password encrypted)
if profile_key != "@NONE@":
@ -556,9 +556,20 @@ class Params(object):
node = self.__getParamNode(name, category, '@ALL@')
if not node:
error(_('Requesting an unknown parameter (%(category)s/%(name)s)') % {'category': category, 'name': name})
error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
% {'category': category, 'name': name})
return
if security_limit >= 0:
abort = True
if node[1].hasAttribute("security"):
if int(node[1].getAttribute("security")) <= security_limit:
abort = False
if abort:
warning(_("Trying to set parameter '%s' in category '%s' without authorization!!!"
% (name, category)))
return
if node[0] == 'general':
self.params_gen[(category, name)] = value
self.storage.setGenParam(category, name, value)
@ -921,8 +932,8 @@ class Memory(object):
def getParamsCategories(self):
return self.params.getParamsCategories()
def setParam(self, name, value, category, profile_key):
return self.params.setParam(name, value, category, profile_key)
def setParam(self, name, value, category, security_limit, profile_key):
return self.params.setParam(name, value, category, security_limit, profile_key)
def importParams(self, xml):
return self.params.importParams(xml)

View file

@ -117,9 +117,12 @@ class MiscAccount(object):
def _profileRegistered(self, result, email, password, profile):
#FIXME: values must be in a config file instead of hardcoded
self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), "Connection", profile)
self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER, "Connection", profile)
self.host.memory.setParam("Password", password, "Connection", profile)
self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE),
"Connection", profile_key=profile)
self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER,
"Connection", profile_key=profile)
self.host.memory.setParam("Password", password,
"Connection", profile_key=profile)
#and the account
#XXX: we use "prosodyctl adduser" because "register" doesn't check conflict

View file

@ -798,9 +798,12 @@ class XEP_0065_handler(XMPPHandler):
if len(streamhost_elts) != 1:
warning(_("Multiple streamhost elements in proxy not managed, keeping only the first one"))
streamhost_elt = streamhost_elts[0]
proxy = self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""), "File Transfer", self.parent.profile)
proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""), "File Transfer", self.parent.profile)
proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""), "File Transfer", self.parent.profile)
proxy = self.host.memory.setParam("Proxy", streamhost_elt.getAttribute("jid", ""),
"File Transfer", profile_key=self.parent.profile)
proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host", ""),
"File Transfer", profile_key=self.parent.profile)
proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port", ""),
"File Transfer", profile_key=self.parent.profile)
def connectionInitialized(self):
def after_init(ignore):