remote_update.lua 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- Copyright 2009 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. module("luci.controller.freifunk.remote_update", package.seeall)
  4. function index()
  5. if not nixio.fs.access("/usr/sbin/remote-update") then
  6. return
  7. end
  8. entry({"admin", "system", "remote_update"}, call("act_remote_update"),
  9. _("Freifunk Remote Update"), 90)
  10. end
  11. function act_remote_update()
  12. if luci.http.formvalue("flash") == "1" then
  13. if luci.http.formvalue("confirm") == "1" then
  14. local nobackup = ( luci.http.formvalue("keepcfg") ~= "1" )
  15. local noverify = ( luci.http.formvalue("verify") ~= "1" )
  16. luci.http.redirect("/luci-static/flashing.html")
  17. os.execute("start-stop-daemon -S -b -x /usr/sbin/remote-update -- %s%s-s 5 -y" % {
  18. noverify and "-v " or "",
  19. nobackup and "-n " or ""
  20. })
  21. else
  22. luci.template.render("freifunk/remote_update", {confirm=1})
  23. end
  24. else
  25. local fd = io.popen("remote-update -c")
  26. local update = { }
  27. if fd then
  28. while true do
  29. local ln=fd:read("*l")
  30. if not ln then break
  31. elseif ln:find("Local: ") then update.locvar = ln:match("Local: (%d+)")
  32. elseif ln:find("Remote: ") then update.remver = ln:match("Remote: (%d+)")
  33. elseif ln == "--" then update.info = ""
  34. elseif update.info ~= nil then
  35. update.info = update.info .. ln .. "\n"
  36. end
  37. end
  38. fd:close()
  39. end
  40. luci.template.render("freifunk/remote_update", {update=update})
  41. end
  42. end