luci-app-adblock: sync with adblock 2.6.0
[project/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / configuration_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 adbinput = "/etc/config/adblock"
7
8 if not nixio.fs.access(adbinput) then
9         m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
10         return m
11 end
12
13 m = SimpleForm("input", nil)
14 m:append(Template("adblock/config_css"))
15
16 s = m:section(SimpleSection, nil,
17         translate("This form allows you to modify the content of the main adblock configuration file (/etc/config/adblock)."))
18
19 f = s:option(TextValue, "data")
20 f.rows = 20
21 f.rmempty = true
22
23 function f.cfgvalue()
24         return nixio.fs.readfile(adbinput) or ""
25 end
26
27 function f.write(self, section, data)
28         return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
29 end
30
31 function s.handle(self, state, data)
32         return true
33 end
34
35 return m