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