NIU: More restructuring, Add: change password, hostname
[project/luci.git] / modules / niu / luasrc / model / cbi / niu / system / general.lua
index df438e8..046691c 100644 (file)
@@ -7,11 +7,28 @@ d.allow_cancel = true
 d:add("general1", load("niu/system/general1"))
 
 function d.on_cancel()
-       cursor:revert("system")
+       cursor:revert("luci")
 end
 
 function d.on_done()
-       cursor:commit("system")
+       local pw1 = cursor:get("luci", "main", "_pw1")
+       if pw1 and pw1 ~= "**********" then
+               cursor:delete("luci", "main", "_pw1")
+               require "luci.sys".user.setpasswd("root", pw1)
+       end
+
+       local hn = cursor:get("luci", "main", "_uniquename")
+       if hn then
+               cursor:foreach("system", "system", function(s)
+                       cursor:set("system", s[".name"], "hostname", hn)
+               end)
+               cursor:commit("system")
+
+               require "nixio.fs".writefile("/proc/sys/kernel/hostname", hn)
+               cursor:delete("luci", "main", "_uniquename")
+       end
+
+       cursor:commit("luci")
 end
 
 return d
\ No newline at end of file