From 2cc08d53216abf6203ed971cdb3a88b410a45f08 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 9 Apr 2008 15:00:48 +0000 Subject: Cleaning up the code and activating all visible functions (show/expert/logfile) git-svn-id: svn://svn.alpinelinux.org/acf/dnscache/trunk@983 ab2d0c66-481e-0410-8bed-d214d4d58bed --- dnscache-model.lua | 73 ++++++++++++++++++++++-------------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) (limited to 'dnscache-model.lua') diff --git a/dnscache-model.lua b/dnscache-model.lua index d67f80d..f5a2722 100644 --- a/dnscache-model.lua +++ b/dnscache-model.lua @@ -12,41 +12,16 @@ require("socket") require("processinfo") -- Set variables -local configfile = "/etc/quagga/bgpd.conf" -local processname = "bgpd" -local packagename = "quagga" -local baseurl = "/etc/quagga/" +local configfile = "/etc/conf.d/dnscache" +local processname = "dnscache" +local packagename = "dnscache" +local baseurl = "/etc/dnscache/" local descr = { } -- ################################################################################ -- LOCAL FUNCTIONS -local function get_routes() - local cmd_output_result, cmd_output_error - local cmd = "/sbin/route -n 2>/dev/null" - local f = io.popen( cmd ) - local cmd_output_result = f:read("*a") - return cmd_output_result,cmd_output_error -end - -local function get_iproute() - local cmd_output_result, cmd_output_error - local cmd = "/bin/ip route 2>/dev/null" - local f = io.popen( cmd ) - local cmd_output_result = f:read("*a") - return cmd_output_result,cmd_output_error -end - -local function get_bgpinfo() - local cmd_output_result, cmd_output_error - local cmd = "/usr/sbin/bgpd --version 2>/dev/null" - local f = io.popen( cmd ) - local cmd_output_result = f:read("*a") - -- bgpdport=179 - return cmd_output_result,cmd_output_error -end - local function process_status_text(procname) local t = procps.pidof(procname) if (t) and (#t > 0) then @@ -56,6 +31,21 @@ local function process_status_text(procname) end end +local function humanreadable(value) + local myvalue = tonumber(value) + if not (myvalue) then + return false + end + if ( myvalue > 1073741824 ) then + myvalue=((myvalue/1073741824) - (myvalue/1073741824%0.1)) .. "G" + elseif ( myvalue > 1048576 ) then + myvalue=((myvalue/1048576) - (myvalue/1048576%0.1)) .. "M" + elseif ( myvalue > 1024 ) then + myvalue=((myvalue/1024) - (myvalue/1024%0.1)) .. "k" + end + return myvalue +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -69,7 +59,7 @@ end function getstatus() local status = {} - + local config = getconfig() local value, errtxt = processinfo.package_version(packagename) status.version = cfe({ name = "version", label="Program version", @@ -89,19 +79,14 @@ function getstatus() errtxt=autostart_errtxt, }) - status.iproute = cfe({ name="iproute", - label="ip route", - value=get_iproute(), + status.ip = cfe({ name="ip", + label="Listening on", + value=config.IP, }) - status.routes = cfe({ name="routes", - label="route -n", - value=get_routes(), - }) - - status.bgpstats = cfe({ name="bgpstats", - label="BGP version", - value=get_bgpinfo(), + status.cachesize = cfe({ name="cachesize", + label="Cache size", + value=humanreadable(config.CACHESIZE), }) return status @@ -131,8 +116,10 @@ function get_logfile () end function getconfig() - local config = {} - return config + if (fs.is_file(configfile)) then + return getopts.getoptsfromfile(configfile) + end + return false end function get_filedetails(self,num) -- cgit v1.2.3