diff options
author | Andreas Brodmann <andreas.brodmann@gmail.com> | 2007-12-28 08:23:22 +0000 |
---|---|---|
committer | Andreas Brodmann <andreas.brodmann@gmail.com> | 2007-12-28 08:23:22 +0000 |
commit | 269ff2d1bf02a57311d0682b16e937ab5d44b347 (patch) | |
tree | 0095acb56c724037b4cafd930004f81e1c5577c7 | |
parent | 4bbff2d10dbd88bb8781ada7c6e0549b51032018 (diff) | |
download | acf-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
-rw-r--r-- | squid-controller.lua | 19 | ||||
-rw-r--r-- | squid-model.lua | 161 |
2 files changed, 175 insertions, 5 deletions
diff --git a/squid-controller.lua b/squid-controller.lua index 4d3ffa5..c37b05b 100644 --- a/squid-controller.lua +++ b/squid-controller.lua @@ -46,6 +46,25 @@ basic = function( self ) end end + if self.clientdata.cmd then + local cmd = self.clientdata.cmd + if cmd == "save" then + local newconfig = { proxyip = { value=self.clientdata.proxyip, type="text", label="" }, + proxyport = { value=self.clientdata.proxyport, type="text", label="" }, + filterip = { value=self.clientdata.filterip, type="text", label="" }, + filterport = { value=self.clientdata.filterport, type="text", label="" }, + filterregex = { value=self.clientdata.filterregex, type="text", label="" }, + safeports = { value=self.clientdata.safeports, type="text", label="" }, + sslports = { value=self.clientdata.sslports, type="text", label="" }, + accesslog = { value=self.clientdata.accesslog, type="select", label="", option={ "yes", "no" } }, + diskcache = { value=self.clientdata.diskcache, type="select", label="", option={ "yes", "no" } }, + authmethod = { value=self.clientdata.authmethod, type="text", label="" } + } + + self.model.update_basic_config( newconfig ) + end + end + service.status = self.model.get_status() service.config, service.error = self.model.get_basic_config() 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 + |