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