From b60df8c6a658b177115ff94fbc52a5d842a6938e Mon Sep 17 00:00:00 2001 From: Andreas Brodmann Date: Mon, 26 Nov 2007 18:47:26 +0000 Subject: update2 to /acf/squid git-svn-id: svn://svn.alpinelinux.org/acf/squid/trunk@369 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dansguardian-controller.lua | 68 ++++++++++++++++++ dansguardian-general-html.lsp | 77 ++++++++++++++++++++ dansguardian-model.lua | 159 ++++++++++++++++++++++++++++++++++++++++++ dansguardian.menu | 4 ++ squid-cfilter-html.lsp | 77 -------------------- 5 files changed, 308 insertions(+), 77 deletions(-) create mode 100644 dansguardian-controller.lua create mode 100644 dansguardian-general-html.lsp create mode 100644 dansguardian-model.lua create mode 100644 dansguardian.menu delete mode 100644 squid-cfilter-html.lsp diff --git a/dansguardian-controller.lua b/dansguardian-controller.lua new file mode 100644 index 0000000..e749965 --- /dev/null +++ b/dansguardian-controller.lua @@ -0,0 +1,68 @@ +-- the squid controller + +module (..., package.seeall) + +-- Cause an http redirect to our "read" action +-- We use the self.conf table because it already has prefix,controller,etc +-- The redir code is defined in the application error handler (acf-controller) +local list_redir = function (self) + self.conf.action = "general" + self.conf.type = "redir" + error (self.conf) +end + +local pvt = {} +mvc= {} +mvc.on_load = function( self, parent ) + -- If they try to run a bogus action, send them to read + if ( rawget(self.worker, self.conf.action) == nil ) then + list_redir(self) + end + pvt.parent_on_exec = parent.worker.mvc.post_exec +end + +mvc.pre_exec = function( self ) + -- pvt.parent_on_exec () +end + +mvc.post_exec = function( self ) + return pvt.parent_on_exec() +end + +general = 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 + self.model.service_control( srvcmd ) + end + end + + 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_general_config( config ) + end + end + + service.status = self.model.get_status() + service.config, service.cfgerr = self.model.get_general_config() + + return ( cfe ({ option = option, service = service }) ) +end + diff --git a/dansguardian-general-html.lsp b/dansguardian-general-html.lsp new file mode 100644 index 0000000..faddfdf --- /dev/null +++ b/dansguardian-general-html.lsp @@ -0,0 +1,77 @@ + +

Content Filter

+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. +This page defines the basic network configuration settings for DansGuardian.

+ +

Status

+
+ + + + + +
dansguardian is: style="width:100px"> style="width:100px"> style="width:100px">
+
+ +

+

+ +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 applied +until you restart the service.


+ +
+

Configuration

+

Listener service

+These parameters define the interface and port that Dansguardian uses to accept connections.

+ + + + +
filterip
filterport

+ +

Proxy service

+These parameters define the ip address and port that Dansguardian should forward requests on to.

+ + + + +
proxyip
proxyport

+ +

Filter Actions

+These parameters define how sensitive the filter is, and where to redirect requests if the content filter +determines that the content is inappropriate. The "naughtynesslimit" is more sensitive the lower it is set. +The author recommends 50 for "young children", 100 for "older children" and 160 for "young adults".

+ + + + +
accessdeniedaddress
naughtynesslimit


+ +
+
+ diff --git a/dansguardian-model.lua b/dansguardian-model.lua new file mode 100644 index 0000000..f313eec --- /dev/null +++ b/dansguardian-model.lua @@ -0,0 +1,159 @@ +-- acf model for squid +-- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2 +module (..., package.seeall) + +dansguardiancfg = "/etc/dansguardian/dansguardian.conf" + +get_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 = "" + + local ptr = io.popen( "/etc/init.d/dansguardian " .. control, "r" ) + if ptr ~= nil then + local retmsg = ptr:read( "*a" ) + ptr:close() + if retmsg ~= nil then + retval = retmsg + else + retval = "service_control(): Failed to read output from initscript!\n" + end + else + retval = "service_control(): Failed to start/stop/restart service!\n" + end + + return retval +end + +get_general_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_general_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 + diff --git a/dansguardian.menu b/dansguardian.menu new file mode 100644 index 0000000..ec99d87 --- /dev/null +++ b/dansguardian.menu @@ -0,0 +1,4 @@ +# Prefix and controller are already known at this point +# Cat Group Tab Action +Web_Proxy Content_Filter - general +Web_Proxy Content_Filter_(Adv) advanced diff --git a/squid-cfilter-html.lsp b/squid-cfilter-html.lsp deleted file mode 100644 index faddfdf..0000000 --- a/squid-cfilter-html.lsp +++ /dev/null @@ -1,77 +0,0 @@ - -

Content Filter

-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. -This page defines the basic network configuration settings for DansGuardian.

- -

Status

-
- - - - - -
dansguardian is: style="width:100px"> style="width:100px"> style="width:100px">
-
- -

-

- -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 applied -until you restart the service.


- -
-

Configuration

-

Listener service

-These parameters define the interface and port that Dansguardian uses to accept connections.

- - - - -
filterip
filterport

- -

Proxy service

-These parameters define the ip address and port that Dansguardian should forward requests on to.

- - - - -
proxyip
proxyport

- -

Filter Actions

-These parameters define how sensitive the filter is, and where to redirect requests if the content filter -determines that the content is inappropriate. The "naughtynesslimit" is more sensitive the lower it is set. -The author recommends 50 for "young children", 100 for "older children" and 160 for "young adults".

- - - - -
accessdeniedaddress
naughtynesslimit


- -
-
- -- cgit v1.2.3