1 module("luci.controller.admin.system", package.seeall)
7 require("luci.model.ipkg")
8 require("luci.model.uci")
11 local page = node("admin", "system")
12 page.target = template("admin_system/index")
16 local page = node("admin", "system", "packages")
17 page.target = action_packages
18 page.title = "Paketverwaltung"
21 local page = node("admin", "system", "packages", "ipkg")
22 page.target = action_ipkg
23 page.title = "IPKG-Konfiguration"
25 local page = node("admin", "system", "passwd")
26 page.target = action_passwd
27 page.title = "Passwort ändern"
30 local page = node("admin", "system", "sshkeys")
31 page.target = action_sshkeys
32 page.title = "SSH-Schlüssel"
35 local page = node("admin", "system", "hostname")
36 page.target = cbi("admin_system/hostname")
37 page.title = "Hostname"
40 local page = node("admin", "system", "fstab")
41 page.target = cbi("admin_system/fstab")
42 page.title = "Einhängepunkte"
45 local page = node("admin", "system", "upgrade")
46 page.target = action_upgrade
47 page.title = "Firmwareupgrade"
50 local page = node("admin", "system", "reboot")
51 page.target = action_reboot
52 page.title = "Neu starten"
56 function action_editor()
57 local file = luci.http.formvalue("file", "")
58 local data = luci.http.formvalue("data")
64 stat, err = luci.fs.writefile(file, data)
68 err = luci.util.split(err, " ")
70 msg = table.concat(err, " ")
73 local cnt, err = luci.fs.readfile(file)
75 cnt = luci.util.pcdata(cnt)
77 luci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
80 function action_ipkg()
81 local file = "/etc/ipkg.conf"
82 local data = luci.http.formvalue("data")
87 stat, err = luci.fs.writefile(file, data)
90 local cnt = luci.fs.readfile(file)
92 cnt = luci.util.pcdata(cnt)
95 luci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
98 function action_packages()
99 local ipkg = luci.model.ipkg
101 local submit = luci.http.formvalue("submit")
105 local query = luci.http.formvalue("query")
106 query = (query ~= '') and query or nil
109 -- Packets to be installed
110 local install = submit and luci.http.formvaluetable("install")
113 local url = luci.http.formvalue("url")
114 if url and url ~= '' and submit then
123 for k, v in pairs(install) do
124 void, install[k] = ipkg.install(k)
130 local remove = submit and luci.http.formvaluetable("remove")
132 for k, v in pairs(remove) do
133 void, remove[k] = ipkg.remove(k)
138 -- Update all packets
139 local update = luci.http.formvalue("update")
141 void, update = ipkg.update()
145 -- Upgrade all packets
146 local upgrade = luci.http.formvalue("upgrade")
148 void, upgrade = ipkg.upgrade()
153 local info = luci.model.ipkg.info(query)
157 -- Sort after status and name
158 for k, v in pairs(info) do
160 for i, j in pairs(pkgs) do
161 local vins = (v.Status and v.Status.installed)
162 local jins = (j.Status and j.Status.installed)
168 if j.Package > v.Package then
174 table.insert(pkgs, x+1, v)
177 luci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
178 install=install, remove=remove, update=update, upgrade=upgrade})
181 function action_passwd()
182 local p1 = luci.http.formvalue("pwd1")
183 local p2 = luci.http.formvalue("pwd2")
188 stat = luci.sys.user.setpasswd("root", p1)
194 luci.template.render("admin_system/passwd", {stat=stat})
197 function action_reboot()
198 local reboot = luci.http.formvalue("reboot")
199 luci.template.render("admin_system/reboot", {reboot=reboot})
205 function action_sshkeys()
206 local file = "/etc/dropbear/authorized_keys"
207 local data = luci.http.formvalue("data")
212 stat, err = luci.fs.writefile(file, data)
215 local cnt = luci.fs.readfile(file)
217 cnt = luci.util.pcdata(cnt)
220 luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
223 function action_upgrade()
225 local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
227 local image = luci.http.upload("image")
228 local keepcfg = luci.http.formvalue("keepcfg")
230 if plat and image then
233 local files = luci.model.uci.sections("luci").flash_keep
234 if files.luci and files.luci.flash_keep then
236 for k,v in pairs(files.luci.flash_keep) do
237 kpattern = kpattern .. " " .. v
241 ret = luci.sys.flash(image, kpattern)
244 luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})