2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
11 http://www.apache.org/licenses/LICENSE-2.0
16 module("luci.controller.mini.system", package.seeall)
19 luci.i18n.loadc("admin-core")
20 local i18n = luci.i18n.translate
22 entry({"mini", "system"}, alias("mini", "system", "index"), i18n("system"), 40).index = true
23 entry({"mini", "system", "index"}, cbi("mini/system", {autoapply=true}), i18n("general"), 1)
24 entry({"mini", "system", "passwd"}, form("mini/passwd"), i18n("a_s_changepw"), 10)
25 entry({"mini", "system", "backup"}, call("action_backup"), i18n("a_s_backup"), 80)
26 entry({"mini", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash"), 90)
27 entry({"mini", "system", "reboot"}, call("action_reboot"), i18n("reboot"), 100)
30 function action_backup()
31 local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
32 local restore_cmd = "gunzip | tar -xC/ >/dev/null 2>&1"
33 local backup_cmd = "tar -c %s | gzip 2>/dev/null"
36 luci.http.setfilehandler(
37 function(meta, chunk, eof)
38 if not restore_fpi then
39 restore_fpi = io.popen(restore_cmd, "w")
42 restore_fpi:write(chunk)
50 local upload = luci.http.formvalue("archive")
51 local backup = luci.http.formvalue("backup")
52 local reset = reset_avail and luci.http.formvalue("reset")
54 if upload and #upload > 0 then
55 luci.template.render("mini/applyreboot")
58 luci.util.perror(backup_cmd:format(_keep_pattern()))
59 local backup_fpi = io.popen(backup_cmd:format(_keep_pattern()), "r")
60 luci.http.header('Content-Disposition', 'attachment; filename="backup.tar.gz"')
61 luci.http.prepare_content("application/x-targz")
62 luci.ltn12.pump.all(luci.ltn12.source.file(backup_fpi), luci.http.write)
64 luci.template.render("mini/applyreboot")
65 luci.util.exec("mtd -r erase rootfs_data")
67 luci.template.render("mini/backup", {reset_avail = reset_avail})
71 function action_reboot()
72 local reboot = luci.http.formvalue("reboot")
73 luci.template.render("mini/reboot", {reboot=reboot})
79 function action_upgrade()
80 require("luci.model.uci")
83 local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
84 local tmpfile = "/tmp/firmware.img"
85 local keep_avail = true
88 luci.http.setfilehandler(
89 function(meta, chunk, eof)
91 file = io.open(tmpfile, "w")
102 local fname = luci.http.formvalue("image")
103 local keepcfg = keep_avail and luci.http.formvalue("keepcfg")
105 if plat and fname then
107 return luci.sys.flash(tmpfile, keepcfg and _keep_pattern())
111 luci.http.prepare_content("text/html")
112 luci.template.render("mini/upgrade", {sysupgrade=plat, ret=ret, keep_avail=keep_avail})
115 function _keep_pattern()
117 local files = luci.model.uci.cursor():get_all("luci", "flash_keep")
120 for k, v in pairs(files) do
121 if k:sub(1,1) ~= "." and luci.fs.glob(v) then
122 kpattern = kpattern .. " " .. v