diff options
Diffstat (limited to 'squid-model.lua')
-rw-r--r-- | squid-model.lua | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/squid-model.lua b/squid-model.lua index 7e7fed7..0a080a2 100644 --- a/squid-model.lua +++ b/squid-model.lua @@ -5,6 +5,7 @@ module (..., package.seeall) require "format" squidconf = "/etc/squid/squid.conf" +squidtempl = "/etc/squid/squid.conf.template" --- the tokenizer functions - must be dislocated into a library later tokenizer = {} @@ -768,3 +769,94 @@ update_basic_config = function( config ) return error end +upd_authmethod = function( method ) + + local tmpfilename = os.tmpname() + local tmpfile = io.open( tmpfilename, "w+" ) + local cfgfile = io.open( squidconf, "r" ) + local error = "" + local line = "" + local done = false + + config_preblock_copy( cfgfile, tmpfile, "### ACF-SQUID-TAG-0004" ) + + while not done do + line = cfgfile:read( "*l" ) + if string.sub( line, 1, 7 ) == "### ACF" then + done = true + tmpfile:write( line .. "\n" ) + else + if string.sub( line, 1, 17 ) == "auth_param digest" then + if string.find( method, "D" ) ~= nil then + tmpfile:write( line .. "\n" ) + else + tmpfile:write( "#" .. line .. "\n" ) + end + elseif string.sub( line, 1, 18 ) == "#auth_param digest" then + if string.find( method, "D" ) ~= nil then + tmpfile:write( string.sub( line, 2 ) .. "\n" ) + else + tmpfile:write( line .. "\n" ) + end + elseif string.sub( line, 1, 15 ) == "auth_param ntlm" then + if string.find( method, "N" ) ~= nil then + tmpfile:write( line .. "\n" ) + else + tmpfile:write( "#" .. line .. "\n" ) + end + elseif string.sub( line, 1, 16 ) == "#auth_param ntlm" then + if string.find( method, "N" ) ~= nil then + tmpfile:write( string.sub( line, 2 ) .. "\n" ) + else + tmpfile:write( line .. "\n" ) + end + else + tmpfile:write( line .. "\n" ) + end + end + end + + config_postblock_copy( cfgfile, tmpfile ) + + tmpfile:close() + cfgfile:close() + os.rename( tmpfilename, squidconf ) + + return error +end + +dependancy_ok = function() + + local retval = false + local cfgfile = io.open( squidconf ) + local line = "" + + if cfgfile ~= nil then + line = cfgfile:read( "*l" ) + if string.sub( line, 1, 19 ) == "### ACF-SQUID-MAGIC" then + retval = true + end + end + + return retval +end + +create_cfg_from_template = function() + + local from = io.open( squidtempl ) + local to = io.open( squidconf, "wb+" ) + local line = "" + + while line ~= nil do + line = from:read( "*l" ) + if line ~= nil then + to:write( line .. "\n" ) + end + end + + from:close() + to:close() + + return +end + |