From 3712f8795c2527cf4afbee641b7802a96854e8f0 Mon Sep 17 00:00:00 2001
From: Nils Schneider <nils@nilsschneider.net>
Date: Tue, 18 Feb 2014 23:13:42 +0100
Subject: [PATCH] gluon-luci-admin: remove backup/restore

---
 .../lib/lua/luci/controller/admin/system.lua  | 72 -------------------
 .../lib/lua/luci/view/admin/applyreboot.htm   | 21 ------
 .../usr/lib/lua/luci/view/admin/backup.htm    | 39 ----------
 3 files changed, 132 deletions(-)
 delete mode 100644 package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/applyreboot.htm
 delete mode 100644 package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/backup.htm

diff --git a/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/system.lua b/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/system.lua
index fb7eabde3..a27fb7a1f 100644
--- a/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/system.lua
+++ b/package/gluon-luci-admin/files/usr/lib/lua/luci/controller/admin/system.lua
@@ -17,51 +17,9 @@ module("luci.controller.admin.system", package.seeall)
 
 function index()
 	entry({"admin", "passwd"}, cbi("admin/passwd"), "Admin Password", 10)
-	entry({"admin", "backup"}, call("action_backup"), "Backup / Restore", 80)
 	entry({"admin", "upgrade"}, call("action_upgrade"), "Flash Firmware", 90)
 end
 
-function action_backup()
-	local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
-	local restore_cmd = "gunzip | tar -xC/ >/dev/null 2>&1"
-	local backup_cmd  = "tar -c %s | gzip 2>/dev/null"
-	
-	local restore_fpi 
-	luci.http.setfilehandler(
-		function(meta, chunk, eof)
-			if not restore_fpi then
-				restore_fpi = io.popen(restore_cmd, "w")
-			end
-			if chunk then
-				restore_fpi:write(chunk)
-			end
-			if eof then
-				restore_fpi:close()
-			end
-		end
-	)
-		  
-	local upload = luci.http.formvalue("archive")
-	local backup = luci.http.formvalue("backup")
-	local reset  = reset_avail and luci.http.formvalue("reset")
-	
-	if upload and #upload > 0 then
-		luci.template.render("admin/applyreboot")
-		luci.sys.reboot()
-	elseif backup then
-		local reader = ltn12_popen(backup_cmd:format(_keep_pattern()))
-		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.ltn12.pump.all(reader, luci.http.write)
-	elseif reset then
-		luci.template.render("admin/applyreboot")
-		luci.util.exec("mtd -r erase rootfs_data")
-	else
-		luci.template.render("admin/backup", {reset_avail = reset_avail})
-	end
-end
-
 function action_upgrade()
 	require("luci.model.uci")
 
@@ -187,36 +145,6 @@ function _keep_pattern()
 	return kpattern
 end
 
-function ltn12_popen(command)
-
-	local fdi, fdo = nixio.pipe()
-	local pid = nixio.fork()
-
-	if pid > 0 then
-		fdo:close()
-		local close
-		return function()
-			local buffer = fdi:read(2048)
-			local wpid, stat = nixio.waitpid(pid, "nohang")
-			if not close and wpid and stat == "exited" then
-				close = true
-			end
-
-			if buffer and #buffer > 0 then
-				return buffer
-			elseif close then
-				fdi:close()
-				return nil
-			end
-		end
-	elseif pid == 0 then
-		nixio.dup(fdo, nixio.stdout)
-		fdi:close()
-		fdo:close()
-		nixio.exec("/bin/sh", "-c", command)
-	end
-end
-
 function fork_exec(command)
 	local pid = nixio.fork()
 	if pid > 0 then
diff --git a/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/applyreboot.htm b/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/applyreboot.htm
deleted file mode 100644
index 46fa4b6db..000000000
--- a/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/applyreboot.htm
+++ /dev/null
@@ -1,21 +0,0 @@
-<%#
-LuCI - Lua Configuration Interface
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-	http://www.apache.org/licenses/LICENSE-2.0
-
-$Id$
-
--%>
-<%+header%>
-<h2><a id="content" name="content">System</a></h2>
-<br />
-<p><% if msg then %><%=msg%><% else %>Changes applied.<% end %></p>
-<p>Please wait: Device rebooting...</p>
-<script type="text/javascript">setTimeout("location='<%=controller%>'", 60000)</script>
-<%+footer%>
diff --git a/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/backup.htm b/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/backup.htm
deleted file mode 100644
index 5299b0134..000000000
--- a/package/gluon-luci-admin/files/usr/lib/lua/luci/view/admin/backup.htm
+++ /dev/null
@@ -1,39 +0,0 @@
-<%#
-LuCI - Lua Configuration Interface
-Copyright 2008 Steven Barth <steven@midlink.org>
-Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-	http://www.apache.org/licenses/LICENSE-2.0
-
-$Id$
-
--%>
-<%+header%>
-<h2><a id="content" name="content">Backup / Restore</a></h2>
-<p>Here you can backup and restore your configuration and - if possible - reset this device to the default settings.</p>
-<br />
-<div>
-	<ul>
-	<li><a href="<%=REQUEST_URI%>?backup=kthxbye">Create backup</a></li>
-	<% if reset_avail then -%>
-	<li><a href="<%=REQUEST_URI%>?reset=yarly" onclick="return confirm('Proceed reverting all settings and resetting to firmware defaults?')">Reset this device to defaults</a></li>
-	<% end -%>
-	</ul>
-</div>
-
-<br />
-
-<form method="post" action="<%=REQUEST_URI%>" enctype="multipart/form-data">
-	<div class="left">Backup Archive:</div>
-	<div>
-		<input type="file" size="30" name="archive" />
-	</div>
-	<div>
-		<input type="submit" class="cbi-button cbi-input-apply" value="Restore backup" />
-	</div>
-</form>
-<%+footer%>
-- 
GitLab