* Added reboot page
[project/luci.git] / src / ffluci / controller / admin / system.lua
1 module("ffluci.controller.admin.system", package.seeall)
2
3 require("ffluci.sys")
4 require("ffluci.http")
5 require("ffluci.util")
6 require("ffluci.fs")
7
8 menu = {
9 descr = "System",
10 order = 20,
11 entries = {
12 {action = "passwd", descr = "Passwort ändern"},
13 {action = "sshkeys", descr = "SSH-Schlüssel"},
14 {action = "reboot", descr = "Neu starten"},
15 }
16 }
17
18 function action_editor()
19 local file = ffluci.http.formvalue("file", "")
20 local data = ffluci.http.formvalue("data")
21 local err = nil
22 local msg = nil
23 local stat = true
24
25 if file and data then
26 stat, err = ffluci.fs.writefile(file, data)
27 end
28
29 if not stat then
30 err = ffluci.util.split(err, " ")
31 table.remove(err, 1)
32 msg = table.concat(err, " ")
33 end
34
35 local cnt, err = ffluci.fs.readfile(file)
36 if cnt then
37 cnt = ffluci.util.pcdata(cnt)
38 end
39 ffluci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
40 end
41
42 function action_passwd()
43 local p1 = ffluci.http.formvalue("pwd1")
44 local p2 = ffluci.http.formvalue("pwd2")
45 local stat = nil
46
47 if p1 or p2 then
48 if p1 == p2 then
49 stat = ffluci.sys.user.setpasswd("root", p1)
50 else
51 stat = 10
52 end
53 end
54
55 ffluci.template.render("admin_system/passwd", {stat=stat})
56 end
57
58 function action_reboot()
59 ffluci.template.render("admin_system/reboot")
60 ffluci.sys.reboot()
61 end
62
63 function action_sshkeys()
64 local file = "/etc/dropbear/authorized_keys"
65 local data = ffluci.http.formvalue("data")
66 local stat = nil
67 local err = nil
68
69 if data then
70 stat, err = ffluci.fs.writefile(file, data)
71 end
72
73 local cnt = ffluci.fs.readfile(file)
74 if cnt then
75 cnt = ffluci.util.pcdata(cnt)
76 end
77
78 ffluci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
79 end