backupfiles.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Licensed to the public under the Apache License 2.0.
  4. if luci.http.formvalue("cbid.luci.1._list") then
  5. luci.http.redirect(luci.dispatcher.build_url("admin/system/flashops/backupfiles") .. "?display=list")
  6. elseif luci.http.formvalue("cbid.luci.1._edit") then
  7. luci.http.redirect(luci.dispatcher.build_url("admin/system/flashops/backupfiles") .. "?display=edit")
  8. return
  9. end
  10. m = SimpleForm("luci", translate("Backup file list"))
  11. m:append(Template("admin_system/backupfiles"))
  12. if luci.http.formvalue("display") ~= "list" then
  13. f = m:section(SimpleSection, nil, translate("This is a list of shell glob patterns for matching files and directories to include during sysupgrade. Modified files in /etc/config/ and certain other configurations are automatically preserved."))
  14. l = f:option(Button, "_list", translate("Show current backup file list"))
  15. l.inputtitle = translate("Open list...")
  16. l.inputstyle = "apply"
  17. c = f:option(TextValue, "_custom")
  18. c.forcewrite = true
  19. c.rmempty = true
  20. c.cols = 70
  21. c.rows = 30
  22. c.cfgvalue = function(self, section)
  23. return nixio.fs.readfile("/etc/sysupgrade.conf")
  24. end
  25. m.handle = function(self, state, data)
  26. if state == FORM_VALID then
  27. if data._custom then
  28. nixio.fs.writefile("/etc/sysupgrade.conf", data._custom:gsub("\r\n", "\n"))
  29. else
  30. nixio.fs.writefile("/etc/sysupgrade.conf", "")
  31. end
  32. end
  33. return true
  34. end
  35. else
  36. m.submit = false
  37. m.reset = false
  38. f = m:section(SimpleSection, nil, translate("Below is the determined list of files to backup. It consists of changed configuration files marked by opkg, essential base files and the user defined backup patterns."))
  39. l = f:option(Button, "_edit", translate("Back to configuration"))
  40. l.inputtitle = translate("Close list...")
  41. l.inputstyle = "link"
  42. d = f:option(DummyValue, "_detected")
  43. d.rawhtml = true
  44. d.cfgvalue = function(s)
  45. local list = io.popen(
  46. "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
  47. "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
  48. "opkg list-changed-conffiles ) | sort -u"
  49. )
  50. if list then
  51. local files = { "<ul>" }
  52. while true do
  53. local ln = list:read("*l")
  54. if not ln then
  55. break
  56. else
  57. files[#files+1] = "<li>"
  58. files[#files+1] = luci.util.pcdata(ln)
  59. files[#files+1] = "</li>"
  60. end
  61. end
  62. list:close()
  63. files[#files+1] = "</ul>"
  64. return table.concat(files, "")
  65. end
  66. return "<em>" .. translate("No files found") .. "</em>"
  67. end
  68. end
  69. return m