1 module("ffluci.controller.admin.system", package.seeall)
7 require("ffluci.model.ipkg")
9 function action_editor()
10 local file = ffluci.http.formvalue("file", "")
11 local data = ffluci.http.formvalue("data")
17 stat, err = ffluci.fs.writefile(file, data)
21 err = ffluci.util.split(err, " ")
23 msg = table.concat(err, " ")
26 local cnt, err = ffluci.fs.readfile(file)
28 cnt = ffluci.util.pcdata(cnt)
30 ffluci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
33 function action_ipkg()
34 local file = "/etc/ipkg.conf"
35 local data = ffluci.http.formvalue("data")
40 stat, err = ffluci.fs.writefile(file, data)
43 local cnt = ffluci.fs.readfile(file)
45 cnt = ffluci.util.pcdata(cnt)
48 ffluci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
51 function action_packages()
52 local ipkg = ffluci.model.ipkg
54 local submit = ffluci.http.formvalue("submit")
58 local query = ffluci.http.formvalue("query")
59 query = (query ~= '') and query or nil
62 -- Packets to be installed
63 local install = ffluci.http.formvalue("install")
64 install = (type(install) == "table" and submit) and install or nil
67 local url = ffluci.http.formvalue("url")
68 if url and url ~= '' and submit then
77 for k, v in pairs(install) do
78 void, install[k] = ipkg.install(k)
84 local remove = ffluci.http.formvalue("remove")
85 remove = (type(remove) == "table" and submit) and remove or nil
87 for k, v in pairs(remove) do
88 void, remove[k] = ipkg.remove(k)
94 local update = ffluci.http.formvalue("update")
96 void, update = ipkg.update()
100 -- Upgrade all packets
101 local upgrade = ffluci.http.formvalue("upgrade")
103 void, upgrade = ipkg.upgrade()
108 local info = ffluci.model.ipkg.info(query)
111 -- Sort after status and name
112 for k, v in pairs(info) do
114 for i, j in pairs(pkgs) do
115 local vins = (v.Status and v.Status.installed)
116 local jins = (j.Status and j.Status.installed)
122 if j.Package > v.Package then
128 table.insert(pkgs, x+1, v)
131 ffluci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
132 install=install, remove=remove, update=update, upgrade=upgrade})
135 function action_passwd()
136 local p1 = ffluci.http.formvalue("pwd1")
137 local p2 = ffluci.http.formvalue("pwd2")
142 stat = ffluci.sys.user.setpasswd("root", p1)
148 ffluci.template.render("admin_system/passwd", {stat=stat})
151 function action_reboot()
152 local reboot = ffluci.http.formvalue("reboot")
153 ffluci.template.render("admin_system/reboot", {reboot=reboot})
159 function action_sshkeys()
160 local file = "/etc/dropbear/authorized_keys"
161 local data = ffluci.http.formvalue("data")
166 stat, err = ffluci.fs.writefile(file, data)
169 local cnt = ffluci.fs.readfile(file)
171 cnt = ffluci.util.pcdata(cnt)
174 ffluci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})