2013-07-28 20:37:59 -04:00
|
|
|
-- Use a table for fast concatenation of strings
|
|
|
|
local SiteContent = {}
|
|
|
|
function Output(String)
|
|
|
|
table.insert(SiteContent, String)
|
|
|
|
end
|
|
|
|
|
2013-08-06 13:28:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
function GetTableSize(Table)
|
|
|
|
local Size = 0
|
|
|
|
for key,value in pairs(Table) do
|
|
|
|
Size = Size + 1
|
|
|
|
end
|
|
|
|
return Size
|
|
|
|
end
|
|
|
|
|
2013-08-06 13:28:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-21 04:58:15 -04:00
|
|
|
function GetDefaultPage()
|
2013-07-28 20:37:59 -04:00
|
|
|
local PM = cRoot:Get():GetPluginManager()
|
|
|
|
|
2014-10-27 19:08:29 -04:00
|
|
|
local SubTitle = "Current Game"
|
2013-07-28 20:37:59 -04:00
|
|
|
local Content = ""
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2014-10-27 19:08:29 -04:00
|
|
|
Content = Content .. "<h4>Plugins:</h4><ul>"
|
2015-04-19 04:57:41 -04:00
|
|
|
PM:ForEachPlugin(
|
|
|
|
function (a_CBPlugin)
|
|
|
|
if (a_CBPlugin:IsLoaded()) then
|
|
|
|
Content = Content .. "<li>" .. a_CBPlugin:GetName() .. " (version " .. a_CBPlugin:GetVersion() .. ")</li>"
|
|
|
|
end
|
2014-10-27 19:08:29 -04:00
|
|
|
end
|
2015-04-19 04:57:41 -04:00
|
|
|
)
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2014-10-27 19:08:29 -04:00
|
|
|
Content = Content .. "</ul>"
|
|
|
|
Content = Content .. "<h4>Players:</h4><ul>"
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2015-04-19 04:57:41 -04:00
|
|
|
cRoot:Get():ForEachPlayer(
|
|
|
|
function(a_CBPlayer)
|
2015-05-02 13:16:25 -04:00
|
|
|
Content = Content .. "<li>" .. a_CBPlayer:GetName() .. "</li>"
|
2015-04-19 04:57:41 -04:00
|
|
|
end
|
|
|
|
)
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2014-10-27 19:08:29 -04:00
|
|
|
Content = Content .. "</ul><br>";
|
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
return Content, SubTitle
|
|
|
|
end
|
|
|
|
|
2013-08-06 13:28:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
function ShowPage(WebAdmin, TemplateRequest)
|
|
|
|
SiteContent = {}
|
2016-03-21 04:58:15 -04:00
|
|
|
local BaseURL = WebAdmin:GetBaseURL(TemplateRequest.Request.Path)
|
2015-07-12 06:31:43 -04:00
|
|
|
local Title = "Cuberite WebAdmin"
|
2014-12-30 04:31:16 -05:00
|
|
|
local NumPlayers = cRoot:Get():GetServer():GetNumPlayers()
|
2013-10-08 14:24:35 -04:00
|
|
|
local MemoryUsageKiB = cRoot:GetPhysicalRAMUsage()
|
2013-07-28 20:37:59 -04:00
|
|
|
local NumChunks = cRoot:Get():GetTotalChunkCount()
|
2016-03-21 04:58:15 -04:00
|
|
|
local PluginPage = WebAdmin:GetPage(TemplateRequest.Request)
|
2013-07-28 20:37:59 -04:00
|
|
|
local PageContent = PluginPage.Content
|
2016-03-21 04:58:15 -04:00
|
|
|
local SubTitle = PluginPage.PluginName
|
|
|
|
if (PluginPage.TabName ~= "") then
|
|
|
|
SubTitle = PluginPage.PluginName .. " - " .. PluginPage.TabName
|
2013-07-28 20:37:59 -04:00
|
|
|
end
|
|
|
|
if (PageContent == "") then
|
|
|
|
PageContent, SubTitle = GetDefaultPage()
|
|
|
|
end
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2014-10-05 05:08:10 -04:00
|
|
|
local reqParamsClass = ""
|
2016-03-21 04:58:15 -04:00
|
|
|
|
|
|
|
for key,value in pairs(TemplateRequest.Request.Params) do
|
2014-10-05 05:08:10 -04:00
|
|
|
reqParamsClass = reqParamsClass .. " param-" .. string.lower(string.gsub(key, "[^a-zA-Z0-9]+", "-") .. "-" .. string.gsub(value, "[^a-zA-Z0-9]+", "-"))
|
|
|
|
end
|
2016-03-21 04:58:15 -04:00
|
|
|
|
2014-10-05 05:08:10 -04:00
|
|
|
if (string.gsub(reqParamsClass, "%s", "") == "") then
|
|
|
|
reqParamsClass = " no-param"
|
|
|
|
end
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
Output([[
|
2016-01-01 15:05:09 -05:00
|
|
|
<!-- Copyright Justin S and Cuberite Team, licensed under CC-BY-SA 3.0 -->
|
2014-10-28 17:12:57 -04:00
|
|
|
<html>
|
2013-07-28 20:37:59 -04:00
|
|
|
<head>
|
2014-10-28 17:12:57 -04:00
|
|
|
<title>]] .. Title .. [[</title>
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
<link rel="stylesheet" type="text/css" href="/style.css">
|
|
|
|
<link rel="icon" href="/favicon.ico">
|
2013-07-28 20:37:59 -04:00
|
|
|
</head>
|
|
|
|
<body>
|
2014-11-05 08:20:03 -05:00
|
|
|
<div class="contention push25">
|
2014-11-03 18:17:14 -05:00
|
|
|
<div class="pagehead">
|
|
|
|
<div class="row1">
|
|
|
|
<div class="wrapper">
|
2016-01-01 15:05:09 -05:00
|
|
|
<img src="/logo_login.png" alt="Cuberite Logo" class="logo">
|
2014-11-03 18:17:14 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div id="panel">
|
|
|
|
<div class="upper">
|
|
|
|
<div class="wrapper">
|
|
|
|
<ul class="menu top_links">
|
2014-12-29 14:21:57 -05:00
|
|
|
<li><a>Players online: <strong>]] .. NumPlayers .. [[</strong></a></li>
|
2015-04-20 03:41:27 -04:00
|
|
|
<li><a>Memory: <strong>]] .. string.format("%.2f", MemoryUsageKiB / 1024) .. [[MB</strong></a></li>
|
2014-11-03 18:17:14 -05:00
|
|
|
<li><a>Chunks: <strong>]] .. NumChunks .. [[</strong></a></li>
|
|
|
|
</ul>
|
|
|
|
<div class="welcome"><strong>Welcome back, ]] .. TemplateRequest.Request.Username .. [[</strong> <a href=".././"><img src="/log_out.png" style="vertical-align:bottom;"> Log Out</a></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2014-11-05 08:20:03 -05:00
|
|
|
<div class="row2">
|
|
|
|
<div class="wrapper">
|
|
|
|
<table width="100%" border="0" align="center">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td width="180" valign="top">
|
|
|
|
<table border="0" cellspacing="0" cellpadding="5" class="tborder">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td class="thead"><strong>Menu</strong></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td class="trow1 smalltext"><a href=']] .. BaseURL .. [[' class='usercp_nav_item usercp_nav_home'>Home</a></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td class="tcat"><div><span class="smalltext"><strong><font color="#000">Server Management</font></strong></span></div></td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
<tbody style="" id="usercppms_e">
|
|
|
|
<tr>
|
|
|
|
<td class="trow1 smalltext">
|
2013-07-28 20:37:59 -04:00
|
|
|
]])
|
2013-08-06 13:28:09 -04:00
|
|
|
|
2016-03-21 04:58:15 -04:00
|
|
|
|
|
|
|
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("<div><a class='usercp_nav_item usercp_nav_pmfolder' style='text-decoration:none;'><b>"..PluginWebTitle.."</b></a></div>\n");
|
|
|
|
|
|
|
|
for webname,prettyname in pairs(TabNames) do
|
|
|
|
Output("<div><a href='" .. BaseURL .. PluginWebTitle .. "/" .. webname .. "' class='usercp_nav_item usercp_nav_sub_pmfolder'>" .. prettyname .. "</a></div>\n")
|
2013-07-28 20:37:59 -04:00
|
|
|
end
|
2016-03-21 04:58:15 -04:00
|
|
|
|
|
|
|
Output("<br>\n");
|
2013-07-28 20:37:59 -04:00
|
|
|
end
|
|
|
|
end
|
2013-08-06 13:28:09 -04:00
|
|
|
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2014-11-03 18:17:14 -05:00
|
|
|
Output([[
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
<td valign="top" style='padding-left:25px;'>
|
|
|
|
<table border="0" cellspacing="0" cellpadding="5" class="tborder">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td class="thead" colspan="2"><strong>]] .. SubTitle .. [[</strong></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td class="trow2">]] .. PageContent .. [[</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
2014-10-27 13:45:41 -04:00
|
|
|
<div id="footer">
|
2014-11-03 18:17:14 -05:00
|
|
|
<div class="upper">
|
|
|
|
<div class="wrapper">
|
|
|
|
<ul class="menu bottom_links">
|
2016-01-30 19:25:03 -05:00
|
|
|
<li><a href="http://cuberite.org/" target="_blank">Cuberite</a></li>
|
|
|
|
<li><a href="https://forum.cuberite.org/" target="_blank">Forums</a></li>
|
|
|
|
<li><a href="https://builds.cuberite.org/" target="_blank">Buildserver</a></li>
|
|
|
|
<li><a href="http://api-docs.cuberite.org/" target="_blank">API Documentation</a></li>
|
2015-12-19 09:30:32 -05:00
|
|
|
<li><a href="https://book.cuberite.org/" target="_blank">User's Manual</a></li>
|
2014-11-03 18:17:14 -05:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="lower">
|
|
|
|
<div class="wrapper">
|
2016-01-30 19:25:03 -05:00
|
|
|
<span id="copyright">Copyright © <a href="http://cuberite.org/" target="_blank">Cuberite Team</a>.</span>
|
2014-11-03 18:17:14 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
2014-10-27 13:45:41 -04:00
|
|
|
</div>
|
2014-11-05 08:20:03 -05:00
|
|
|
</div>
|
2014-11-03 18:17:14 -05:00
|
|
|
</body>
|
|
|
|
</html>
|
2014-10-05 05:08:10 -04:00
|
|
|
]])
|
2015-12-19 09:30:32 -05:00
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
return table.concat(SiteContent)
|
2014-08-31 08:39:58 -04:00
|
|
|
end
|