summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--dansguardian-advanced-html.lsp58
-rw-r--r--dansguardian-controller.lua56
-rw-r--r--dansguardian-edit-html.lsp34
-rw-r--r--dansguardian-model.lua144
-rw-r--r--dansguardian.menu2
6 files changed, 294 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 3b77e0c..009963b 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,8 @@ APP_DIST=squid-controller.lua \
dansguardian-controller.lua \
dansguardian-model.lua \
dansguardian-general-html.lsp \
+ dansguardian-advanced-html.lsp \
+ dansguardian-edit-html.lsp \
dansguardian-plain-html.lsp \
dansguardian.menu
diff --git a/dansguardian-advanced-html.lsp b/dansguardian-advanced-html.lsp
new file mode 100644
index 0000000..92c1d81
--- /dev/null
+++ b/dansguardian-advanced-html.lsp
@@ -0,0 +1,58 @@
+<?
+ local form = ...
+ local data = form.option
+ local service = form.service
+ local config = form.service.config
+
+ local srv1fill = ""
+ local srv2fill = "disabled"
+ if service.status == "running" then
+ srv1fill = "disabled"
+ srv2fill = ""
+ end
+
+ local ifthen = function( variable, value, result )
+ if variable == value then
+ io.write( result )
+ end
+ end
+
+?>
+<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 lets you manually configure the filter rule files for DansGuardian.</b><br><br>
+
+<h1>Status</h1>
+<form action="" method="POST">
+<table><tr>
+<td>dansguardian is: <b><? io.write( service.status ) ?> </b> </td>
+<td><input type="submit" name="srvcmd" value="start" <? io.write( srv1fill ) ?> style="width:100px"></td>
+<td><input type="submit" name="srvcmd" value="stop" <? io.write( srv2fill ) ?> style="width:100px"></td>
+<td><input type="submit" name="srvcmd" value="restart" <? io.write( srv2fill ) ?> style="width:100px"></td>
+</tr></table>
+</form>
+
+<pre style="color: #ff2020;"><? io.write( service.message ) ?></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><br>
+
+<h1>Configuration</h1>
+<pre style="color: #ff2020;"><? io.write( service.cfgerr ) ?></pre><br>
+<h2>Files</h2>
+Click on one of the files to edit it.<br><br>
+
+<table>
+<?
+ for k,v in ipairs( config.files ) do
+ io.write( "<tr><td><a href=\"" .. data.script .. data.prefix .. data.controller .. "/edit?name=" .. v .. "\">" .. v .. "</a></td></tr>\n" )
+ end
+?>
+</table>
+
diff --git a/dansguardian-controller.lua b/dansguardian-controller.lua
index db72884..3259f8c 100644
--- a/dansguardian-controller.lua
+++ b/dansguardian-controller.lua
@@ -66,6 +66,30 @@ general = function( self )
return ( cfe ({ option = option, service = service }) )
end
+advanced = function( self )
+
+ local option = { script = ENV["SCRIPT_NAME"],
+ prefix = self.conf.prefix,
+ controller = self.conf.controller,
+ action = self.conf.action,
+ extra = ""
+ }
+
+ local service = { message="", status="", config="" }
+
+ if self.clientdata.srvcmd then
+ srvcmd = self.clientdata.srvcmd
+ if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
+ service.message = self.model.service_control( srvcmd )
+ end
+ end
+
+ service.status = self.model.get_status()
+ service.config, service.cfgerr = self.model.get_advanced_config()
+
+ return ( cfe ({ option = option, service = service }) )
+end
+
plain = function( self )
local option = { script = ENV["SCRIPT_NAME"],
@@ -98,3 +122,35 @@ plain = function( self )
return ( cfe ({ option = option, service = service }) )
end
+edit = function( self )
+
+ if not self.clientdata.name then
+ list_redir( self )
+ end
+
+ local option = { script = ENV["SCRIPT_NAME"],
+ prefix = self.conf.prefix,
+ controller = self.conf.controller,
+ action = self.conf.action,
+ extra = ""
+ }
+
+ local service = { message="", status="", config="" }
+
+ if self.clientdata.cmd then
+ if self.clientdata.cmd == "save" then
+ self.model.update_edit_config( self.clientdata.name, self.clientdata.config )
+ end
+ end
+
+ service.status = self.model.get_status()
+ service.config, service.cfgerr = self.model.get_edit_config( self.clientdata.name )
+ service.name = self.clientdata.name
+
+ if service.cfgerr == "Hacker" then
+ list_redir( self )
+ end
+
+ return ( cfe ({ option = option, service = service }) )
+end
+
diff --git a/dansguardian-edit-html.lsp b/dansguardian-edit-html.lsp
new file mode 100644
index 0000000..d74ea5d
--- /dev/null
+++ b/dansguardian-edit-html.lsp
@@ -0,0 +1,34 @@
+<?
+ local form = ...
+ local data = form.option
+ local service = form.service
+ local config = form.service.config
+
+ local srv1fill = ""
+ local srv2fill = "disabled"
+ if service.status == "running" then
+ srv1fill = "disabled"
+ srv2fill = ""
+ end
+
+ local ifthen = function( variable, value, result )
+ if variable == value then
+ io.write( result )
+ end
+ end
+
+?>
+<h1>Content Filter (<? io.write( service.name ) ?>)</h1>
+
+<form action="" method="POST">
+<pre style="color: #ff2020;"><? io.write( service.cfgerr ) ?></pre><br>
+These parameters define the interface and port that Dansguardian uses to accept connections.<br><br>
+
+<table>
+<tr><td><textarea name="config" style="width:600px"><? io.write( service.config ) ?></textarea></td></tr>
+</table><br>
+<input type="hidden" name="name" value="<? io.write( service.name ) ?>">
+
+<input type="submit" name="cmd" value="save" style="width:100px"><br>
+</form>
+
diff --git a/dansguardian-model.lua b/dansguardian-model.lua
index 5289ee3..3660b37 100644
--- a/dansguardian-model.lua
+++ b/dansguardian-model.lua
@@ -2,7 +2,10 @@
-- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2
module (..., package.seeall)
+require "posix"
+
dansguardiancfg = "/etc/dansguardian/dansguardian.conf"
+dansguardiancfg2 = "/etc/dansguardian/dansguardianf1.conf"
get_status = function()
@@ -76,6 +79,22 @@ get_general_config = function()
else
error = "Failed to open " .. dansguardiancfg .. " file!"
end
+
+ local fptr2 = io.open( dansguardiancfg2, "r" )
+ if fptr2 ~= nil then
+ local line = fptr2:read( "*l" )
+ while line ~= nil do
+ if string.sub( line, 1, 1 ) ~= "#" then
+ if string.sub( line, 1, 16 ) == "naughtynesslimit" then
+ retval.naughtynesslimit.value = get_cfg_value( line )
+ end
+ end
+ line = fptr2:read( "*l" ) -- read one config file line
+ end
+ fptr2:close()
+ else
+ error = "Failed to open " .. dansguardiancfg2 .. " file!"
+ end
return retval, error
end
@@ -100,6 +119,50 @@ get_plain_config = function()
return retval, error
end
+get_edit_config = function( name )
+
+ local retval = ""
+ local error = ""
+
+ if not is_valid_configfile( name ) then
+ return "", "Hacker"
+ end
+
+ local fptr = io.open( "/etc/dansguardian/" .. name )
+ if fptr ~= nil then
+ retval = fptr:read( "*a" )
+ fptr:close()
+ if retval == nil then
+ retval = ""
+ error = "Failed to read /etc/dansguardian/" .. name .. " file!"
+ end
+ else
+ error = "Failed to open /etc/dansguardian/" .. name .. " file!"
+ end
+
+ return retval, error
+end
+
+update_edit_config = function( name, config )
+
+ local retval = ""
+
+ if not is_valid_configfile( name ) then
+ return "", "Hacker"
+ end
+
+ local fptr = io.open( "/etc/dansguardian/" .. name, "wb+" )
+ if fptr ~= nil then
+ fptr:write( config )
+ fptr:close()
+ retval = ""
+ else
+ error = "Failed to open /etc/dansguardian/" .. name .. " file!"
+ end
+
+ return retval
+end
+
update_general_config = function( config )
local retval = ""
@@ -140,9 +203,36 @@ update_general_config = function( config )
tmpfile:close()
cfgptr:close()
-
os.rename( tmpfilename, dansguardiancfg )
+ --- step 2 - dansguardiancfg2
+
+ tmpfile = io.open( tmpfilename, "wb+" )
+ if tmpfile == nil then
+ return "Failed to create temporary config file!"
+ end
+
+ cfgptr = io.open( dansguardiancfg2, "r" )
+ if cfgptr == nil then
+ tmpfile:close()
+ os.remove( tmpfilename )
+ return "Failed to open " .. dansguardiancfg2 .. "!"
+ end
+
+ line = cfgptr:read( "*l" )
+ while line ~= nil do
+ if string.sub( line, 1, 16 ) == "naughtynesslimit" then
+ tmpfile:write( "naughtynesslimit = " .. config.naughtynesslimit .. "\n" )
+ else
+ tmpfile:write( line .. "\n" )
+ end
+ line = cfgptr:read( "*l" )
+ end
+
+ tmpfile:close()
+ cfgptr:close()
+ os.rename( tmpfilename, dansguardiancfg2 )
+
return retval
end
@@ -194,3 +284,55 @@ get_cfg_value = function( str )
return retval
end
+get_advanced_config = function()
+
+ local retval = { files = {} }
+ local errmsg = ""
+
+ get_file_tree( retval.files, "/etc/dansguardian", "" )
+
+ return retval, errmsg
+end
+
+get_file_tree = function( treetable, dir, prefix )
+
+ local entries = posix.dir( dir )
+ local k = ""
+ local v = ""
+ for k,v in ipairs( entries ) do
+ local attrs = posix.stat( dir .. "/" .. v )
+ if attrs.type == "regular" and string.sub( v, -4) ~= ".gif" then
+ table.insert( treetable, prefix .. v )
+ end
+ end
+
+ entries = posix.dir( dir )
+ for k,v in ipairs( entries ) do
+ local attrs = posix.stat( dir .. "/" .. v )
+ if attrs.type == "directory" and v~= "." and v~= ".." then
+ get_file_tree( treetable, dir .. "/" .. v, prefix .. v .. "/" )
+ end
+ end
+
+ return
+end
+
+is_valid_configfile = function( name )
+
+ local retval = false
+ local ftable = {}
+ local k
+ local v
+
+
+ get_file_tree( ftable, "/etc/dansguardian", "" )
+
+ for k,v in ipairs( ftable ) do
+ if v == name then
+ retval = true
+ end
+ end
+
+ return retval
+end
+
diff --git a/dansguardian.menu b/dansguardian.menu
index ea2dbad..ea3414c 100644
--- a/dansguardian.menu
+++ b/dansguardian.menu
@@ -2,4 +2,4 @@
# Cat Group Tab Action
Web_Proxy Content_Filter - general
Web_Proxy Content_Filter_(Plain) - plain
-Web_Proxy Content_Filter_(Advanced) advanced
+Web_Proxy Content_Filter_(Advanced) - advanced