AdGuardHome.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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=uci:get("AdGuardHome","AdGuardHome","binpath")
  10. if (binpath==nil) then
  11. binpath="/usr/bin/AdGuardHome/AdGuardHome"
  12. end
  13. local httpport=luci.sys.exec("awk '/bind_port:/{printf($2);exit;}' "..configpath.." 2>nul")
  14. if (httpport=="") then
  15. httpport=uci:get("AdGuardHome","AdGuardHome","httpport")
  16. end
  17. mp = Map("AdGuardHome", translate("AdGuard Home"))
  18. mp.description = translate("免费和开源,功能强大的全网络广告和跟踪程序拦截DNS服务器")
  19. mp:section(SimpleSection).template = "AdGuardHome/AdGuardHome_status"
  20. s = mp:section(TypedSection, "AdGuardHome")
  21. s.anonymous=true
  22. s.addremove=false
  23. ---- enable
  24. o = s:option(Flag, "enabled", translate("启用广告屏蔽"))
  25. o.default = 0
  26. o.rmempty = false
  27. ---- httport
  28. o =s:option(Value,"httpport",translate("网页管理端口(覆盖配置)"))
  29. o.placeholder=3000
  30. o.default=3000
  31. o.datatype="port"
  32. o.rmempty=false
  33. 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.."/')\"/>")
  34. ---- update warning not safe
  35. if fs.access(configpath) then
  36. e=luci.sys.exec(binpath.." -c "..configpath.." --check-config 2>&1")
  37. e=string.match(e,'(v%d+\.%d+\.%d+)')
  38. if (e==nil) then
  39. e="not found bin"
  40. end
  41. else
  42. if fs.access(binpath) then
  43. maybev=uci:get("AdGuardHome","AdGuardHome","version")
  44. if (maybev==nil) then
  45. e=""
  46. else
  47. e="not find config"..maybev
  48. end
  49. else
  50. e="not found bin and config"
  51. end
  52. end
  53. o=s:option(Button,"restart",translate("手动更新"))
  54. o.inputtitle=translate("更新核心版本")
  55. o.template = "AdGuardHome/AdGuardHome_check"
  56. o.description=string.format(translate("目前运行主程序版本").."<strong><font color=\"green\">: %s </font></strong>",e)
  57. ---- port warning not safe
  58. local port=luci.sys.exec("awk '/ port:/{printf($2);exit;}' "..configpath.." 2>nul")
  59. if (port=="") then
  60. port="?"
  61. end
  62. ---- Redirect
  63. o = s:option(ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
  64. o.placeholder = "none"
  65. o:value("none", translate("none"))
  66. o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
  67. o:value("redirect", translate("Redirect 53 port to AdGuardHome"))
  68. o.default = "none"
  69. o.rempty = false
  70. ---- bin path
  71. o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download"))
  72. o.default = "/usr/bin/AdGuardHome/AdGuardHome"
  73. o.datatype = "string"
  74. o.rempty = false
  75. ---- config path
  76. o = s:option(Value, "configpath", translate("Config Path"), translate("AdGuardHome config path"))
  77. o.default = "/etc/AdGuardHome.yaml"
  78. o.datatype = "string"
  79. o.rempty = false
  80. ---- work dir
  81. o = s:option(Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir"))
  82. o.default = "/usr/bin/AdGuardHome"
  83. o.datatype = "string"
  84. o.rempty = false
  85. ---- log file
  86. o = s:option(Value, "logfile", translate("Log File"), translate("AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"))
  87. o.default = ""
  88. o.datatype = "string"
  89. o.rempty = false
  90. ---- debug
  91. o = s:option(Flag, "verbose", translate("verbose debug"))
  92. o.default = 0
  93. o.rmempty = false
  94. ---- gfwlist
  95. o=s:option(Button,"gfwadd",translate("add gfwlist to adguardhome"))
  96. o.inputtitle=translate("add")
  97. o.write=function()
  98. luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh 2>&1")
  99. luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
  100. end
  101. o = s:option(Value, "gfwupstream", translate("gfw upstream dns server"), translate("gfwlist domain upstream dns service"))
  102. o.default = "tcp://208.67.220.220#5353"
  103. o.datatype = "string"
  104. o.rmempty = false
  105. ---- chpass
  106. o = s:option(Value, "hashpass", translate("更改密码"), translate("点击计算后应用设置"))
  107. o.default = ""
  108. o.datatype = "string"
  109. o.rmempty = false
  110. o.template = "AdGuardHome/AdGuardHome_chpass"
  111. local apply = luci.http.formvalue("cbi.apply")
  112. if apply then
  113. io.popen("/etc/init.d/AdGuardHome reload")
  114. end
  115. return mp