From ac11c15126f83bffc7e47251baf41224ae58a113 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Thu, 8 May 2008 15:00:25 +0000 Subject: When looking at a category-object, you now see if the reason why it's marked red or not (by clicking on the object). You also see the content and other information about the category object. git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1113 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dansguardian-category-html.lsp | 4 +- dansguardian-controller.lua | 40 +++++++++-------- dansguardian-editcategories-html.lsp | 43 ++++++++++++++++-- dansguardian-model.lua | 84 +++++++++++++++++++++++++++++++++--- 4 files changed, 142 insertions(+), 29 deletions(-) diff --git a/dansguardian-category-html.lsp b/dansguardian-category-html.lsp index 66c972d..c2ffce6 100644 --- a/dansguardian-category-html.lsp +++ b/dansguardian-category-html.lsp @@ -43,7 +43,7 @@ displayinfo(myform,tags,"viewonly")
".. v1.name .. "[ Edit ]" ) + io.write(">".. v1.name .. "[ Edit ]" ) -- for k2,v2 in pairs(v1) do --io.write(html.form(v1.type(v1))) -- io.write("") diff --git a/dansguardian-controller.lua b/dansguardian-controller.lua index e647954..c72d17c 100644 --- a/dansguardian-controller.lua +++ b/dansguardian-controller.lua @@ -222,28 +222,34 @@ category = function( self ) label="Categories available", value={}, }) - for k,v in pairs(self.model.get_categories()) do - local types = { weighted, banned, exception } - --- for k,v in pairs(types) do --- if (fs.is_file( - --table.insert(weighted, cfe({type="link", value="value", name="name", label="label",})) --- end - - table.insert(service.config.categories.value, v ) - end + service.config.categories = self.model.get_categories() return ( cfe ({ option = option, service = service, info = info }) ) end editcategories = function( self ) - local info = { - status=self.model.get_status(), - version = self.model.get_dansguardian_version(), - autostart = self.model.get_autostart(), - srvctrl = { value = srvctrl} - } + local info = self.model.get_category(self.clientdata.category, self.clientdata.object) + if not (info) then + redirect(self, "category") + end + + -- Add a cmd button to the view + info.cmdsave = cfe({ name="cmdsave", + label="Save/Apply above settings", + value="Save", + type="submit", + disabled="yes", + errtxt="This button is not configured to work", + }) + + info.cmddelete = cfe({ name="cmddelete", + label="Permanently remove object", + value="Delete", + type="submit", + disabled="yes", + errtxt="This button is not configured to work", + }) local option = { script = ENV["SCRIPT_NAME"], prefix = self.conf.prefix, @@ -252,6 +258,6 @@ editcategories = function( self ) extra = "" } - return ( cfe ({ option = option, info = info }) ) + return ( cfe ({ option = option, info = info, mhdebug=self.clientdata }) ) end diff --git a/dansguardian-editcategories-html.lsp b/dansguardian-editcategories-html.lsp index 1421cf4..ab814fa 100644 --- a/dansguardian-editcategories-html.lsp +++ b/dansguardian-editcategories-html.lsp @@ -2,22 +2,59 @@ require("viewfunctions") ?> DEBUGGING

DEBUG INFO: CFE

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

SYSTEM INFO

+

INFO

+

CONFIGURE

+

General

+
+ +
+ +

Details

+') +io.write(html.form[myform.filecontent.type](myform.filecontent)) +?> + +

Save

+
+ +
+ +

Delete

+

You can delete this object. This will result in erazing instead of deactivating it.

+

When deleting a object, you will not be able to get it back! If you are unsure, it's better to only deactivate this object instead of deleting it.

+
+ +
+

CONFIGURATION

diff --git a/dansguardian-model.lua b/dansguardian-model.lua index 73c2b2c..3159644 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -6,7 +6,9 @@ require "posix" require "format" require("processinfo") require("procps") +require("fs") require("daemoncontrol") +require("validator") -- Set variables dansguardiancfg = "/etc/dansguardian/dansguardian.conf" @@ -14,7 +16,11 @@ dansguardiancfg2 = "/etc/dansguardian/dansguardianf1.conf" local processname = "dansguardian" local packagename = "dansguardian" local baseurl = "/etc/dansguardian" -- Without trailing / - +local categoryfiles = { + ['weighted'] = tostring(baseurl .. "/weightedphraselist"), + ['banned'] = tostring(baseurl .. "/bannedphraselist"), + ['exception'] = tostring(baseurl .. "/exceptionphraselist"), + } -- ################################################################################ -- LOCAL FUNCTIONS @@ -30,6 +36,13 @@ local function get_includes_from_file(file) return retval end +local categoryfilecontent = { + ['weighted'] = get_includes_from_file(categoryfiles['weighted']), + ['banned'] = get_includes_from_file(categoryfiles['banned']), + ['exception'] = get_includes_from_file(categoryfiles['exception']), + } + + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -374,11 +387,6 @@ is_valid_configfile = function( name ) end get_categories = function() - local phrases = {} - phrases.weighted = get_includes_from_file(baseurl .. "/weightedphraselist") - phrases.banned = get_includes_from_file(baseurl .. "/bannedphraselist") - phrases.exception = get_includes_from_file(baseurl .. "/exceptionphraselist") - local retval = {} local entries = posix.dir( baseurl .. "/phraselists" ) @@ -392,7 +400,7 @@ get_categories = function() for k1,v1 in pairs(posix.dir( baseurl .. "/phraselists/" .. v )) do if not string.match(v1, "^%.") then local active - if (phrases[string.match(v1,'%w*')][baseurl .. "/phraselists/" .. v .."/" .. v1]) then + if (categoryfilecontent[string.match(v1,'%w*')][baseurl .. "/phraselists/" .. v .."/" .. v1]) then active = true someactive = true end @@ -406,3 +414,65 @@ get_categories = function() return retval end +get_category = function(category, object) + local filename = baseurl .. "/phraselists/" .. category .. "/" .. object + + if not (categoryfilecontent[string.match(object,'%w*')]) or + not (fs.is_file(filename)) or + not (validator.is_valid_filename(filename, baseurl)) then + return nil, "Something went wrong." + end + + local retval = {} + + retval.activate = cfe({ + label="Activate this object", + type="checkbox", + checked="yes", + }) + if not (categoryfilecontent[string.match(object,'%w*')][filename]) then + retval.activestatus = cfe({ + label="Category object is currently", + errtxt = "Deactivated", + }) + retval.activate.checked=nil + end + + retval.configfile = cfe({ + label="Activation is done in", + value=categoryfiles[string.match(object,'%w*')], + }) + + local filedetails = fs.stat(filename) + retval.mtime = cfe({ + label="Modify date", + value=filedetails.mtime, + }) + + retval.category = cfe({ + name="category", + label="Category name", + value=category, + }) + + retval.name = cfe({ + name="name", + label="Object name", + value=object, + }) + + retval.filename = cfe({ + name="filename", + label="Filename", + type="hidden", + value=filename, + }) + retval.filecontent = cfe({ + label="Filename", + value=fs.read_file(filename), + type="longtext", + }) + + return retval +end + -- cgit v1.2.3