- local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
- local restore_cmd = "tar -xzC/ >/dev/null 2>&1"
- local backup_cmd = "tar -czT %s 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_system/applyreboot")
- luci.sys.reboot()
- elseif backup then
- local filelist = "/tmp/luci-backup-list.%d" % os.time()
-
- sys.call(
- "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
- "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
- "opkg list-changed-conffiles ) | sort -u > %s" % filelist
- )
-
- if fs.access(filelist) then
- local reader = ltn12_popen(backup_cmd:format(filelist))
- 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)
- fs.unlink(filelist)
- end
- elseif reset then
- luci.template.render("admin_system/applyreboot")
- luci.util.exec("mtd -r erase rootfs_data")
- else
- luci.template.render("admin_system/backup", {reset_avail = reset_avail})
- end
-end
-
-function action_passwd()
- local p1 = luci.http.formvalue("pwd1")
- local p2 = luci.http.formvalue("pwd2")
- local stat = nil
-
- if p1 or p2 then
- if p1 == p2 then
- stat = luci.sys.user.setpasswd("root", p1)
- else
- stat = 10
- end
- end
-
- luci.template.render("admin_system/passwd", {stat=stat})
-end
-
-function action_reboot()
- local reboot = luci.http.formvalue("reboot")
- luci.template.render("admin_system/reboot", {reboot=reboot})
- if reboot then
- luci.sys.reboot()
- end
-end
-
-function action_upgrade()
- require("luci.model.uci")