From 3ea735592f26616c35ecddd44cf1a54415df20ac Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 8 Feb 2011 09:29:16 +0000 Subject: Add URI in html title. --- server/src/admin_connection.cc | 61 ++++++++++++++++++++++++++++++------------ server/src/admin_rc.cc | 21 ++++++++++++--- 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 act = env.sessions.activeSessions(); + std::vector::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" + "/sessionunlock?id=[ID] unlock session with [ID] as its session id.\n" + "/listactivesessions lists all active sessions on the server.\n" + "/flushsessions 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[] = "\n" "\n" "\n" - " Pracro admin\n" + " Pracro admin: "; + +static const char header2[] = + "\n" " \n" + " \n" " \n" " \n" - "
";
+  "    
";
 
 static const char footer[] =
   "
\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; } -- cgit v1.2.3