Commit 2764edea authored by Ted Trask's avatar Ted Trask

Modified dansguardian. Changed advanced to listfiles and expert to...

Modified dansguardian.  Changed advanced to listfiles and expert to listconfigfiles.  Made general and edit be normal forms.  Removed categories, which didn't work.

git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1465 ab2d0c66-481e-0410-8bed-d214d4d58bed
parent 6d20b13c
<%
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 %>
......@@ -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
<%
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
<% 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>
<% --]] %>
../expert-html.lsp
\ No newline at end of file
<%
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>
......
<%
<% 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>
......
......@@ -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+" )