From dac97826f7d0c9b9135c1a08c4d5f16b61494bd1 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 26 Aug 2015 10:58:51 +0200 Subject: Renamed output directory to Server --- Server/webadmin/template.lua | 200 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 Server/webadmin/template.lua (limited to 'Server/webadmin/template.lua') diff --git a/Server/webadmin/template.lua b/Server/webadmin/template.lua new file mode 100644 index 000000000..5b3ecf152 --- /dev/null +++ b/Server/webadmin/template.lua @@ -0,0 +1,200 @@ +-- Use a table for fast concatenation of strings +local SiteContent = {} +function Output(String) + table.insert(SiteContent, String) +end + + + + + +function GetTableSize(Table) + local Size = 0 + for key,value in pairs(Table) do + Size = Size + 1 + end + return Size +end + + + + + +function GetDefaultPage() + local PM = cRoot:Get():GetPluginManager() + + local SubTitle = "Current Game" + local Content = "" + + Content = Content .. "

Plugins:

" + Content = Content .. "

Players:


"; + + return Content, SubTitle +end + + + + + +function ShowPage(WebAdmin, TemplateRequest) + SiteContent = {} + local BaseURL = WebAdmin:GetBaseURL(TemplateRequest.Request.Path) + local Title = "Cuberite WebAdmin" + local NumPlayers = cRoot:Get():GetServer():GetNumPlayers() + local MemoryUsageKiB = cRoot:GetPhysicalRAMUsage() + local NumChunks = cRoot:Get():GetTotalChunkCount() + local PluginPage = WebAdmin:GetPage(TemplateRequest.Request) + local PageContent = PluginPage.Content + local SubTitle = PluginPage.PluginName + if (PluginPage.TabName ~= "") then + SubTitle = PluginPage.PluginName .. " - " .. PluginPage.TabName + end + if (PageContent == "") then + PageContent, SubTitle = GetDefaultPage() + end + + local reqParamsClass = "" + + for key,value in pairs(TemplateRequest.Request.Params) do + reqParamsClass = reqParamsClass .. " param-" .. string.lower(string.gsub(key, "[^a-zA-Z0-9]+", "-") .. "-" .. string.gsub(value, "[^a-zA-Z0-9]+", "-")) + end + + if (string.gsub(reqParamsClass, "%s", "") == "") then + reqParamsClass = " no-param" + end + + Output([[ + + + + ]] .. Title .. [[ + + + + + +
+
+
+
+ +
+
+ +
+
+
+ + + + + + + +
+ + + + + + + + + + + + + + + + + +
Menu
Home
Server Management
+ ]]) + + + local AllPlugins = WebAdmin:GetPlugins() + for key,value in pairs(AllPlugins) do + local PluginWebTitle = value:GetWebTitle() + local TabNames = value:GetTabNames() + if (GetTableSize(TabNames) > 0) then + Output("\n"); + + for webname,prettyname in pairs(TabNames) do + Output("\n") + end + + Output("
\n"); + end + end + + + Output([[ +
+
+ + + + + + + + + +
]] .. SubTitle .. [[
]] .. PageContent .. [[
+
+
+
+ +
+ + +]]) + + return table.concat(SiteContent) +end -- cgit v1.2.3