AdGuardHome.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. module("luci.controller.AdGuardHome",package.seeall)
  2. nixio=require"nixio"
  3. local uci=require"luci.model.uci".cursor()
  4. function index()
  5. entry({"admin", "services", "AdGuardHome"},
  6. alias("admin", "services", "AdGuardHome", "base"),
  7. _("AdGuard Home"), 10).dependent = true
  8. entry({"admin","services","AdGuardHome","base"},cbi("AdGuardHome/base"),_("Base Setting"),1).leaf = true
  9. entry({"admin","services","AdGuardHome","log"},form("AdGuardHome/log"),_("Log"),2).leaf = true
  10. entry({"admin","services","AdGuardHome","manual"},cbi("AdGuardHome/manual"),_("Manual Config"),3).leaf = true
  11. entry({"admin","services","AdGuardHome","status"},call("act_status")).leaf=true
  12. entry({"admin", "services", "AdGuardHome", "check"}, call("check_update"))
  13. entry({"admin", "services", "AdGuardHome", "doupdate"}, call("do_update"))
  14. end
  15. function act_status()
  16. local e={}
  17. binpath=uci:get("AdGuardHome","AdGuardHome","binpath")
  18. e.running=luci.sys.call("pgrep "..binpath.." >/dev/null")==0
  19. luci.http.prepare_content("application/json")
  20. luci.http.write_json(e)
  21. end
  22. function do_update()
  23. nixio.fs.writefile("/var/run/lucilogpos","0")
  24. luci.sys.exec("(touch /var/run/update_core ; sh /usr/share/AdGuardHome/update_core.sh >/tmp/AdGuardHome_update.log;rm /var/run/update_core) &")
  25. luci.http.prepare_content("application/json")
  26. luci.http.write('')
  27. end
  28. function check_update()
  29. luci.http.prepare_content("text/plain; charset=utf-8")
  30. logpos=nixio.fs.readfile("/var/run/lucilogpos")
  31. if (logpos ~= nil) then
  32. fdp=tonumber(logpos)
  33. else
  34. fdp=0
  35. end
  36. f=io.open("/tmp/AdGuardHome_update.log", "r+")
  37. f:seek("set",fdp)
  38. a=f:read(8192)
  39. if (a==nil) then
  40. a=""
  41. end
  42. fdp=f:seek()
  43. nixio.fs.writefile("/var/run/lucilogpos",tostring(fdp))
  44. f:close()
  45. if nixio.fs.access("/var/run/update_core") then
  46. luci.http.write(a)
  47. else
  48. luci.http.write(a.."\0")
  49. end
  50. end