diff --git a/luasrc/model/cbi/commotion/basic_ns.lua b/luasrc/model/cbi/commotion/basic_ns.lua index 7a1fc92..88a9e7b 100644 --- a/luasrc/model/cbi/commotion/basic_ns.lua +++ b/luasrc/model/cbi/commotion/basic_ns.lua @@ -40,7 +40,7 @@ shn.addremove = false --Create a value field for hostname local hname = shn:option(Value, "hostname", translate("Node Name"), translate("The node name (hostname) is a unique name for this device, visible to other devices and users on the network. Name this device in the field provided.")) -hname.datatype = "rangelength(1, 63)" +hname.datatype = "rangelength(1, 53)" hname.rmempty = false function hname.validate(self,value) @@ -52,14 +52,19 @@ function hname.validate(self,value) end function hname.write(self, section, value) - local node_id = cnet.nodeid() - --check if the nodeid is the same and don't write hostname if it is. This means that if a person changes the hostname, but appends the old nodeif to the end of it the hostname will not change. But who in their right mind would do that. - hn, nid = value:match("(.-)%-([%d]*)$") - if nid and nid == node_id then - return true + hn = self:formvalue(section) + old_hn = self:cfgvalue(section) + if hn and hn == old_hn then + return true else - local new_hn = value.."-"..string.sub(node_id, 1, 10) - return self.map:set(section, self.option, new_hn) + local node_id = cnet.nodeid() + if string.match(hn, node_id) then + -- requested hn already has nodeid + return self.map:set(section, self.option, hn) + else + local new_hn = hn.."-"..string.sub(node_id, 1, 10) + return self.map:set(section, self.option, new_hn) + end end end