c4ba027cbc4cde94977733d19a2dd6c523250d34
[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 function action_editor()
9 local file = ffluci.http.formvalue("file", "")
10 local data = ffluci.http.formvalue("data")
11 local err = nil
12 local msg = nil
13 local stat = true
14
15 if file and data then
16 stat, err = ffluci.fs.writefile(file, data)
17 end
18
19 if not stat then
20 err = ffluci.util.split(err, " ")
21 table.remove(err, 1)
22 msg = table.concat(err, " ")
23 end
24
25 local cnt, err = ffluci.fs.readfile(file)
26 if cnt then
27 cnt = ffluci.util.pcdata(cnt)
28 end
29 ffluci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
30 end
31
32 function action_passwd()
33 local p1 = ffluci.http.formvalue("pwd1")
34 local p2 = ffluci.http.formvalue("pwd2")
35 local stat = nil
36
37 if p1 or p2 then
38 if p1 == p2 then
39 stat = ffluci.sys.user.setpasswd("root", p1)
40 else
41 stat = 10
42 end
43 end
44
45 ffluci.template.render("admin_system/passwd", {stat=stat})
46 end
47
48 function action_reboot()
49 ffluci.template.render("admin_system/reboot")
50 ffluci.sys.reboot()
51 end
52
53 function action_sshkeys()
54 local file = "/etc/dropbear/authorized_keys"
55 local data = ffluci.http.formvalue("data")
56 local stat = nil
57 local err = nil
58
59 if data then
60 stat, err = ffluci.fs.writefile(file, data)
61 end
62
63 local cnt = ffluci.fs.readfile(file)
64 if cnt then
65 cnt = ffluci.util.pcdata(cnt)
66 end
67
68 ffluci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
69 end