summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--squid-cfilter-html.lsp21
-rw-r--r--squid-controller.lua17
-rw-r--r--squid-model.lua127
4 files changed, 154 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 75a7491..612fb61 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ APP_DIST=squid-controller.lua \
squid-model.lua \
squid-basic-html.lsp \
squid-advanced-html.lsp \
+ squid-cfilter-html.lsp \
squid.menu
EXTRA_DIST=README Makefile config.mk
diff --git a/squid-cfilter-html.lsp b/squid-cfilter-html.lsp
index 89c8aab..faddfdf 100644
--- a/squid-cfilter-html.lsp
+++ b/squid-cfilter-html.lsp
@@ -18,14 +18,14 @@
end
?>
-<h1>Content Filter</1>
+<h1>Content Filter</h1>
DansGuardian is web content filtering software. It works as a web proxy,
making web requests in behalf of the client, and inspecting the returned
content before passing on to the client. DansGuardian uses phraselists to
identify harmful content. This means that updated "blacklists" are
generally not necessary. DansGuardian must be used in combination with a
"smart proxy", such as squid.
-<b>This page defines the basic network configuration settings for DansGuardian.</b><br>
+<b>This page defines the basic network configuration settings for DansGuardian.</b><br><br>
<h1>Status</h1>
<form action="" method="POST">
@@ -38,10 +38,11 @@ generally not necessary. DansGuardian must be used in combination with a
</form>
<pre style="color: #ff2020;"><? io.write( service.message ) ?></pre><br>
+<pre style="color: #ff2020;"><? io.write( service.cfgerr ) ?></pre><br>
This process runs as a service. When you make and save changes, the configuration
files for the service are changed. However, the changes will not be <i>applied</i>
-until you restart the service.<br><br>
+until you restart the service.<br><br><br>
<form action="" method="POST">
<h1>Configuration</h1>
@@ -49,16 +50,16 @@ until you restart the service.<br><br>
These parameters define the interface and port that Dansguardian uses to accept connections.<br><br>
<table>
-<tr><td align="right"><b>filterip</b></td><td><input type="text" name="filterip" value="<? io.write( config.filterip.value ) ?>"></td></tr>
-<tr><td align="right"><b>filterport</b></td><td><input type="text" name="filterport" value="<? io.write( config.filterport.value ) ?>"></td></tr>
+<tr><td align="right"><b>filterip</b></td><td><input type="text" name="filterip" value="<? io.write( config.filterip.value ) ?>" style="width:100px"></td></tr>
+<tr><td align="right"><b>filterport</b></td><td><input type="text" name="filterport" value="<? io.write( config.filterport.value ) ?>" style="width:100px"></td></tr>
</table><br>
<h2>Proxy service</h2>
These parameters define the ip address and port that Dansguardian should forward requests on to.<br><br>
<table>
-<tr><td align="right"><b>proxyip</b></td><td><input type="text" name="proxyip" value="<? io.write( config.proxyip.value ) ?>"></td></tr>
-<tr><td align="right"><b>proxyport</b></td><td><input type="text" name="proxyport" value="<? io.write( config.proxyport.value ) ?>"></td></tr>
+<tr><td align="right"><b>proxyip</b></td><td><input type="text" name="proxyip" value="<? io.write( config.proxyip.value ) ?>" style="width:100px"></td></tr>
+<tr><td align="right"><b>proxyport</b></td><td><input type="text" name="proxyport" value="<? io.write( config.proxyport.value ) ?>" style="width:100px"></td></tr>
</table><br>
<h2>Filter Actions</h2>
@@ -67,9 +68,9 @@ determines that the content is inappropriate. The "naughtynesslimit" is more sen
The author recommends 50 for "young children", 100 for "older children" and 160 for "young adults".<br><br>
<table>
-<tr><td align="right"><b>accessdeniedaddress</b></td><td><input type="text" name="accessdeniedaddress" value="<? io.write( config.accessdeniedaddress.value ) ?>"</td></tr>
-<tr><td align="right"><b>naughtynesslimit</b></td><td><input type="text" name="naughtynesslimit" value="<? io.write( config.naughtynesslimit.value ) ?>"></td></tr>
-</table><br>
+<tr><td align="right"><b>accessdeniedaddress</b></td><td><input type="text" name="accessdeniedaddress" value="<? io.write( config.accessdeniedaddress.value ) ?>" style="width:250px"></td></tr>
+<tr><td align="right"><b>naughtynesslimit</b></td><td><input type="text" name="naughtynesslimit" value="<? io.write( config.naughtynesslimit.value ) ?>" style="width:100px"></td></tr>
+</table><br><br>
<input type="submit" name="cmd" value="save" style="width:100px"><br>
</form>
diff --git a/squid-controller.lua b/squid-controller.lua
index f8e5f56..4e9c134 100644
--- a/squid-controller.lua
+++ b/squid-controller.lua
@@ -92,8 +92,21 @@ cfilter = function( self )
local service = { message="", status="", config="" }
- service.status = self.model.get_status()
- service.config = self.model.get_adv_config()
+ if self.clientdata.cmd then
+ if self.clientdata.cmd == "save" then
+ local conf = self.clientdata
+ local config = { filterip = conf.filterip, filterport = conf.filterport,
+ proxyip = conf.proxyip, proxyport = conf.proxyport,
+ accessdeniedaddress = conf.accessdeniedaddress,
+ naughtynesslimit = conf.naughtynesslimit
+ }
+
+ self.model.update_filter_config( config )
+ end
+ end
+
+ service.status = self.model.get_dansguardian_status()
+ service.config, service.cfgerr = self.model.get_filter_config()
return ( cfe ({ option = option, service = service }) )
end
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