-- acf model for squid -- Copyright(c) 2007 A. Brodmann - Licensed under terms of GPL2 module (..., package.seeall) get_status = function() local retval = "stopped" local ptr = io.popen( "/bin/pidof squid" ) local pid = ptr:read( "*a" ) ptr:close() if pid ~= nil then if #pid > 1 then retval = "running" end end return retval end service_control = function( control ) local retval = "" local ptr = io.popen( "/etc/init.d/squid " .. 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 else retval = "service_control(): Failed to start/stop/restart service!\n" end 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