removed some raw EAP debug output
[strongswan.git] / src / manager / controller / gateway_controller.c
1 /*
2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "gateway_controller.h"
17 #include "../manager.h"
18 #include "../gateway.h"
19
20 #include <library.h>
21
22
23 typedef struct private_gateway_controller_t private_gateway_controller_t;
24
25 /**
26 * private data of the gateway_controller
27 */
28 struct private_gateway_controller_t {
29
30 /**
31 * public functions
32 */
33 gateway_controller_t public;
34
35 /**
36 * manager instance
37 */
38 manager_t *manager;
39
40 };
41
42 static void list(private_gateway_controller_t *this, request_t *request)
43 {
44 enumerator_t *enumerator;
45 char *name, *address;
46 int id, port;
47
48 enumerator = this->manager->create_gateway_enumerator(this->manager);
49 while (enumerator->enumerate(enumerator, &id, &name, &port, &address))
50 {
51 request->setf(request, "gateways.%d.name=%s", id, name);
52 if (port)
53 {
54 request->setf(request, "gateways.%d.address=tcp://%s:%d",
55 id, address, port);
56 }
57 else
58 {
59 request->setf(request, "gateways.%d.address=unix://%s",
60 id, IPSEC_PIDDIR"/charon.xml");
61 }
62 }
63 enumerator->destroy(enumerator);
64 request->set(request, "action", "select");
65 request->set(request, "title", "Choose gateway");
66 request->render(request, "templates/gateway/list.cs");
67 }
68
69 static void _select(private_gateway_controller_t *this, request_t *request)
70 {
71 char *id;
72
73 id = request->get_query_data(request, "gateway");
74 if (id)
75 {
76 if (this->manager->select_gateway(this->manager, atoi(id)))
77 {
78 request->redirect(request, "ikesa/list");
79 return;
80 }
81 }
82 request->redirect(request, "gateway/list");
83 }
84
85 /**
86 * Implementation of controller_t.get_name
87 */
88 static char* get_name(private_gateway_controller_t *this)
89 {
90 return "gateway";
91 }
92
93 /**
94 * Implementation of controller_t.handle
95 */
96 static void handle(private_gateway_controller_t *this,
97 request_t *request, char *action)
98 {
99 if (!this->manager->logged_in(this->manager))
100 {
101 return request->redirect(request, "auth/login");
102 }
103 if (action)
104 {
105 if (streq(action, "list"))
106 {
107 return list(this, request);
108 }
109 else if (streq(action, "select"))
110 {
111 return _select(this, request);
112 }
113 }
114 request->redirect(request, "gateway/list");
115 }
116
117
118 /**
119 * Implementation of controller_t.destroy
120 */
121 static void destroy(private_gateway_controller_t *this)
122 {
123 free(this);
124 }
125
126 /*
127 * see header file
128 */
129 controller_t *gateway_controller_create(context_t *context, void *param)
130 {
131 private_gateway_controller_t *this = malloc_thing(private_gateway_controller_t);
132
133 this->public.controller.get_name = (char*(*)(controller_t*))get_name;
134 this->public.controller.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle;
135 this->public.controller.destroy = (void(*)(controller_t*))destroy;
136
137 this->manager = (manager_t*)context;
138
139 return &this->public.controller;
140 }
141