2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
14 module("luci.controller.admin.system", package.seeall)
17 luci.i18n.loadc("admin-core")
18 local i18n = luci.i18n.translate
20 entry({"admin", "system"}, template("admin_system/index"), i18n("system", "System"), 30)
21 entry({"admin", "system", "packages"}, call("action_packages"), i18n("a_s_packages", "Paketverwaltung"), 10)
22 entry({"admin", "system", "packages", "ipkg"}, call("action_ipkg"), i18n("a_s_p_ipkg", "IPKG-Konfiguration"))
23 entry({"admin", "system", "passwd"}, call("action_passwd"), i18n("a_s_changepw", "Passwort ändern"), 20)
24 entry({"admin", "system", "sshkeys"}, call("action_sshkeys"), i18n("a_s_sshkeys", "SSH-Schlüssel"), 30)
25 entry({"admin", "system", "system"}, cbi("admin_system/system"), i18n("system", "System"), 40)
26 entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("a_s_fstab", "Einhängepunkte"), 50)
27 entry({"admin", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash", "Firmwareupgrade"), 60)
28 entry({"admin", "system", "reboot"}, call("action_reboot"), i18n("reboot", "Neu starten"), 70)
31 function action_editor()
32 local file = luci.http.formvalue("file", "")
33 local data = luci.http.formvalue("data")
39 stat, err = luci.fs.writefile(file, data)
43 err = luci.util.split(err, " ")
45 msg = table.concat(err, " ")
48 local cnt, err = luci.fs.readfile(file)
50 cnt = luci.util.pcdata(cnt)
52 luci.template.render("admin_system/editor", {fn=file, cnt=cnt, msg=msg})
55 function action_ipkg()
56 local file = "/etc/ipkg.conf"
57 local data = luci.http.formvalue("data")
62 stat, err = luci.fs.writefile(file, data)
65 local cnt = luci.fs.readfile(file)
67 cnt = luci.util.pcdata(cnt)
70 luci.template.render("admin_system/ipkg", {cnt=cnt, msg=err})
73 function action_packages()
74 local ipkg = require("luci.model.ipkg")
76 local submit = luci.http.formvalue("submit")
80 local query = luci.http.formvalue("query")
81 query = (query ~= '') and query or nil
84 -- Packets to be installed
85 local install = submit and luci.http.formvaluetable("install")
88 local url = luci.http.formvalue("url")
89 if url and url ~= '' and submit then
98 for k, v in pairs(install) do
99 void, install[k] = ipkg.install(k)
105 local remove = submit and luci.http.formvaluetable("remove")
107 for k, v in pairs(remove) do
108 void, remove[k] = ipkg.remove(k)
113 -- Update all packets
114 local update = luci.http.formvalue("update")
116 void, update = ipkg.update()
120 -- Upgrade all packets
121 local upgrade = luci.http.formvalue("upgrade")
123 void, upgrade = ipkg.upgrade()
128 local info = luci.model.ipkg.info(query)
132 -- Sort after status and name
133 for k, v in pairs(info) do
135 for i, j in pairs(pkgs) do
136 local vins = (v.Status and v.Status.installed)
137 local jins = (j.Status and j.Status.installed)
143 if j.Package > v.Package then
149 table.insert(pkgs, x+1, v)
152 luci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
153 install=install, remove=remove, update=update, upgrade=upgrade})
156 function action_passwd()
157 local p1 = luci.http.formvalue("pwd1")
158 local p2 = luci.http.formvalue("pwd2")
163 stat = luci.sys.user.setpasswd("root", p1)
169 luci.template.render("admin_system/passwd", {stat=stat})
172 function action_reboot()
173 local reboot = luci.http.formvalue("reboot")
174 luci.template.render("admin_system/reboot", {reboot=reboot})
180 function action_sshkeys()
181 local file = "/etc/dropbear/authorized_keys"
182 local data = luci.http.formvalue("data")
187 stat, err = luci.fs.writefile(file, data)
190 local cnt = luci.fs.readfile(file)
192 cnt = luci.util.pcdata(cnt)
195 luci.template.render("admin_system/sshkeys", {cnt=cnt, msg=err})
198 function action_upgrade()
199 require("luci.model.uci")
202 local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
203 local tmpfile = "/tmp/firmware.img"
206 luci.http.setfilehandler(
207 function(meta, chunk, eof)
209 file = io.open(tmpfile, "w")
220 local fname = luci.http.formvalue("image")
221 local keepcfg = luci.http.formvalue("keepcfg")
223 if plat and fname then
226 local files = luci.model.uci.get_all("luci", "flash_keep")
227 if files.luci and files.luci.flash_keep then
229 for k,v in pairs(files.luci.flash_keep) do
230 kpattern = kpattern .. " " .. v
234 ret = luci.sys.flash(tmpfile, kpattern)
237 luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret})