module(..., package.seeall) --require("pidof") require("split") local function get_version() local cmd = "/sbin/apk_version -v -s busybox | cut -d ' ' -f 1" local cmd_output = io.popen( cmd ) local cmd_output_result = cmd_output:read("*a") or "" cmd_output:close() return cmd_output_result end local is_running = function( process ) local statusreport = nil local cmdoutput = {} local cmd, error = io.popen("pidof " .. process ,r) local cmdoutput = string.gsub(cmd:read("*a"), "%s", "") cmd:close() if (cmdoutput ~= "") then statusreport = "Running" else statusreport = "Stopped" end return statusreport end local function readopts(optname) local opts = {} local line local f = io.open("/etc/conf.d/syslog", "r") if (f == nil) then return nil end for line in f:lines() do local optstr = string.match(line, "^" .. optname .. "=\"?(.*)%\"+") if optstr then local option = "" local optvalue = "" opts["org"]=optstr for j = 1, string.len(optstr) do if (string.sub(optstr, j, j) == "-") then option=string.sub(optstr, j, j+1) for k = j+1, string.len(optstr) do if (string.sub(optstr, k, k) == "-") then opts[option] = string.match(string.sub(optstr, j+2, k-1),"^%s*(.*)%s?") break end if (k == string.len(optstr)) then opts[option] = string.match(string.sub(optstr, j+2, k),"^%s*(.*)%s?") break end end end end end end return opts end -- ################################################################################ -- EXPERIMENTAL LOCAL FUNCTIONS -- ################################################################################ -- PUBLIC FUNCTIONS function getstatus() local opts = readopts("SYSLOGD_OPTS") local status = {} local version = get_version() status.version = version local isrunning = is_running("syslogd") status.status = isrunning status.logfile = opts["-O"] or "/var/log/messages" status.remote = opts["-R"] return status end function getconfig() local opts = readopts("SYSLOGD_OPTS") local config = {} config.debug = opts config.logfile = opts["-O"] or "" config.loglevel = opts["-l"] or "" config.smallog = opts["-S"] --FIXME: DOESNT WORK!!! config.maxsize = opts["-s"] or "" config.logrotate = opts["-b"] or "" config.remote = opts["-R"] or "" return config end service_control = function ( self, srvcmd ) local srvcmd = string.lower(srvcmd) local retval = "" local line = "" if (srvcmd == "start") or (srvcmd == "stop") or (srvcmd == "restart") then local file = io.popen( "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin /etc/init.d/syslog " .. srvcmd .. " 2>&1" ) if file ~= nil then line = file:read( "*l" ) while line ~= nil do retval = retval .. "\n" .. line line = file:read( "*l" ) end file:close() end else retval = "Unknown command!" end return retval end -- ################################################################################ -- OTHER FUNCTIONS -- we actually need root permissions to get the process list --[[ priv = {} function priv.is_enabled() return (pidof.pidof("syslogd")) end function priv.enable(opts) if opts and opts.remote then local f = io.open("/etc/conf.d/syslog", "w") if f == nil then return nil end f:write("# this file was written by and will be overwritten by acf\n") f:write("SYSLOGD_OPTS=\"-R "..opts.remote.."\"") f:close() end os.system("/etc/init.d/syslogd restart; rc_add -k -s 20 syslog") end --]] --[[ -- this func does not need privileges local function readopts() local opts = {} local line local f = io.open("/etc/conf.d/syslog", "r") if f == nil then return nil end for line in f:lines() do local optstr = string.match(line, "^SYSLOGD_OPTS=\"?(.*)\"?") if optstr then opts.remote = string.match(optstr, "-R%s*(.*)%s*.*$") opts.optstr = optstr end end return opts end --]]