backupfiles.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.rmempty = false
  19. c.cols = 70
  20. c.rows = 30
  21. c.cfgvalue = function(self, section)
  22. return nixio.fs.readfile("/etc/sysupgrade.conf")
  23. end
  24. c.write = function(self, section, value)
  25. value = value:gsub("\r\n?", "\n")
  26. return nixio.fs.writefile("/etc/sysupgrade.conf", value)
  27. end
  28. else
  29. m.submit = false
  30. m.reset = false
  31. 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."))
  32. l = f:option(Button, "_edit", translate("Back to configuration"))
  33. l.inputtitle = translate("Close list...")
  34. l.inputstyle = "link"
  35. d = f:option(DummyValue, "_detected")
  36. d.rawhtml = true
  37. d.cfgvalue = function(s)
  38. local list = io.popen(
  39. "( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' /etc/sysupgrade.conf " ..
  40. "/lib/upgrade/keep.d/* 2>/dev/null) -type f 2>/dev/null; " ..
  41. "opkg list-changed-conffiles ) | sort -u"
  42. )
  43. if list then
  44. local files = { "<ul>" }
  45. while true do
  46. local ln = list:read("*l")
  47. if not ln then
  48. break
  49. else
  50. files[#files+1] = "<li>"
  51. files[#files+1] = luci.util.pcdata(ln)
  52. files[#files+1] = "</li>"
  53. end
  54. end
  55. list:close()
  56. files[#files+1] = "</ul>"
  57. return table.concat(files, "")
  58. end
  59. return "<em>" .. translate("No files found") .. "</em>"
  60. end
  61. end
  62. return m