diff options
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | squid-advanced-html.lsp | 49 | ||||
-rw-r--r-- | squid-controller.lua | 29 | ||||
-rw-r--r-- | squid-model.lua | 33 |
4 files changed, 113 insertions, 1 deletions
@@ -3,8 +3,9 @@ PACKAGE=acf-$(APP_NAME) VERSION=1.0_alpha1 APP_DIST=squid-controller.lua \ - squid-basic-html.lsp \ squid-model.lua \ + squid-basic-html.lsp \ + squid-advanced-html.lsp \ squid.menu EXTRA_DIST=README Makefile config.mk diff --git a/squid-advanced-html.lsp b/squid-advanced-html.lsp new file mode 100644 index 0000000..afcc642 --- /dev/null +++ b/squid-advanced-html.lsp @@ -0,0 +1,49 @@ +<? + local form = ... + local data = form.option + local service = form.service + + local srv1fill = "" + local srv2fill = "disabled" + if service.status == "running" then + srv1fill = "disabled" + srv2fill = "" + end + +?> +<h1>Web Proxy Configuration</h1> +<table border="2"> + <tr> + <td style="width:80%"> + <center> + <div style="color: #ff2020; font-weight: bold;">WARNING:</div><br> + Modifying the web proxy configuration file is generally not necessary. + You must be familiar with the configuration file before proceeding. + </center> + </td> + </tr> +</table> + +<h2>Status</h2> +<form action="" method="POST"> +<table><tr> +<td>squid is: <b><? io.write( service.status ) ?> </b> </td> +<td><input type="submit" name="srvcmd" value="start" <? io.write( srv1fill ) ?> style="width:100px"></td> +<td><input type="submit" name="srvcmd" value="stop" <? io.write( srv2fill ) ?> style="width:100px"></td> +<td><input type="submit" name="srvcmd" value="restart" <? io.write( srv2fill ) ?> style="width:100px"></td> +</tr></table> +</form> + +<pre style="color: #ff2020;"><? io.write( service.message ) ?></pre><br> + +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.<br> + +<h2>Configuration</h2> +<form action="" method="POST"> +<table> +<tr><td><textarea name="config" style="width:600px;"><? io.write( service.config ) ?></textarea></td></tr> +<tr><td><input type="submit" name="cmd" value="save" style="width:600px;"></td></tr> +</table> +</form> diff --git a/squid-controller.lua b/squid-controller.lua index 46da101..3e8522f 100644 --- a/squid-controller.lua +++ b/squid-controller.lua @@ -51,3 +51,32 @@ basic = function( self ) return ( cfe ({ option = option, service = service }) ) end +advanced = function( self ) + + local option = { script = ENV["SCRIPT_NAME"], + prefix = self.conf.prefix, + controller = self.conf.controller, + action = self.conf.action, + extra = "" + } + + local service = { message="", status="", config="" } + if self.clientdata.srvcmd then + local 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 + service.message = self.model.update_config( self.clientdata.config ) + end + end + + service.status = self.model.get_status() + service.config = self.model.get_config() + + return ( cfe ({ option = option, service = service }) ) +end + diff --git a/squid-model.lua b/squid-model.lua index c61a4e7..f1fee43 100644 --- a/squid-model.lua +++ b/squid-model.lua @@ -38,3 +38,36 @@ service_control = function( control ) return retval end +get_config = function() + + local retval = "" + + local ptr = io.open( "/etc/squid/squid.conf", "r" ) + if ptr ~= nil then + local retcfg = ptr:read( "*a" ) + ptr:close() + if retcfg == nil then + retval = "\n\n Error: Failed to read /etc/squid/squid.conf!\n\n" + else + retval = retcfg + end + end + + return retval +end + +update_config = function( config ) + + local retval = "Successfully updated /etc/squid/squid.conf!" + + local ptr = io.open( "/etc/squid/squid.conf", "wb+" ) + if ptr ~= nil then + ptr:write( config ) + ptr:close() + else + retval = "update_config(): Error, failed to open /etc/squid/squid.conf!\n" + end + + return retval +end + |