From 282f4a170b989030a3918cf532364cd06aafa373 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 18 Jul 2018 14:48:31 -0700 Subject: [PATCH] Added the Nodes locally hosted service listing to sysinfo.json (#78) * Added the Nodes locally hosted service listing to sysinfo.json Added the Nodes locally hosted service listing to sysinfo.json file. * Forgot to change api_version * Change info[] section to be services_local to keep in line with the function is called was info[local_services] now info[services_local] --- files/www/cgi-bin/sysinfo.json | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/files/www/cgi-bin/sysinfo.json b/files/www/cgi-bin/sysinfo.json index 252ada12..5e023b19 100755 --- a/files/www/cgi-bin/sysinfo.json +++ b/files/www/cgi-bin/sysinfo.json @@ -55,7 +55,7 @@ end info={} -- API version -info['api_version']="1.2" +info['api_version']="1.3" -- NODE name css=getUciConfType("system", "system") @@ -244,6 +244,33 @@ if string.find(nixio.getenv("QUERY_STRING"):lower(),"services=1") then info["services"]=services end +-- LOCALLY HOSTED SERVICES ONLY +if string.find(nixio.getenv("QUERY_STRING"):lower(),"services_local=1") then + local filelines={} + local lclsrvs={} + local lclsrvfile=io.open("/etc/config/services", "r") + if lclsrvfile~=nil then + for line in lclsrvfile:lines() do + table.insert(filelines, line) + end + lclsrvfile:close() + for pos,val in pairs(filelines) do + local service={} + local link,protocol,name = string.match(val,"^([^|]*)|(.+)|([^\t]*).*") + if link and protocol and name then + service['name']=name + service['protocol']=protocol + service['link']=link + table.insert(lclsrvs, service) + end + end + else + service['error']="Cannot read local services file" + table.insert(lclsrvs, service) + end + info['services_local']=lclsrvs +end + -- Output the HTTP header for JSON json_header()