luci-app-adblock: sync with adblock 2.6.0
[project/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / whitelist_tab.lua
1 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
4 local fs = require("nixio.fs")
5 local util = require("luci.util")
6 local uci = require("uci")
7 local adbinput = uci.get("adblock", "global", "adb_whitelist") or "/etc/adblock/adblock.whitelist"
8
9 if not nixio.fs.access(adbinput) then
10         m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
11         return m
12 end
13
14 m = SimpleForm("input", nil)
15 m:append(Template("adblock/config_css"))
16
17 s = m:section(SimpleSection, nil,
18         translatef("This form allows you to modify the content of the adblock whitelist (%s).<br />", adbinput)
19         .. translate("Please add only one domain per line. Comments introduced with '#' are allowed - ip addresses, wildcards and regex are not."))
20
21 f = s:option(TextValue, "data")
22 f.datatype = "string"
23 f.rows = 20
24 f.rmempty = true
25
26 function f.cfgvalue()
27         return nixio.fs.readfile(adbinput) or ""
28 end
29
30 function f.write(self, section, data)
31         return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
32 end
33
34 function s.handle(self, state, data)
35         return true
36 end
37
38 return m