uci.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. -- Copyright 2008 Steven Barth <steven@midlink.org>
  2. -- Copyright 2010-2015 Jo-Philipp Wich <jow@openwrt.org>
  3. -- Licensed to the public under the Apache License 2.0.
  4. module("luci.controller.admin.uci", package.seeall)
  5. function index()
  6. local redir = luci.http.formvalue("redir", true) or
  7. luci.dispatcher.build_url(unpack(luci.dispatcher.context.request))
  8. entry({"admin", "uci"}, nil, _("Configuration"))
  9. entry({"admin", "uci", "changes"}, call("action_changes"), _("Changes"), 40).query = {redir=redir}
  10. entry({"admin", "uci", "revert"}, post("action_revert"), _("Revert"), 30).query = {redir=redir}
  11. entry({"admin", "uci", "apply"}, post("action_apply"), _("Apply"), 20).query = {redir=redir}
  12. entry({"admin", "uci", "saveapply"}, post("action_apply"), _("Save &#38; Apply"), 10).query = {redir=redir}
  13. end
  14. function action_changes()
  15. local uci = luci.model.uci.cursor()
  16. local changes = uci:changes()
  17. luci.template.render("admin_uci/changes", {
  18. changes = next(changes) and changes
  19. })
  20. end
  21. function action_apply()
  22. local path = luci.dispatcher.context.path
  23. local uci = luci.model.uci.cursor()
  24. local changes = uci:changes()
  25. local reload = {}
  26. -- Collect files to be applied and commit changes
  27. for r, tbl in pairs(changes) do
  28. table.insert(reload, r)
  29. if path[#path] ~= "apply" then
  30. uci:load(r)
  31. uci:commit(r)
  32. uci:unload(r)
  33. end
  34. end
  35. luci.template.render("admin_uci/apply", {
  36. changes = next(changes) and changes,
  37. configs = reload
  38. })
  39. end
  40. function action_revert()
  41. local uci = luci.model.uci.cursor()
  42. local changes = uci:changes()
  43. -- Collect files to be reverted
  44. for r, tbl in pairs(changes) do
  45. uci:load(r)
  46. uci:revert(r)
  47. uci:unload(r)
  48. end
  49. luci.template.render("admin_uci/revert", {
  50. changes = next(changes) and changes
  51. })
  52. end