From 4837cd73c1d79b17af443e0335cc04259505cd23 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 7 May 2008 15:10:35 +0000 Subject: Saving work for today. Sketching on a idea on howto edit categories (now showing if a category exists but is not configured to be used/activated in the main config). git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1109 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dansguardian-model.lua | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'dansguardian-model.lua') diff --git a/dansguardian-model.lua b/dansguardian-model.lua index b02b99b..73c2b2c 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -13,6 +13,25 @@ dansguardiancfg = "/etc/dansguardian/dansguardian.conf" dansguardiancfg2 = "/etc/dansguardian/dansguardianf1.conf" local processname = "dansguardian" local packagename = "dansguardian" +local baseurl = "/etc/dansguardian" -- Without trailing / + + +-- ################################################################################ +-- LOCAL FUNCTIONS + +local function get_includes_from_file(file) + local retval = {} + for k,v in pairs(fs.read_file_as_array(file)) do + if (string.match(v, '^%s*.Include')) then + local val = string.match(v,'^%s*.Include<(.*)>%s*') + retval[val] = true + end + end + return retval +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS get_autostart = function() local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) @@ -355,16 +374,32 @@ 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( "/etc/dansguardian/phraselists" ) - local k = "" - local v = "" + local entries = posix.dir( baseurl .. "/phraselists" ) for k,v in ipairs( entries ) do - local attrs = posix.stat( "/etc/dansguardian/phraselists/" .. v ) + local attrs = posix.stat( baseurl .. "/phraselists/" .. v ) + if attrs.type == "directory" and v ~= "." and v ~= ".." then - table.insert( retval, v ) + local entrycontent = {} + local someactive = false + 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 + active = true + someactive = true + end + table.insert(entrycontent, {name=v1, active=active, mhdebug=string.match(v1,'%w*'),mhdebug2=baseurl .. "/phraselists/" .. v .."/" .. v1}) + end + end + table.insert( retval, {name=v, option=entrycontent, active=someactive} ) end end -- cgit v1.2.3