Widget improvements

This commit is contained in:
Luca Deri 2020-04-18 21:26:35 +02:00
parent 281012610a
commit 17bbfb7c78
10 changed files with 176 additions and 141 deletions

View file

@ -0,0 +1,47 @@
--
-- (C) 2020 - ntop.org
--
--
-- This is the main widget entrypoint that renders all widgets
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require ("lua_utils")
local dkjson = require("dkjson")
local datasources_utils = require("datasources_utils")
local widget_utils = require("widget_utils")
local function reportError(msg)
print(dkjson.encode({ success = false, message = msg }))
end
-- ###############################################
local json = _GET["JSON"]
local widget_data
if(json == nil) then
widget_data = {}
else
widget_data = dkjson.decode(json)
end
sendHTTPContentTypeHeader('application/json')
if(widget_data.widgetKey == nil) then
reportError("Missing widget_key parameter")
return
end
local widget = widget_utils.get_widget(widget_data.widgetKey)
if (widget == nil) then
reportError("The requested widget was not found")
return
end
-- Generate the widget response
print(widget_utils.generate_response(widget, widget_data))