From 06e38aae23a85a64ff3290417ecd74ff3d5fa849 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 29 Sep 2008 18:01:28 +0000 Subject: 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 --- dansguardian-model.lua | 26 ++++++++++++++------------ 1 file 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 -- cgit v1.2.3