diff options
author | Andreas Brodmann <andreas.brodmann@gmail.com> | 2007-11-28 15:31:40 +0000 |
---|---|---|
committer | Andreas Brodmann <andreas.brodmann@gmail.com> | 2007-11-28 15:31:40 +0000 |
commit | 63e86a0669837c3845db1eb581f58ba388705ced (patch) | |
tree | 4c8f8666e7470e3f43bc94ba9a588bf6ce432da4 /dansguardian-model.lua | |
parent | 9032d7d132e275795287d243553cc32871669fd7 (diff) | |
download | acf-squid-63e86a0669837c3845db1eb581f58ba388705ced.tar.bz2 acf-squid-63e86a0669837c3845db1eb581f58ba388705ced.tar.xz |
/acf/squid: updated dansguardian config gui, yet missing: category editor
git-svn-id: svn://svn.alpinelinux.org/acf/squid/trunk@381 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'dansguardian-model.lua')
-rw-r--r-- | dansguardian-model.lua | 144 |
1 files changed, 143 insertions, 1 deletions
diff --git a/dansguardian-model.lua b/dansguardian-model.lua index 5289ee3..3660b37 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -2,7 +2,10 @@ -- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2 module (..., package.seeall) +require "posix" + dansguardiancfg = "/etc/dansguardian/dansguardian.conf" +dansguardiancfg2 = "/etc/dansguardian/dansguardianf1.conf" get_status = function() @@ -76,6 +79,22 @@ get_general_config = function() else error = "Failed to open " .. dansguardiancfg .. " file!" end + + local fptr2 = io.open( dansguardiancfg2, "r" ) + if fptr2 ~= nil then + local line = fptr2:read( "*l" ) + while line ~= nil do + if string.sub( line, 1, 1 ) ~= "#" then + if string.sub( line, 1, 16 ) == "naughtynesslimit" then + retval.naughtynesslimit.value = get_cfg_value( line ) + end + end + line = fptr2:read( "*l" ) -- read one config file line + end + fptr2:close() + else + error = "Failed to open " .. dansguardiancfg2 .. " file!" + end return retval, error end @@ -100,6 +119,50 @@ get_plain_config = function() return retval, error end +get_edit_config = function( name ) + + local retval = "" + local error = "" + + if not is_valid_configfile( name ) then + return "", "Hacker" + end + + local fptr = io.open( "/etc/dansguardian/" .. name ) + if fptr ~= nil then + retval = fptr:read( "*a" ) + fptr:close() + if retval == nil then + retval = "" + error = "Failed to read /etc/dansguardian/" .. name .. " file!" + end + else + error = "Failed to open /etc/dansguardian/" .. name .. " file!" + end + + return retval, error +end + +update_edit_config = function( name, config ) + + local retval = "" + + if not is_valid_configfile( name ) then + return "", "Hacker" + end + + local fptr = io.open( "/etc/dansguardian/" .. name, "wb+" ) + if fptr ~= nil then + fptr:write( config ) + fptr:close() + retval = "" + else + error = "Failed to open /etc/dansguardian/" .. name .. " file!" + end + + return retval +end + update_general_config = function( config ) local retval = "" @@ -140,9 +203,36 @@ update_general_config = function( config ) tmpfile:close() cfgptr:close() - os.rename( tmpfilename, dansguardiancfg ) + --- step 2 - dansguardiancfg2 + + tmpfile = io.open( tmpfilename, "wb+" ) + if tmpfile == nil then + return "Failed to create temporary config file!" + end + + cfgptr = io.open( dansguardiancfg2, "r" ) + if cfgptr == nil then + tmpfile:close() + os.remove( tmpfilename ) + return "Failed to open " .. dansguardiancfg2 .. "!" + end + + line = cfgptr:read( "*l" ) + while line ~= nil do + if string.sub( line, 1, 16 ) == "naughtynesslimit" then + tmpfile:write( "naughtynesslimit = " .. config.naughtynesslimit .. "\n" ) + else + tmpfile:write( line .. "\n" ) + end + line = cfgptr:read( "*l" ) + end + + tmpfile:close() + cfgptr:close() + os.rename( tmpfilename, dansguardiancfg2 ) + return retval end @@ -194,3 +284,55 @@ get_cfg_value = function( str ) return retval end +get_advanced_config = function() + + local retval = { files = {} } + local errmsg = "" + + get_file_tree( retval.files, "/etc/dansguardian", "" ) + + return retval, errmsg +end + +get_file_tree = function( treetable, dir, prefix ) + + local entries = posix.dir( dir ) + local k = "" + local v = "" + for k,v in ipairs( entries ) do + local attrs = posix.stat( dir .. "/" .. v ) + if attrs.type == "regular" and string.sub( v, -4) ~= ".gif" then + table.insert( treetable, prefix .. v ) + end + end + + entries = posix.dir( dir ) + for k,v in ipairs( entries ) do + local attrs = posix.stat( dir .. "/" .. v ) + if attrs.type == "directory" and v~= "." and v~= ".." then + get_file_tree( treetable, dir .. "/" .. v, prefix .. v .. "/" ) + end + end + + return +end + +is_valid_configfile = function( name ) + + local retval = false + local ftable = {} + local k + local v + + + get_file_tree( ftable, "/etc/dansguardian", "" ) + + for k,v in ipairs( ftable ) do + if v == name then + retval = true + end + end + + return retval +end + |