From c01f7bf989dedcc61e4e812fd57d6d73997cfd85 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Fri, 14 Sep 2007 14:07:30 +0000 Subject: added subnets of CHILD_SAs to xml interface a first design of Managers IKE_SA list page --- src/charon/control/interfaces/xml_interface.c | 37 +- src/manager/Makefile.am | 7 +- src/manager/controller/auth_controller.c | 30 +- src/manager/controller/gateway_controller.c | 40 +- src/manager/controller/static_controller.c | 103 - src/manager/controller/static_controller.h | 47 - src/manager/controller/status_controller.c | 85 +- src/manager/lib/controller.h | 21 +- src/manager/lib/dispatcher.c | 23 +- src/manager/lib/dispatcher.h | 7 +- src/manager/lib/response.c | 10 + src/manager/lib/response.h | 7 + src/manager/lib/session.c | 20 +- src/manager/lib/session.h | 2 +- src/manager/lib/template.c | 2 + src/manager/lib/template.h | 4 + src/manager/main.c | 15 +- src/manager/templates/auth/login.cs | 8 +- src/manager/templates/auth/logout.cs | 0 src/manager/templates/footer.cs | 2 + src/manager/templates/gateway/list.cs | 2 + src/manager/templates/header.cs | 20 +- src/manager/templates/static/client-left.png | Bin 0 -> 6649 bytes src/manager/templates/static/client-right.png | Bin 0 -> 6703 bytes src/manager/templates/static/gateway-left.png | Bin 0 -> 2441 bytes src/manager/templates/static/gateway-right.png | Bin 0 -> 2488 bytes src/manager/templates/static/jquery.js | 2965 ++++++++++++++++++++++++ src/manager/templates/static/nat.png | Bin 0 -> 4751 bytes src/manager/templates/static/pipe-bad.png | Bin 0 -> 4445 bytes src/manager/templates/static/pipe-good.png | Bin 0 -> 4536 bytes src/manager/templates/static/pipe.png | Bin 0 -> 316 bytes src/manager/templates/static/router.png | Bin 0 -> 5059 bytes src/manager/templates/static/script.js | 8 + src/manager/templates/static/strongswan.png | Bin 0 -> 19837 bytes src/manager/templates/static/style.css | 206 +- src/manager/templates/status/ikesalist.cs | 135 +- 36 files changed, 3391 insertions(+), 415 deletions(-) delete mode 100644 src/manager/controller/static_controller.c delete mode 100644 src/manager/controller/static_controller.h delete mode 100644 src/manager/templates/auth/logout.cs create mode 100644 src/manager/templates/static/client-left.png create mode 100644 src/manager/templates/static/client-right.png create mode 100644 src/manager/templates/static/gateway-left.png create mode 100644 src/manager/templates/static/gateway-right.png create mode 100644 src/manager/templates/static/jquery.js create mode 100644 src/manager/templates/static/nat.png create mode 100644 src/manager/templates/static/pipe-bad.png create mode 100644 src/manager/templates/static/pipe-good.png create mode 100644 src/manager/templates/static/pipe.png create mode 100644 src/manager/templates/static/router.png create mode 100644 src/manager/templates/static/script.js create mode 100644 src/manager/templates/static/strongswan.png (limited to 'src') diff --git a/src/charon/control/interfaces/xml_interface.c b/src/charon/control/interfaces/xml_interface.c index 7710ae19c..3946611db 100644 --- a/src/charon/control/interfaces/xml_interface.c +++ b/src/charon/control/interfaces/xml_interface.c @@ -145,6 +145,41 @@ static void write_address(xmlTextWriterPtr writer, char *element, host_t *host) xmlTextWriterEndElement(writer); } +/** + * write a list of traffic_selector_t + */ +static void write_ts(xmlTextWriterPtr writer, linked_list_t *list) +{ + iterator_t *iterator; + traffic_selector_t *ts; + + iterator = list->create_iterator(list, TRUE); + while (iterator->iterate(iterator, (void**)&ts)) + { + xmlTextWriterStartElement(writer, "net"); + xmlTextWriterWriteAttribute(writer, "type", + ts->get_type(ts) == TS_IPV4_ADDR_RANGE ? "ipv4" : "ipv6"); + xmlTextWriterWriteFormatString(writer, "%R", ts); + xmlTextWriterEndElement(writer); + } + iterator->destroy(iterator); +} + +/** + * write a child_sa_t + */ +static void write_child(xmlTextWriterPtr writer, child_sa_t *child) +{ + xmlTextWriterStartElement(writer, "childsa"); + xmlTextWriterStartElement(writer, "local"); + write_ts(writer, child->get_traffic_selectors(child, TRUE)); + xmlTextWriterEndElement(writer); + xmlTextWriterStartElement(writer, "remote"); + write_ts(writer, child->get_traffic_selectors(child, FALSE)); + xmlTextWriterEndElement(writer); + xmlTextWriterEndElement(writer); +} + /** * process a ikesalist query request message */ @@ -214,7 +249,7 @@ static void request_query_ikesa(xmlTextReaderPtr reader, xmlTextWriterPtr writer children = ike_sa->create_child_sa_iterator(ike_sa); while (children->iterate(children, (void**)&child_sa)) { - /* TODO: Children */ + write_child(writer, child_sa); } children->destroy(children); /* */ diff --git a/src/manager/Makefile.am b/src/manager/Makefile.am index 686c312df..7a8ffe0b1 100644 --- a/src/manager/Makefile.am +++ b/src/manager/Makefile.am @@ -3,7 +3,6 @@ ipsec_PROGRAMS = manager.fcgi manager_fcgi_SOURCES = \ main.c manager.c manager.h gateway.h gateway.c database.h database.c \ controller/auth_controller.c controller/auth_controller.h \ -controller/static_controller.c controller/static_controller.h \ controller/status_controller.c controller/status_controller.h \ controller/gateway_controller.c controller/gateway_controller.h @@ -21,6 +20,7 @@ lib/template.h lib/template.c lib/dict.h lib/dict.c lib/xml.h lib/xml.c lib/enum libappserv_la_LDFLAGS = -lstrongswan -lfcgi -lpthread -lneo_cs -lneo_utl ${xml_LIBS} INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/manager/lib -I/usr/include/ClearSilver ${xml_CFLAGS} +AM_CFLAGS = -rdynamic -DIPSECDIR=\"${ipsecdir}\" -DIPSEC_PIDDIR=\"${piddir}\" ipsec_DATA = sqlite.db @@ -29,7 +29,7 @@ ipsec_templatesdir = ${ipsecdir}/templates ipsec_templates_DATA = templates/header.cs templates/footer.cs ipsec_templates_authdir = ${ipsec_templatesdir}/auth -ipsec_templates_auth_DATA = templates/auth/login.cs templates/auth/logout.cs +ipsec_templates_auth_DATA = templates/auth/login.cs ipsec_templates_gatewaydir = ${ipsec_templatesdir}/gateway ipsec_templates_gateway_DATA = templates/gateway/list.cs @@ -37,6 +37,9 @@ ipsec_templates_gateway_DATA = templates/gateway/list.cs ipsec_templates_statusdir = ${ipsec_templatesdir}/status ipsec_templates_status_DATA = templates/status/ikesalist.cs +ipsec_templates_staticdir = ${ipsec_templatesdir}/static +ipsec_templates_static_DATA = templates/static/style.css templates/static/script.js + EXTRA_DIST = sqlite.db templates/header.cs templates/footer.cs \ templates/auth/login.cs templates/auth/logout.cs \ templates/gateway/list.cs templates/status/ikesalist.cs diff --git a/src/manager/controller/auth_controller.c b/src/manager/controller/auth_controller.c index 1026b5eeb..68332da46 100644 --- a/src/manager/controller/auth_controller.c +++ b/src/manager/controller/auth_controller.c @@ -51,6 +51,7 @@ static void login(private_auth_controller_t *this, { template_t *t = template_create("templates/auth/login.cs"); t->set(t, "action", "check"); + t->set(t, "title", "Login"); t->render(t, response); t->destroy(t); } @@ -65,7 +66,7 @@ static void check(private_auth_controller_t *this, if (username && password && this->manager->login(this->manager, username, password)) { - response->redirect(response, "status/test"); + response->redirect(response, "status/ikesalist"); } else { @@ -89,14 +90,27 @@ static char* get_name(private_auth_controller_t *this) } /** - * Implementation of controller_t.get_handler + * Implementation of controller_t.handle */ -static controller_handler_t get_handler(private_auth_controller_t *this, char *name) +static void handle(private_auth_controller_t *this, + request_t *request, response_t *response, char *action) { - if (streq(name, "login")) return (controller_handler_t)login; - if (streq(name, "check")) return (controller_handler_t)check; - if (streq(name, "logout")) return (controller_handler_t)logout; - return NULL; + if (action) + { + if (streq(action, "login")) + { + return login(this, request, response); + } + else if (streq(action, "check")) + { + return check(this, request, response); + } + else if (streq(action, "logout")) + { + return logout(this, request, response); + } + } + response->redirect(response, "auth/login"); } /** @@ -115,7 +129,7 @@ controller_t *auth_controller_create(context_t *context, void *param) private_auth_controller_t *this = malloc_thing(private_auth_controller_t); this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.get_handler = (controller_handler_t(*)(controller_t*,char*))get_handler; + this->public.controller.handle = (void(*)(controller_t*,request_t*,response_t*,char*,char*,char*,char*,char*))handle; this->public.controller.destroy = (void(*)(controller_t*))destroy; this->manager = (manager_t*)context; diff --git a/src/manager/controller/gateway_controller.c b/src/manager/controller/gateway_controller.c index 32576216e..1ebb51192 100644 --- a/src/manager/controller/gateway_controller.c +++ b/src/manager/controller/gateway_controller.c @@ -72,6 +72,7 @@ static void list(private_gateway_controller_t *this, } enumerator->destroy(enumerator); t->set(t, "action", "select"); + t->set(t, "title", "Choose gateway"); t->render(t, response); t->destroy(t); } @@ -90,16 +91,7 @@ static void _select(private_gateway_controller_t *this, return; } } - response->printf(response, "selecting dings failed: %s", id); -} - -/** - * redirect to authentication login - */ -static void login(private_gateway_controller_t *this, - request_t *request, response_t *response) -{ - response->redirect(response, "auth/login"); + response->printf(response, "selecting gateway failed: %s", id); } /** @@ -111,16 +103,30 @@ static char* get_name(private_gateway_controller_t *this) } /** - * Implementation of controller_t.get_handler + * Implementation of controller_t.handle */ -static controller_handler_t get_handler(private_gateway_controller_t *this, char *name) +static void handle(private_gateway_controller_t *this, + request_t *request, response_t *response, char *action) { - if (!this->manager->logged_in(this->manager)) return (controller_handler_t)login; - if (streq(name, "list")) return (controller_handler_t)list; - if (streq(name, "select")) return (controller_handler_t)_select; - return NULL; + if (!this->manager->logged_in(this->manager)) + { + return response->redirect(response, "auth/login"); + } + if (action) + { + if (streq(action, "list")) + { + return list(this, request, response); + } + else if (streq(action, "select")) + { + return _select(this, request, response); + } + } + response->redirect(response, "gateway/list"); } + /** * Implementation of controller_t.destroy */ @@ -137,7 +143,7 @@ controller_t *gateway_controller_create(context_t *context, void *param) private_gateway_controller_t *this = malloc_thing(private_gateway_controller_t); this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.get_handler = (controller_handler_t(*)(controller_t*,char*))get_handler; + this->public.controller.handle = (void(*)(controller_t*,request_t*,response_t*,char*,char*,char*,char*,char*))handle; this->public.controller.destroy = (void(*)(controller_t*))destroy; this->manager = (manager_t*)context; diff --git a/src/manager/controller/static_controller.c b/src/manager/controller/static_controller.c deleted file mode 100644 index 8968c873c..000000000 --- a/src/manager/controller/static_controller.c +++ /dev/null @@ -1,103 +0,0 @@ -/** - * @file static_controller.c - * - * @brief Implementation of static_controller_t. - * - */ - -/* - * Copyright (C) 2007 Martin Willi - * Hochschule fuer Technik Rapperswil - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. See . - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#include "static_controller.h" -#include "../manager.h" -#include "../gateway.h" - -#include - -#include - - -typedef struct private_static_controller_t private_static_controller_t; - -/** - * private data of the task manager - */ -struct private_static_controller_t { - - /** - * public functions - */ - static_controller_t public; - - /** - * manager instance - */ - manager_t *manager; - -}; - -/** - * serve style.css - */ -static void style(private_static_controller_t *this, - request_t *request, response_t *response) -{ - template_t *t = template_create("templates/static/style.css"); - response->set_content_type(response, "text/css"); - t->render(t, response); - t->destroy(t); -} - -/** - * Implementation of controller_t.get_name - */ -static char* get_name(private_static_controller_t *this) -{ - return "static"; -} - -/** - * Implementation of controller_t.get_handler - */ -static controller_handler_t get_handler(private_static_controller_t *this, char *name) -{ - if (streq(name, "style.css")) return (controller_handler_t)style; - return NULL; -} - -/** - * Implementation of controller_t.destroy - */ -static void destroy(private_static_controller_t *this) -{ - free(this); -} - -/* - * see header file - */ -controller_t *static_controller_create(context_t *context, void *param) -{ - private_static_controller_t *this = malloc_thing(private_static_controller_t); - - this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.get_handler = (controller_handler_t(*)(controller_t*,char*))get_handler; - this->public.controller.destroy = (void(*)(controller_t*))destroy; - - this->manager = (manager_t*)context; - - return &this->public.controller; -} - diff --git a/src/manager/controller/static_controller.h b/src/manager/controller/static_controller.h deleted file mode 100644 index 8181a7a16..000000000 --- a/src/manager/controller/static_controller.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * @file static_controller.h - * - * @brief Interface of static_controller_t. - * - */ - -/* - * Copyright (C) 2007 Martin Willi - * Hochschule fuer Technik Rapperswil - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. See . - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#ifndef STATIC_CONTROLLER_H_ -#define STATIC_CONTROLLER_H_ - - -#include - -typedef struct static_controller_t static_controller_t; - -/** - * @brief Static controller, serves static files. - */ -struct static_controller_t { - - /** - * Implements controller_t interface. - */ - controller_t controller; -}; - -/** - * @brief Create a static_controller controller instance. - */ -controller_t *static_controller_create(context_t *context, void *param); - -#endif /* STATIC_CONTROLLER_H_ */ diff --git a/src/manager/controller/status_controller.c b/src/manager/controller/status_controller.c index e3abda00f..70711763a 100644 --- a/src/manager/controller/status_controller.c +++ b/src/manager/controller/status_controller.c @@ -53,9 +53,9 @@ static void ikesalist(private_status_controller_t *this, { char *str; gateway_t *gateway; - xml_t *doc, *node; - enumerator_t *e1, *e2, *e3, *e4, *e5, *e6; - char *name, *value, *id, *section; + xml_t *node; + enumerator_t *e1, *e2, *e3, *e4, *e5, *e6, *e7, *e8; + char *name, *value, *id = "", *section; gateway = this->manager->select_gateway(this->manager, 0); str = gateway->request(gateway, "" @@ -69,8 +69,8 @@ static void ikesalist(private_status_controller_t *this, return; } - doc = xml_create(str); - if (doc == NULL) + node = xml_create(str); + if (node == NULL) { response->printf(response, "parsing XML failed"); return; @@ -78,7 +78,7 @@ static void ikesalist(private_status_controller_t *this, template_t *t = template_create("templates/status/ikesalist.cs"); - e1 = doc->children(doc); + e1 = node->children(node); while (e1->enumerate(e1, &node, &name, &value)) { if (streq(name, "message")) @@ -116,6 +116,33 @@ static void ikesalist(private_status_controller_t *this, } e6->destroy(e6); } + else if (streq(name, "childsalist")) + { + e6 = node->children(node); + while (e6->enumerate(e6, &node, &name, &value)) + { + if (streq(name, "childsa")) + { + e7 = node->children(node); + while (e7->enumerate(e7, &node, &name, &value)) + { + if (streq(name, "local") || + streq(name, "remote")) + { + section = name; + e8 = node->children(node); + while (e8->enumerate(e8, &node, &name, &value)) + { + t->setf(t, "ikesas.%s.childsas.%s.%s=%s", id, section, name, value); + } + e8->destroy(e8); + } + } + e7->destroy(e7); + } + } + e6->destroy(e6); + } else { t->setf(t, "ikesas.%s.%s=%s", id, name, value); @@ -135,29 +162,12 @@ static void ikesalist(private_status_controller_t *this, } e1->destroy(e1); + t->set(t, "title", "IKE SA overview"); t->render(t, response); t->destroy(t); free(str); } -/** - * redirect to authentication login - */ -static void login(private_status_controller_t *this, - request_t *request, response_t *response) -{ - response->redirect(response, "auth/login"); -} - -/** - * redirect to gateway selection - */ -static void selection(private_status_controller_t *this, - request_t *request, response_t *response) -{ - response->redirect(response, "gateway/list"); -} - /** * Implementation of controller_t.get_name */ @@ -167,14 +177,27 @@ static char* get_name(private_status_controller_t *this) } /** - * Implementation of controller_t.get_handler + * Implementation of controller_t.handle */ -static controller_handler_t get_handler(private_status_controller_t *this, char *name) +static void handle(private_status_controller_t *this, + request_t *request, response_t *response, char *action) { - if (!this->manager->logged_in(this->manager)) return (controller_handler_t)login; - if (this->manager->select_gateway(this->manager, 0) == NULL) return (controller_handler_t)selection; - if (streq(name, "ikesalist")) return (controller_handler_t)ikesalist; - return NULL; + if (!this->manager->logged_in(this->manager)) + { + return response->redirect(response, "auth/login"); + } + if (this->manager->select_gateway(this->manager, 0) == NULL) + { + return response->redirect(response, "gateway/list"); + } + if (action) + { + if (streq(action, "ikesalist")) + { + return ikesalist(this, request, response); + } + } + return response->redirect(response, "status/ikesalist"); } /** @@ -193,7 +216,7 @@ controller_t *status_controller_create(context_t *context, void *param) private_status_controller_t *this = malloc_thing(private_status_controller_t); this->public.controller.get_name = (char*(*)(controller_t*))get_name; - this->public.controller.get_handler = (controller_handler_t(*)(controller_t*,char*))get_handler; + this->public.controller.handle = (void(*)(controller_t*,request_t*,response_t*,char*,char*,char*,char*,char*))handle; this->public.controller.destroy = (void(*)(controller_t*))destroy; this->manager = (manager_t*)context; diff --git a/src/manager/lib/controller.h b/src/manager/lib/controller.h index 92968d8a6..fe6177513 100644 --- a/src/manager/lib/controller.h +++ b/src/manager/lib/controller.h @@ -59,13 +59,24 @@ struct controller_t { char* (*get_name)(controller_t *this); /** - * @brief Get the controllers handler function for an action name. + * @brief Handle a HTTP request for that controller. * - * @param name name of the action - * @return controllers handler + * Request URLs are parsed in the form + * controller_name/p1/p2/p3/p4/p5 with a maximum of 5 parameters. Each + * parameter not found in the request URL is set to NULL. + * + * @param request HTTP request + * @param response HTTP response + * @param p1 first parameter + * @param p2 second parameter + * @param p3 third parameter + * @param p4 forth parameter + * @param p5 fifth parameter + * @return */ - controller_handler_t (*get_handler)(controller_t *this, char *name); - + void (*handle)(controller_t *this, request_t *request, response_t *response, + char *a1, char *a2, char *a3, char *a4, char *a5); + /** * @brief Destroy the controller instance. */ diff --git a/src/manager/lib/dispatcher.c b/src/manager/lib/dispatcher.c index 018122e6f..db99110c3 100644 --- a/src/manager/lib/dispatcher.c +++ b/src/manager/lib/dispatcher.c @@ -146,6 +146,7 @@ static session_entry_t *session_entry_create(private_dispatcher_t *this) entry->waiting = 1; pthread_cond_init(&entry->cond, NULL); entry->session = load_session(this); + entry->used = time(NULL); return entry; } @@ -208,16 +209,19 @@ static void dispatch(private_dispatcher_t *this) iterator = this->sessions->create_iterator_locked(this->sessions, &this->mutex); while (iterator->iterate(iterator, (void**)¤t)) { - if (sid && streq(current->session->get_sid(current->session), sid)) - { - found = current; - found->waiting++; - } - else if (current->waiting == 0 && - current->used + this->timeout > now) + /* check all sessions for timeout */ + if (current->waiting == 0 && + current->used < now - this->timeout) { iterator->remove(iterator); session_entry_destroy(current); + continue; + } + if (!found && sid && + streq(current->session->get_sid(current->session), sid)) + { + found = current; + found->waiting++; } } iterator->destroy(iterator); @@ -319,7 +323,8 @@ static void destroy(private_dispatcher_t *this) /* * see header file */ -dispatcher_t *dispatcher_create(context_constructor_t constructor, void *param) +dispatcher_t *dispatcher_create(int timeout, context_constructor_t constructor, + void *param) { private_dispatcher_t *this = malloc_thing(private_dispatcher_t); @@ -334,7 +339,7 @@ dispatcher_t *dispatcher_create(context_constructor_t constructor, void *param) pthread_mutex_init(&this->mutex, NULL); this->param = param; this->fd = 0; - this->timeout = 180; + this->timeout = timeout; FCGX_Init(); diff --git a/src/manager/lib/dispatcher.h b/src/manager/lib/dispatcher.h index 5119a1eab..f46e5f32d 100644 --- a/src/manager/lib/dispatcher.h +++ b/src/manager/lib/dispatcher.h @@ -40,6 +40,9 @@ struct dispatcher_t { /** * @brief Register a controller to the dispatcher. * + * The first controller added serves as default controller. Client's + * get redirected to it if no other controller matches. + * * @param constructor constructor function to the conntroller * @param param param to pass to constructor */ @@ -70,9 +73,11 @@ struct dispatcher_t { * The context constructor is invoked to create a session context for * each session. * + * @param timeout session timeout * @param constructor construction function for session context * @param param parameter to supply to context constructor */ -dispatcher_t *dispatcher_create(context_constructor_t constructor, void *param); +dispatcher_t *dispatcher_create(int timeout, + context_constructor_t constructor, void *param); #endif /* DISPATCHER_H_ */ diff --git a/src/manager/lib/response.c b/src/manager/lib/response.c index ae74ab6e5..be933792f 100644 --- a/src/manager/lib/response.c +++ b/src/manager/lib/response.c @@ -186,6 +186,15 @@ static void redirect(private_response_t *this, char *location) *location == '/' ? "" : "/", location); } + +/** + * Implementation of response_t.get_base. + */ +static char* get_base(private_response_t *this) +{ + return FCGX_GetParam("SCRIPT_NAME", this->req->envp); +} + /** * Implementation of response_t.destroy */ @@ -210,6 +219,7 @@ response_t *response_create(FCGX_Request *request) this->public.set_content_type = (void(*)(response_t*, char *type))set_content_type; this->public.add_cookie = (void(*)(response_t*, char *name, char *value))add_cookie; this->public.redirect = (void(*)(response_t*, char *location))redirect; + this->public.get_base = (char*(*)(response_t*))get_base; this->public.destroy = (void(*)(response_t*))destroy; this->req = request; diff --git a/src/manager/lib/response.h b/src/manager/lib/response.h index e3be2cf43..50d0eacc1 100644 --- a/src/manager/lib/response.h +++ b/src/manager/lib/response.h @@ -78,6 +78,13 @@ struct response_t { * @param location location to redirect to */ void (*redirect)(response_t *this, char *location); + + /** + * @brief Get the base path of the application. + * + * @return base path + */ + char* (*get_base)(response_t *this); /** * @brief Destroy a response_t. diff --git a/src/manager/lib/session.c b/src/manager/lib/session.c index be25f2737..7520c3226 100644 --- a/src/manager/lib/session.c +++ b/src/manager/lib/session.c @@ -91,7 +91,6 @@ static void process(private_session_t *this, char *pos, *path, *controller, *action; iterator_t *iterator; bool handled = FALSE; - controller_handler_t handler; controller_t *current; if (this->sid == NULL) @@ -126,12 +125,8 @@ static void process(private_session_t *this, { if (streq(current->get_name(current), controller)) { - handler = current->get_handler(current, action); - if (handler) - { - handler(current, request, response); - handled = TRUE; - } + current->handle(current, request, response, action, NULL, NULL, NULL, NULL); + handled = TRUE; break; } } @@ -140,8 +135,15 @@ static void process(private_session_t *this, free(action); if (!handled) { - response->add_header(response, "Status", "400 Not Found"); - response->printf(response, "

Not Found

\n"); + if (this->controllers->get_first(this->controllers, + (void**)¤t) == SUCCESS) + { + response->redirect(response, current->get_name(current)); + } + else + { + response->printf(response, "No controllers loaded!\n"); + } } } diff --git a/src/manager/lib/session.h b/src/manager/lib/session.h index baaacd098..a66b1a8e2 100644 --- a/src/manager/lib/session.h +++ b/src/manager/lib/session.h @@ -68,7 +68,7 @@ struct session_t { /** * @brief Create a session. * - * @param context user defined session context instance + * @param context user defined session context instance */ session_t *session_create(context_t *context); diff --git a/src/manager/lib/template.c b/src/manager/lib/template.c index 3ae7c87a3..36a4d294e 100644 --- a/src/manager/lib/template.c +++ b/src/manager/lib/template.c @@ -66,6 +66,8 @@ static void render(private_template_t *this, response_t *response) NEOERR* err; CSPARSE *parse; + hdf_set_value(this->hdf, "base", response->get_base(response)); + err = cs_init(&parse, this->hdf); if (!err) { diff --git a/src/manager/lib/template.h b/src/manager/lib/template.h index 1a8c2f7b7..6e17177a1 100644 --- a/src/manager/lib/template.h +++ b/src/manager/lib/template.h @@ -55,6 +55,10 @@ struct template_t { /** * @brief Render a template to a response object. * + * The render() function additionally sets a clearsilver variable "base" + * which points to the root of the web application and allows to point to + * other targets without to worry about path location. + * * @param response response to render to * @return rendered template string */ diff --git a/src/manager/main.c b/src/manager/main.c index 5aec02156..abfc52912 100644 --- a/src/manager/main.c +++ b/src/manager/main.c @@ -25,12 +25,13 @@ #include "manager.h" #include "database.h" -#include "controller/static_controller.h" #include "controller/auth_controller.h" #include "controller/status_controller.h" #include "controller/gateway_controller.h" -#define DBFILE "/usr/local/libexec/ipsec/sqlite.db" +#define DBFILE IPSECDIR "/sqlite.db" +#define SESSION_TIMEOUT 180 +#define THREADS 10 int main (int arc, char *argv[]) { @@ -44,14 +45,13 @@ int main (int arc, char *argv[]) return 1; } - dispatcher = dispatcher_create((context_constructor_t)manager_create, database); - - dispatcher->add_controller(dispatcher, static_controller_create, NULL); - dispatcher->add_controller(dispatcher, auth_controller_create, NULL); + dispatcher = dispatcher_create(SESSION_TIMEOUT, + (context_constructor_t)manager_create, database); dispatcher->add_controller(dispatcher, status_controller_create, NULL); dispatcher->add_controller(dispatcher, gateway_controller_create, NULL); + dispatcher->add_controller(dispatcher, auth_controller_create, NULL); - dispatcher->run(dispatcher, 10); + dispatcher->run(dispatcher, THREADS); dispatcher->waitsignal(dispatcher); @@ -60,3 +60,4 @@ int main (int arc, char *argv[]) return 0; } + diff --git a/src/manager/templates/auth/login.cs b/src/manager/templates/auth/login.cs index f84c6307c..49a8ec6e0 100644 --- a/src/manager/templates/auth/login.cs +++ b/src/manager/templates/auth/login.cs @@ -1,15 +1,17 @@ +
- +
- + - +
UsernameUsername
PasswordPassword
+
diff --git a/src/manager/templates/auth/logout.cs b/src/manager/templates/auth/logout.cs deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/manager/templates/footer.cs b/src/manager/templates/footer.cs index b605728ee..db3601961 100644 --- a/src/manager/templates/footer.cs +++ b/src/manager/templates/footer.cs @@ -1,2 +1,4 @@ + + diff --git a/src/manager/templates/gateway/list.cs b/src/manager/templates/gateway/list.cs index 5cc8603b1..b93364d6f 100644 --- a/src/manager/templates/gateway/list.cs +++ b/src/manager/templates/gateway/list.cs @@ -1,4 +1,5 @@ +

+
diff --git a/src/manager/templates/header.cs b/src/manager/templates/header.cs index b417ef916..64a859a9a 100644 --- a/src/manager/templates/header.cs +++ b/src/manager/templates/header.cs @@ -2,7 +2,23 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - - strongSwan management + <?cs var:title ?> - strongSwan Manager + +