+ luci.ltn12.pump.all(reader, luci.http.write)
+ elseif luci.http.formvalue("restore") then
+ --
+ -- Unpack received .tar.gz
+ --
+ local upload = luci.http.formvalue("archive")
+ if upload and #upload > 0 then
+ luci.template.render("admin_system/applyreboot")
+ luci.sys.reboot()
+ end
+ elseif luci.http.formvalue("image") or luci.http.formvalue("step") then
+ --
+ -- Initiate firmware flash
+ --
+ local step = tonumber(luci.http.formvalue("step") or 1)
+ if step == 1 then
+ if image_supported() then
+ luci.template.render("admin_system/upgrade", {
+ checksum = image_checksum(),
+ storage = storage_size(),
+ size = nixio.fs.stat(image_tmp).size,
+ keep = (not not luci.http.formvalue("keep"))
+ })
+ else
+ nixio.fs.unlink(image_tmp)
+ luci.template.render("admin_system/flashops", {
+ reset_avail = reset_avail,
+ upgrade_avail = upgrade_avail,
+ image_invalid = true
+ })
+ end
+ --
+ -- Start sysupgrade flash
+ --
+ elseif step == 2 then
+ local keep = (luci.http.formvalue("keep") == "1") and "" or "-n"
+ luci.template.render("admin_system/applyreboot", {
+ title = luci.i18n.translate("Flashing..."),
+ msg = luci.i18n.translate("The system is flashing now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings."),
+ addr = (#keep > 0) and "192.168.1.1" or nil
+ })
+ fork_exec("killall dropbear uhttpd; sleep 1; /sbin/sysupgrade %s %q" %{ keep, image_tmp })
+ end
+ elseif reset_avail and luci.http.formvalue("reset") then
+ --
+ -- Reset system
+ --
+ luci.template.render("admin_system/applyreboot", {
+ title = luci.i18n.translate("Erasing..."),
+ msg = luci.i18n.translate("The system is erasing the configuration partition now and will reboot itself when finished."),
+ addr = "192.168.1.1"
+ })
+ fork_exec("killall dropbear uhttpd; sleep 1; mtd -r erase rootfs_data")