base.lua 4.9 KB

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