diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-09-29 18:01:28 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-09-29 18:01:28 +0000 |
commit | 06e38aae23a85a64ff3290417ecd74ff3d5fa849 (patch) | |
tree | 40171a162f22bf2dff222a29ecb1642c59db3eae /dansguardian-model.lua | |
parent | c76f1caee069b56be73b9e3995e92ba90f5cba37 (diff) | |
download | acf-dansguardian-06e38aae23a85a64ff3290417ecd74ff3d5fa849.tar.bz2 acf-dansguardian-06e38aae23a85a64ff3290417ecd74ff3d5fa849.tar.xz |
Removed getopts library and added functionality to format library as opts_to_table, table_to_opts, parse_configfile2, update_configfile2, get_section, and set_section. New functions work on strings, not files. Modified all code using getopts to use format instead. Fixed nil string bugs in TCPProxy. Fixed forward only bug in DNSCache.
git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1535 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'dansguardian-model.lua')
-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 |