From 210f1c930825f872aa6003f37a8908a63c2c91f5 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 6 May 2008 15:11:55 +0000 Subject: Changing buttons to be cfe's (coming from controller) rather than created by the view-file. Reorganized the view-files so they look a bit more like other ACF's. git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1108 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dansguardian-advanced-html.lsp | 71 ++++++++++++------ dansguardian-category-html.lsp | 71 +++++++++++++----- dansguardian-controller.lua | 161 ++++++++++++++++++++++++++++------------- dansguardian-general-html.lsp | 88 ++++++++++++++-------- dansguardian-model.lua | 88 +++++++++++----------- dansguardian-plain-html.lsp | 78 ++++++++++++++------ dansguardian.menu | 2 +- 7 files changed, 367 insertions(+), 192 deletions(-) diff --git a/dansguardian-advanced-html.lsp b/dansguardian-advanced-html.lsp index 0f6b78a..73e6015 100644 --- a/dansguardian-advanced-html.lsp +++ b/dansguardian-advanced-html.lsp @@ -1,4 +1,5 @@ -

Content Filter

+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + +

SYSTEM INFO

+
+ +
+

General Information

DansGuardian is web content filtering software. It works as a web proxy, @@ -32,32 +50,37 @@ generally not necessary. DansGuardian must be used in combination with a This page lets you manually configure the filter rule files for DansGuardian.

-

Status

-
Program version
-
Process status
-
Process information
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.
-
-
Daemon control
-
> -> ->
-

-
+

Configuration

+ 0) then ?> +

Errors

+
Config errors
+
+
+ -

Configuration

-
-

Files

-

-Click on one of the files to edit it. -

+

Files

+
+ + + + + + -
FileSizeLast Modified
\n" ) + io.write( "\n" ) end ?> -
" .. v .. "
" .. v.path .. "" .. (v.size or "--") .."" .. (v.mtime or "--") .."
+ +
+

MANAGEMENT

+
+
+
Daemon control
> +> +> + 0) then ?>
+
+
diff --git a/dansguardian-category-html.lsp b/dansguardian-category-html.lsp index bbe1a20..1edcc71 100644 --- a/dansguardian-category-html.lsp +++ b/dansguardian-category-html.lsp @@ -1,4 +1,5 @@ -

Content Filter

+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + +

SYSTEM INFO

+
+ +
+ +

General Information

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 @@ -27,31 +46,27 @@ generally not necessary. DansGuardian must be used in combination with a "smart proxy", such as squid. This page lets you manually add/remove categories for DansGuardian.

-

Status

-
-
dansguardian is:
-
Daemon control
-
> -> ->
-
- -

-

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.

Categories

-

Add Category

To add a category, or to add a file to an existing category, please fill in the corresponding information below. (Due to a limitation with DansGuardian, all categories must be lowercase.)

-
Category name
-
Category files
weighted banned exception
-
Action
+
+
Category name
+
Category files
weighted banned exception
+ +
+ +

Delete Category

@@ -61,12 +76,28 @@ delete the link in the corresponding phraselist above. You will also need to edi above if you delete a category.

-
Categories available
(please check the ones you want to delete)
+
+
Categories available
(please check the ones you want to delete)
" .. v .. "
\n" ) + io.write( "
" .. v .. "\n" ) end ?> -
Action
+ + +
+

MANAGEMENT

+
+
+
Daemon control
> +> +> + 0) then ?>
+
+
diff --git a/dansguardian-controller.lua b/dansguardian-controller.lua index bcb7bed..9b19314 100644 --- a/dansguardian-controller.lua +++ b/dansguardian-controller.lua @@ -6,7 +6,20 @@ default_action = "general" general = function( self ) - local info = { status = { value = "stopped" }, version = { value = self.model.get_dansguardian_version() }, srvctrl = { value = srvctrl} }; + local service = {} + if self.clientdata.srvcmd then + local srvcmd = self.clientdata.srvcmd + if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then + service.srvcmdresult, service.message = self.model.service_control( srvcmd ) + end + end + + local info = { + status=self.model.get_status(), + version = self.model.get_dansguardian_version(), + autostart = self.model.get_autostart(), + srvctrl = { value = srvctrl} + } local option = { script = ENV["SCRIPT_NAME"], prefix = self.conf.prefix, @@ -15,30 +28,25 @@ general = function( self ) 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 - - 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 + -- Add a cmd button to the view + service.cmdsave = cfe({ name="cmdsave", + label="Save/Apply above settings", + value="Save", + type="submit", + }) + + if self.clientdata.cmdsave 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 ) + service.cmdsave.descr="* Changes has been saved!" end - + service.status = self.model.get_status() - info.status.value = service.status service.config, service.cfgerr = self.model.get_general_config() return ( cfe ({ option = option, service = service, info = info }) ) @@ -46,7 +54,20 @@ end advanced = function( self ) - local info = { status = { value = "stopped" }, version = { value = self.model.get_dansguardian_version() }, srvctrl = { value = srvctrl} }; + local service = {} + if self.clientdata.srvcmd then + local srvcmd = self.clientdata.srvcmd + if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then + service.srvcmdresult, service.message = self.model.service_control( srvcmd ) + end + end + + local info = { + status=self.model.get_status(), + version = self.model.get_dansguardian_version(), + autostart = self.model.get_autostart(), + srvctrl = { value = srvctrl} + } local option = { script = ENV["SCRIPT_NAME"], prefix = self.conf.prefix, @@ -55,17 +76,7 @@ advanced = function( self ) 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() - info.status.value = service.status service.config, service.cfgerr = self.model.get_advanced_config() return ( cfe ({ option = option, service = service, info = info }) ) @@ -73,34 +84,46 @@ end plain = function( self ) + local service = {} + if self.clientdata.srvcmd then + local srvcmd = self.clientdata.srvcmd + if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then + service.srvcmdresult, service.message = self.model.service_control( srvcmd ) + end + end + local option = { script = ENV["SCRIPT_NAME"], prefix = self.conf.prefix, controller = self.conf.controller, action = self.conf.action, extra = "" } + + local info = { + status=self.model.get_status(), + version = self.model.get_dansguardian_version(), + autostart = self.model.get_autostart(), + srvctrl = { value = srvctrl} + } - 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 - - if self.clientdata.cmd then - if self.clientdata.cmd == "save" then - local conf = self.clientdata - local config = conf.config - self.model.update_plain_config( config ) - end + -- Add a cmd button to the view + service.cmdsave = cfe({ name="cmdsave", + label="Save/Apply above settings", + value="Save", + type="submit", + }) + + if self.clientdata.cmdsave then + local conf = self.clientdata + local config = conf.config + self.model.update_plain_config( config ) + service.cmdsave.descr="* Changes has been saved!" end service.status = self.model.get_status() service.config, service.cfgerr = self.model.get_plain_config() - return ( cfe ({ option = option, service = service }) ) + return ( cfe ({ option = option, service = service, info = info }) ) end edit = function( self ) @@ -121,6 +144,7 @@ edit = function( self ) if self.clientdata.cmd then if self.clientdata.cmd == "save" then self.model.update_edit_config( self.clientdata.name, self.clientdata.config ) + redirect( self, "advanced" ) end end @@ -137,6 +161,22 @@ end category = function( self ) + local service = { message="", status="", config="", cfgerr="" } + + if self.clientdata.srvcmd then + local srvcmd = self.clientdata.srvcmd + if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then + service.srvcmdresult, service.message = self.model.service_control( srvcmd ) + end + end + + local info = { + status=self.model.get_status(), + version = self.model.get_dansguardian_version(), + autostart = self.model.get_autostart(), + srvctrl = { value = srvctrl} + } + local option = { script = ENV["SCRIPT_NAME"], prefix = self.conf.prefix, controller = self.conf.controller, @@ -144,10 +184,27 @@ category = function( self ) extra = "" } - local service = { message="", status="", config="", cfgerr="" } + -- Add a cmd button to the view + service.cmdadd = cfe({ + name="cmdadd", + label="Action", + value="Add", + type="submit", + disabled="yes", + errtxt="This button is currently out of order", + }) + + service.cmddelete = cfe({ + name="cmddelete", + label="Action", + value="Delete", + type="submit", + disabled="yes", + errtxt="This button is currently out of order", + }) service.config = self.model.get_categories() - return ( cfe ({ option = option, service = service }) ) + return ( cfe ({ option = option, service = service, info = info }) ) end diff --git a/dansguardian-general-html.lsp b/dansguardian-general-html.lsp index 10ea6b7..2a4ca5c 100644 --- a/dansguardian-general-html.lsp +++ b/dansguardian-general-html.lsp @@ -1,4 +1,5 @@ -

Content Filter

+ +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + +

SYSTEM INFO

+
+ +
+

General Information

DansGuardian is web content filtering software. It works as a web proxy, @@ -31,52 +49,64 @@ generally not necessary. DansGuardian must be used in combination with a This page defines the basic network configuration settings for DansGuardian.

-

Status

-
Program version
-
Process status
-
Process information
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.
-
-
Daemon control
-
> -> ->
-
- -

-

-

-

Configuration

-

+

Configuration

+

General

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

-
filterip
-
filterport
+
+
filterip
+
filterport
+
-

Proxy service

+

Proxy service

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

-
proxyip
-
proxyport
+
+
proxyip
+
proxyport
+
-

Filter Actions

+

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
+
+
accessdeniedaddress
+
naughtynesslimit
+

Save Changes

-
Save the above changes?
+
+ + 0) then ?> +
Config status
+ +
Process information
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.
+
+
+

MANAGEMENT

+
+
+
Daemon control
> +> +> + 0) then ?>
+
+
diff --git a/dansguardian-model.lua b/dansguardian-model.lua index 63694e2..b02b99b 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -1,61 +1,60 @@ --- acf model for squid -- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2 module (..., package.seeall) +-- Load libraries require "posix" require "format" +require("processinfo") +require("procps") +require("daemoncontrol") +-- Set variables dansguardiancfg = "/etc/dansguardian/dansguardian.conf" dansguardiancfg2 = "/etc/dansguardian/dansguardianf1.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 - +local processname = "dansguardian" +local packagename = "dansguardian" + +get_autostart = function() + local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) + local retval = cfe({ name="autostart", + label="Autostart sequence", + value=autostart_sequense, + errtxt=autostart_errtxt, + }) 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 +get_status = function() + local t = procps.pidof(procname) + local stats + if (t) and (#t > 0) then + stats = "Enabled" else - retval = "service_control(): Failed to start/stop/restart service!\n" + stats = "Disabled" end - + local retval = cfe({ name="status", + label="Program status", + value=stats, + }) return retval end -get_dansguardian_version = function() +service_control = function( cmd ) + local action = {value=cmd} + local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd) + action.descr=cmdmessage + action.errtxt=cmderror + return cmdresult,action +end - local retval = "" - - local ptr = io.popen( "/usr/sbin/dansguardian -v" ) - if ptr ~= nil then - retval = ptr:read( "*l" ) - ptr:close() - else - retval = "Error - Failed to program version" - end - + +get_dansguardian_version = function() + local value, errtxt = processinfo.package_version(packagename) + local retval = cfe({ name = "version", + label="Program version", + value=value, + errtxt=errtxt, + }) return retval end @@ -318,7 +317,10 @@ get_file_tree = function( treetable, dir, prefix ) 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 ) + local path = dir .. "/" .. v + local filedetails = fs.stat(path) + filedetails.path = prefix .. v + table.insert( treetable, filedetails ) end end @@ -344,7 +346,7 @@ is_valid_configfile = function( name ) get_file_tree( ftable, "/etc/dansguardian", "" ) for k,v in ipairs( ftable ) do - if v == name then + if v.path == name then retval = true end end diff --git a/dansguardian-plain-html.lsp b/dansguardian-plain-html.lsp index cf76317..7ef2847 100644 --- a/dansguardian-plain-html.lsp +++ b/dansguardian-plain-html.lsp @@ -1,4 +1,5 @@ + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + +

SYSTEM INFO

+
+ +
+

Content Filter (Plain Config File)

-

WARNING:

-

Modifying the DansGuardian configuration file is generally not necessary. -You must be familiar with the configuration file before proceeding.

+
+
Warning
+
Modifying the DansGuardian configuration file is generally not necessary. +You must be familiar with the configuration file before proceeding.
+
Information
+
These parameters define the interface and port that Dansguardian uses to accept connections.
+
-

Status

-
dansguardian is:
-
> -> ->
-
-

+

Configuration

+ -

-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

-

-

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

+

Save changes

+
+ + 0) then ?> +
Config status
+ + 0) then ?> +
Config status
+ - +
Process information
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.
-

Save Changes

-
Save the contents of the above box
+
+

MANAGEMENT

+
+
+
Daemon control
> +> +> + 0) then ?>
+
+
diff --git a/dansguardian.menu b/dansguardian.menu index c7f2580..d7d6be2 100644 --- a/dansguardian.menu +++ b/dansguardian.menu @@ -1,6 +1,6 @@ # Prefix and controller are already known at this point # Cat Group Tab Action -Applications 20Content_Filter Basic basic +Applications 20Content_Filter Basic general Applications 20Content_Filter Advanced advanced Applications 20Content_Filter Plain plain Applications 20Content_Filter Category category -- cgit v1.2.3