[PATCH V2 0/4] bug fix: accept all characters for network name except / and "

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> V1 - V2 just restrict " and /. " is not allowed in dnsmasq configure file. / is not allowed in a linux file name. we should not put extra restrictions. ShaoHe Feng (4): bug fix: network name can be any characters except " and / network name support unicode. escape < > and & in in xml for network name. escape special characters for jQuery selector. src/kimchi/model/networks.py | 11 ++++++++--- ui/js/src/kimchi.network.js | 28 ++++++++++++++-------------- ui/js/src/kimchi.utils.js | 7 +++++++ ui/pages/tabs/network.html.tmpl | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) -- 1.9.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> " is not allowed in dnsmasq configure file. / is not allowed in a linux file name. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.network.js | 2 +- ui/pages/tabs/network.html.tmpl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js index 54a6594..639fcc1 100644 --- a/ui/js/src/kimchi.network.js +++ b/ui/js/src/kimchi.network.js @@ -336,7 +336,7 @@ kimchi.cleanNetworkDialog = function() { }; kimchi.setupNetworkFormEvent = function() { $("#networkName").on("keyup", function(event) { - $("#networkName").toggleClass("invalid-field", !$("#networkName").val().match(/^[a-zA-Z0-9_]+$/)); + $("#networkName").toggleClass("invalid-field", !$("#networkName").val().match(/^[^\"\/]+$/)); kimchi.updateNetworkFormButton(); }); $("#networkTypeIso").on("click", function(event) { diff --git a/ui/pages/tabs/network.html.tmpl b/ui/pages/tabs/network.html.tmpl index 35380f4..558d999 100644 --- a/ui/pages/tabs/network.html.tmpl +++ b/ui/pages/tabs/network.html.tmpl @@ -49,7 +49,7 @@ <input type="text" id="networkName" class="network-label"/> <div class="input-hint"> <span class="ui-icon ui-icon-info input-hint-icon"></span> - <span class="input-hint-text">$_("Alphanumeric and '_' characters only.")</span> + <span class="input-hint-text">$_("Name should not contain '/' and '\"'.")</span> </div> </div> </div> -- 1.9.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> We should allow user to create a network with his local language name. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/networks.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index 63886e0..af9e940 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -100,7 +100,7 @@ def create(self, params): xml = networkxml.to_network_xml(**params) try: - network = conn.networkDefineXML(xml) + network = conn.networkDefineXML(xml.encode("utf-8")) network.setAutostart(True) except libvirt.libvirtError as e: raise OperationFailed("KCHNET0008E", @@ -110,7 +110,8 @@ def create(self, params): def get_list(self): conn = self.conn.get() - return sorted(conn.listNetworks() + conn.listDefinedNetworks()) + names = conn.listNetworks() + conn.listDefinedNetworks() + return sorted(map(lambda x: x.decode('utf-8'), names)) def _get_available_address(self, addr_pools=[]): invalid_addrs = [] @@ -188,7 +189,7 @@ def get_all_networks_interfaces(self): interfaces = [] for name in net_names: conn = self.conn.get() - network = conn.networkLookupByName(name) + network = conn.networkLookupByName(name.encode("utf-8")) xml = network.XMLDesc(0) net_dict = NetworkModel.get_network_from_xml(xml) forward = net_dict['forward'] @@ -324,6 +325,7 @@ def delete(self, name): @staticmethod def get_network(conn, name): + name = name.encode("utf-8") try: return conn.networkLookupByName(name) except libvirt.libvirtError: -- 1.9.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> < > and & are special characters in xml. so when create a xml, we should escape them. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- src/kimchi/model/networks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index af9e940..a267af6 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -23,6 +23,8 @@ import ipaddr import libvirt +from xml.sax.saxutils import escape + from kimchi import netinfo from kimchi import network as knetwork from kimchi import networkxml @@ -97,6 +99,7 @@ def create(self, params): if connection == 'bridge': self._set_network_bridge(params) + params['name'] = escape(params['name']) xml = networkxml.to_network_xml(**params) try: -- 1.9.3

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> When where are some special characters in html element names, jQuery will not find the element. These characters should be escape. add a escape function in util for it. Signed-off-by: ShaoHe Feng <shaohef@linux.vnet.ibm.com> --- ui/js/src/kimchi.network.js | 26 +++++++++++++------------- ui/js/src/kimchi.utils.js | 7 +++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js index 639fcc1..68cf559 100644 --- a/ui/js/src/kimchi.network.js +++ b/ui/js/src/kimchi.network.js @@ -79,7 +79,7 @@ kimchi.getNetworkItemHtml = function(network) { }; kimchi.stopNetwork = function(network,menu) { - $(".network-state", $("#" + network.name)).switchClass("up", "nw-loading"); + $(".network-state", $("#" + kimchi.escapeStr(network.name))).switchClass("up", "nw-loading"); $("[nwAct='stop']", menu).addClass("ui-state-disabled"); kimchi.toggleNetwork(network.name, false, function() { $("[nwAct='start']", menu).removeClass("hide-action-item"); @@ -89,9 +89,9 @@ kimchi.stopNetwork = function(network,menu) { $("[nwAct='delete']", menu).removeClass("ui-state-disabled"); $(":first-child", $("[nwAct='delete']", menu)).removeAttr("disabled"); } - $(".network-state", $("#" + network.name)).switchClass("nw-loading", "down"); + $(".network-state", $("#" + kimchi.escapeStr(network.name))).switchClass("nw-loading", "down"); }, function(err) { - $(".network-state", $("#" + network.name)).switchClass("nw-loading", "up"); + $(".network-state", $("#" + kimchi.escapeStr(network.name))).switchClass("nw-loading", "up"); if (!network.in_use) { $("[nwAct='stop']", menu).removeClass("ui-state-disabled"); } @@ -100,17 +100,17 @@ kimchi.stopNetwork = function(network,menu) { } kimchi.addNetworkActions = function(network) { - $(".menu-container", "#" + network.name).menu({ + $(".menu-container", "#" + kimchi.escapeStr(network.name)).menu({ position : { my : "left top", at : "left bottom", - of : "#" + network.name + of : "#" + kimchi.escapeStr(network.name) }, select : function(evt, ui) { - $(".menu-container", "#" + network.name).toggle(false); + $(".menu-container", "#" + kimchi.escapeStr(network.name)).toggle(false); var menu = $(evt.currentTarget).parent(); if ($(evt.currentTarget).attr("nwAct") === "start") { - $(".network-state", $("#" + network.name)).switchClass("down", "nw-loading"); + $(".network-state", $("#" + kimchi.escapeStr(network.name))).switchClass("down", "nw-loading"); $("[nwAct='start']", menu).addClass("ui-state-disabled"); $("[nwAct='delete']", menu).addClass("ui-state-disabled"); $(":first-child", $("[nwAct='delete']", menu)).attr("disabled", true); @@ -121,9 +121,9 @@ kimchi.addNetworkActions = function(network) { if (network.in_use) { $("[nwAct='stop']", menu).addClass("ui-state-disabled"); } - $(".network-state", $("#" + network.name)).switchClass("nw-loading", "up"); + $(".network-state", $("#" + kimchi.escapeStr(network.name))).switchClass("nw-loading", "up"); }, function(err) { - $(".network-state", $("#" + network.name)).switchClass("nw-loading","down"); + $(".network-state", $("#" + kimchi.escapeStr(network.name))).switchClass("nw-loading","down"); $("[nwAct='start']", menu).removeClass("ui-state-disabled"); if (!network.in_use) { $("[nwAct='delete']", menu).removeClass("ui-state-disabled"); @@ -161,16 +161,16 @@ kimchi.addNetworkActions = function(network) { } } }); - $(".column-action", "#" + network.name).children(":first").button({ + $(".column-action", "#" + kimchi.escapeStr(network.name)).children(":first").button({ icons : { secondary : "action-button-icon" } }).click(function() { - $(".menu-container", "#" + network.name).toggle(); + $(".menu-container", "#" + kimchi.escapeStr(network.name)).toggle(); window.scrollBy(0, 150); }); - $(".menu-container", "#" + network.name).mouseleave(function() { - $(".menu-container", "#" + network.name).toggle(false); + $(".menu-container", "#" + kimchi.escapeStr(network.name)).mouseleave(function() { + $(".menu-container", "#" + kimchi.escapeStr(network.name)).toggle(false); }); }; diff --git a/ui/js/src/kimchi.utils.js b/ui/js/src/kimchi.utils.js index d1ea105..c7103f8 100644 --- a/ui/js/src/kimchi.utils.js +++ b/ui/js/src/kimchi.utils.js @@ -176,3 +176,10 @@ kimchi.isServer = function(server) { return true; } }; + +kimchi.escapeStr = function(str) { + if (str) + return str.replace(/([ #;?%&,.+*~\\':"!^$[\]()<=>`{|}\/@])/g,'\\$&'); + + return str; +}; -- 1.9.3

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> Probably we need to do the same for the other resources: storage pool, vm, etc. On 06/16/2014 01:45 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
V1 - V2 just restrict " and /.
" is not allowed in dnsmasq configure file. / is not allowed in a linux file name. we should not put extra restrictions.
ShaoHe Feng (4): bug fix: network name can be any characters except " and / network name support unicode. escape < > and & in in xml for network name. escape special characters for jQuery selector.
src/kimchi/model/networks.py | 11 ++++++++--- ui/js/src/kimchi.network.js | 28 ++++++++++++++-------------- ui/js/src/kimchi.utils.js | 7 +++++++ ui/pages/tabs/network.html.tmpl | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-)

On 06/18/2014 06:55 AM, Aline Manera wrote:
Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com>
Probably we need to do the same for the other resources: storage pool, vm, etc.
ACK. we need to check the storage pool, vm, etc.
On 06/16/2014 01:45 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
V1 - V2 just restrict " and /.
" is not allowed in dnsmasq configure file. / is not allowed in a linux file name. we should not put extra restrictions.
ShaoHe Feng (4): bug fix: network name can be any characters except " and / network name support unicode. escape < > and & in in xml for network name. escape special characters for jQuery selector.
src/kimchi/model/networks.py | 11 ++++++++--- ui/js/src/kimchi.network.js | 28 ++++++++++++++-------------- ui/js/src/kimchi.utils.js | 7 +++++++ ui/pages/tabs/network.html.tmpl | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-)
-- Thanks and best regards! Sheldon Feng(冯少合)<shaohef@linux.vnet.ibm.com> IBM Linux Technology Center

I can't apply it. Need rebase. On 06/16/2014 01:45 AM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@linux.vnet.ibm.com>
V1 - V2 just restrict " and /.
" is not allowed in dnsmasq configure file. / is not allowed in a linux file name. we should not put extra restrictions.
ShaoHe Feng (4): bug fix: network name can be any characters except " and / network name support unicode. escape < > and & in in xml for network name. escape special characters for jQuery selector.
src/kimchi/model/networks.py | 11 ++++++++--- ui/js/src/kimchi.network.js | 28 ++++++++++++++-------------- ui/js/src/kimchi.utils.js | 7 +++++++ ui/pages/tabs/network.html.tmpl | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-)
participants (3)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com
-
Sheldon