luci-mod-admin-full: check backup.tar.gz on apply
authorFlorian Eckert <fe@dev.tdt.de>
Tue, 15 May 2018 09:35:40 +0000 (11:35 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 3 Jul 2018 15:45:12 +0000 (17:45 +0200)
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 <archive>" 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 <fe@dev.tdt.de>
modules/luci-mod-admin-full/luasrc/controller/admin/system.lua
modules/luci-mod-admin-full/luasrc/view/admin_system/flashops.htm

index 0c19893cf8cddc46d992bfbbbaebb48f00e301d2..153615b58a24651e4f3fe182282b2c81ba708034 100644 (file)
@@ -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
 
index 0a4bc6578c591a36791b28195a53c605cb19f98f..f90a6f54245084155f7ec6caeda16d9b395e1ebc 100644 (file)
                                </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>
        <% if reset_avail then %>
-       <div class="alert-message warning"><%:Custom files (certificates, scripts) may remain on the system. To prevent this, perform a factory-reset first.%></div>
+               <div class="alert-message warning"><%:Custom files (certificates, scripts) may remain on the system. To prevent this, perform a factory-reset first.%></div>
        <% end %>
 </div>