diff options
Diffstat (limited to 'modules/luci-mod-system/luasrc')
4 files changed, 1 insertions, 430 deletions
diff --git a/modules/luci-mod-system/luasrc/controller/admin/system.lua b/modules/luci-mod-system/luasrc/controller/admin/system.lua index d6e1dc7815..c7d8ac5323 100644 --- a/modules/luci-mod-system/luasrc/controller/admin/system.lua +++ b/modules/luci-mod-system/luasrc/controller/admin/system.lua @@ -29,229 +29,12 @@ function index() entry({"admin", "system", "leds"}, view("system/leds"), _("<abbr title=\"Light Emitting Diode\">LED</abbr> Configuration"), 60) end - entry({"admin", "system", "flashops"}, call("action_flashops"), _("Backup / Flash Firmware"), 70) - entry({"admin", "system", "flashops", "reset"}, post("action_reset")) - entry({"admin", "system", "flashops", "backup"}, post("action_backup")) - entry({"admin", "system", "flashops", "backupmtdblock"}, post("action_backupmtdblock")) - entry({"admin", "system", "flashops", "backupfiles"}, form("admin_system/backupfiles")) - - -- call() instead of post() due to upload handling! - entry({"admin", "system", "flashops", "restore"}, call("action_restore")) - entry({"admin", "system", "flashops", "sysupgrade"}, call("action_sysupgrade")) + entry({"admin", "system", "flash"}, view("system/flash"), _("Backup / Flash Firmware"), 70) entry({"admin", "system", "reboot"}, template("admin_system/reboot"), _("Reboot"), 90) entry({"admin", "system", "reboot", "call"}, post("action_reboot")) end -local function image_supported(image) - return (os.execute("sysupgrade -T %q >/dev/null" % image) == 0) -end - -local function image_checksum(image) - return (luci.sys.exec("md5sum %q" % image):match("^([^%s]+)")) -end - -local function image_sha256_checksum(image) - return (luci.sys.exec("sha256sum %q" % image):match("^([^%s]+)")) -end - -local function supports_sysupgrade() - return nixio.fs.access("/lib/upgrade/platform.sh") -end - -local function supports_reset() - return (os.execute([[grep -sq "^overlayfs:/overlay / overlay " /proc/mounts]]) == 0) -end - -local function storage_size() - local size = 0 - if nixio.fs.access("/proc/mtd") then - for l in io.lines("/proc/mtd") do - local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"') - if n == "linux" or n == "firmware" then - size = tonumber(s, 16) - break - end - end - elseif nixio.fs.access("/proc/partitions") then - for l in io.lines("/proc/partitions") do - local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)') - if b and n and not n:match('[0-9]') then - size = tonumber(b) * 1024 - break - end - end - end - return size -end - - -function action_flashops() - -- - -- Overview - -- - luci.template.render("admin_system/flashops", { - reset_avail = supports_reset(), - upgrade_avail = supports_sysupgrade() - }) -end - -function action_sysupgrade() - local fs = require "nixio.fs" - local http = require "luci.http" - local image_tmp = "/tmp/firmware.img" - - local fp - http.setfilehandler( - function(meta, chunk, eof) - if not fp and meta and meta.name == "image" then - fp = io.open(image_tmp, "w") - end - if fp and chunk then - fp:write(chunk) - end - if fp and eof then - fp:close() - end - end - ) - - if not luci.dispatcher.test_post_security() then - fs.unlink(image_tmp) - return - end - - -- - -- Cancel firmware flash - -- - if http.formvalue("cancel") then - fs.unlink(image_tmp) - http.redirect(luci.dispatcher.build_url('admin/system/flashops')) - return - end - - -- - -- Initiate firmware flash - -- - local step = tonumber(http.formvalue("step")) or 1 - if step == 1 then - local force = http.formvalue("force") - if image_supported(image_tmp) or force then - luci.template.render("admin_system/upgrade", { - checksum = image_checksum(image_tmp), - sha256ch = image_sha256_checksum(image_tmp), - storage = storage_size(), - size = (fs.stat(image_tmp, "size") or 0), - keep = (not not http.formvalue("keep")), - force = (not not http.formvalue("force")) - }) - else - fs.unlink(image_tmp) - luci.template.render("admin_system/flashops", { - reset_avail = supports_reset(), - upgrade_avail = supports_sysupgrade(), - image_invalid = true - }) - end - - -- - -- Start sysupgrade flash - -- - elseif step == 2 then - local keep = (http.formvalue("keep") == "1") and "" or "-n" - local force = (http.formvalue("force") == "1") and "-F" or "" - 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 (#force > 0) and "192.168.1.1" or nil - }) - luci.sys.process.exec({ "/bin/sh", "-c","sleep 1; killall dropbear uhttpd; sleep 1; /sbin/sysupgrade %s %s %q" %{ keep, force, image_tmp } }, nil, nil, true) - end -end - -function action_backup() - luci.http.header('Content-Disposition', 'attachment; filename="backup-%s-%s.tar.gz"' - %{ luci.sys.hostname(), os.date("%Y-%m-%d") }) - - luci.http.prepare_content("application/x-targz") - luci.sys.process.exec({ "/sbin/sysupgrade", "--create-backup", "-" }, luci.http.write) -end - -function action_backupmtdblock() - local mv = luci.http.formvalue("mtdblockname") or "" - local m, n = mv:match('^([^%s%./"]+)/%d+/(%d+)$') - - if not m and n then - luci.http.status(400, "Bad Request") - return - end - - luci.http.header('Content-Disposition', 'attachment; filename="backup-%s-%s-%s.bin"' - %{ luci.sys.hostname(), m, os.date("%Y-%m-%d") }) - - luci.http.prepare_content("application/octet-stream") - luci.sys.process.exec({ "/bin/dd", "if=/dev/mtd%s" % n, "conv=fsync,notrunc" }, luci.http.write) -end - -function action_restore() - local fs = require "nixio.fs" - local http = require "luci.http" - local archive_tmp = "/tmp/restore.tar.gz" - - local fp - http.setfilehandler( - function(meta, chunk, eof) - if not fp and meta and meta.name == "archive" then - fp = io.open(archive_tmp, "w") - end - if fp and chunk then - fp:write(chunk) - end - if fp and eof then - fp:close() - end - end - ) - - if not luci.dispatcher.test_post_security() then - fs.unlink(archive_tmp) - return - end - - local upload = http.formvalue("archive") - if upload and #upload > 0 then - if os.execute("gunzip -t %q >/dev/null 2>&1" % archive_tmp) == 0 then - luci.template.render("admin_system/applyreboot") - os.execute("tar -C / -xzf %q >/dev/null 2>&1" % archive_tmp) - luci.sys.reboot() - else - luci.template.render("admin_system/flashops", { - reset_avail = supports_reset(), - upgrade_avail = supports_sysupgrade(), - backup_invalid = true - }) - end - return - end - - http.redirect(luci.dispatcher.build_url('admin/system/flashops')) -end - -function action_reset() - if supports_reset() then - 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" - }) - - luci.sys.process.exec({ "/bin/sh", "-c", "sleep 1; killall dropbear uhttpd; sleep 1; jffs2reset -y && reboot" }, nil, nil, true) - return - end - - http.redirect(luci.dispatcher.build_url('admin/system/flashops')) -end - function action_reboot() luci.sys.reboot() end diff --git a/modules/luci-mod-system/luasrc/view/admin_system/backupfiles.htm b/modules/luci-mod-system/luasrc/view/admin_system/backupfiles.htm deleted file mode 100644 index c1f3361ae2..0000000000 --- a/modules/luci-mod-system/luasrc/view/admin_system/backupfiles.htm +++ /dev/null @@ -1,10 +0,0 @@ -<%# - Copyright 2008 Steven Barth <steven@midlink.org> - Copyright 2008 Jo-Philipp Wich <jow@openwrt.org> - Licensed to the public under the Apache License 2.0. --%> - -<ul class="cbi-tabmenu"> - <li class="cbi-tab-disabled"><a href="<%=url("admin/system/flashops")%>"><%:Actions%></a></li> - <li class="cbi-tab"><a href="#"><%:Configuration%></a></li> -</ul> diff --git a/modules/luci-mod-system/luasrc/view/admin_system/flashops.htm b/modules/luci-mod-system/luasrc/view/admin_system/flashops.htm deleted file mode 100644 index 8204d38e34..0000000000 --- a/modules/luci-mod-system/luasrc/view/admin_system/flashops.htm +++ /dev/null @@ -1,137 +0,0 @@ -<%# - Copyright 2008 Steven Barth <steven@midlink.org> - Copyright 2008-2015 Jo-Philipp Wich <jow@openwrt.org> - Licensed to the public under the Apache License 2.0. --%> - -<%+header%> - -<h2 name="content"><%:Flash operations%></h2> - -<ul class="cbi-tabmenu"> - <li class="cbi-tab"><a href="#"><%:Actions%></a></li> - <li class="cbi-tab-disabled"><a href="<%=url('admin/system/flashops/backupfiles')%>"><%:Configuration%></a></li> -</ul> - -<div class="cbi-section"> - <h3><%:Backup%></h3> - <div class="cbi-section-descr"><%:Click "Generate archive" to download a tar archive of the current configuration files.%></div> - <div class="cbi-section-node"> - <form class="inline" method="post" action="<%=url('admin/system/flashops/backup')%>"> - <input type="hidden" name="token" value="<%=token%>" /> - <div class="cbi-value<% if not reset_avail then %> cbi-value-last<% end %>"> - <label class="cbi-value-title" for="image"><%:Download backup%></label> - <div class="cbi-value-field"> - <input class="cbi-button cbi-button-action important" type="submit" name="backup" value="<%:Generate archive%>" /> - </div> - </div> - </form> - </div> - - <h3><%:Restore%></h3> - <div class="cbi-section-descr"><%:To restore configuration files, you can upload a previously generated backup archive here. To reset the firmware to its initial state, click "Perform reset" (only possible with squashfs images).%></div> - <div class="cbi-section-node"> - <% if reset_avail then %> - <form class="inline" method="post" action="<%=url('admin/system/flashops/reset')%>"> - <input type="hidden" name="token" value="<%=token%>" /> - <div class="cbi-value cbi-value-last"> - <label class="cbi-value-title"><%:Reset to defaults%></label> - <div class="cbi-value-field"> - <input onclick="return confirm('<%:Really reset all changes?%>')" class="cbi-button cbi-button-reset" type="submit" name="reset" value="<%:Perform reset%>" /> - </div> - </div> - </form> - <% end %> - <form class="inline" method="post" action="<%=url('admin/system/flashops/restore')%>" enctype="multipart/form-data"> - <div class="cbi-value cbi-value-last"> - <label class="cbi-value-title" for="archive"><%:Restore backup%></label> - <div class="cbi-value-field"> - <input type="hidden" name="token" value="<%=token%>" /> - <input type="file" name="archive" id="archive" /> - <input type="submit" class="cbi-button cbi-button-action important" name="restore" value="<%:Upload archive...%>" /> - <% if reset_avail then %> - <div class="cbi-value-description"><%:Custom files (certificates, scripts) may remain on the system. To prevent this, perform a factory-reset first.%></div> - <% end %> - </div> - </div> - </form> - <% if backup_invalid then %> - <div class="cbi-section-error"><%:The backup archive does not appear to be a valid gzip file.%></div> - <% end %> - </div> - - <% local mtds = require("luci.sys").mtds(); if #mtds > 0 then -%> - <h3><%:Save mtdblock contents%></h3> - <div class="cbi-section-descr"><%:Click "Save mtdblock" to download specified mtdblock file. (NOTE: THIS FEATURE IS FOR PROFESSIONALS! )%></div> - <div class="cbi-section-node"> - <form class="inline" method="post" action="<%=url('admin/system/flashops/backupmtdblock')%>"> - <input type="hidden" name="token" value="<%=token%>" /> - <div class="cbi-value"> - <label class="cbi-value-title" for="mtdblockname"><%:Choose mtdblock%></label> - <div class="cbi-value-field"> - <select class="cbi-input-select" data-update="change" name="mtdblockname" id="mtdblockname"> - <% for i, key in ipairs(mtds) do - if key and key.name ~= "rootfs_data" then -%> - <option<%= - attr("id", "mtdblockname-" .. key.name) .. - attr("value", key.name .. '/'.. key.size .. '/' .. i - 1) .. - attr("data-index", i) .. - ifattr(key.name == "linux" or key.name == "firmware", "selected", "selected") - %>><%=pcdata(key.name)%></option> - <% end - end -%> - </select> - </div> - </div> - <div class="cbi-value cbi-value-last<% if reset_avail then %> cbi-value-error<% end %>"> - <label class="cbi-value-title" for="image"><%:Download mtdblock%></label> - <div class="cbi-value-field"> - <input type="submit" class="cbi-button cbi-button-action important" value="<%:Save mtdblock%>" /> - </div> - </div> - </form> - </div> - <% end %> - -</div> - -<div class="cbi-section"> - <h3><%:Flash new firmware image%></h3> - <% if upgrade_avail then %> - <form method="post" action="<%=url('admin/system/flashops/sysupgrade')%>" enctype="multipart/form-data"> - <input type="hidden" name="token" value="<%=token%>" /> - <div class="cbi-section-descr"><%:Upload a sysupgrade-compatible image here to replace the running firmware. Check "Keep settings" to retain the current configuration (requires a compatible firmware image).%></div> - <div class="cbi-section-node"> - <div class="cbi-value"> - <label class="cbi-value-title" for="keep"><%:Keep settings%></label> - <div class="cbi-value-field"> - <input type="checkbox" name="keep" id="keep" checked="checked" /> - </div> - </div> - <% if image_invalid then %> - <div class="cbi-value"> - <label class="cbi-value-title" for="force"><%:Force upgrade%></label> - <div class="cbi-value-field"> - <input type="checkbox" name="force" id="force" /> - </div> - <div class="cbi-section-error"> - <%:The uploaded image file does not contain a supported format. Make sure that you choose the generic image format for your platform. %> - <%:Select 'Force upgrade' to flash the image even if the image format check fails. Use only if you are sure that the firmware is correct and meant for your device! %> - </div> - </div> - <% end %> - <div class="cbi-value cbi-value-last<% if image_invalid then %> cbi-value-error<% end %>"> - <label class="cbi-value-title" for="image"><%:Image%></label> - <div class="cbi-value-field"> - <input type="file" name="image" id="image" /> - <input type="submit" class="cbi-button cbi-button-action important" value="<%:Flash image...%>" /> - </div> - </div> - </div> - </form> - <% else %> - <div class="cbi-section-descr"><%:Sorry, there is no sysupgrade support present; a new firmware image must be flashed manually. Please refer to the wiki for device specific install instructions.%></div> - <% end %> -</div> - -<%+footer%> diff --git a/modules/luci-mod-system/luasrc/view/admin_system/upgrade.htm b/modules/luci-mod-system/luasrc/view/admin_system/upgrade.htm deleted file mode 100644 index 597ddfd6bf..0000000000 --- a/modules/luci-mod-system/luasrc/view/admin_system/upgrade.htm +++ /dev/null @@ -1,65 +0,0 @@ -<%# - Copyright 2008 Steven Barth <steven@midlink.org> - Copyright 2008-2009 Jo-Philipp Wich <jow@openwrt.org> - Licensed to the public under the Apache License 2.0. --%> - -<%+header%> - -<h2 name="content"><%:Flash Firmware%> - <%:Verify%></h2> -<p> - <%_ The flash image was uploaded. - Below is the checksum and file size listed, - compare them with the original file to ensure data integrity.<br /> - Click "Proceed" below to start the flash procedure. %> - - <% if storage > 0 and size > storage then %> - <br /><br /> - <div class="error"><%:It appears that you are trying to - flash an image that does not fit into the flash memory, please verify - the image file! %></div> - <% end %> - -</p> - -<div class="cbi-section"> - <ul> - <li><%:Checksum%><br /> - <%:MD5%>: <code><%=checksum%></code><br /> - <%:SHA256%>: <code><%=sha256ch%></code></li> - <li><%:Size%>: <% - local w = require "luci.tools.webadmin" - write(w.byte_format(size)) - - if storage > 0 then - write(luci.i18n.translatef( - " (%s available)", - w.byte_format(storage) - )) - end - %></li> - <li><% if keep then %> - <%:Configuration files will be kept%> - <% else %> - <%:Caution: Configuration files will be erased%> - <% end %></li> - <% if force then %> - <li> - <%:Caution: System upgrade will be forced%> - </li> - <% end %> - </ul> -</div> - -<div class="cbi-page-actions right"> - <form class="inline" action="<%=REQUEST_URI%>" method="post"> - <input type="hidden" name="token" value="<%=token%>" /> - <input type="hidden" name="step" value="2" /> - <input type="hidden" name="keep" value="<%=keep and "1" or ""%>" /> - <input type="hidden" name="force" value="<%=force and "1" or ""%>" /> - <input class="cbi-button cbi-button-reset" name="cancel" type="submit" value="<%:Cancel%>" /> - <input class="cbi-button cbi-button-apply" type="submit" value="<%:Proceed%>" /> - </form> -</div> - -<%+footer%> |