luci-app-adblock: fix function calls
[project/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / blacklist_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", "blacklist", "adb_src") or "/etc/adblock/adblock.blacklist"
8
9 if not nixio.fs.access(adbinput) then
10         m = SimpleForm("error", nil,
11                 translate("Input file not found, please check your configuration."))
12         m.reset = false
13         m.submit = false
14         return m
15 end
16
17 if nixio.fs.stat(adbinput).size > 524288 then
18         m = SimpleForm("error", nil,
19                 translate("The file size is too large for online editing in LuCI (> 512 KB). ")
20                 .. translate("Please edit this file directly in a terminal session."))
21         m.reset = false
22         m.submit = false
23         return m
24 end
25
26 m = SimpleForm("input", nil)
27 m:append(Template("adblock/config_css"))
28 m.submit = translate("Save")
29 m.reset = false
30
31 s = m:section(SimpleSection, nil,
32         translatef("This form allows you to modify the content of the adblock blacklist (%s).<br />", adbinput)
33         .. translate("Please add only one domain per line. Comments introduced with '#' are allowed - ip addresses, wildcards and regex are not."))
34
35 f = s:option(TextValue, "data")
36 f.datatype = "string"
37 f.rows = 20
38 f.rmempty = true
39
40 function f.cfgvalue()
41         return nixio.fs.readfile(adbinput) or ""
42 end
43
44 function f.write(self, section, data)
45         return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
46 end
47
48 function s.handle(self, state, data)
49         return true
50 end
51
52 return m