Commit 7ccca721 authored by Ted Trask's avatar Ted Trask

Modified dansguardian to use new status, startstop, and expert (replaced plain) actions.

git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1380 ab2d0c66-481e-0410-8bed-d214d4d58bed
parent a538c188
<%
require("viewfunctions")
local form = ...
local form, viewlibrary = ...
local data = form.option
local service = form.service
local config = form.service.config
local srv1fill = ""
local srv2fill = "disabled"
if form.info.status.value == "Enabled" then
srv1fill = "disabled"
srv2fill = ""
end
local ifthen = function( variable, value, result )
if variable == value then
io.write( result )
end
end
%>
<%
<%
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(form))
......@@ -28,14 +15,9 @@ io.write("</span>")
--]]
%>
<H1>SYSTEM INFO</H1>
<DL>
<%
local myform = form.info
local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("status")
end %>
<h1>Configuration</h1>
<% if (#service.cfgerr > 0) then %>
......@@ -59,12 +41,6 @@ displayinfo(myform,tags,"viewonly")
%>
</TABLE>
<h1>MANAGEMENT</h1>
<form action="" method="POST">
<dl>
<DT>Daemon control</DT><dd><input class="submit" type="submit" name="srvcmd" value="start" <% io.write( srv1fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="stop" <% io.write( srv2fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="restart" <% io.write( srv2fill ) %>>
<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %><pre><% io.write( service.message.descr ) %></pre><% end %></dd>
</dl>
</form>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("startstop")
end %>
<%
require("viewfunctions")
local form = ...
local data = form.option
local service = form.service
local config = form.service.config
local srv1fill = ""
local srv2fill = "disabled"
if form.info.status.value == "Enabled" then
srv1fill = "disabled"
srv2fill = ""
end
local ifthen = function( variable, value, result )
if variable == value then
io.write( result )
end
end
local form, viewlibrary = ...
%>
<%
......@@ -28,14 +11,9 @@ io.write("</span>")
--]]
%>
<H1>SYSTEM INFO</H1>
<DL>
<%
local myform = form.info
local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("status")
end %>
<h1>Modify Categories</h1>
......@@ -73,12 +51,6 @@ end
</form>
<h1>MANAGEMENT</h1>
<form action="" method="POST">
<dl>
<DT>Daemon control</DT><dd><input class="submit" type="submit" name="srvcmd" value="start" <% io.write( srv1fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="stop" <% io.write( srv2fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="restart" <% io.write( srv2fill ) %>>
<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %><pre><% io.write( service.message.descr ) %></pre><% end %></dd>
</dl>
</form>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("startstop")
end %>
......@@ -2,50 +2,22 @@
module (..., package.seeall)
require("controllerfunctions")
default_action = "status"
status = function( self )
return self.model.get_status()
end
local info = {
status=self.model.get_status(),
version = self.model.get_dansguardian_version(),
autostart = self.model.get_autostart(),
srvctrl = { value = srvctrl}
}
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 }) )
startstop = function( self )
return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.get_status, self.clientdata)
end
general = function( self )
local service = {}
if self.clientdata.srvcmd then
local srvcmd = self.clientdata.srvcmd
if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
service.srvcmdresult, service.message = self.model.service_control( srvcmd )
end
end
local info = {
status=self.model.get_status(),
version = self.model.get_dansguardian_version(),
autostart = self.model.get_autostart(),
srvctrl = { value = srvctrl}
}
local option = { script = self.conf.script,
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
-- Add a cmd button to the view
service.cmdsave = cfe({ name="cmdsave",
label="Save/Apply above settings",
......@@ -64,29 +36,15 @@ general = function( self )
service.cmdsave.descr="* Changes has been saved!"
end
service.status = self.model.get_status()
service.config, service.cfgerr = self.model.get_general_config()
return ( cfe ({ option = option, service = service, info = info }) )
return ( cfe ({ service = service }) )
end
advanced = function( self )
local service = {}
if self.clientdata.srvcmd then
local srvcmd = self.clientdata.srvcmd
if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
service.srvcmdresult, service.message = self.model.service_control( srvcmd )
end
end
local info = {
status=self.model.get_status(),
version = self.model.get_dansguardian_version(),
autostart = self.model.get_autostart(),
srvctrl = { value = srvctrl}
}
local option = { script = self.conf.script,
prefix = self.conf.prefix,
controller = self.conf.controller,
......@@ -94,54 +52,13 @@ advanced = function( self )
extra = ""
}
service.status = self.model.get_status()
service.config, service.cfgerr = self.model.get_advanced_config()
return ( cfe ({ option = option, service = service, info = info }) )
return ( cfe ({ option = option, service = service }) )
end
plain = function( self )
local service = {}
if self.clientdata.srvcmd then
local srvcmd = self.clientdata.srvcmd
if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
service.srvcmdresult, service.message = self.model.service_control( srvcmd )
end
end
local option = { script = self.conf.script,
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
local info = {
status=self.model.get_status(),
version = self.model.get_dansguardian_version(),
autostart = self.model.get_autostart(),
srvctrl = { value = srvctrl}
}
-- 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 = conf.config
self.model.update_plain_config( config )
service.cmdsave.descr="* Changes has been saved!"
end
service.status = self.model.get_status()
service.config, service.cfgerr = self.model.get_plain_config()
return ( cfe ({ option = option, service = service, info = info }) )
expert = function( self )
return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.updateconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
edit = function( self )
......@@ -150,13 +67,6 @@ edit = function( self )
redirect( self )
end
local option = { script = self.conf.script,
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
local service = { message="", status="", config="" }
if self.clientdata.cmd then
......@@ -166,7 +76,6 @@ edit = function( self )
end
end
service.status = self.model.get_status()
service.config, service.cfgerr = self.model.get_edit_config( self.clientdata.name )
service.name = self.clientdata.name
......@@ -174,48 +83,13 @@ edit = function( self )
redirect( self )
end
return ( cfe ({ option = option, service = service }) )
return ( cfe ({ service = service }) )
end
category = function( self )
local service = { message="", status="", config="", cfgerr="" }
if self.clientdata.srvcmd then
local srvcmd = self.clientdata.srvcmd
if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
service.srvcmdresult, service.message = self.model.service_control( srvcmd )
end
end
local info = {
status=self.model.get_status(),
version = self.model.get_dansguardian_version(),
autostart = self.model.get_autostart(),
srvctrl = { value = srvctrl}
}
local option = { script = self.conf.script,
prefix = self.conf.prefix,
controller = self.conf.controller,
action = self.conf.action,
extra = ""
}
-- Add a cmd button to the view
service.cmdadd = cfe({
name="cmdadd",
label="Action",
value="Add",
type="submit",
})
service.cmdaddvalue = cfe({
name="cmdaddvalue",
value="",
type="text",
})
service.config = {}
service.config.categories = cfe({
name="categories",
......@@ -224,7 +98,7 @@ category = function( self )
})
service.config.categories = self.model.get_categories()
return ( cfe ({ option = option, service = service, info = info }) )
return ( cfe ({ service = service }) )
end
editcategories = function( self )
......
<%
local form = ...
local data = form.option
local service = form.service
local config = form.service.config
local srv1fill = ""
local srv2fill = "disabled"
if service.status == "running" then
srv1fill = "disabled"
srv2fill = ""
end
local ifthen = function( variable, value, result )
if variable == value then
io.write( result )
end
end
%>
<h1>Content Filter (<% io.write( service.name ) %>)</h1>
......
../expert-html.lsp
\ No newline at end of file
<%
require("viewfunctions")
local form = ...
local data = form.option
local form, viewlibrary = ...
local service = form.service
local config = form.service.config
local srv1fill = ""
local srv2fill = "disabled"
if form.info.status.value == "Enabled" then
srv1fill = "disabled"
srv2fill = ""
end
local ifthen = function( variable, value, result )
if variable == value then
io.write( result )
end
end
%>
<%
......@@ -28,14 +14,9 @@ io.write("</span>")
--]]
%>
<H1>SYSTEM INFO</H1>
<DL>
<%
local myform = form.info
local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("status")
end %>
<form action="" method="POST">
<h1>Configuration</h1>
......@@ -88,12 +69,6 @@ until you restart the service.</DD>
</form>
<h1>MANAGEMENT</h1>
<form action="" method="POST">
<dl>
<DT>Daemon control</DT><dd><input class="submit" type="submit" name="srvcmd" value="start" <% io.write( srv1fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="stop" <% io.write( srv2fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="restart" <% io.write( srv2fill ) %>>
<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %><pre><% io.write( service.message.descr ) %></pre><% end %></dd>
</dl>
</form>
<% if viewlibrary and viewlibrary.dispatch_component then
viewlibrary.dispatch_component("startstop")
end %>
......@@ -2,6 +2,7 @@
module (..., package.seeall)
-- Load libraries
require("modelfunctions")
require "posix"
require "format"
require("processinfo")
......@@ -46,48 +47,12 @@ local categoryfilecontent = {
-- ################################################################################
-- PUBLIC FUNCTIONS
get_autostart = function()
local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname)
local retval = cfe({ name="autostart",
label="Autostart sequence",
value=autostart_sequense,
errtxt=autostart_errtxt,
})
return retval
end
get_status = function()
local t = procps.pidof(procname)
local stats
if (t) and (#t > 0) then
stats = "Enabled"
else
stats = "Disabled"
end
local retval = cfe({ name="status",
label="Program status",
value=stats,
})
return retval
return modelfunctions.getstatus(processname, packagename, "Dans Guardian Status")
end
service_control = function( cmd )
local action = {value=cmd}
local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd)
action.descr=cmdmessage
action.errtxt=cmderror
return cmdresult,action
end
get_dansguardian_version = function()
local value, errtxt = processinfo.package_version(packagename)
local retval = cfe({ name = "version",
label="Program version",
value=value,
errtxt=errtxt,
})
return retval
startstop_service = function( action )
return modelfunctions.startstop_service(processname, action)
end
get_general_config = function()
......@@ -146,24 +111,8 @@ get_general_config = function()
return retval, error
end
get_plain_config = function()
local retval = ""
local error = ""
local fptr = io.open( dansguardiancfg, "r" )
if fptr ~= nil then
retval = fptr:read( "*a" )
fptr:close()
if retval == nil then
retval = ""
error = "Failed to read " .. dansguardiancfg .. " file!"
end
else
error = "Failed to open " .. dansguardiancfg .. " file!"
end
return retval, error
getconfigfile = function()
return modelfunctions.getfiledetails(dansguardiancfg)
end
get_edit_config = function( name )
......@@ -283,21 +232,9 @@ update_general_config = function( config )
return retval
end
update_plain_config = function( config )
local retval = ""
local cfgptr = -1
local error = ""
cfgptr = io.open( dansguardiancfg, "wb+" )
if cfgptr ~= nil then
cfgptr:write( config )
cfgptr:close()
else
retval = "Failed to open " .. dansguardiancfg .. " file!"
end
return retval
updateconfigfile = function( filedetails )
filedetails.value.filename.value = dansguardiancfg
return modelfunctions.setfiledetails(dansguardiancfg)
end
get_cfg_value = function( str )
......
<%
require("viewfunctions")
local form = ...
local data = form.option
local service = form.service
local config = form.service.config
local srv1fill = ""
local srv2fill = "disabled"
if form.info.status.value == "Enabled" then
srv1fill = "disabled"
srv2fill = ""
end
local ifthen = function( variable, value, result )
if variable == value then
io.write( result )
end
end
%>
<%
--[[ 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>SYSTEM INFO</H1>
<DL>
<%
local myform = form.info
local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<h1>Content Filter (Plain Config File)</h1>
<DL>
<DT>Warning</DT>
<DD class=warning>Modifying the DansGuardian configuration file is generally not necessary.
You must be familiar with the configuration file before proceeding.</DD>
<DT>Information</DT>
<DD>These parameters define the interface and port that Dansguardian uses to accept connections.</DD>
</DL>
<form action="" method="POST">
<h2>Configuration</h2>
<textarea name="config"><% io.write( service.config ) %></textarea>
<h2>Save changes</h2>
<dl>
<%
local myform = form.service
local tags = { "cmdsave", }
displayinfo(myform,tags)
%>
<% if (service) and (service.error) and (#service.error > 0) then %>
<DT>Config status</DT><DD class="error"><% io.write(service.error ) %></DD>
<% end %>
<% 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>
</dl>
</form>
<h1>MANAGEMENT</h1>
<form action="" method="POST">
<dl>
<DT>Daemon control</DT><dd><input class="submit" type="submit" name="srvcmd" value="start" <% io.write( srv1fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="stop" <% io.write( srv2fill ) %>>
<input class="submit" type="submit" name="srvcmd" value="restart" <% io.write( srv2fill ) %>>
<% if (service.message) and (service.message.descr) and (#service.message.descr > 0) then %><pre><% io.write( service.message.descr ) %></pre><% end %></dd>
</dl>
</form>
../startstop-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>SYSTEM INFO</H1>
<DL>
<%
local myform = form.info
local tags = { "status", "version", "autostart", }
displayinfo(myform,tags,"viewonly")
%>
</DL>
<h2>General Information</h2>
<p>DansGuardian is web content filtering software.<BR>It works as a web proxy,
making web requests in behalf of the client, and inspecting the returned
content before passing on to the client.<BR>DansGuardian uses phraselists to
identify harmful content.<BR>This means that updated "blacklists" are
generally not necessary.<BR>DansGuardian must be used in combination with a
"smart proxy", such as squid.</p>
<p>This process runs as a service.<BR>When you make and save changes, the configuration