035b99e5e31c72283a1e06b44aed9e764ac1021f
[project/luci.git] / applications / luci-app-adblock / luasrc / model / cbi / adblock / configuration_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 adbinput = "/etc/config/adblock"
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 translate("This form allows you to modify the content of the main adblock configuration file (/etc/config/adblock)."))
19
20 f = s:option(TextValue, "data")
21         f.rmempty = true
22         f.rows = 20
23
24         function f.cfgvalue()
25                 return nixio.fs.readfile(adbinput) or ""
26         end
27
28         function f.write(self, section, data)
29                 return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
30         end
31
32         function s.handle(self, state, data)
33                 return true
34         end
35
36 return m