diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-05-08 15:00:25 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-05-08 15:00:25 +0000 |
commit | ac11c15126f83bffc7e47251baf41224ae58a113 (patch) | |
tree | 07bed27c8ca82c73c7f38f87b63237729edc1067 | |
parent | 4837cd73c1d79b17af443e0335cc04259505cd23 (diff) | |
download | acf-dansguardian-ac11c15126f83bffc7e47251baf41224ae58a113.tar.bz2 acf-dansguardian-ac11c15126f83bffc7e47251baf41224ae58a113.tar.xz |
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
-rw-r--r-- | dansguardian-category-html.lsp | 4 | ||||
-rw-r--r-- | dansguardian-controller.lua | 40 | ||||
-rw-r--r-- | dansguardian-editcategories-html.lsp | 43 | ||||
-rw-r--r-- | 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") <form action="" method="POST"> <dl> <? -local myform = form["service"]["config"]["categories"]["value"] +local myform = form["service"]["config"]["categories"] for k,v in ipairs( myform ) do io.write("<DT ") if not (v.active) then io.write("CLASS='error'") end @@ -53,7 +53,7 @@ for k,v in ipairs( myform ) do for k1,v1 in pairs(v.option) do io.write("<TR><TD STYLE='font-weight:bold;' WIDTH='180px' ") if not (v1.active) then io.write("CLASS='error'") end - io.write(">".. v1.name .. "</TD><TD>[ <A HREF='editcategories?phrase=".. v.name .. "&object=".. v1.name .. "'>Edit</A> ]</TD></TD>" ) + io.write(">".. v1.name .. "</TD><TD>[ <A HREF='editcategories?category=".. v.name .. "&object=".. v1.name .. "'>Edit</A> ]</TD></TD>" ) -- for k2,v2 in pairs(v1) do --io.write(html.form(v1.type(v1))) -- io.write("<TD>") 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") ?> <? ----[[ DEBUG INFORMATION +--[[ DEBUG INFORMATION io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") io.write(html.cfe_unpack(form)) io.write("</span>") --]] ?> -<H1>SYSTEM INFO</H1> +<H1>INFO</H1> <DL> <? local myform = form.info -local tags = { "status", "version", "autostart", } +local tags = { "configfile","mtime","category", "name", "activestatus", } displayinfo(myform,tags,"viewonly") ?> </DL> +<H1>CONFIGURE</H1> +<H2>General</H2> +<DL> +<? +local myform = form.info +local tags = { "activate" } +displayinfo(myform,tags) +?> +</DL> + +<H2>Details</H2> +<? +local myform = form.info +io.write('<input type="hidden" value="' .. myform.filename.value .. '" name="name">') +io.write(html.form[myform.filecontent.type](myform.filecontent)) +?> + +<H2>Save</H2> +<DL> +<? +local myform = form.info +local tags = { "cmdsave" } +displayinfo(myform,tags) +?> +</DL> + +<H1>Delete</H1> +<p>You can delete this object. This will result in erazing instead of deactivating it.</p> +<p>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.</p> +<DL> +<? +local myform = form.info +local tags = { "cmddelete" } +displayinfo(myform,tags) +?> +</DL> + <? --[[ ?> <form name="myform" action="" method="POST"> <h1>CONFIGURATION</h1> 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 + |