1 module("luci.controller.admin.system", package.seeall)
4 luci.i18n.loadc("admin-core")
5 local i18n = luci.i18n.translate
7 entry({"admin", "system"}, template("admin_system/index"), i18n("system", "System"), 30)
8 entry({"admin", "system", "packages"}, call("action_packages"), i18n("a_s_packages", "Paketverwaltung"), 10)
9 entry({"admin", "system", "packages", "ipkg"}, call("action_ipkg"), i18n("a_s_p_ipkg", "IPKG-Konfiguration"))
10 entry({"admin", "system", "passwd"}, call("action_passwd"), i18n("a_s_changepw", "Passwort ändern"), 20)
11 entry({"admin", "system", "sshkeys"}, call("action_sshkeys"), i18n("a_s_sshkeys", "SSH-Schlüssel"), 30)
12 entry({"admin", "system", "hostname"}, cbi("admin_system/hostname"), i18n("hostname", "Hostname"), 40)
13 entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("a_s_fstab", "Einhängepunkte"), 50)
14 entry({"admin", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash", "Firmwareupgrade"), 60)
15 entry({"admin", "system", "reboot"}, call("action_reboot"), i18n("reboot", "Neu starten"), 70)
18 function action_editor()
19 local file = luci.http.formvalue("file", "")
20 local data = luci.http.formvalue("data")
26 stat, err = luci.fs.writefile(file, data)
30 err = luci.util.split(err, " ")
32 msg = table.concat(err, " ")
35 local cnt, err = luci.fs.readfile(file)
37 cnt = luci.util.pcdata(cnt)
39 luci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
42 function action_ipkg()
43 local file = "/etc/ipkg.conf"
44 local data = luci.http.formvalue("data")
49 stat, err = luci.fs.writefile(file, data)
52 local cnt = luci.fs.readfile(file)
54 cnt = luci.util.pcdata(cnt)
57 luci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
60 function action_packages()
61 local ipkg = require("luci.model.ipkg")
63 local submit = luci.http.formvalue("submit")
67 local query = luci.http.formvalue("query")
68 query = (query ~= '') and query or nil
71 -- Packets to be installed
72 local install = submit and luci.http.formvaluetable("install")
75 local url = luci.http.formvalue("url")
76 if url and url ~= '' and submit then
85 for k, v in pairs(install) do
86 void, install[k] = ipkg.install(k)
92 local remove = submit and luci.http.formvaluetable("remove")
94 for k, v in pairs(remove) do
95 void, remove[k] = ipkg.remove(k)
100 -- Update all packets
101 local update = luci.http.formvalue("update")
103 void, update = ipkg.update()
107 -- Upgrade all packets
108 local upgrade = luci.http.formvalue("upgrade")
110 void, upgrade = ipkg.upgrade()
115 local info = luci.model.ipkg.info(query)
119 -- Sort after status and name
120 for k, v in pairs(info) do
122 for i, j in pairs(pkgs) do
123 local vins = (v.Status and v.Status.installed)
124 local jins = (j.Status and j.Status.installed)
130 if j.Package > v.Package then
136 table.insert(pkgs, x+1, v)
139 luci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
140 install=install, remove=remove, update=update, upgrade=upgrade})
143 function action_passwd()
144 local p1 = luci.http.formvalue("pwd1")
145 local p2 = luci.http.formvalue("pwd2")
150 stat = luci.sys.user.setpasswd("root", p1)
156 luci.template.render("admin_system/passwd", {stat=stat})
159 function action_reboot()
160 local reboot = luci.http.formvalue("reboot")
161 luci.template.render("admin_system/reboot", {reboot=reboot})
167 function action_sshkeys()
168 local file = "/etc/dropbear/authorized_keys"
169 local data = luci.http.formvalue("data")
174 stat, err = luci.fs.writefile(file, data)
177 local cnt = luci.fs.readfile(file)
179 cnt = luci.util.pcdata(cnt)
182 luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
185 function action_upgrade()
186 require("luci.model.uci")
188 local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
190 local image = luci.http.upload("image")
191 local keepcfg = luci.http.formvalue("keepcfg")
193 if plat and image then
196 local files = luci.model.uci.get_all("luci", "flash_keep")
197 if files.luci and files.luci.flash_keep then
199 for k,v in pairs(files.luci.flash_keep) do
200 kpattern = kpattern .. " " .. v
204 ret = luci.sys.flash(image, kpattern)
207 luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})