From 7ccca7213d3137b0764ef02165c44f4bd3373f45 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 12 Aug 2008 15:53:20 +0000 Subject: Modified dansguardian to use new status, startstop, and expert (replaced plain) actions. git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1380 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dansguardian-advanced-html.lsp | 40 +++-------- dansguardian-category-html.lsp | 42 ++--------- dansguardian-controller.lua | 152 ++++------------------------------------ dansguardian-edit-html.lsp | 15 ---- dansguardian-expert-html.lsp | 1 + dansguardian-general-html.lsp | 39 ++--------- dansguardian-model.lua | 81 +++------------------ dansguardian-plain-html.lsp | 83 ---------------------- dansguardian-startstop-html.lsp | 1 + dansguardian-status-html.lsp | 33 +-------- dansguardian.menu | 2 +- dansguardian.roles | 2 +- 12 files changed, 49 insertions(+), 442 deletions(-) create mode 120000 dansguardian-expert-html.lsp delete mode 100644 dansguardian-plain-html.lsp create mode 120000 dansguardian-startstop-html.lsp mode change 100644 => 120000 dansguardian-status-html.lsp diff --git a/dansguardian-advanced-html.lsp b/dansguardian-advanced-html.lsp index 7316774..24dd8fb 100644 --- a/dansguardian-advanced-html.lsp +++ b/dansguardian-advanced-html.lsp @@ -1,26 +1,13 @@ <% require("viewfunctions") - local form = ... + local form, viewlibrary = ... local data = form.option local service = form.service local config = form.service.config - local srv1fill = "" - local srv2fill = "disabled" - if form.info.status.value == "Enabled" then - srv1fill = "disabled" - srv2fill = "" - end - - local ifthen = function( variable, value, result ) - if variable == value then - io.write( result ) - end - end - %> -<% +<% --[[ DEBUG INFORMATION io.write("

DEBUGGING

DEBUG INFO: CFE

") io.write(html.cfe_unpack(form)) @@ -28,14 +15,9 @@ io.write("
") --]] %> -

SYSTEM INFO

-
-<% -local myform = form.info -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -
+<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %>

Configuration

<% if (#service.cfgerr > 0) then %> @@ -59,12 +41,6 @@ displayinfo(myform,tags,"viewonly") %> -

MANAGEMENT

-
-
-
Daemon control
> -> -> -<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %>
<% io.write( service.message.descr ) %>
<% end %>
-
-
+<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("startstop") +end %> diff --git a/dansguardian-category-html.lsp b/dansguardian-category-html.lsp index 6d6115c..2f94048 100644 --- a/dansguardian-category-html.lsp +++ b/dansguardian-category-html.lsp @@ -1,23 +1,6 @@ <% require("viewfunctions") - local form = ... - local data = form.option - local service = form.service - local config = form.service.config - - local srv1fill = "" - local srv2fill = "disabled" - if form.info.status.value == "Enabled" then - srv1fill = "disabled" - srv2fill = "" - end - - local ifthen = function( variable, value, result ) - if variable == value then - io.write( result ) - end - end - + local form, viewlibrary = ... %> <% @@ -28,14 +11,9 @@ io.write("") --]] %> -

SYSTEM INFO

-
-<% -local myform = form.info -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -
+<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %>

Modify Categories

@@ -73,12 +51,6 @@ end -

MANAGEMENT

-
-
-
Daemon control
> -> -> -<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %>
<% io.write( service.message.descr ) %>
<% end %>
-
-
+<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("startstop") +end %> diff --git a/dansguardian-controller.lua b/dansguardian-controller.lua index c88743f..97e2849 100644 --- a/dansguardian-controller.lua +++ b/dansguardian-controller.lua @@ -2,50 +2,22 @@ module (..., package.seeall) +require("controllerfunctions") + default_action = "status" status = function( self ) + return self.model.get_status() +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 = self.conf.script, - prefix = self.conf.prefix, - controller = self.conf.controller, - action = self.conf.action, - extra = "" - } - - return ( cfe ({ option = option, info = info }) ) +startstop = function( self ) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.get_status, self.clientdata) end + general = 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 info = { - status=self.model.get_status(), - version = self.model.get_dansguardian_version(), - autostart = self.model.get_autostart(), - srvctrl = { value = srvctrl} - } - - local option = { script = self.conf.script, - prefix = self.conf.prefix, - controller = self.conf.controller, - action = self.conf.action, - extra = "" - } - -- Add a cmd button to the view service.cmdsave = cfe({ name="cmdsave", label="Save/Apply above settings", @@ -64,29 +36,15 @@ general = function( self ) service.cmdsave.descr="* Changes has been saved!" end - service.status = self.model.get_status() service.config, service.cfgerr = self.model.get_general_config() - return ( cfe ({ option = option, service = service, info = info }) ) + return ( cfe ({ service = service }) ) end advanced = 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 info = { - status=self.model.get_status(), - version = self.model.get_dansguardian_version(), - autostart = self.model.get_autostart(), - srvctrl = { value = srvctrl} - } - local option = { script = self.conf.script, prefix = self.conf.prefix, controller = self.conf.controller, @@ -94,54 +52,13 @@ advanced = function( self ) extra = "" } - service.status = self.model.get_status() service.config, service.cfgerr = self.model.get_advanced_config() - return ( cfe ({ option = option, service = service, info = info }) ) + return ( cfe ({ option = option, service = service }) ) 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 = self.conf.script, - 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} - } - - -- 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, info = info }) ) +expert = function( self ) + return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.updateconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Set") end edit = function( self ) @@ -150,13 +67,6 @@ edit = function( self ) redirect( self ) end - local option = { script = self.conf.script, - prefix = self.conf.prefix, - controller = self.conf.controller, - action = self.conf.action, - extra = "" - } - local service = { message="", status="", config="" } if self.clientdata.cmd then @@ -166,7 +76,6 @@ edit = function( self ) 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 @@ -174,48 +83,13 @@ edit = function( self ) redirect( self ) end - return ( cfe ({ option = option, service = service }) ) + return ( cfe ({ service = service }) ) 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 = self.conf.script, - prefix = self.conf.prefix, - controller = self.conf.controller, - action = self.conf.action, - extra = "" - } - - -- Add a cmd button to the view - service.cmdadd = cfe({ - name="cmdadd", - label="Action", - value="Add", - type="submit", - }) - - service.cmdaddvalue = cfe({ - name="cmdaddvalue", - value="", - type="text", - }) - service.config = {} service.config.categories = cfe({ name="categories", @@ -224,7 +98,7 @@ category = function( self ) }) service.config.categories = self.model.get_categories() - return ( cfe ({ option = option, service = service, info = info }) ) + return ( cfe ({ service = service }) ) end editcategories = function( self ) diff --git a/dansguardian-edit-html.lsp b/dansguardian-edit-html.lsp index 3d1c0e6..99cf55a 100644 --- a/dansguardian-edit-html.lsp +++ b/dansguardian-edit-html.lsp @@ -1,21 +1,6 @@ <% 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 %>

Content Filter (<% io.write( service.name ) %>)

diff --git a/dansguardian-expert-html.lsp b/dansguardian-expert-html.lsp new file mode 120000 index 0000000..207f324 --- /dev/null +++ b/dansguardian-expert-html.lsp @@ -0,0 +1 @@ +../expert-html.lsp \ No newline at end of file diff --git a/dansguardian-general-html.lsp b/dansguardian-general-html.lsp index 09d1600..6c0ca60 100644 --- a/dansguardian-general-html.lsp +++ b/dansguardian-general-html.lsp @@ -1,23 +1,9 @@ <% require("viewfunctions") - local form = ... - local data = form.option + local form, viewlibrary = ... local service = form.service local config = form.service.config - local srv1fill = "" - local srv2fill = "disabled" - if form.info.status.value == "Enabled" then - srv1fill = "disabled" - srv2fill = "" - end - - local ifthen = function( variable, value, result ) - if variable == value then - io.write( result ) - end - end - %> <% @@ -28,14 +14,9 @@ io.write("") --]] %> -

SYSTEM INFO

-
-<% -local myform = form.info -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -
+<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("status") +end %>

Configuration

@@ -88,12 +69,6 @@ until you restart the service.
-

MANAGEMENT

-
-
-
Daemon control
> -> -> -<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %>
<% io.write( service.message.descr ) %>
<% end %>
-
-
+<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("startstop") +end %> diff --git a/dansguardian-model.lua b/dansguardian-model.lua index 3159644..7fb76a1 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -2,6 +2,7 @@ module (..., package.seeall) -- Load libraries +require("modelfunctions") require "posix" require "format" require("processinfo") @@ -46,48 +47,12 @@ local categoryfilecontent = { -- ################################################################################ -- PUBLIC FUNCTIONS -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 - get_status = function() - local t = procps.pidof(procname) - local stats - if (t) and (#t > 0) then - stats = "Enabled" - else - stats = "Disabled" - end - local retval = cfe({ name="status", - label="Program status", - value=stats, - }) - return retval + return modelfunctions.getstatus(processname, packagename, "Dans Guardian Status") end -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 - - -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 +startstop_service = function( action ) + return modelfunctions.startstop_service(processname, action) end get_general_config = function() @@ -146,24 +111,8 @@ get_general_config = function() return retval, error end -get_plain_config = function() - - local retval = "" - local error = "" - - local fptr = io.open( dansguardiancfg, "r" ) - if fptr ~= nil then - retval = fptr:read( "*a" ) - fptr:close() - if retval == nil then - retval = "" - error = "Failed to read " .. dansguardiancfg .. " file!" - end - else - error = "Failed to open " .. dansguardiancfg .. " file!" - end - - return retval, error +getconfigfile = function() + return modelfunctions.getfiledetails(dansguardiancfg) end get_edit_config = function( name ) @@ -283,21 +232,9 @@ update_general_config = function( config ) return retval end -update_plain_config = function( config ) - - local retval = "" - local cfgptr = -1 - local error = "" - - cfgptr = io.open( dansguardiancfg, "wb+" ) - if cfgptr ~= nil then - cfgptr:write( config ) - cfgptr:close() - else - retval = "Failed to open " .. dansguardiancfg .. " file!" - end - - return retval +updateconfigfile = function( filedetails ) + filedetails.value.filename.value = dansguardiancfg + return modelfunctions.setfiledetails(dansguardiancfg) end get_cfg_value = function( str ) diff --git a/dansguardian-plain-html.lsp b/dansguardian-plain-html.lsp deleted file mode 100644 index 5ad57b9..0000000 --- a/dansguardian-plain-html.lsp +++ /dev/null @@ -1,83 +0,0 @@ -<% -require("viewfunctions") - local form = ... - local data = form.option - local service = form.service - local config = form.service.config - - local srv1fill = "" - local srv2fill = "disabled" - if form.info.status.value == "Enabled" then - srv1fill = "disabled" - srv2fill = "" - end - - local ifthen = function( variable, value, result ) - if variable == value then - io.write( result ) - end - end - -%> - -<% ---[[ DEBUG INFORMATION -io.write("

DEBUGGING

DEBUG INFO: CFE

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

SYSTEM INFO

-
-<% -local myform = form.info -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -
- -

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.
-
Information
-
These parameters define the interface and port that Dansguardian uses to accept connections.
-
- -
-

Configuration

- - - -

Save changes

-
-<% -local myform = form.service -local tags = { "cmdsave", } -displayinfo(myform,tags) -%> -<% if (service) and (service.error) and (#service.error > 0) then %> -
Config status
<% io.write(service.error ) %>
-<% end %> -<% if (service) and (service.cfgerr) and (#service.cfgerr > 0) then %> -
Config status
<% io.write(service.cfgerr ) %>
-<% end %> - -
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
> -> -> -<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %>
<% io.write( service.message.descr ) %>
<% end %>
-
-
diff --git a/dansguardian-startstop-html.lsp b/dansguardian-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/dansguardian-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp \ No newline at end of file diff --git a/dansguardian-status-html.lsp b/dansguardian-status-html.lsp deleted file mode 100644 index 33efc1b..0000000 --- a/dansguardian-status-html.lsp +++ /dev/null @@ -1,32 +0,0 @@ -<% local form = ... -require("viewfunctions") -%> - -<% ---[[ DEBUG INFORMATION -io.write("

DEBUGGING

DEBUG INFO: CFE

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

SYSTEM INFO

-
-<% -local myform = form.info -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -
- -

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 -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 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.

diff --git a/dansguardian-status-html.lsp b/dansguardian-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/dansguardian-status-html.lsp @@ -0,0 +1 @@ +../status-html.lsp \ No newline at end of file diff --git a/dansguardian.menu b/dansguardian.menu index e4e6a4e..a679ad7 100644 --- a/dansguardian.menu +++ b/dansguardian.menu @@ -3,5 +3,5 @@ Applications 20Content_Filter Status status Applications 20Content_Filter Basic general Applications 20Content_Filter Advanced advanced -Applications 20Content_Filter Plain plain Applications 20Content_Filter Category category +Applications 20Content_Filter Expert expert diff --git a/dansguardian.roles b/dansguardian.roles index a8db1c9..e19712f 100644 --- a/dansguardian.roles +++ b/dansguardian.roles @@ -1,2 +1,2 @@ READ=dansguardian:status -UPDATE=dansguardian:general,dansguardian:advanced,dansguardian:plain,dansguardian:edit,dansguardian:category,dansguardian:editcategories +UPDATE=dansguardian:general,dansguardian:advanced,dansguardian:expert,dansguardian:edit,dansguardian:category,dansguardian:editcategories,dansguardian:startstop -- cgit v1.2.3