diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-05-06 15:11:55 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-05-06 15:11:55 +0000 |
commit | 210f1c930825f872aa6003f37a8908a63c2c91f5 (patch) | |
tree | 81fb2cc025a43173c17a5732053f208514810797 | |
parent | 236a2b6bf29167ace2fbca2273f3c9b246387b17 (diff) | |
download | acf-dansguardian-210f1c930825f872aa6003f37a8908a63c2c91f5.tar.bz2 acf-dansguardian-210f1c930825f872aa6003f37a8908a63c2c91f5.tar.xz |
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
-rw-r--r-- | dansguardian-advanced-html.lsp | 71 | ||||
-rw-r--r-- | dansguardian-category-html.lsp | 71 | ||||
-rw-r--r-- | dansguardian-controller.lua | 161 | ||||
-rw-r--r-- | dansguardian-general-html.lsp | 88 | ||||
-rw-r--r-- | dansguardian-model.lua | 88 | ||||
-rw-r--r-- | dansguardian-plain-html.lsp | 78 | ||||
-rw-r--r-- | dansguardian.menu | 2 |
7 files changed, 367 insertions, 192 deletions
diff --git a/dansguardian-advanced-html.lsp b/dansguardian-advanced-html.lsp index 0f6b78a..73e6015 100644 --- a/dansguardian-advanced-html.lsp +++ b/dansguardian-advanced-html.lsp @@ -1,4 +1,5 @@ <? +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> diff --git a/dansguardian-category-html.lsp b/dansguardian-category-html.lsp index bbe1a20..1edcc71 100644 --- a/dansguardian-category-html.lsp +++ b/dansguardian-category-html.lsp @@ -1,4 +1,5 @@ <? +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> diff --git a/dansguardian-controller.lua b/dansguardian-controller.lua index bcb7bed..9b19314 100644 --- a/dansguardian-controller.lua +++ b/dansguardian-controller.lua @@ -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 diff --git a/dansguardian-general-html.lsp b/dansguardian-general-html.lsp index 10ea6b7..2a4ca5c 100644 --- a/dansguardian-general-html.lsp +++ b/dansguardian-general-html.lsp @@ -1,4 +1,5 @@ <? +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> diff --git a/dansguardian-model.lua b/dansguardian-model.lua index 63694e2..b02b99b 100644 --- a/dansguardian-model.lua +++ b/dansguardian-model.lua @@ -1,61 +1,60 @@ --- 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 - local retval = "" - - local ptr = io.popen( "/usr/sbin/dansguardian -v" ) - if ptr ~= nil then - retval = ptr:read( "*l" ) - ptr:close() - else - retval = "Error - Failed to program version" - 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 end @@ -318,7 +317,10 @@ get_file_tree = function( treetable, dir, prefix ) 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 ) + local path = dir .. "/" .. v + local filedetails = fs.stat(path) + filedetails.path = prefix .. v + table.insert( treetable, filedetails ) end end @@ -344,7 +346,7 @@ is_valid_configfile = function( name ) get_file_tree( ftable, "/etc/dansguardian", "" ) for k,v in ipairs( ftable ) do - if v == name then + if v.path == name then retval = true end end diff --git a/dansguardian-plain-html.lsp b/dansguardian-plain-html.lsp index cf76317..7ef2847 100644 --- a/dansguardian-plain-html.lsp +++ b/dansguardian-plain-html.lsp @@ -1,4 +1,5 @@ <? +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,34 +19,65 @@ 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> -<p class=warning>WARNING:</p> -<p>Modifying the DansGuardian configuration file is generally not necessary. -You must be familiar with the configuration file before proceeding.</p> +<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> -<h2>Status</h2> <form action="" method="POST"> -<dl><dt>dansguardian is: <? io.write( service.status ) ?> </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 class="error"><? io.write( service.message ) ?></p> +<h2>Configuration</h2> +<textarea name="config"><? io.write( service.config ) ?></textarea> -<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> -<form action="" method="POST"> -<h2>Configuration</h2> -<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> +<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 ?> -<textarea name="config"><? io.write( service.config ) ?></textarea> +<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> -<h3>Save Changes</h3> -<dl><dt>Save the contents of the above box</dt><dd><input class="submit" type="submit" name="cmd" value="save"></dd></dl> +</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> diff --git a/dansguardian.menu b/dansguardian.menu index c7f2580..d7d6be2 100644 --- a/dansguardian.menu +++ b/dansguardian.menu @@ -1,6 +1,6 @@ # Prefix and controller are already known at this point # Cat Group Tab Action -Applications 20Content_Filter Basic basic +Applications 20Content_Filter Basic general Applications 20Content_Filter Advanced advanced Applications 20Content_Filter Plain plain Applications 20Content_Filter Category category |