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 = submit and ffluci.http.formvaluetable("install")
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 = submit and ffluci.http.formvaluetable("remove")
86 for k, v in pairs(remove) do
87 void, remove[k] = ipkg.remove(k)
93 local update = ffluci.http.formvalue("update")
95 void, update = ipkg.update()
99 -- Upgrade all packets
100 local upgrade = ffluci.http.formvalue("upgrade")
102 void, upgrade = ipkg.upgrade()
107 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})
177 function action_upgrade()
179 local plat = ffluci.fs.mtime("/lib/upgrade/platform.sh")
181 local image = ffluci.http.formvalue("image")
182 local imgname = ffluci.http.formvalue("image_name")
183 local keepcfg = ffluci.http.formvalue("keepcfg")
185 if plat and imgname then
188 local files = ffluci.model.uci.sections("luci").flash_keep
189 if files.luci and files.luci.flash_keep then
191 for k,v in pairs(files.luci.flash_keep) do
192 kpattern = kpattern .. " " .. v
196 ret = ffluci.sys.flash(image, kpattern)
199 ffluci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})