Commit 210f1c93 authored by Mika Havela's avatar Mika Havela

Changing buttons to be cfe's (coming from controller) rather than created by the view-file.

Reorganized the view-files so they look a bit more like other ACF's.

git-svn-id: svn://svn.alpinelinux.org/acf/dansguardian/trunk@1108 ab2d0c66-481e-0410-8bed-d214d4d58bed
parent 236a2b6b
<?
require("viewfunctions")
local form = ...
local data = form.option
local service = form.service
......@@ -6,7 +7,7 @@
local srv1fill = ""
local srv2fill = "disabled"
if service.status == "running" then
if form.info.status.value == "Enabled" then
srv1fill = "disabled"
srv2fill = ""
end
......@@ -18,7 +19,24 @@
end
?>
<h1>Content Filter</h1>
<?
--[[ 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. It works as a web proxy,
......@@ -32,32 +50,37 @@ generally not necessary. DansGuardian must be used in combination with a
This page lets you manually configure the filter rule files for DansGuardian.
</p>
<h2>Status</h2>
<dl><dt>Program version</dt><dd><? io.write( form.info.version.value ) ?></dd></dl>
<dl><dt>Process status</dt><dd><? io.write( form.info.status.value ) ?></dd></dl>
<dl><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 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 ) ?>></dd></dl>
<p class="error"><? io.write( service.message ) ?></p>
</form>
<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 ?>
<h2>Configuration</h2>
<pre class=error><? io.write( service.cfgerr ) ?></pre>
<h3>Files</h3>
<p>
Click on one of the files to edit it.
</p>
<h2>Files</h2>
<DL>
<TABLE>
<TR style="background:#eee;font-weight:bold;">
<TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">File</TD>
<TD style="padding-right:20px;white-space:nowrap;text-align:left;" class="header">Size</TD>
<TD style="white-space:nowrap;text-align:left;" class="header">Last Modified</TD>
</TR>
<table>
<?
for k,v in ipairs( config.files ) do
io.write( "<tr><td><a href=\"" .. data.script .. data.prefix .. data.controller .. "/edit?name=" .. v .. "\">" .. v .. "</a></td></tr>\n" )
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" )
end
?>
</table>
</TABLE>
</DL>
<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>
<?
require("viewfunctions")
local form = ...
local data = form.option
local service = form.service
......@@ -6,7 +7,7 @@
local srv1fill = ""
local srv2fill = "disabled"
if service.status == "running" then
if form.info.status.value == "Enabled" then
srv1fill = "disabled"
srv2fill = ""
end
......@@ -18,7 +19,25 @@
end
?>
<h1>Content Filter</h1>
<?
--[[ 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. 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. DansGuardian uses phraselists to
......@@ -27,31 +46,27 @@ generally not necessary. DansGuardian must be used in combination with a
"smart proxy", such as squid.
<b>This page lets you manually add/remove categories for DansGuardian.</b></p>
<h1>Status</h1>
<form action="" method="POST">
<dl><dt>dansguardian is:</dt><dd><b><? io.write( service.status ) ?></b></dd></dl>
<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 ) ?>></dd></dl>
</form>
<p><pre class=error><? io.write( service.message ) ?></pre></p>
<p>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.</p>
<h1>Categories</h1>
<p><pre class=error><? io.write( service.cfgerr ) ?></pre></p>
<h2>Add Category</h2>
<p>
To add a category, or to add a file to an existing category, please fill in the corresponding information below.
(Due to a limitation with DansGuardian, all categories must be lowercase.)
</p>
<dl><dt>Category name</dt><dd><input type="text" name="newcat" value=""></dd></dl>
<dl><dt>Category files</dt><dd><input type="checkbox" name="cattype" value="w">weighted <input type="checkbox" name="cattype" value="b">banned <input type="checkbox" name="cattype" value="e">exception</dd></dl>
<dl><dt>Action</dt><dd><input class="submit" type="submit" name="cmd" value="add"></dd></dl>
<dl>
<dt>Category name</dt><dd><input class="text" type="text" name="newcat" value=""></dd>
<dt>Category files</dt><dd><input type="checkbox" name="cattype" value="w">weighted <input type="checkbox" name="cattype" value="b">banned <input type="checkbox" name="cattype" value="e">exception</dd>
<?
local myform = form.service
local tags = { "cmdadd", }
displayinfo(myform,tags)
?>
</dl>
<p><pre class=error><? io.write( service.cfgerr ) ?></pre></p>
<p></p>
<h2>Delete Category</h2>
......@@ -61,12 +76,28 @@ delete the link in the corresponding phraselist above. You will also need to edi
above if you delete a category.
</p>
<form action="" method="POST">
<dl><dt>Categories available</dt><dd>(please check the ones you want to delete)</dd></dl>
<dl>
<dt>Categories available</dt><dd>(please check the ones you want to delete)
<?
for k,v in ipairs( config ) do
io.write( "<dl><dt></dt><dd><input type=\"checkbox\" name=\"cats\" value=\"" .. v .. "\"> " .. v .. "</dd></dl>\n" )
io.write( "<BR><input type=\"checkbox\" name=\"cats\" value=\"" .. v .. "\"> " .. v .. "\n" )
end
?>
<dl><dt>Action</dt><dd><input class="submit" type="submit" name="cmd" value="delete"></dd></dl>
</DD>
<?
local myform = form.service
local tags = { "cmddelete", }
displayinfo(myform,tags)
?>
</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>
......@@ -6,7 +6,20 @@ default_action = "general"
general = function( self )
local info = { status = { value = "stopped" }, version = { value = self.model.get_dansguardian_version() }, srvctrl = { value = srvctrl} };
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 = ENV["SCRIPT_NAME"],
prefix = self.conf.prefix,
......@@ -15,30 +28,25 @@ general = function( self )
extra = ""
}
local service = { message="", status="", config="" }
if self.clientdata.srvcmd then
srvcmd = self.clientdata.srvcmd
if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
service.message = self.model.service_control( srvcmd )
end
end
if self.clientdata.cmd then
if self.clientdata.cmd == "save" 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 )
end
-- 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.status = self.model.get_status()
info.status.value = service.status
service.config, service.cfgerr = self.model.get_general_config()
return ( cfe ({ option = option, service = service, info = info }) )
......@@ -46,7 +54,20 @@ end
advanced = function( self )
local info = { status = { value = "stopped" }, version = { value = self.model.get_dansguardian_version() }, srvctrl = { value = srvctrl} };
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 = ENV["SCRIPT_NAME"],
prefix = self.conf.prefix,
......@@ -55,17 +76,7 @@ advanced = function( self )
extra = ""
}
local service = { message="", status="", config="" }
if self.clientdata.srvcmd then
srvcmd = self.clientdata.srvcmd
if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
service.message = self.model.service_control( srvcmd )
end
end
service.status = self.model.get_status()
info.status.value = service.status
service.config, service.cfgerr = self.model.get_advanced_config()
return ( cfe ({ option = option, service = service, info = info }) )
......@@ -73,34 +84,46 @@ 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 = ENV["SCRIPT_NAME"],
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}
}
local service = { message="", status="", config="" }
if self.clientdata.srvcmd then
srvcmd = self.clientdata.srvcmd
if srvcmd == "start" or srvcmd == "stop" or srvcmd == "restart" then
service.message = self.model.service_control( srvcmd )
end
end
if self.clientdata.cmd then
if self.clientdata.cmd == "save" then
local conf = self.clientdata
local config = conf.config
self.model.update_plain_config( config )
end
-- 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 }) )
return ( cfe ({ option = option, service = service, info = info }) )
end
edit = function( self )
......@@ -121,6 +144,7 @@ edit = function( self )
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
......@@ -137,6 +161,22 @@ 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 = ENV["SCRIPT_NAME"],
prefix = self.conf.prefix,
controller = self.conf.controller,
......@@ -144,10 +184,27 @@ category = function( self )
extra = ""
}
local service = { message="", status="", config="", cfgerr="" }
-- Add a cmd button to the view
service.cmdadd = cfe({
name="cmdadd",
label="Action",
value="Add",
type="submit",
disabled="yes",
errtxt="This button is currently out of order",
})
service.cmddelete = cfe({
name="cmddelete",
label="Action",
value="Delete",
type="submit",
disabled="yes",
errtxt="This button is currently out of order",
})
service.config = self.model.get_categories()
return ( cfe ({ option = option, service = service }) )
return ( cfe ({ option = option, service = service, info = info }) )
end
<?
require("viewfunctions")
local form = ...
local data = form.option
local service = form.service
......@@ -6,7 +7,7 @@
local srv1fill = ""
local srv2fill = "disabled"
if form.info.status.value == "running" then
if form.info.status.value == "Enabled" then
srv1fill = "disabled"
srv2fill = ""
end
......@@ -18,7 +19,24 @@
end
?>
<h1>Content Filter</h1>
<?
--[[ 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. It works as a web proxy,
......@@ -31,52 +49,64 @@ generally not necessary. DansGuardian must be used in combination with a
This page defines the basic network configuration settings for DansGuardian.
</p>
<h2>Status</h2>
<dl><dt>Program version</dt><dd><? io.write( form.info.version.value ) ?></dd></dl>
<dl><dt>Process status</dt><dd><? io.write( form.info.status.value ) ?></dd></dl>
<dl><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 applied until you restart the service.</dd></dl>
<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 ) ?>></dd></dl>
</form>
<p>
<pre class="attention"><? io.write( service.message ) ?></pre>
</p>
<form action="" method="POST">
<h2>Configuration</h2>
<p><pre class=error><? io.write( service.cfgerr ) ?></pre></p>
<h1>Configuration</h1>
<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></dl>
<dl><dt>filterport</dt><dd><input class="text" type="text" name="filterport" value="<? io.write( config.filterport.value ) ?>" ></dd></dl>
<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>
</dl>
<h3>Proxy service</h3>
<h2>Proxy service</h2>
<p>
These parameters define the ip address and port that Dansguardian should forward requests on to.
</p>
<dl><dt>proxyip</dt><dd><input class="text" type="text" name="proxyip" value="<? io.write( config.proxyip.value ) ?>"></dd></dl>
<dl><dt>proxyport</dt><dd><input class="text" type="text" name="proxyport" value="<? io.write( config.proxyport.value ) ?>"></dd></dl>
<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>
</dl>
<h3>Filter Actions</h3>
<h2>Filter Actions</h2>
<p>
These parameters define how sensitive the filter is, and where to redirect requests if the content filter
determines that the content is inappropriate. The "naughtynesslimit" is more sensitive the lower it is set.
The author recommends 50 for "young children", 100 for "older children" and 160 for "young adults".
</p>
<dl><dt>accessdeniedaddress</dt><dd><input class="text" type="text" name="accessdeniedaddress" value="<? io.write( config.accessdeniedaddress.value ) ?>"></dd></dl>
<dl><dt>naughtynesslimit</dt><dd><input class="text" type="text" name="naughtynesslimit" value="<? io.write( config.naughtynesslimit.value ) ?>"></dd></dl>
<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>
</dl>
<h2>Save Changes</h2>
<dl><dt>Save the above changes?</dt><dd><input class="submit" type="submit" name="cmd" value="save"></dd></dl>
<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>
</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>
-- acf model for squid
-- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2
module (..., package.seeall)
-- Load libraries
require "posix"
require "format"
require("processinfo")
require("procps")
require("daemoncontrol")
-- Set variables
dansguardiancfg = "/etc/dansguardian/dansguardian.conf"
dansguardiancfg2 = "/etc/dansguardian/dansguardianf1.conf"
get_status = function()
local retval = "stopped"
local ptr = io.popen( "/bin/pidof dansguardian" )
local pid = ptr:read( "*a" )
ptr:close()
if pid ~= nil then
if #pid > 1 then
retval = "running"
end
end
local processname = "dansguardian"
local packagename = "dansguardian"
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
service_control = function( control )
local retval = ""
local ptr = io.popen( "/etc/init.d/dansguardian " .. control, "r" )
if ptr ~= nil then
local retmsg = ptr:read( "*a" )
ptr:close()
if retmsg ~= nil then
retval = retmsg
else
retval = "service_control(): Failed to read output from initscript!\n"
end
get_status = function()
local t = procps.pidof(procname)
local stats
if (t) and (#t > 0) then
stats = "Enabled"
else
retval = "service_control(): Failed to start/stop/restart service!\n"
stats = "Disabled"
end
local retval = cfe({ name="status",
label="Program status",
value=stats,
})
return retval
end
get_dansguardian_version = function()
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