1 module("luci.controller.admin.system", package.seeall)
7 require("luci.model.ipkg")
8 require("luci.model.uci")
11 luci.i18n.loadc("admin-core")
12 local i18n = luci.i18n.translate
14 entry({"admin", "system"}, template("admin_system/index"), i18n("system", "System"), 30)
15 entry({"admin", "system", "packages"}, call("action_packages"), i18n("a_s_packages", "Paketverwaltung"), 10)
16 entry({"admin", "system", "packages", "ipkg"}, call("action_ipkg"), i18n("a_s_p_ipkg", "IPKG-Konfiguration"))
17 entry({"admin", "system", "passwd"}, call("action_passwd"), i18n("a_s_changepw", "Passwort ändern"), 20)
18 entry({"admin", "system", "sshkeys"}, call("action_sshkeys"), i18n("a_s_sshkeys", "SSH-Schlüssel"), 30)
19 entry({"admin", "system", "hostname"}, cbi("admin_system/hostname"), i18n("hostname", "Hostname"), 40)
20 entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("a_s_fstab", "Einhängepunkte"), 50)
21 entry({"admin", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash", "Firmwareupgrade"), 60)
22 entry({"admin", "system", "reboot"}, call("action_reboot"), i18n("reboot", "Neu starten"), 70)
25 function action_editor()
26 local file = luci.http.formvalue("file", "")
27 local data = luci.http.formvalue("data")
33 stat, err = luci.fs.writefile(file, data)
37 err = luci.util.split(err, " ")
39 msg = table.concat(err, " ")
42 local cnt, err = luci.fs.readfile(file)
44 cnt = luci.util.pcdata(cnt)
46 luci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
49 function action_ipkg()
50 local file = "/etc/ipkg.conf"
51 local data = luci.http.formvalue("data")
56 stat, err = luci.fs.writefile(file, data)
59 local cnt = luci.fs.readfile(file)
61 cnt = luci.util.pcdata(cnt)
64 luci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
67 function action_packages()
68 local ipkg = luci.model.ipkg
70 local submit = luci.http.formvalue("submit")
74 local query = luci.http.formvalue("query")
75 query = (query ~= '') and query or nil
78 -- Packets to be installed
79 local install = submit and luci.http.formvaluetable("install")
82 local url = luci.http.formvalue("url")
83 if url and url ~= '' and submit then
92 for k, v in pairs(install) do
93 void, install[k] = ipkg.install(k)
99 local remove = submit and luci.http.formvaluetable("remove")
101 for k, v in pairs(remove) do
102 void, remove[k] = ipkg.remove(k)
107 -- Update all packets
108 local update = luci.http.formvalue("update")
110 void, update = ipkg.update()
114 -- Upgrade all packets
115 local upgrade = luci.http.formvalue("upgrade")
117 void, upgrade = ipkg.upgrade()
122 local info = luci.model.ipkg.info(query)
126 -- Sort after status and name
127 for k, v in pairs(info) do
129 for i, j in pairs(pkgs) do
130 local vins = (v.Status and v.Status.installed)
131 local jins = (j.Status and j.Status.installed)
137 if j.Package > v.Package then
143 table.insert(pkgs, x+1, v)
146 luci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
147 install=install, remove=remove, update=update, upgrade=upgrade})
150 function action_passwd()
151 local p1 = luci.http.formvalue("pwd1")
152 local p2 = luci.http.formvalue("pwd2")
157 stat = luci.sys.user.setpasswd("root", p1)
163 luci.template.render("admin_system/passwd", {stat=stat})
166 function action_reboot()
167 local reboot = luci.http.formvalue("reboot")
168 luci.template.render("admin_system/reboot", {reboot=reboot})
174 function action_sshkeys()
175 local file = "/etc/dropbear/authorized_keys"
176 local data = luci.http.formvalue("data")
181 stat, err = luci.fs.writefile(file, data)
184 local cnt = luci.fs.readfile(file)
186 cnt = luci.util.pcdata(cnt)
189 luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
192 function action_upgrade()
194 local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
196 local image = luci.http.upload("image")
197 local keepcfg = luci.http.formvalue("keepcfg")
199 if plat and image then
202 local files = luci.model.uci.sections("luci").flash_keep
203 if files.luci and files.luci.flash_keep then
205 for k,v in pairs(files.luci.flash_keep) do
206 kpattern = kpattern .. " " .. v
210 ret = luci.sys.flash(image, kpattern)
213 luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})