summaryrefslogtreecommitdiffstats
path: root/squid-model.lua
diff options
context:
space:
mode:
authorAndreas Brodmann <andreas.brodmann@gmail.com>2007-11-26 18:23:03 +0000
committerAndreas Brodmann <andreas.brodmann@gmail.com>2007-11-26 18:23:03 +0000
commitfe04e58f47a99e0adf8df823e5d2e12efb788c96 (patch)
tree254eff002b7accc4655a72237625b58b4aca1616 /squid-model.lua
parent31f83752e43f441acaffa5c516f59f57005e802e (diff)
downloadacf-squid-fe04e58f47a99e0adf8df823e5d2e12efb788c96.tar.bz2
acf-squid-fe04e58f47a99e0adf8df823e5d2e12efb788c96.tar.xz
updated daily work on /acf/squid
git-svn-id: svn://svn.alpinelinux.org/acf/squid/trunk@367 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'squid-model.lua')
-rw-r--r--squid-model.lua127
1 files changed, 127 insertions, 0 deletions
diff --git a/squid-model.lua b/squid-model.lua
index 2ab54c8..9010039 100644
--- a/squid-model.lua
+++ b/squid-model.lua
@@ -2,6 +2,8 @@
-- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2
module (..., package.seeall)
+dansguardiancfg = "/etc/dansguardian/dansguardian.conf"
+
get_status = function()
local retval = "stopped"
@@ -18,6 +20,22 @@ get_status = function()
return retval
end
+get_dansguardian_status = function()
+
+ local retval = "stopped"
+
+ local ptr = io.popen( "/bin/pidof dansguardian" )
+ local pid = ptr:read( "*a" )
+ ptr:close()
+ if pid ~= nil then
+ if #pid > 1 then
+ retval = "running"
+ end
+ end
+
+ return retval
+end
+
service_control = function( control )
local retval = ""
@@ -58,8 +76,117 @@ end
get_filter_config = function()
+ local retval = {}
+ local error = ""
+
+ retval = { filterip = { label="Filter IP", type="text", value="" },
+ filterport = { label="Filter Port", type="text", value="" },
+ proxyip = { label="Proxy IP", type="text", value="" },
+ proxyport = { label="Proxy Port", type="text", value="" },
+ accessdeniedaddress = { label="AccessDeniedAddress", type="text", value="" },
+ naughtynesslimit = { label="NaughtynessLimit", type="text", value="" }
+ }
+
+ local fptr = io.open( dansguardiancfg, "r" )
+ if fptr ~= nil then
+ local line = fptr:read( "*l" )
+ while line ~= nil do
+ if string.sub( line, 1, 1 ) ~= "#" then
+ if string.sub( line, 1, 8 ) == "filterip" then
+ retval.filterip.value = get_cfg_value( line )
+ elseif string.sub( line, 1, 10 ) == "filterport" then
+ retval.filterport.value = get_cfg_value( line )
+ elseif string.sub( line, 1, 7 ) == "proxyip" then
+ retval.proxyip.value = get_cfg_value( line )
+ elseif string.sub( line, 1, 9 ) == "proxyport" then
+ retval.proxyport.value = get_cfg_value( line )
+ elseif string.sub( line, 1, 19 ) == "accessdeniedaddress" then
+ retval.accessdeniedaddress.value = get_cfg_value( line )
+ end
+ end
+ line = fptr:read( "*l" ) -- read one config file
+ end
+ fptr:close()
+ else
+ error = "Failed to open /etc/dansguardian/dansguardian.conf file!"
+ end
+
+ return retval, error
+end
+
+update_filter_config = function( config )
+
local retval = ""
+ local tmpfilename = os.tmpname()
+ local tmpfile = -1
+ local cfgptr = -1
+ local line = ""
+
+ tmpfile = io.open( tmpfilename, "wb+" )
+ if tmpfile == nil then
+ return "Failed to create temporary config file!"
+ end
+ cfgptr = io.open( dansguardiancfg, "r" )
+ if cfgptr == nil then
+ tmpfile:close()
+ os.remove( tmpfilename )
+ return "Failed to open " .. dansguardiancfg .. "!"
+ end
+
+ line = cfgptr:read( "*l" )
+ while line ~= nil do
+ if string.sub( line, 1, 8 ) == "filterip" then
+ tmpfile:write( "filterip = " .. config.filterip .. "\n" )
+ elseif string.sub( line, 1, 10 ) == "filterport" then
+ tmpfile:write( "filterport = " .. config.filterport .. "\n" )
+ elseif string.sub( line, 1, 7 ) == "proxyip" then
+ tmpfile:write( "proxyip = " .. config.proxyip .. "\n" )
+ elseif string.sub( line, 1, 9 ) == "proxyport" then
+ tmpfile:write( "proxyport = " .. config.proxyport .. "\n" )
+ elseif string.sub( line, 1, 19 ) == "accessdeniedaddress" then
+ tmpfile:write( "accessdeniedaddress = " .. config.accessdeniedaddress .. "\n" )
+ else
+ tmpfile:write( line .. "\n" )
+ end
+ line = cfgptr:read( "*l" )
+ end
+
+ tmpfile:close()
+ cfgptr:close()
+
+ os.rename( tmpfilename, dansguardiancfg )
+
+ return retval
+end
+
+get_cfg_value = function( str )
+
+ local retval = ""
+ local pos = 1
+ local found = false
+ local found2 = false
+
+ while not found and pos < #str -1 do
+ if string.sub( str, pos, pos ) == "=" then
+ found = true
+ end
+ pos = pos + 1
+ end
+
+ if found then
+ pos = pos - 1
+ while not found2 and pos < #str -1 do
+ if string.sub( str, pos+1, pos+1 ) ~= " " then
+ found2 = true
+ end
+ pos = pos + 1
+ end
+ end
+
+ if found2 then
+ retval = string.sub( str, pos )
+ end
return retval
end