diff options
-rw-r--r-- | dansguardian-model.lua | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/dansguardian-model.lua b/dansguardian-model.lua index f8fba15..685ff67 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -3,9 +3,9 @@ module (..., package.seeall) -- Load libraries require("modelfunctions") -require("getopts") --require "posix" require("fs") +require("format") require("validator") -- Set variables @@ -95,7 +95,7 @@ read_general_config = function() naughtynesslimit = cfe({ label="NaughtynessLimit" }) } - local config = getopts.getoptsfromfile(dansguardiancfg, "") + local config = format.parse_configfile2(fs.read_file(dansguardiancfg), "") if config then if config.filterip then retval.filterip.value = config.filterip end if config.filterport then retval.filterport.value = config.filterport end @@ -104,7 +104,7 @@ read_general_config = function() if config.accessdeniedaddress then retval.accessdeniedaddress.value = string.sub(config.accessdeniedaddress, 2, -2) end end - config = getopts.getoptsfromfile(dansguardiancfg2, "") + config = format.parse_configfile2(fs.read_file(dansguardiancfg2), "") if config then if config.naughtynesslimit then retval.naughtynesslimit.value = config.naughtynesslimit end end @@ -116,16 +116,18 @@ update_general_config = function( config ) local success, config = validate_general_config(config) if success then - local a,b,c local text = fs.read_file(dansguardiancfg) or "" - a,b,c,text = getopts.setoptsinfile(text, "", "filterip", config.value.filterip.value) - a,b,c,text = getopts.setoptsinfile(text, "", "filterport", config.value.filterport.value) - a,b,c,text = getopts.setoptsinfile(text, "", "proxyip", config.value.proxyip.value) - a,b,c,text = getopts.setoptsinfile(text, "", "proxyport", config.value.proxyport.value) - a,b,c,text = getopts.setoptsinfile(text, "", "accessdeniedaddress", "'"..config.value.accessdeniedaddress.value.."'") - fs.write_file(dansguardiancfg, string.gsub(text, "\n+$", "")) - if not fs.is_file(dansguardiancfg2) then fs.create_file(dansguardiancfg2) end - getopts.setoptsinfile(dansguardiancfg2, "", "naughtynesslimit", config.value.naughtynesslimit.value) + + text = format.update_configfile2(text, "", "filterip", config.value.filterip.value) + text = format.update_configfile2(text, "", "filterport", config.value.filterport.value) + text = format.update_configfile2(text, "", "proxyip", config.value.proxyip.value) + text = format.update_configfile2(text, "", "proxyport", config.value.proxyport.value) + text = format.update_configfile2(text, "", "accessdeniedaddress", "'"..config.value.accessdeniedaddress.value.."'") + fs.write_file(dansguardiancfg, text) + + text = fs.read_file(dansguardiancfg2) or "" + text = format.update_configfile2(text, "", "naughtynesslimit", config.value.naughtynesslimit.value) + fs.write_file(dansguardiancfg2, text) else config.errtxt = "Failed to set config" end |