diff --git a/WebContent/admin.jsp b/WebContent/admin.jsp
new file mode 100644
index 0000000..a359a00
--- /dev/null
+++ b/WebContent/admin.jsp
@@ -0,0 +1,99 @@
+
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+ pageEncoding="UTF-8" %>
+<%@ page import="com.google.inject.Injector" %>
+<%@ page import="net.socialgamer.cah.StartupUtils" %>
+<%@ page import="net.socialgamer.cah.data.ConnectedUsers" %>
+<%@ page import="net.socialgamer.cah.data.User" %>
+<%@ page import="java.util.Collection" %>
+<%@ page import="java.util.Date" %>
+
+<%
+String remoteAddr = request.getRemoteAddr();
+if (!(remoteAddr.equals("0:0:0:0:0:0:0:1") || remoteAddr.equals("127.0.0.1"))) {
+ response.sendError(403, "Access is restricted to known hosts");
+}
+%>
+
+
+
+
+
+CAH - Admin
+
+
+
+
+<%
+ServletContext servletContext = pageContext.getServletContext();
+Injector injector = (Injector) servletContext.getAttribute(StartupUtils.INJECTOR);
+%>
+
+
+ Server up since
+ <%
+ Date startedDate = (Date) servletContext.getAttribute(StartupUtils.DATE_NAME);
+ long uptime = System.currentTimeMillis() - startedDate.getTime();
+ uptime /= 1000l;
+ long seconds = uptime % 60l;
+ long minutes = (uptime / 60l) % 60l;
+ long hours = (uptime / 60l / 60l) % 24l;
+ long days = (uptime / 60l / 60l / 24l);
+ out.print(String.format("%s (%d hours, %02d:%02d:%02d)",
+ startedDate.toString(), days, hours, minutes, seconds));
+ %>
+
+
+
+
+ Stat |
+ MiB |
+
+
+ In Use |
+ <% out.print((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024); %> |
+
+
+ Free |
+ <% out.print(Runtime.getRuntime().freeMemory() / 1024 / 1024); %> |
+
+
+ JVM Allocated |
+ <% out.print(Runtime.getRuntime().totalMemory() / 1024 / 1024); %> |
+
+
+ JVM Max |
+ <% out.print(Runtime.getRuntime().maxMemory() / 1024 / 1024); %> |
+
+
+
+<%
+ConnectedUsers connectedUsers = injector.getInstance(ConnectedUsers.class);
+Collection users = connectedUsers.getUsers();
+%>
+
+
+
+ Username |
+
+ <%
+ for (User u : users) {
+ %>
+
+ <% out.print(u.getNickname()); %> |
+
+ <%
+ }
+ %>
+
+
+
+
diff --git a/src/net/socialgamer/cah/StartupUtils.java b/src/net/socialgamer/cah/StartupUtils.java
index 7a053c1..5fae531 100644
--- a/src/net/socialgamer/cah/StartupUtils.java
+++ b/src/net/socialgamer/cah/StartupUtils.java
@@ -1,5 +1,6 @@
package net.socialgamer.cah;
+import java.util.Date;
import java.util.Timer;
import javax.servlet.ServletContext;
@@ -20,6 +21,10 @@ public class StartupUtils extends GuiceServletContextListener {
private static final String PING_TIMER_NAME = "ping_timer";
+ public static final String DATE_NAME = "started_at";
+
+ private Date serverStarted;
+
@Override
public void contextDestroyed(final ServletContextEvent contextEvent) {
final ServletContext context = contextEvent.getServletContext();
@@ -28,6 +33,9 @@ public class StartupUtils extends GuiceServletContextListener {
timer.cancel();
context.removeAttribute(PING_TIMER_NAME);
context.removeAttribute(INJECTOR);
+ context.removeAttribute(DATE_NAME);
+
+ super.contextDestroyed(contextEvent);
}
@Override
@@ -37,8 +45,10 @@ public class StartupUtils extends GuiceServletContextListener {
final UserPing ping = injector.getInstance(UserPing.class);
final Timer timer = new Timer();
timer.schedule(ping, PING_START_DELAY, PING_CHECK_DELAY);
+ serverStarted = new Date();
context.setAttribute(PING_TIMER_NAME, timer);
context.setAttribute(INJECTOR, injector);
+ context.setAttribute(DATE_NAME, serverStarted);
}
@Override