AdGuardHome.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. require("luci.sys")
  2. require("luci.util")
  3. local fs=require"nixio.fs"
  4. local uci=require"luci.model.uci".cursor()
  5. local configpath=uci:get("AdGuardHome","AdGuardHome","configpath")
  6. if (configpath==nil) then
  7. configpath="/etc/AdGuardHome.yaml"
  8. end
  9. local binpath="/usr/bin/AdGuardHome/AdGuardHome"
  10. local httpport=luci.sys.exec("awk '/bind_port:/{printf($2)}' "..configpath.." 2>nul")
  11. mp = Map("AdGuardHome", translate("AdGuard Home"))
  12. mp.description = translate("免费和开源,功能强大的全网络广告和跟踪程序拦截DNS服务器")
  13. mp:section(SimpleSection).template = "AdGuardHome/AdGuardHome_status"
  14. s = mp:section(TypedSection, "AdGuardHome")
  15. s.anonymous=true
  16. s.addremove=false
  17. ---- enable
  18. o = s:option(Flag, "enabled", translate("启用广告屏蔽"))
  19. o.default = 0
  20. o.rmempty = false
  21. ---- httport
  22. o =s:option(Value,"httpport",translate("网页管理端口(覆盖配置)"))
  23. o.placeholder=3000
  24. o.default=3000
  25. o.datatype="port"
  26. o.rmempty=false
  27. o.description = translate("<input type=\"button\" style=\"width:180px;border-color:Teal; text-align:center;font-weight:bold;color:Green;\" value=\"AdGuardHome Web:"..httpport.."\" onclick=\"window.open('http://'+window.location.hostname+':"..httpport.."/')\"/>")
  28. ---- update warning not safe
  29. local e=luci.sys.exec(binpath.." --check-config 2>&1")
  30. e=string.match(e,'(v%d+\.%d+\.%d+)')
  31. o=s:option(Button,"restart",translate("手动更新"))
  32. o.inputtitle=translate("更新核心版本")
  33. if (e==nil) then
  34. e="not found"
  35. end
  36. o.description=string.format(translate("目前运行主程序版本").."<strong><font color=\"green\">: %s </font></strong>",e)
  37. o.inputstyle="reload"
  38. o.write=function()
  39. luci.sys.exec("bash /usr/share/AdGuardHome/update_core.sh 2>&1")
  40. luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
  41. end
  42. ---- port warning not safe
  43. local port=luci.sys.exec("awk '/ port:/{printf($2)}' "..configpath.." 2>nul")
  44. ---- Redirect
  45. o = s:option(ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
  46. o.placeholder = "none"
  47. o:value("none", translate("none"))
  48. o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
  49. o:value("redirect", translate("Redirect 53 port to AdGuardHome"))
  50. o.default = "none"
  51. o.rempty = false
  52. ---- bin path
  53. o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download"))
  54. o.default = "/usr/bin/AdGuardHome/AdGuardHome"
  55. o.datatype = "string"
  56. o.rempty = false
  57. ---- config path
  58. o = s:option(Value, "configpath", translate("Config Path"), translate("AdGuardHome config path"))
  59. o.default = "/etc/AdGuardHome.yaml"
  60. o.datatype = "string"
  61. o.rempty = false
  62. ---- work dir
  63. o = s:option(Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir"))
  64. o.default = "/usr/bin/AdGuardHome"
  65. o.datatype = "string"
  66. o.rempty = false
  67. ---- log file
  68. o = s:option(Value, "logfile", translate("Log File"), translate("AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"))
  69. o.default = ""
  70. o.datatype = "string"
  71. o.rempty = false
  72. ---- debug
  73. o = s:option(Flag, "verbose", translate("verbose debug"))
  74. o.default = 0
  75. o.rmempty = false
  76. local apply = luci.http.formvalue("cbi.apply")
  77. if apply then
  78. io.popen("/etc/init.d/AdGuardHome reload")
  79. end
  80. return mp