From a919b6b5fe537a7406d4081b7de8c4cb9e305743 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 20 Jul 2011 14:26:02 +0000 Subject: Prevent config from uncommenting multiple access_log or cache_dir lines, report error instead --- squid-model.lua | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'squid-model.lua') diff --git a/squid-model.lua b/squid-model.lua index 43c333e..2523462 100644 --- a/squid-model.lua +++ b/squid-model.lua @@ -195,17 +195,18 @@ end update_config = function(newconfig) local success, newconfig = validate_config(newconfig) + + local lastport, lastlog, lastcache, lastauth + local didports = {} + local didlog, didcache + local didauths = {} + local lines = {} + if success then configcontent = configcontent or fs.read_file(squidconf) or "" - - local lastport, lastlog, lastcache, lastauth - local didports = {} - local didlog, didcache - local didauths = {} local reverseports = {} for i,port in ipairs(newconfig.value.httpports.value) do reverseports[port] = i end local reverseauths = {} for i,auth in ipairs(newconfig.value.authmethod.value) do reverseauths[auth] = i end - local lines = {} -- first loop to comment out / uncomment existing lines local linenum = 0 for line in string.gmatch(configcontent, "([^\n]*)\n?") do @@ -226,6 +227,10 @@ update_config = function(newconfig) if (newconfig.value.accesslog.value and second == "none") or (not newconfig.value.accesslog.value and second ~= "none") then line = "# "..line + elseif didlog then + success = false + newconfig.value.accesslog.errtxt = "There are multiple access_log lines" + break else didlog = true end @@ -235,6 +240,10 @@ update_config = function(newconfig) if (newconfig.value.diskcache.value and second == "null") or (not newconfig.value.diskcache.value and second ~= "null") then line = "# "..line + elseif didcache then + success = false + newconfig.value.diskcache.errtxt = "There are multiple cache_dir lines" + break else didcache = true end @@ -252,7 +261,8 @@ update_config = function(newconfig) end lines[#lines+1] = line end - + end + if success then -- We've gone through the file, now check to see if everything is done local tobedone = {} local line -- cgit v1.2.3