1 module("luci.controller.admin.system", package.seeall)
7 require("luci.model.ipkg")
8 require("luci.model.uci")
11 entry({"admin", "system"}, template("admin_system/index"), "System", 30)
12 entry({"admin", "system", "packages"}, call("action_packages"), "Paketverwaltung", 10)
13 entry({"admin", "system", "packages", "ipkg"}, call("action_ipkg"), "IPKG-Konfiguration")
14 entry({"admin", "system", "passwd"}, call("action_passwd"), "Passwort ändern", 20)
15 entry({"admin", "system", "sshkeys"}, call("action_sshkeys"), "SSH-Schlüssel", 30)
16 entry({"admin", "system", "hostname"}, cbi("admin_system/hostname"), "Hostname", 40)
17 entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), "Einhängepunkte", 50)
18 entry({"admin", "system", "upgrade"}, call("action_upgrade"), "Firmwareupgrade", 60)
19 entry({"admin", "system", "reboot"}, call("action_reboot"), "Neu starten", 70)
22 function action_editor()
23 local file = luci.http.formvalue("file", "")
24 local data = luci.http.formvalue("data")
30 stat, err = luci.fs.writefile(file, data)
34 err = luci.util.split(err, " ")
36 msg = table.concat(err, " ")
39 local cnt, err = luci.fs.readfile(file)
41 cnt = luci.util.pcdata(cnt)
43 luci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
46 function action_ipkg()
47 local file = "/etc/ipkg.conf"
48 local data = luci.http.formvalue("data")
53 stat, err = luci.fs.writefile(file, data)
56 local cnt = luci.fs.readfile(file)
58 cnt = luci.util.pcdata(cnt)
61 luci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
64 function action_packages()
65 local ipkg = luci.model.ipkg
67 local submit = luci.http.formvalue("submit")
71 local query = luci.http.formvalue("query")
72 query = (query ~= '') and query or nil
75 -- Packets to be installed
76 local install = submit and luci.http.formvaluetable("install")
79 local url = luci.http.formvalue("url")
80 if url and url ~= '' and submit then
89 for k, v in pairs(install) do
90 void, install[k] = ipkg.install(k)
96 local remove = submit and luci.http.formvaluetable("remove")
98 for k, v in pairs(remove) do
99 void, remove[k] = ipkg.remove(k)
104 -- Update all packets
105 local update = luci.http.formvalue("update")
107 void, update = ipkg.update()
111 -- Upgrade all packets
112 local upgrade = luci.http.formvalue("upgrade")
114 void, upgrade = ipkg.upgrade()
119 local info = luci.model.ipkg.info(query)
123 -- Sort after status and name
124 for k, v in pairs(info) do
126 for i, j in pairs(pkgs) do
127 local vins = (v.Status and v.Status.installed)
128 local jins = (j.Status and j.Status.installed)
134 if j.Package > v.Package then
140 table.insert(pkgs, x+1, v)
143 luci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
144 install=install, remove=remove, update=update, upgrade=upgrade})
147 function action_passwd()
148 local p1 = luci.http.formvalue("pwd1")
149 local p2 = luci.http.formvalue("pwd2")
154 stat = luci.sys.user.setpasswd("root", p1)
160 luci.template.render("admin_system/passwd", {stat=stat})
163 function action_reboot()
164 local reboot = luci.http.formvalue("reboot")
165 luci.template.render("admin_system/reboot", {reboot=reboot})
171 function action_sshkeys()
172 local file = "/etc/dropbear/authorized_keys"
173 local data = luci.http.formvalue("data")
178 stat, err = luci.fs.writefile(file, data)
181 local cnt = luci.fs.readfile(file)
183 cnt = luci.util.pcdata(cnt)
186 luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
189 function action_upgrade()
191 local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
193 local image = luci.http.upload("image")
194 local keepcfg = luci.http.formvalue("keepcfg")
196 if plat and image then
199 local files = luci.model.uci.sections("luci").flash_keep
200 if files.luci and files.luci.flash_keep then
202 for k,v in pairs(files.luci.flash_keep) do
203 kpattern = kpattern .. " " .. v
207 ret = luci.sys.flash(image, kpattern)
210 luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})