From 65ba4b8b8ae21fde49d0636bc1398940522322ff Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Tue, 15 May 2018 11:35:40 +0200 Subject: [PATCH] luci-mod-admin-full: check backup.tar.gz on apply If an uploaded backup.tar.gz is not valid we will not get a respond from LuCI. The system will perform a reboot without applying the "tar.gz" even though the backup import failed. To fix this check if the backup archive is valid with the command "gunzip -t " and if the validation fails render the flashops page with a hint. On the other hand apply the backup archive and perform a reboot as before. Signed-off-by: Florian Eckert --- .../luasrc/controller/admin/system.lua | 14 +++++++++++--- .../luasrc/view/admin_system/flashops.htm | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua b/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua index 0c19893cf..153615b58 100644 --- a/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua +++ b/modules/luci-mod-admin-full/luasrc/controller/admin/system.lua @@ -341,9 +341,17 @@ function action_restore() local upload = http.formvalue("archive") if upload and #upload > 0 then - luci.template.render("admin_system/applyreboot") - os.execute("tar -C / -xzf %q >/dev/null 2>&1" % archive_tmp) - luci.sys.reboot() + 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 diff --git a/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm b/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm index 0a4bc6578..f90a6f542 100644 --- a/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm +++ b/modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm @@ -50,9 +50,12 @@ + <% if backup_invalid then %> +
<%:The backup archive does not appear to be a valid gzip file.%>
+ <% end %> <% if reset_avail then %> -
<%:Custom files (certificates, scripts) may remain on the system. To prevent this, perform a factory-reset first.%>
+
<%:Custom files (certificates, scripts) may remain on the system. To prevent this, perform a factory-reset first.%>
<% end %> -- 2.25.1