diff options
Diffstat (limited to 'server/src/admin_connection.cc')
-rw-r--r-- | server/src/admin_connection.cc | 137 |
1 files changed, 73 insertions, 64 deletions
diff --git a/server/src/admin_connection.cc b/server/src/admin_connection.cc index fac52a1..76c88ea 100644 --- a/server/src/admin_connection.cc +++ b/server/src/admin_connection.cc @@ -35,6 +35,7 @@ #include "debug.h" #include "configuration.h" +#include "sessionserialiser.h" static std::string admin_sessionunlock(Environment &env, std::string id) { @@ -59,18 +60,28 @@ 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(); + std::vector<Sessions::SessionInfo> act = env.sessions.activeSessions(); + std::vector<Sessions::SessionInfo>::iterator i = act.begin(); while(i != act.end()) { - // NOTE: Returned session is returned in locked state! - Session *s = NULL; - SessionAutounlock l(&s); - s = env.sessions.lockedSession(*i); - str += "Session " + *i + ": "+s->templ+" on "+s->patientid+" "+ - std::string(s->idle()?"[idle]":"[active]")+"\n"; + str += "Session " + i->id + ": "+i->templ+" on "+i->patientid+" "+ + std::string(i->idle?"[idle]":"[active]")+"\n"; i++; } + SessionSerialiser ser(&env, Conf::session_path); + std::map<std::string, SessionHeaderParser::Header> files = ser.sessionFiles(); + + std::map<std::string, SessionHeaderParser::Header>::iterator j = files.begin(); + while(j != files.end()) { + std::string file = j->first; + SessionHeaderParser::Header header = j->second; + + str += "Session " + header.id + ": " + header.templ + " on " + + header.patientid + " [session file: " + file + "]\n"; + + j++; + } + return str; } @@ -90,70 +101,68 @@ AdminConnection::AdminConnection(Environment &e, headers_t a, std::string u) AdminConnection::~AdminConnection() {} -bool AdminConnection::handle(const char *data, size_t size) +bool AdminConnection::data(const char *, size_t) { return true; } + +bool AdminConnection::handle() { status = 200; // OK - if(data == NULL && size == 0) { - DEBUG(admin, "URI: %s\n", uri.c_str()); - - if(uri == "/") { - reply = admin_header(uri) + - "Command list:\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" - "<strong>/export?template=<em>[TEMPLATE]</em></strong> export template with name [TEMPLATE] to a\n csf file (comma seperated file, that can be opened in OOCalc or Excel).\n" - + admin_rc("footer"); - return true; - } - - if(uri == "/sessionunlock" && args.find("id") != args.end()) { - 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; - } - - if(uri == "/export" && args.find("template") != args.end()) { - time_t from = 0; - if(args.find("from") != args.end()) from = atoi(args["from"].c_str()); - - time_t to = time(NULL); - if(args.find("to") != args.end()) to = atoi(args["to"].c_str()); - bool ok; - std::string res = admin_export(env, args["template"], &ok, from, to); - if(!ok) reply = admin_header(uri) + res + admin_rc("footer"); - else { - reply = res; - hdrs["Content-Type"] = "text/csv; charset=UTF-8"; - hdrs["Content-Disposition"] = "attachment; filename=\""+args["template"]+".csv\""; - } - return true; - } - - if(uri == "/favicon.ico") { - hdrs["Content-Type"] = "image/ico"; - reply = admin_rc("favicon"); - return true; - } + DEBUG(admin, "URI: %s\n", uri.c_str()); - reply = admin_header(uri) + - "'" + uri + "' not recognised as a valid command." + if(uri == "/") { + reply = admin_header(uri) + + "Command list:\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" + "<strong>/export?template=<em>[TEMPLATE]</em></strong> export template with name [TEMPLATE] to a\n csf file (comma seperated file, that can be opened in OOCalc or Excel).\n" + + admin_rc("footer"); + return true; + } + + if(uri == "/sessionunlock" && args.find("id") != args.end()) { + 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; + } + + if(uri == "/export" && args.find("template") != args.end()) { + time_t from = 0; + if(args.find("from") != args.end()) from = atoi(args["from"].c_str()); + + time_t to = time(NULL); + if(args.find("to") != args.end()) to = atoi(args["to"].c_str()); + bool ok; + std::string res = admin_export(env, args["template"], &ok, from, to); + if(!ok) reply = admin_header(uri) + res + admin_rc("footer"); + else { + reply = res; + hdrs["Content-Type"] = "text/csv; charset=UTF-8"; + hdrs["Content-Disposition"] = "attachment; filename=\""+args["template"]+".csv\""; + } + return true; + } + if(uri == "/favicon.ico") { + hdrs["Content-Type"] = "image/ico"; + reply = admin_rc("favicon"); + return true; + } + + reply = admin_header(uri) + + "'" + uri + "' not recognised as a valid command." + + admin_rc("footer"); return true; } |