NIU: More restructuring, Add: change password, hostname
[project/luci.git] / modules / niu / luasrc / model / cbi / niu / system / general.lua
1 local cursor = require "luci.model.uci".cursor()
2 local d = Delegator()
3 d.allow_finish = true
4 d.allow_back = true
5 d.allow_cancel = true
6
7 d:add("general1", load("niu/system/general1"))
8
9 function d.on_cancel()
10 cursor:revert("luci")
11 end
12
13 function d.on_done()
14 local pw1 = cursor:get("luci", "main", "_pw1")
15 if pw1 and pw1 ~= "**********" then
16 cursor:delete("luci", "main", "_pw1")
17 require "luci.sys".user.setpasswd("root", pw1)
18 end
19
20 local hn = cursor:get("luci", "main", "_uniquename")
21 if hn then
22 cursor:foreach("system", "system", function(s)
23 cursor:set("system", s[".name"], "hostname", hn)
24 end)
25 cursor:commit("system")
26
27 require "nixio.fs".writefile("/proc/sys/kernel/hostname", hn)
28 cursor:delete("luci", "main", "_uniquename")
29 end
30
31 cursor:commit("luci")
32 end
33
34 return d