diff options
-rw-r--r-- | dansguardian-category-html.lsp | 56 | ||||
-rw-r--r-- | dansguardian-controller.lua | 118 | ||||
l---------[-rw-r--r--] | dansguardian-edit-html.lsp | 19 | ||||
-rw-r--r-- | dansguardian-editcategories-html.lsp | 98 | ||||
l--------- | dansguardian-expert-html.lsp | 1 | ||||
-rw-r--r-- | dansguardian-general-html.lsp | 40 | ||||
-rw-r--r-- | dansguardian-html.lsp (renamed from dansguardian-advanced-html.lsp) | 18 | ||||
-rw-r--r-- | dansguardian-model.lua | 353 | ||||
-rw-r--r-- | dansguardian.menu | 5 | ||||
-rw-r--r-- | dansguardian.roles | 2 |
10 files changed, 138 insertions, 572 deletions
diff --git a/dansguardian-category-html.lsp b/dansguardian-category-html.lsp deleted file mode 100644 index 2f94048..0000000 --- a/dansguardian-category-html.lsp +++ /dev/null @@ -1,56 +0,0 @@ -<% -require("viewfunctions") - local form, viewlibrary = ... -%> - -<% ---[[ 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>") ---]] -%> - -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("status") -end %> - -<h1>Modify Categories</h1> - -<h2>Category list</h2> -<form action="" method="POST"> -<dl> -<% -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 - io.write("><img src='/static/tango/16x16/categories/applications-system.png' height='16' width='16'> "..v.name.."</DT>\n") - io.write("<DD><TABLE>") - if (v.option) then - for k1,v1 in pairs(v.option) do - io.write("<TR><TD STYLE='font-weight:bold;border:none;' WIDTH='180px' ") - if not (v1.active) then io.write("CLASS='error'") end - io.write(">".. v1.name .. "</TD><TD STYLE='border:none;'>[ <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 STYLE='border:none;'>") --- io.write("[ " ..html.link(v2) .. " ] ") --- io.write(tostring(v2)) --- io.write("</TD>") --- end - io.write("</TR>\n") - end - io.write("<TR><TD STYLE='font-weight:bold;border:none;' WIDTH='180px'><INPUT TYPE='text' CLASS='text'></TD><TD STYLE='border:none;'><INPUT TYPE='submit' CLASS='submit' VALUE='Create' disabled></TD></TD></TR>\n" ) - end - io.write("</TABLE></DD>") ---io.write( "<BR><input type=\"checkbox\" name=\"cats\" value=\"" .. v .. "\"> " .. v .. "\n" ) -end -%> -</dl> -</form> - - -<% if viewlibrary and viewlibrary.dispatch_component then - viewlibrary.dispatch_component("startstop") -end %> diff --git a/dansguardian-controller.lua b/dansguardian-controller.lua index 97e2849..37470bd 100644 --- a/dansguardian-controller.lua +++ b/dansguardian-controller.lua @@ -15,123 +15,17 @@ startstop = function( self ) end general = function( self ) - - local service = {} - - -- Add a cmd button to the view - service.cmdsave = cfe({ name="cmdsave", - label="Save/Apply above settings", - value="Save", - type="submit", - }) - - if self.clientdata.cmdsave then - local conf = self.clientdata - local config = { filterip = conf.filterip, filterport = conf.filterport, - proxyip = conf.proxyip, proxyport = conf.proxyport, - accessdeniedaddress = conf.accessdeniedaddress, - naughtynesslimit = conf.naughtynesslimit - } - self.model.update_general_config( config ) - service.cmdsave.descr="* Changes has been saved!" - end - - service.config, service.cfgerr = self.model.get_general_config() - - return ( cfe ({ service = service }) ) + return controllerfunctions.handle_form(self, self.model.read_general_config, self.model.update_general_config, self.clientdata, "Save", "Edit General Configuration", "General Configuration Set") end -advanced = function( self ) - - local service = {} - - local option = { script = self.conf.script, - prefix = self.conf.prefix, - controller = self.conf.controller, - action = self.conf.action, - extra = "" - } - - service.config, service.cfgerr = self.model.get_advanced_config() - - return ( cfe ({ option = option, service = service }) ) +listfiles = function( self ) + return self.model.list_files() end -expert = function( self ) - return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.updateconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Set") +listconfigfiles = function( self ) + return self.model.list_config_files() end edit = function( self ) - - if not self.clientdata.name then - redirect( self ) - end - - local service = { message="", status="", config="" } - - if self.clientdata.cmd then - if self.clientdata.cmd == "save" then - self.model.update_edit_config( self.clientdata.name, self.clientdata.config ) - redirect( self, "advanced" ) - end - end - - service.config, service.cfgerr = self.model.get_edit_config( self.clientdata.name ) - service.name = self.clientdata.name - - if service.cfgerr == "Hacker" then - redirect( self ) - end - - return ( cfe ({ service = service }) ) -end - -category = function( self ) - - local service = { message="", status="", config="", cfgerr="" } - - service.config = {} - service.config.categories = cfe({ - name="categories", - label="Categories available", - value={}, - }) - - service.config.categories = self.model.get_categories() - return ( cfe ({ service = service }) ) -end - -editcategories = function( self ) - - 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 = self.conf.script, - prefix = self.conf.prefix, - controller = self.conf.controller, - action = self.conf.action, - extra = "" - } - - return ( cfe ({ option = option, info = info, mhdebug=self.clientdata }) ) + return controllerfunctions.handle_form(self, function() return self.model.get_file(self.clientdata.filename) end, self.model.update_file, self.clientdata, "Save", "Edit File", "File Saved") end - diff --git a/dansguardian-edit-html.lsp b/dansguardian-edit-html.lsp index 99cf55a..15b1930 100644..120000 --- a/dansguardian-edit-html.lsp +++ b/dansguardian-edit-html.lsp @@ -1,18 +1 @@ -<% - local form = ... - local service = form.service - -%> -<h1>Content Filter (<% io.write( service.name ) %>)</h1> - -<form action="" method="POST"> -<p><pre class=error><% io.write( service.cfgerr ) %></pre></p> -<p>These parameters define the interface and port that Dansguardian uses to accept connections.</p> - -<textarea name="config"><% io.write( service.config ) %></textarea> -<input class="text" type="hidden" name="name" value="<% io.write( service.name ) %>"> - -<h3>Save Changes</h3> -<dl><dt>Save the content of the above box</dt><dd><input class="submit" type="submit" name="cmd" value="save"></dd></dl> -</form> - +../filedetails-html.lsp
\ No newline at end of file diff --git a/dansguardian-editcategories-html.lsp b/dansguardian-editcategories-html.lsp deleted file mode 100644 index 63087bf..0000000 --- a/dansguardian-editcategories-html.lsp +++ /dev/null @@ -1,98 +0,0 @@ -<% local form = ... -require("viewfunctions") -%> -<% ---[[ 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>INFO</H1> -<DL> -<% -local myform = form.info -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> -<H2>Expert config</H2> -<h3>File details</h3> -<DL> -<% -local myform = form.file -local tags = { "filename", "filesize", "mtime", "sumerrors", } -displayinfo(myform,tags,"viewonly") -%> -</DL> - -<H3>FILE CONTENT</H3> -<% -local myform = form.file -io.write('<input type="hidden" value="' .. myform.filename.value .. '" name="name">') -io.write(html.form[myform.filecontent.type](myform.filecontent)) -%> - -<H2>SAVE AND APPLY ABOVE SETTINGS</H2> -<DL> -<% -local tags = { "cmddelete", "cmdsave", } -displayinfo(myform,tags) -%> -</DL> - -<% --- Management buttons -local myform = form.management -local tags = { "start", "stop", "restart" } -if (myform) then - io.write("<H1>MANAGEMENT</H1>\n<DL>") - displaymanagement(myform,tags) - io.write("</DL>") -end -%> -</form> -<% --]] %> - diff --git a/dansguardian-expert-html.lsp b/dansguardian-expert-html.lsp deleted file mode 120000 index 207f324..0000000 --- a/dansguardian-expert-html.lsp +++ /dev/null @@ -1 +0,0 @@ -../expert-html.lsp
\ No newline at end of file diff --git a/dansguardian-general-html.lsp b/dansguardian-general-html.lsp index 6c0ca60..e7bd1af 100644 --- a/dansguardian-general-html.lsp +++ b/dansguardian-general-html.lsp @@ -1,9 +1,6 @@ <% require("viewfunctions") local form, viewlibrary = ... - local service = form.service - local config = form.service.config - %> <% @@ -20,14 +17,23 @@ end %> <form action="" method="POST"> <h1>Configuration</h1> +<% + if form.descr then io.write('<P CLASS="descr">' .. string.gsub(form.descr, "\n", "<BR>") .. "</P>\n") end + if form.errtxt then io.write('<P CLASS="error">' .. string.gsub(form.errtxt, "\n", "<BR>") .. "</P>\n") end + for field,val in pairs(form.value) do + val.name = field + end +%> <h2>General</h2> <p> These parameters define the interface and port that Dansguardian uses to accept connections. </p> <dl> -<dt>filterip</dt><dd><input class="text" type="text" name="filterip" value="<% io.write( config.filterip.value ) %>" ></dd> -<dt>filterport</dt><dd><input class="text" type="text" name="filterport" value="<% io.write( config.filterport.value ) %>" ></dd> +<% + displayformitem(form.value.filterip) + displayformitem(form.value.filterport) +%> </dl> <h2>Proxy service</h2> @@ -36,8 +42,10 @@ These parameters define the ip address and port that Dansguardian should forward </p> <dl> -<dt>proxyip</dt><dd><input class="text" type="text" name="proxyip" value="<% io.write( config.proxyip.value ) %>"></dd> -<dt>proxyport</dt><dd><input class="text" type="text" name="proxyport" value="<% io.write( config.proxyport.value ) %>"></dd> +<% + displayformitem(form.value.proxyip) + displayformitem(form.value.proxyport) +%> </dl> <h2>Filter Actions</h2> @@ -48,23 +56,15 @@ The author recommends 50 for "young children", 100 for "older children" and 160 </p> <dl> -<dt>accessdeniedaddress</dt><dd><input class="text" type="text" name="accessdeniedaddress" value="<% io.write( config.accessdeniedaddress.value ) %>"></dd> -<dt>naughtynesslimit</dt><dd><input class="text" type="text" name="naughtynesslimit" value="<% io.write( config.naughtynesslimit.value ) %>"></dd> +<% + displayformitem(form.value.accessdeniedaddress) + displayformitem(form.value.naughtynesslimit) +%> </dl> <h2>Save Changes</h2> <dl> -<% -local myform = form.service -local tags = { "cmdsave", } -displayinfo(myform,tags) -%> -<% if (service) and (service.cfgerr) and (#service.cfgerr > 0) then %> -<DT>Config status</DT><DD class="error"><% io.write(service.cfgerr ) %></DD> -<% end %> -<DT>Process information</DT><DD>This process runs as a service. When you make and save changes, the configuration -files for the service are changed. However, the changes will not be <i>applied</i> -until you restart the service.</DD> +<DT></DT><DD><input class="submit" type="submit" name="<%= form.option %>" value="<%= (form.submit or form.option) %>"></DD> </dl> </form> diff --git a/dansguardian-advanced-html.lsp b/dansguardian-html.lsp index 24dd8fb..83b17eb 100644 --- a/dansguardian-advanced-html.lsp +++ b/dansguardian-html.lsp @@ -1,10 +1,5 @@ -<% +<% local view, viewlibrary, page_info = ... require("viewfunctions") - local form, viewlibrary = ... - local data = form.option - local service = form.service - local config = form.service.config - %> <% @@ -20,13 +15,6 @@ io.write("</span>") end %> <h1>Configuration</h1> -<% if (#service.cfgerr > 0) then %> -<h2>Errors</h2> -<DL><DT>Config errors</DT> -<DD><pre class=error><% io.write( service.cfgerr ) %></pre></DD> -</DL> -<% end %> - <TABLE> <TR style="background:#eee;font-weight:bold;"> <TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">File</TD> @@ -35,8 +23,8 @@ end %> </TR> <% - for k,v in ipairs( config.files ) do - io.write( "<tr><td><a href=\"" .. data.script .. data.prefix .. data.controller .. "/edit?name=" .. v.path .. "\">" .. v.path .. "</a></td><td>" .. (v.size or "--") .."</td><td>" .. (v.mtime or "--") .."</td></tr>\n" ) + for k,v in ipairs( view.value ) do + io.write( "<tr><td><a href=\"" .. page_info.script .. page_info.prefix .. page_info.controller .. "/edit?filename=" .. v.filename .. "\">" .. v.filename .. "</a></td><td>" .. v.size .."</td><td>" .. v.mtime .."</td></tr>\n" ) end %> </TABLE> diff --git a/dansguardian-model.lua b/dansguardian-model.lua index 7fb76a1..f24748e 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -3,12 +3,9 @@ module (..., package.seeall) -- Load libraries require("modelfunctions") -require "posix" -require "format" -require("processinfo") -require("procps") +require("getopts") +--require "posix" require("fs") -require("daemoncontrol") require("validator") -- Set variables @@ -16,7 +13,9 @@ dansguardiancfg = "/etc/dansguardian/dansguardian.conf" dansguardiancfg2 = "/etc/dansguardian/dansguardianf1.conf" local processname = "dansguardian" local packagename = "dansguardian" -local baseurl = "/etc/dansguardian" -- Without trailing / +local baseurl = "/etc/dansguardian" + +--[[ local categoryfiles = { ['weighted'] = tostring(baseurl .. "/weightedphraselist"), ['banned'] = tostring(baseurl .. "/bannedphraselist"), @@ -42,7 +41,39 @@ local categoryfilecontent = { ['banned'] = get_includes_from_file(categoryfiles['banned']), ['exception'] = get_includes_from_file(categoryfiles['exception']), } +--]] + +local validate_general_config = function( config ) + local success = true + if config.value.filterip.value ~= "" and not validator.is_ipv4(config.value.filterip.value) then + config.value.filterip.errtxt = "Invalid IP address" + success = false + end + if not validator.is_port(config.value.filterport.value) then + config.value.filterport.errtxt = "Invalid port" + success = false + end + if not validator.is_ipv4(config.value.proxyip.value) then + config.value.proxyip.errtxt = "Invalid IP address" + success = false + end + if not validator.is_port(config.value.proxyport.value) then + config.value.proxyport.errtxt = "Invalid port" + success = false + end + -- FIXME don't know how to validate accessdeniedaddress + if not validator.is_integer(config.value.naughtynesslimit.value) then + config.value.naughtynesslimit.errtxt = "Invalid number" + success = false + end + + return success, config +end +local is_valid_filename = function(filename) + local dirname = dirname(filename) + return validator.is_valid_filename(filename) and string.match(dirname, baseurl) and not string.match(dirname, "%.%.") +end -- ################################################################################ -- PUBLIC FUNCTIONS @@ -55,274 +86,100 @@ startstop_service = function( action ) return modelfunctions.startstop_service(processname, action) end -get_general_config = function() +read_general_config = function() + local retval = { filterip = cfe({ label="Filter IP", descr="Leave blank to listen on all IPs" }), + filterport = cfe({ label="Filter Port" }), + proxyip = cfe({ label="Proxy IP" }), + proxyport = cfe({ label="Proxy Port" }), + accessdeniedaddress = cfe({ label="AccessDeniedAddress" }), + naughtynesslimit = cfe({ label="NaughtynessLimit" }) + } - local retval = {} - local error = "" - - retval = { filterip = { label="Filter IP", type="text", value="" }, - filterport = { label="Filter Port", type="text", value="" }, - proxyip = { label="Proxy IP", type="text", value="" }, - proxyport = { label="Proxy Port", type="text", value="" }, - accessdeniedaddress = { label="AccessDeniedAddress", type="text", value="" }, - naughtynesslimit = { label="NaughtynessLimit", type="text", value="" } - } - - local fptr = io.open( dansguardiancfg, "r" ) - if fptr ~= nil then - local line = fptr:read( "*l" ) - while line ~= nil do - if string.sub( line, 1, 1 ) ~= "#" then - if string.sub( line, 1, 8 ) == "filterip" then - retval.filterip.value = get_cfg_value( line ) - elseif string.sub( line, 1, 10 ) == "filterport" then - retval.filterport.value = get_cfg_value( line ) - elseif string.sub( line, 1, 7 ) == "proxyip" then - retval.proxyip.value = get_cfg_value( line ) - elseif string.sub( line, 1, 9 ) == "proxyport" then - retval.proxyport.value = get_cfg_value( line ) - elseif string.sub( line, 1, 19 ) == "accessdeniedaddress" then - retval.accessdeniedaddress.value = get_cfg_value( line ) - end - end - line = fptr:read( "*l" ) -- read one config file - end - fptr:close() - else - error = "Failed to open " .. dansguardiancfg .. " file!" + local config = getopts.getoptsfromfile(dansguardiancfg, "") + if config then + if config.filterip then retval.filterip.value = config.filterip end + if config.filterport then retval.filterport.value = config.filterport end + if config.proxyip then retval.proxyip.value = config.proxyip end + if config.proxyport then retval.proxyport.value = config.proxyport end + if config.accessdeniedaddress then retval.accessdeniedaddress.value = string.sub(config.accessdeniedaddress, 2, -2) end 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!" + config = getopts.getoptsfromfile(dansguardiancfg2, "") + if config then + if config.naughtynesslimit then retval.naughtynesslimit.value = config.naughtynesslimit end end - return retval, error -end - -getconfigfile = function() - return modelfunctions.getfiledetails(dansguardiancfg) + return cfe({ type="group", value=retval, label="Dansguardian General Config" }) 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!" +update_general_config = function( config ) + local success, config = validate_general_config(config) + + if success then + local a,b,c + local text = fs.read_file(dansguardiancfg) + a,b,c,text = getopts.setoptsinfile(text, "", "filterip", config.value.filterip.value) + a,b,c,text = getopts.setoptsinfile(text, "", "filterport", config.value.filterport.value) + a,b,c,text = getopts.setoptsinfile(text, "", "proxyip", config.value.proxyip.value) + a,b,c,text = getopts.setoptsinfile(text, "", "proxyport", config.value.proxyport.value) + a,b,c,text = getopts.setoptsinfile(text, "", "accessdeniedaddress", "'"..config.value.accessdeniedaddress.value.."'") + fs.write_file(dansguardiancfg, string.gsub(text, "\n+$", "")) + getopts.setoptsinfile(dansguardiancfg2, "", "naughtynesslimit", config.value.naughtynesslimit.value) + else + config.errtxt = "Failed to set config" end - return retval, error + return config 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( format.dostounix( config ) ) - fptr:close() - retval = "" +get_file = function(filename) + local retval + if is_valid_filename(filename) then + retval = modelfunctions.getfiledetails(filename) else - error = "Failed to open /etc/dansguardian/" .. name .. " file!" + retval = modelfunctions.getfiledetails("") + retval.value.filename.value = filename end - - return retval -end - -update_general_config = function( config ) - - local retval = "" - local tmpfilename = os.tmpname() - local tmpfile = -1 - local cfgptr = -1 - local line = "" - tmpfile = io.open( tmpfilename, "wb+" ) - if tmpfile == nil then - return "Failed to create temporary config file!" - end - - cfgptr = io.open( dansguardiancfg, "r" ) - if cfgptr == nil then - tmpfile:close() - os.remove( tmpfilename ) - return "Failed to open " .. dansguardiancfg .. "!" - end - - line = cfgptr:read( "*l" ) - while line ~= nil do - if string.sub( line, 1, 8 ) == "filterip" then - tmpfile:write( "filterip = " .. config.filterip .. "\n" ) - elseif string.sub( line, 1, 10 ) == "filterport" then - tmpfile:write( "filterport = " .. config.filterport .. "\n" ) - elseif string.sub( line, 1, 7 ) == "proxyip" then - tmpfile:write( "proxyip = " .. config.proxyip .. "\n" ) - elseif string.sub( line, 1, 9 ) == "proxyport" then - tmpfile:write( "proxyport = " .. config.proxyport .. "\n" ) - elseif string.sub( line, 1, 19 ) == "accessdeniedaddress" then - tmpfile:write( "accessdeniedaddress = " .. config.accessdeniedaddress .. "\n" ) - else - tmpfile:write( line .. "\n" ) - end - line = cfgptr:read( "*l" ) - end - - 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 -updateconfigfile = function( filedetails ) - filedetails.value.filename.value = dansguardiancfg - return modelfunctions.setfiledetails(dansguardiancfg) -end - -get_cfg_value = function( str ) - - local retval = "" - local pos = 1 - local found = false - local found2 = false - - while not found and pos < #str -1 do - if string.sub( str, pos, pos ) == "=" then - found = true - end - pos = pos + 1 - end - - if found then - pos = pos - 1 - while not found2 and pos < #str -1 do - if string.sub( str, pos+1, pos+1 ) ~= " " then - found2 = true - end - pos = pos + 1 - end - end - - if found2 then - retval = string.sub( str, pos ) +update_file = function(filedetails) + local retval + if is_valid_filename(filedetails.value.filename.value) then + retval = modelfunctions.setfiledetails(filedetails) + else + retval.value.filename.errtxt = "Invalid filename" + retval.errtxt = "Failed to save file" end - - return retval -end - -get_advanced_config = function() - local retval = { files = {} } - local errmsg = "" - - get_file_tree( retval.files, "/etc/dansguardian", "" ) - - return retval, errmsg + return retval 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 - local path = dir .. "/" .. v - local filedetails = fs.stat(path) - filedetails.path = prefix .. v - table.insert( treetable, filedetails ) - 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 .. "/" ) +list_files = function() + local retval = {} + for file in fs.find(null, baseurl) do + local details = fs.stat(file) + if details.type == "regular" and not string.match(file, "logrotation$") and not string.match(file, "%.conf$") and not string.match(file, "%.gif$") then + details.filename = file + table.insert(retval, details) end end - - return + return cfe({ type="structure", value=retval, label="List of Dansguardian files" }) 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.path == name then - retval = true - end - end - - return retval +list_config_files = function() + local list = {} + local details = fs.stat(dansguardiancfg) + details.filename = dansguardiancfg + list[1] = details + details = fs.stat(dansguardiancfg2) + details.filename = dansguardiancfg2 + list[2] = details + return cfe({ type="list", value=list, label="List of Dansguardian config files" }) end +--[[ get_categories = function() local retval = {} @@ -412,4 +269,4 @@ get_category = function(category, object) return retval end - +--]] diff --git a/dansguardian.menu b/dansguardian.menu index a679ad7..61381b9 100644 --- a/dansguardian.menu +++ b/dansguardian.menu @@ -2,6 +2,5 @@ # Cat Group Tab Action Applications 20Content_Filter Status status Applications 20Content_Filter Basic general -Applications 20Content_Filter Advanced advanced -Applications 20Content_Filter Category category -Applications 20Content_Filter Expert expert +Applications 20Content_Filter Advanced listfiles +Applications 20Content_Filter Expert listconfigfiles diff --git a/dansguardian.roles b/dansguardian.roles index e19712f..adcbb49 100644 --- a/dansguardian.roles +++ b/dansguardian.roles @@ -1,2 +1,2 @@ READ=dansguardian:status -UPDATE=dansguardian:general,dansguardian:advanced,dansguardian:expert,dansguardian:edit,dansguardian:category,dansguardian:editcategories,dansguardian:startstop +UPDATE=dansguardian:general,dansguardian:listfiles,dansguardian:listconfigfiles,dansguardian:edit,dansguardian:startstop |