5e32041538af2bfc428e7c5971045f99343d6498
[oweals/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"},
13         }
14 }
15
16 function action_editor()
17         local file = ffluci.http.formvalue("file")
18         local data = ffluci.http.formvalue("data")
19         local err  = nil
20         local msg  = nil
21         local stat = nil
22         
23         if file and data then
24                 stat, err = pcall(ffluci.fs.writefile, file, data)
25         end
26         
27         if not stat then
28                 err = ffluci.util.split(err, " ")
29                 table.remove(err, 1)
30                 msg = table.concat(err, " ")
31         end
32         
33         local stat, cnt = pcall(ffluci.fs.readfile, fname)
34         if stat and cnt then
35                 cnt = ffluci.util.pcdata(cnt)
36         else
37                 cnt = nil
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 msg = nil
46         local cm
47         
48         if p1 or p2 then
49                 msg = ffluci.sys.user.setpasswd("root", p1, p2)
50         end
51         
52         ffluci.template.render("admin_system/passwd", {msg=msg})
53 end