summaryrefslogtreecommitdiffstats
path: root/squid-model.lua
diff options
context:
space:
mode:
authorAndreas Brodmann <andreas.brodmann@gmail.com>2007-12-28 08:23:22 +0000
committerAndreas Brodmann <andreas.brodmann@gmail.com>2007-12-28 08:23:22 +0000
commit269ff2d1bf02a57311d0682b16e937ab5d44b347 (patch)
tree0095acb56c724037b4cafd930004f81e1c5577c7 /squid-model.lua
parent4bbff2d10dbd88bb8781ada7c6e0549b51032018 (diff)
downloadacf-squid-269ff2d1bf02a57311d0682b16e937ab5d44b347.tar.bz2
acf-squid-269ff2d1bf02a57311d0682b16e937ab5d44b347.tar.xz
work in progress on controller and model
git-svn-id: svn://svn.alpinelinux.org/acf/squid/trunk@458 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'squid-model.lua')
-rw-r--r--squid-model.lua161
1 files changed, 156 insertions, 5 deletions
diff --git a/squid-model.lua b/squid-model.lua
index f56750c..3c80828 100644
--- a/squid-model.lua
+++ b/squid-model.lua
@@ -86,12 +86,12 @@ get_adv_config = function()
local retval = ""
- local ptr = io.open( "/etc/squid/squid.conf", "r" )
+ local ptr = io.open( squidconf, "r" )
if ptr ~= nil then
local retcfg = ptr:read( "*a" )
ptr:close()
if retcfg == nil then
- retval = "\n\n Error: Failed to read /etc/squid/squid.conf!\n\n"
+ retval = "\n\n Error: Failed to read " .. squidconf .. "!\n\n"
else
retval = retcfg
end
@@ -102,14 +102,14 @@ end
update_adv_config = function( config )
- local retval = "Successfully updated /etc/squid/squid.conf!"
+ local retval = "Successfully updated " .. squidconf .. "!"
- local ptr = io.open( "/etc/squid/squid.conf", "wb+" )
+ local ptr = io.open( squidconf, "wb+" )
if ptr ~= nil then
ptr:write( config )
ptr:close()
else
- retval = "update_config(): Error, failed to open /etc/squid/squid.conf!\n"
+ retval = "update_config(): Error, failed to open " .. squidconf .. "!\n"
end
return retval
@@ -292,6 +292,31 @@ get_basic_config = function()
end
cfg1tok = nil
+ --- get cache_access log
+ local cfg1, error = get_conf_tag( "### ACF-SQUID-TAG-0003", "### ACF-SQUID-GAT-0003" )
+ if #error > 0 then
+ return config, error
+ end
+
+ cfg1tok = tokenizer.new( cfg1, "\n" )
+ done = false
+ local str1 = ""
+ while str1 ~= nil do
+ cfg1tok, str1 = tokenizer.next( cfg1tok )
+ if str1 ~= nil then
+ if string.sub( str1, 1, 16 ) == "cache_access_log" then
+ config.accesslog.value = "yes"
+ elseif string.sub( str1, 1, 17 ) == "#cache_access_log" or
+ string.sub( str1, 1, 18 ) == "# cache_access_log" then
+ config.accesslog.value = "no"
+ end
+ end
+ end
+ if config.accesslog.value == "" then
+ return nil, "Corrupt squid.conf! Missing 'cache_access_log' statement!"
+ end
+ cfg1tok = nil
+
--- authentication method
local cfg1, error = get_conf_tag( "### ACF-SQUID-TAG-0004", "### ACF-SQUID-GAT-0004" )
if #error > 0 then
@@ -373,3 +398,129 @@ get_basic_config = function()
return config, error
end
+config_preblock_copy = function( fromfile, tofile, tag )
+
+ local done = false
+ local line = ""
+ while not done do
+ line = fromfile:read( "*l" )
+ tofile:write( line .. "\n" )
+ if string.sub( line, 1, #tag ) == tag then
+ done = true
+ end
+ end
+end
+
+copy_postblock_copy = function( fromfile, tofile )
+
+ local done = false
+ local line = ""
+ while not done do
+ line = fromfile:read( "*l" )
+ if line ~= nil then
+ tmpfile:write( line .. "\n" )
+ else
+ done = true
+ end
+ end
+end
+
+update_basic_config = function( config )
+
+ local error = ""
+
+ --- put proxyip, proxyport
+ local tmpfilename = os.tmpname()
+ local tmpfile = io.open( tmpfilename, "w+" )
+ local cfgfile = io.open( squidconf, "r" )
+ local done = false
+
+ config_preblock_copy( cfgfile, tmpfile, "### ACF-SQUID-TAG-0001" )
+
+ local don2 = false
+ while not done do
+ line = cfgfile:read( "*l" )
+ if string.sub( line, 1, 22 ) == "### ACF-SQUID-GAT-0001" then
+ done = true
+ end
+ if don2 then
+ tmpfile:write( line .. "\n" )
+ else
+ if string.sub( line, 1, 10 ) == "http_port " then
+ don2 = true
+ tmpfile:write( "http_port " .. config.proxyip.value .. ":" .. config.proxyport.value .. "\n" )
+ else
+ tmpfile:write( line .. "\n" )
+ end
+ end
+ end
+
+ config_postblock_copy( cfgfile, tmpfile )
+
+ tmpfile:close()
+ cfgfile:close()
+ os.rename( tmpfilename, squidconf )
+
+
+ --- put filterip, filterport
+ tmpfilename = os.tmpname()
+ tmpfile = io.open( tmpfilename, "w+" )
+ cfgfile = io.open( squidconf, "r" )
+ done = false
+
+ config_preblock_copy( cfgfile, tmpfile, "### ACF-SQUID-TAG-0007" )
+
+ local don2 = false
+ while not done do
+ line = cfgfile:read( "*l" )
+ if string.sub( line, 1, 22 ) == "### ACF-SQUID-GAT-0007" then
+ done = true
+ end
+ if don2 then
+ tmpfile:write( line .. "\n" )
+ else
+ if string.sub( line, 1, 11 ) == "cache_peer " then
+ don2 = true
+ local lap = 0
+ local cfg2tok = tokenizer.new( line, " " )
+ local tmpstr = ""
+ while tmpstr ~= nil do
+
+ end
+
+ tmpfile:write( "http_port " .. config.proxyip.value .. ":" .. config.proxyport.value .. "\n" )
+ else
+ tmpfile:write( line .. "\n" )
+ end
+ end
+ end
+
+ config_postblock_copy( cfgfile, tmpfile )
+
+ tmpfile:close()
+ cfgfile:close()
+ os.rename( tmpfilename, squidconf )
+
+
+ --- disk cache parameters
+ tmpfilename = os.tmpname()
+ tmpfile = io.open( tmpfilename, "w+" )
+ cfgfile = io.open( squidconf, "r" )
+ done = false
+
+ config_preblock_copy( cfgfile, tmpfile, "### ACF-SQUID-TAG-0002" )
+
+ while not done do
+ line = cfgfile:read( "*l" )
+
+ end
+
+ config_postblock_copy( cfgfile, tmpfile )
+
+ tmpfile:close()
+ cfgfile:close()
+ os.rename( tmpfilename, squidconf )
+
+ return error
+end
+