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 --- Makefile | 16 +++++------ dnscache-controller.lua | 1 - dnscache-model.lua | 73 ++++++++++++++++++++---------------------------- dnscache-status-html.lsp | 17 +++-------- dnscache.menu | 6 ++-- 5 files changed, 45 insertions(+), 68 deletions(-) diff --git a/Makefile b/Makefile index 05737da..143a892 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ -APP_NAME=quagga +APP_NAME=dnscache PACKAGE=acf-$(APP_NAME) -VERSION=0.2.0 +VERSION=0.1.0 APP_DIST=\ - quagga-controller.lua \ - quagga-model.lua \ - quagga-status-html.lsp \ - quagga-logfile-html.lsp \ - quagga-expert-html.lsp \ - quagga.menu \ + dnscache-controller.lua \ + dnscache-model.lua \ + dnscache-status-html.lsp \ + dnscache-logfile-html.lsp \ + dnscache-expert-html.lsp \ + dnscache.menu \ EXTRA_DIST=README Makefile config.mk diff --git a/dnscache-controller.lua b/dnscache-controller.lua index fdaf6ad..4176ec1 100644 --- a/dnscache-controller.lua +++ b/dnscache-controller.lua @@ -22,7 +22,6 @@ local function displaycmdmanagement(pidofstatus) label="Program control-panel", value="Start", type="submit", - descr="When starting or restarting BGP, the web-page will freeze for some reason!", }) management.stop = cfe({ name="cmdmanagement", label="Program control-panel", 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) diff --git a/dnscache-status-html.lsp b/dnscache-status-html.lsp index c70ea95..b23ad5a 100644 --- a/dnscache-status-html.lsp +++ b/dnscache-status-html.lsp @@ -21,18 +21,9 @@ displayinfo(myform,tags,"viewonly")

PROGRAM SPECIFIC OPTIONS/INFORMATION

0) then io.write(" class='error'") end - io.write(">" .. myform.label .. "\n") - io.write("\t\t
\n") - io.write("\t\t
"..myform.value.."
\n") - io.write("\t\t
\n") - end -end +local myform = form.status +local tags = { "ip", "cachesize", } +displayinfo(myform,tags,"viewonly") ?> -
+ diff --git a/dnscache.menu b/dnscache.menu index d0d6b24..c8a0d32 100644 --- a/dnscache.menu +++ b/dnscache.menu @@ -1,5 +1,5 @@ #CAT GROUP/DESC TAB ACTION -Networking 46BGP Status status -Networking 46BGP Expert expert -Networking 46BGP Logfile logfile +Networking 11DNScache Status status +Networking 11DNScache Expert expert +Networking 11DNScache Logfile logfile -- cgit v1.2.3