1 -- Copyright 2016-2018 Stan Grishin <stangri@melmac.net>
2 -- Licensed to the public under the Apache License 2.0.
4 m = Map("simple-adblock", translate("Simple AdBlock Settings"))
6 h = m:section(NamedSection, "config", "simple-adblock", translate("Service Status"))
8 local packageName = "simple-adblock"
9 local uci = require "luci.model.uci".cursor()
10 local util = require "luci.util"
11 local enabledFlag = uci:get(packageName, "config", "enabled")
12 local status = util.ubus('service', 'list', { name = packageName })
13 if status and status[packageName] and status[packageName]['instances'] and status[packageName]['instances']['status'] and status[packageName]['instances']['status']['data'] and status[packageName]['instances']['status']['data']['status'] then
14 status = status[packageName]['instances']['status']['data']['status']
18 if status:match("Reloading") then
19 ds = h:option(DummyValue, "_dummy", translate("Service Status"))
20 ds.template = "simple-adblock/status"
23 en = h:option(Button, "__toggle")
24 if enabledFlag ~= "1" or status:match("Stopped") then
25 en.title = translate("Service is disabled/stopped")
26 en.inputtitle = translate("Enable/Start")
27 en.inputstyle = "apply"
28 if nixio.fs.access("/var/simple-adblock.cache") then
29 ds = h:option(DummyValue, "_dummy", translate("Service Status"))
30 ds.template = "simple-adblock/status"
31 ds.value = "Cache file containing " .. luci.util.trim(luci.sys.exec("wc -l < /var/simple-adblock.cache")) .. " domains found"
34 en.title = translate("Service is enabled/started")
35 en.inputtitle = translate("Stop/Disable")
36 en.inputstyle = "reset"
37 ds = h:option(DummyValue, "_dummy", translate("Service Status"))
38 ds.template = "simple-adblock/status"
40 if not status:match("Success") then
41 reload = h:option(Button, "__reload")
42 reload.title = translate("Service started with error")
43 reload.inputtitle = translate("Reload")
44 reload.inputstyle = "apply"
45 function reload.write()
46 luci.sys.exec("/etc/init.d/simple-adblock reload")
47 luci.http.redirect(luci.dispatcher.build_url("admin/services/" .. packageName))
52 enabledFlag = enabledFlag == "1" and "0" or "1"
53 uci:set(packageName, "config", "enabled", enabledFlag)
55 uci:commit(packageName)
56 if enabledFlag == "0" then
57 luci.sys.init.stop(packageName)
58 -- luci.sys.exec("/etc/init.d/simple-adblock killcache")
60 luci.sys.init.enable(packageName)
61 luci.sys.init.start(packageName)
63 luci.http.redirect(luci.dispatcher.build_url("admin/services/" .. packageName))
67 s = m:section(NamedSection, "config", "simple-adblock", translate("Configuration"))
69 s:tab("basic", translate("Basic Configuration"))
71 o2 = s:taboption("basic", ListValue, "verbosity", translate("Output Verbosity Setting"),translate("Controls system log and console output verbosity"))
72 o2:value("0", translate("Suppress output"))
73 o2:value("1", translate("Some output"))
74 o2:value("2", translate("Verbose output"))
78 o3 = s:taboption("basic", ListValue, "force_dns", translate("Force Router DNS"), translate("Forces Router DNS use on local devices, also known as DNS Hijacking"))
79 o3:value("0", translate("Let local devices use their own DNS servers if set"))
80 o3:value("1", translate("Force Router DNS server to all local devices"))
84 local sysfs_path = "/sys/class/leds/"
86 if nixio.fs.access(sysfs_path) then
87 leds = nixio.util.consume((nixio.fs.dir(sysfs_path)))
90 o3 = s:taboption("basic", Value, "led", translate("LED to indicate status"), translate("Pick the LED not already used in")
91 .. [[ <a href="]] .. luci.dispatcher.build_url("admin/system/leds") .. [[">]]
92 .. translate("System LED Configuration") .. [[</a>]])
94 o3:value("", translate("none"))
95 for k, v in ipairs(leds) do
100 s:tab("advanced", translate("Advanced Configuration"))
102 o6 = s:taboption("advanced", Value, "boot_delay", translate("Delay (in seconds) for on-boot start"), translate("Run service after set delay on boot"))
104 o6.datatype = "range(1,600)"
106 o7 = s:taboption("advanced", Value, "download_timeout", translate("Download time-out (in seconds)"), translate("Stop the download if it is stalled for set number of seconds"))
108 o7.datatype = "range(1,60)"
110 o8 = s:taboption("advanced", ListValue, "debug", translate("Enable Debugging"), translate("Enables debug output to /tmp/simple-adblock.log"))
111 o8:value("", translate("Disable Debugging"))
112 o8:value("1", translate("Enable Debugging"))
117 s2 = m:section(NamedSection, "config", "simple-adblock", translate("Whitelist and Blocklist Management"))
118 -- Whitelisted Domains
119 d1 = s2:option(DynamicList, "whitelist_domain", translate("Whitelisted Domains"), translate("Individual domains to be whitelisted"))
123 -- Blacklisted Domains
124 d3 = s2:option(DynamicList, "blacklist_domain", translate("Blacklisted Domains"), translate("Individual domains to be blacklisted"))
128 -- Whitelisted Domains URLs
129 d2 = s2:option(DynamicList, "whitelist_domains_url", translate("Whitelisted Domain URLs"), translate("URLs to lists of domains to be whitelisted"))
133 -- Blacklisted Domains URLs
134 d4 = s2:option(DynamicList, "blacklist_domains_url", translate("Blacklisted Domain URLs"), translate("URLs to lists of domains to be blacklisted"))
138 -- Blacklisted Hosts URLs
139 d5 = s2:option(DynamicList, "blacklist_hosts_url", translate("Blacklisted Hosts URLs"), translate("URLs to lists of hosts to be blacklisted"))