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-model.lua | 84 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 7 deletions(-) (limited to 'dansguardian-model.lua') 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