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

From: ShaoHe Feng <shaohef@linux.vnet.ibm.com> V2 -> V3: rebase 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 | 18 +++++++++--------- ui/js/src/kimchi.utils.js | 7 +++++++ ui/pages/tabs/network.html.tmpl | 2 +- 4 files changed, 25 insertions(+), 13 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 16b9ca6..7ab7ff9 100644 --- a/ui/js/src/kimchi.network.js +++ b/ui/js/src/kimchi.network.js @@ -334,7 +334,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 18fccef..92985ff 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 | 16 ++++++++-------- ui/js/src/kimchi.utils.js | 7 +++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ui/js/src/kimchi.network.js b/ui/js/src/kimchi.network.js index 7ab7ff9..7bb3f98 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,12 +100,12 @@ kimchi.stopNetwork = function(network,menu) { } kimchi.addNetworkActions = function(network) { - $(".menu-container", "#" + network.name).menu(); + $(".menu-container", "#" + kimchi.escapeStr(network.name)).menu(); - $('#' + network.name).on('click', '.menu-container li', function(evt) { + $('#' + kimchi.escapeStr(network.name)).on('click', '.menu-container li', function(evt) { 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); @@ -117,9 +117,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"); 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
participants (2)
-
Aline Manera
-
shaohef@linux.vnet.ibm.com