Commit 06e38aae authored by Ted Trask's avatar Ted Trask
Browse files

Removed getopts library and added functionality to format library as...

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
parent c76f1cae
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment