2018-05-18 16:17:31 +00:00
|
|
|
-- Copyright 2017-2018 Dirk Brenken (dev@brenken.org)
|
2017-03-25 20:58:51 +00:00
|
|
|
-- This is free software, licensed under the Apache License, Version 2.0
|
|
|
|
|
2018-07-21 20:32:16 +00:00
|
|
|
local fs = require("nixio.fs")
|
|
|
|
local util = require("luci.util")
|
|
|
|
local input = "/etc/config/adblock"
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2018-07-21 20:32:16 +00:00
|
|
|
if not fs.access(input) then
|
2017-03-25 20:58:51 +00:00
|
|
|
m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
|
2017-05-08 09:15:19 +00:00
|
|
|
m.reset = false
|
|
|
|
m.submit = false
|
2017-03-25 20:58:51 +00:00
|
|
|
return m
|
|
|
|
end
|
|
|
|
|
2018-07-21 20:32:16 +00:00
|
|
|
if fs.stat(input).size >= 102400 then
|
2018-05-18 16:17:31 +00:00
|
|
|
m = SimpleForm("error", nil,
|
|
|
|
translate("The file size is too large for online editing in LuCI (≥ 100 KB). ")
|
|
|
|
.. translate("Please edit this file directly in a terminal session."))
|
|
|
|
m.reset = false
|
|
|
|
m.submit = false
|
|
|
|
return m
|
|
|
|
end
|
|
|
|
|
2017-03-25 20:58:51 +00:00
|
|
|
m = SimpleForm("input", nil)
|
2018-11-14 09:45:18 +00:00
|
|
|
m:append(Template("adblock/adblock_css"))
|
2017-08-04 06:34:34 +00:00
|
|
|
m.submit = translate("Save")
|
2017-04-25 21:17:08 +00:00
|
|
|
m.reset = false
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
s = m:section(SimpleSection, nil,
|
2017-04-10 05:01:33 +00:00
|
|
|
translate("This form allows you to modify the content of the main adblock configuration file (/etc/config/adblock)."))
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
f = s:option(TextValue, "data")
|
2017-04-10 05:01:33 +00:00
|
|
|
f.rows = 20
|
|
|
|
f.rmempty = true
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
function f.cfgvalue()
|
2018-07-21 20:32:16 +00:00
|
|
|
return fs.readfile(input) or ""
|
2017-04-10 05:01:33 +00:00
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
function f.write(self, section, data)
|
2018-07-21 20:32:16 +00:00
|
|
|
return fs.writefile(input, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
function f.remove(self, section, value)
|
|
|
|
return fs.writefile(input, "")
|
2017-04-10 05:01:33 +00:00
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
2017-04-10 05:01:33 +00:00
|
|
|
function s.handle(self, state, data)
|
|
|
|
return true
|
|
|
|
end
|
2017-03-25 20:58:51 +00:00
|
|
|
|
|
|
|
return m
|