summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/admin_connection.cc61
-rw-r--r--server/src/admin_rc.cc21
2 files changed, 61 insertions, 21 deletions
diff --git a/server/src/admin_connection.cc b/server/src/admin_connection.cc
index ae427a3..e8c5b02 100644
--- a/server/src/admin_connection.cc
+++ b/server/src/admin_connection.cc
@@ -31,6 +31,8 @@
#include "debug.h"
+#include "configuration.h"
+
static std::string admin_sessionunlock(Environment &env, std::string id)
{
Session *session = env.sessions.session(id);
@@ -46,6 +48,31 @@ static std::string admin_sessionunlock(Environment &env, std::string id)
return "Session " + id + " does not exist or has been committed.";
}
+static std::string admin_listactivesessions(Environment &env)
+{
+ std::string str;
+
+ std::vector<std::string> act = env.sessions.activeSessions();
+ std::vector<std::string>::iterator i = act.begin();
+ while(i != act.end()) {
+ str += "Session " + *i + "\n";
+ i++;
+ }
+
+ return str;
+}
+
+static std::string admin_header(std::string uri)
+{
+ return admin_rc("header1") + uri + admin_rc("header2");
+}
+
+static std::string admin_flush(Environment &env)
+{
+ env.sessions.store();
+ return "All sessions flushed to disc in " + Conf::session_path + ".";
+}
+
AdminConnection::AdminConnection(Environment &e, headers_t a, std::string u)
: env(e), args(a), uri(u) {}
@@ -57,15 +84,29 @@ bool AdminConnection::handle(const char *data, size_t size)
DEBUG(admin, "URI: %s\n", uri.c_str());
if(uri == "/") {
- reply = admin_rc("header") +
+ reply = admin_header(uri) +
"Command list:\n"
- "/sessionunlock?id=[ID] unlock session with [ID] as its session id.\n"
+ "<strong>/sessionunlock?id=<em>[ID]</em></strong> unlock session with [ID] as its session id.\n"
+ "<strong>/listactivesessions</strong> lists all active sessions on the server.\n"
+ "<strong>/flushsessions</strong> flushes all active sessions to disc.\n"
+ admin_rc("footer");
return true;
}
if(uri == "/sessionunlock" && args.find("id") != args.end()) {
- reply = admin_rc("header") + admin_sessionunlock(env, args["id"])
+ reply = admin_header(uri) + admin_sessionunlock(env, args["id"])
+ + admin_rc("footer");
+ return true;
+ }
+
+ if(uri == "/listactivesessions") {
+ reply = admin_header(uri) + admin_listactivesessions(env)
+ + admin_rc("footer");
+ return true;
+ }
+
+ if(uri == "/flushsessions") {
+ reply = admin_header(uri) + admin_flush(env)
+ admin_rc("footer");
return true;
}
@@ -92,17 +133,3 @@ void AdminConnection::getReply(Httpd::Reply &r)
r.headers = hdrs;
r.status = 200; // http 'OK'
}
-
-#ifdef TEST_ADMIN_CONNECTION
-//deps:
-//cflags:
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
-
-TEST_END;
-
-#endif/*TEST_ADMIN_CONNECTION*/
diff --git a/server/src/admin_rc.cc b/server/src/admin_rc.cc
index ebf733e..bf790ae 100644
--- a/server/src/admin_rc.cc
+++ b/server/src/admin_rc.cc
@@ -389,16 +389,28 @@ static const char favicon[] = {
0x07, 0xff, 0xff
};
-static const char header[] =
+static const char header1[] =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\""
" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
"<head>\n"
- " <title>Pracro admin</title>\n"
+ " <title>Pracro admin: ";
+
+static const char header2[] =
+ "</title>\n"
" <link rel=\"shortcut icon\" href=\"/favicon.ico\"/>\n"
+ " <style type=\"text/css\">\n"
+ " .box {\n"
+ " background-color: #95B1FF;\n"
+ " padding: 10px;\n"
+ " -moz-border-radius: 6px; -khtml-border-radius: 6px; -webkit-border-radius: 6px; border-radius: 6px;\n"
+ " -moz-box-shadow: 5px 5px 5px #ccc; -webkit-box-shadow: 5px 5px 5px #ccc; box-shadow: 5px 5px 5px #ccc;\n"
+ " border: solid 1px #000;\n"
+ " }\n"
+ " </style>\n"
" </head>\n"
" <body>\n"
- " <pre>";
+ " <pre class=\"box\">";
static const char footer[] =
"</pre>\n"
@@ -409,7 +421,8 @@ std::string admin_rc(std::string key)
{
std::string val;
if(key == "favicon") val.append(favicon, faviconsize);
- if(key == "header") val = header;
+ if(key == "header1") val = header1;
+ if(key == "header2") val = header2;
if(key == "footer") val = footer;
return val;
}