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
2013-07-28 20:37:59 -04:00
function GetDefaultPage ( )
local PM = cRoot : Get ( ) : GetPluginManager ( )
local SubTitle = " Current Game "
local Content = " "
Content = Content .. " <h4>Server Name:</h4> "
Content = Content .. " <p> " .. cRoot : Get ( ) : GetServer ( ) : GetServerID ( ) .. " </p> "
Content = Content .. " <h4>Plugins:</h4><ul> "
local AllPlugins = PM : GetAllPlugins ( )
for key , value in pairs ( AllPlugins ) do
if ( value ~= nil and value ~= false ) then
2014-10-22 08:55:21 -04:00
Content = Content .. " <li> " .. key .. " (version " .. value : GetVersion ( ) .. " )</li> "
2013-07-28 20:37:59 -04:00
end
end
Content = Content .. " </ul> "
Content = Content .. " <h4>Players:</h4><ul> "
local AddPlayerToTable = function ( Player )
Content = Content .. " <li> " .. Player : GetName ( ) .. " </li> "
end
cRoot : Get ( ) : ForEachPlayer ( AddPlayerToTable )
Content = Content .. " </ul><br> " ;
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 = { }
local BaseURL = WebAdmin : GetBaseURL ( TemplateRequest.Request . Path )
2014-08-31 08:39:58 -04:00
local Title = " MCServer WebAdmin "
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 ( )
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
2014-10-05 05:08:10 -04:00
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
2013-07-28 20:37:59 -04:00
Output ( [ [
< ! DOCTYPE html >
< head >
< meta http - equiv = " Content-Type " content = " text/html; charset=utf-8 " />
2014-08-31 08:51:07 -04:00
< link rel = " icon " href = " /favicon.ico " >
2013-07-28 20:37:59 -04:00
< title > ] ] .. Title .. [ [ </ title >
2014-10-05 05:08:10 -04:00
< link href = ' http://fonts.googleapis.com/css?family=Open+Sans:400,600,300 ' rel = ' stylesheet ' type = ' text/css ' >
< link rel = " stylesheet " type = " text/css " href = " /style.css " >
2013-07-28 20:37:59 -04:00
</ head >
< body >
2014-10-05 05:08:10 -04:00
< div id = " wrapper " >
< div id = " containerHolder " >
< a href = " ./ " class = " title light " > MCServer </ a >
< div id = " container " >
< div id = " sidebar " >
< ul class = " sideNav " >
< li class = ' link ' >< a href = ' ]] .. BaseURL .. [[ ' > Home </ a ></ li >
2013-07-28 20:37:59 -04:00
] ] )
2013-08-06 13:28:09 -04:00
2014-08-31 08:51:07 -04:00
2013-07-28 20:37:59 -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
2014-08-31 08:51:07 -04:00
Output ( " <li> " .. PluginWebTitle .. " </li> \n " ) ;
2013-07-28 20:37:59 -04:00
for webname , prettyname in pairs ( TabNames ) do
2014-10-05 05:08:10 -04:00
Output ( " <li class='link'><a href=' " .. BaseURL .. PluginWebTitle .. " / " .. webname .. " '> " .. prettyname .. " </a></li> \n " )
2013-07-28 20:37:59 -04:00
end
end
end
2013-08-06 13:28:09 -04:00
2013-07-28 20:37:59 -04:00
Output ( [ [
</ ul >
2014-10-05 05:08:10 -04:00
</ div >
< div id = " main " class = " page-]] .. string.lower(PluginPage.PluginName .. " - " .. string.gsub(PluginPage.TabName, " [ ^ a - zA - Z0 - 9 ] + " , " - " )) .. reqParamsClass .. [[ " >
< h2 class = " welcome-msg " > Welcome < span class = " username " > ] ] .. TemplateRequest.Request . Username .. [ [ </ span ></ h2 >
2013-07-28 20:37:59 -04:00
2014-10-05 05:08:10 -04:00
< hr />
2013-07-28 20:37:59 -04:00
2014-10-05 05:08:10 -04:00
< h3 > ] ] .. SubTitle .. [ [ </ h3 >
] ] .. PageContent .. [ [ </ div >
< div class = " clear " ></ div >
</ div >
2013-07-28 20:37:59 -04:00
</ div >
2014-10-05 05:08:10 -04:00
< div id = " footer " >< div class = " fleft " > running MCServer using < span class = " bold " > ] ] .. MemoryUsageKiB / 1024 .. [[MB</span> of memory; <span class="bold">]] .. NumChunks .. [ [ </ span > chunks </ div >< div class = " fright " > design by < a href = " //www.github.com/WebFreak001 " > WebFreak001 </ a ></ div >< div class = " clear " ></ div ></ div >
</ div >
2013-07-28 20:37:59 -04:00
</ body >
</ html >
2014-10-05 05:08:10 -04:00
] ] )
2013-07-28 20:37:59 -04:00
return table.concat ( SiteContent )
2014-08-31 08:39:58 -04:00
end