summaryrefslogtreecommitdiffstats
path: root/MCServer/webadmin/template.lua
blob: a7480f83e259c0373974d8803eb3d5ef30f71417 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
-- 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 .. "<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
			Content = Content ..  "<li>" .. key .. " V." .. value:GetVersion() .. "</li>"
		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





function ShowPage(WebAdmin, TemplateRequest)
	SiteContent = {}
	local BaseURL = WebAdmin:GetBaseURL(TemplateRequest.Request.Path)
	local Title = "MCServer WebAdmin"
	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
	
	Output([[
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="/favicon.ico">
<title>]] .. Title .. [[</title>
<link rel="stylesheet" type="text/css" media="screen" href="/style.css">
</head>

<body>
	<div id="wrapper">
		<!-- h1 tag stays for the logo, you can use the a tag for linking the index page -->
		<h1>
			<a href="]] .. BaseURL .. [["><span>MCServer</span></a>
		</h1>
		<div id="containerHolder">
			<div id="container">
				<div id="sidebar">
					<ul class="sideNav">
	]])


	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("<li>"..PluginWebTitle.."</li>\n");
			
			for webname,prettyname in pairs(TabNames) do
				Output("<li><a href='" .. BaseURL .. PluginWebTitle .. "/" .. webname .. "'>" .. prettyname .. "</a></li>\n")
			end
		end
	end

	
	Output([[
					</ul>
					<!-- // .sideNav -->
				</div>    
				<!-- // #sidebar -->
				<!-- h2 stays for breadcrumbs -->
				<h2>Welcome ]] .. TemplateRequest.Request.Username .. [[</h2>
				<div id="main">
					<h3>]] .. SubTitle .. [[</h3>
					]] .. PageContent .. [[
				</div>
				<!-- // #main -->
				
				<div class="clear"></div>
				
			</div>
			<!-- // #container -->
		</div>	
		<!-- // #containerHolder -->
	    
		<p id="footer">MCServer is using: ]] .. MemoryUsageKiB / 1024 .. [[ MiB of memory; Current chunk count: ]] .. NumChunks .. [[ </p>
	</div>
	<!-- // #wrapper -->
</body>
</html>
	]])
	
	return table.concat(SiteContent)
end