base.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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>/dev/null")
  14. if (httpport=="") then
  15. httpport=uci:get("AdGuardHome","AdGuardHome","httpport") or "3000"
  16. end
  17. mp = Map("AdGuardHome", "AdGuard Home")
  18. mp.description = translate("Free and open source, powerful network-wide ads & trackers blocking DNS server.")
  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("Enable adblock"))
  25. o.default = 0
  26. o.rmempty = false
  27. ---- httpport
  28. o =s:option(Value,"httpport",translate("Browser management port"))
  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:210px;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. version=uci:get("AdGuardHome","AdGuardHome","version")
  36. e=""
  37. if not fs.access(configpath) then
  38. e=e.." no config"
  39. end
  40. if not fs.access(binpath) then
  41. e=e.." no bin"
  42. else
  43. if (version ~= nil) then
  44. e=version..e
  45. else
  46. e="unknown"..e
  47. end
  48. end
  49. o=s:option(Button,"restart",translate("Update"))
  50. o.inputtitle=translate("Update core version")
  51. o.template = "AdGuardHome/AdGuardHome_check"
  52. o.description=string.format(translate("core version got last time:").."<strong><font id=\"updateversion\" color=\"green\">%s </font></strong>",e)
  53. ---- port warning not safe
  54. local port=luci.sys.exec("awk '/ port:/{printf($2);exit;}' "..configpath.." 2>nul")
  55. if (port=="") then
  56. port="?"
  57. end
  58. ---- Redirect
  59. o = s:option(ListValue, "redirect", port..translate("Redirect"), translate("AdGuardHome redirect mode"))
  60. o.placeholder = "none"
  61. o:value("none", translate("none"))
  62. o:value("dnsmasq-upstream", translate("Run as dnsmasq upstream server"))
  63. o:value("redirect", translate("Redirect 53 port to AdGuardHome"))
  64. o.default = "none"
  65. ---- bin path
  66. o = s:option(Value, "binpath", translate("Bin Path"), translate("AdGuardHome Bin path if no bin will auto download"))
  67. o.default = "/usr/bin/AdGuardHome/AdGuardHome"
  68. o.datatype = "string"
  69. --- upx
  70. o = s:option(ListValue, "upxflag", translate("use upx to compress bin after download"))
  71. o:value("", translate("none"))
  72. o:value("-1", translate("compress faster"))
  73. o:value("-9", translate("compress better"))
  74. o:value("--best", translate("compress best(can be slow for big files)"))
  75. o:value("--brute", translate("try all available compression methods & filters [slow]"))
  76. o:value("--ultra-brute", translate("try even more compression variants [very slow]"))
  77. o.default = ""
  78. o.description=translate("bin use less space,but may have compatibility issues")
  79. ---- config path
  80. o = s:option(Value, "configpath", translate("Config Path"), translate("AdGuardHome config path"))
  81. o.default = "/etc/AdGuardHome.yaml"
  82. o.datatype = "string"
  83. ---- work dir
  84. o = s:option(Value, "workdir", translate("Work dir"), translate("AdGuardHome work dir include rules,audit log and database"))
  85. o.default = "/usr/bin/AdGuardHome"
  86. o.datatype = "string"
  87. ---- log file
  88. o = s:option(Value, "logfile", translate("Runtime log file"), translate("AdGuardHome runtime Log file if 'syslog': write to system log;if empty no log"))
  89. o.default = ""
  90. o.datatype = "string"
  91. ---- debug
  92. o = s:option(Flag, "verbose", translate("Verbose log"))
  93. o.default = 0
  94. ---- gfwlist
  95. local a=luci.sys.call("grep -m 1 -q programadd "..configpath)
  96. if (a==0) then
  97. a="Added"
  98. else
  99. a="Not added"
  100. end
  101. o=s:option(Button,"gfwadd",translate("Add gfwlist"),translate(a))
  102. o.inputtitle=translate("Add")
  103. o.write=function()
  104. luci.sys.exec("sh /usr/share/AdGuardHome/gfw2adg.sh 2>&1")
  105. luci.http.redirect(luci.dispatcher.build_url("admin","services","AdGuardHome"))
  106. end
  107. o = s:option(Value, "gfwupstream", translate("Gfwlist upstream dns server"), translate("Gfwlist domain upstream dns service"))
  108. o.default = "tcp://208.67.220.220#5353"
  109. o.datatype = "string"
  110. ---- chpass
  111. o = s:option(Value, "hashpass", translate("Change browser management password"), translate("Press load culculate model and culculate finally save/apply"))
  112. o.default = ""
  113. o.datatype = "string"
  114. o.template = "AdGuardHome/AdGuardHome_chpass"
  115. local apply = luci.http.formvalue("cbi.apply")
  116. if apply then
  117. io.popen("/etc/init.d/AdGuardHome reload &")
  118. end
  119. return mp