1 module("ffluci.controller.admin.system", package.seeall)
7 require("ffluci.model.ipkg")
8 require("ffluci.model.uci")
10 function action_editor()
11 local file = ffluci.http.formvalue("file", "")
12 local data = ffluci.http.formvalue("data")
18 stat, err = ffluci.fs.writefile(file, data)
22 err = ffluci.util.split(err, " ")
24 msg = table.concat(err, " ")
27 local cnt, err = ffluci.fs.readfile(file)
29 cnt = ffluci.util.pcdata(cnt)
31 ffluci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
34 function action_ipkg()
35 local file = "/etc/ipkg.conf"
36 local data = ffluci.http.formvalue("data")
41 stat, err = ffluci.fs.writefile(file, data)
44 local cnt = ffluci.fs.readfile(file)
46 cnt = ffluci.util.pcdata(cnt)
49 ffluci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
52 function action_packages()
53 local ipkg = ffluci.model.ipkg
55 local submit = ffluci.http.formvalue("submit")
59 local query = ffluci.http.formvalue("query")
60 query = (query ~= '') and query or nil
63 -- Packets to be installed
64 local install = ffluci.http.formvalue("install")
65 install = (type(install) == "table" and submit) and install or nil
68 local url = ffluci.http.formvalue("url")
69 if url and url ~= '' and submit then
78 for k, v in pairs(install) do
79 void, install[k] = ipkg.install(k)
85 local remove = ffluci.http.formvalue("remove")
86 remove = (type(remove) == "table" and submit) and remove or nil
88 for k, v in pairs(remove) do
89 void, remove[k] = ipkg.remove(k)
95 local update = ffluci.http.formvalue("update")
97 void, update = ipkg.update()
101 -- Upgrade all packets
102 local upgrade = ffluci.http.formvalue("upgrade")
104 void, upgrade = ipkg.upgrade()
109 local info = ffluci.model.ipkg.info(query)
113 -- Sort after status and name
114 for k, v in pairs(info) do
116 for i, j in pairs(pkgs) do
117 local vins = (v.Status and v.Status.installed)
118 local jins = (j.Status and j.Status.installed)
124 if j.Package > v.Package then
130 table.insert(pkgs, x+1, v)
133 ffluci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
134 install=install, remove=remove, update=update, upgrade=upgrade})
137 function action_passwd()
138 local p1 = ffluci.http.formvalue("pwd1")
139 local p2 = ffluci.http.formvalue("pwd2")
144 stat = ffluci.sys.user.setpasswd("root", p1)
150 ffluci.template.render("admin_system/passwd", {stat=stat})
153 function action_reboot()
154 local reboot = ffluci.http.formvalue("reboot")
155 ffluci.template.render("admin_system/reboot", {reboot=reboot})
161 function action_sshkeys()
162 local file = "/etc/dropbear/authorized_keys"
163 local data = ffluci.http.formvalue("data")
168 stat, err = ffluci.fs.writefile(file, data)
171 local cnt = ffluci.fs.readfile(file)
173 cnt = ffluci.util.pcdata(cnt)
176 ffluci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
179 function action_upgrade()
181 local plat = ffluci.fs.mtime("/lib/upgrade/platform.sh")
183 local image = ffluci.http.formvalue("image")
184 local imgname = ffluci.http.formvalue("image_name")
185 local keepcfg = ffluci.http.formvalue("keepcfg")
187 if plat and imgname then
190 local files = ffluci.model.uci.show("luci", "flash_keep")
191 if files.luci and files.luci.flash_keep then
193 for k,v in pairs(files.luci.flash_keep) do
194 kpattern = kpattern .. " " .. v
198 ret = ffluci.sys.flash(image, kpattern)
201 ffluci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})