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]
This commit is contained in:
Eric 2018-07-18 14:48:31 -07:00 committed by dman776
parent f05c204a96
commit 282f4a170b
1 changed files with 28 additions and 1 deletions

View File

@ -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()