2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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>.
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
16 #include "ikesa_controller.h"
17 #include "../manager.h"
18 #include "../gateway.h"
25 typedef struct private_ikesa_controller_t private_ikesa_controller_t
;
28 * private data of the task manager
30 struct private_ikesa_controller_t
{
35 ikesa_controller_t
public;
44 * read XML of a childsa element and fill template
46 static void process_childsa(private_ikesa_controller_t
*this, char *id
,
47 enumerator_t
*e
, fast_request_t
*r
)
50 enumerator_t
*e1
, *e2
;
51 char *name
, *value
, *reqid
= "", *section
= "";
54 while (e
->enumerate(e
, &xml
, &name
, &value
))
56 if (streq(name
, "reqid"))
60 else if (streq(name
, "local") || streq(name
, "remote"))
63 e1
= xml
->children(xml
);
64 while (e1
->enumerate(e1
, &xml
, &name
, &value
))
66 if (streq(name
, "networks"))
68 e2
= xml
->children(xml
);
69 while (e2
->enumerate(e2
, &xml
, &name
, &value
))
71 if (streq(name
, "network"))
73 r
->setf(r
, "ikesas.%s.childsas.%s.%s.networks.%d=%s",
74 id
, reqid
, section
, ++num
, value
);
81 r
->setf(r
, "ikesas.%s.childsas.%s.%s.%s=%s",
82 id
, reqid
, section
, name
, value
);
89 r
->setf(r
, "ikesas.%s.childsas.%s.%s=%s",
90 id
, reqid
, name
, value
);
96 * read XML of a ikesa element and fill template
98 static void process_ikesa(private_ikesa_controller_t
*this,
99 enumerator_t
*e
, fast_request_t
*r
)
102 enumerator_t
*e1
, *e2
;
103 char *name
, *value
, *id
= "", *section
= "";
105 while (e
->enumerate(e
, &xml
, &name
, &value
))
107 if (streq(name
, "id"))
111 else if (streq(name
, "local") || streq(name
, "remote"))
114 e1
= xml
->children(xml
);
115 while (e1
->enumerate(e1
, &xml
, &name
, &value
))
117 r
->setf(r
, "ikesas.%s.%s.%s=%s", id
, section
, name
, value
);
121 else if (streq(name
, "childsalist"))
123 e1
= xml
->children(xml
);
124 while (e1
->enumerate(e1
, &xml
, &name
, &value
))
126 if (streq(name
, "childsa"))
128 e2
= xml
->children(xml
);
129 process_childsa(this, id
, e2
, r
);
137 r
->setf(r
, "ikesas.%s.%s=%s", id
, name
, value
);
142 static void list(private_ikesa_controller_t
*this, fast_request_t
*r
)
146 enumerator_t
*e1
, *e2
;
149 gateway
= this->manager
->select_gateway(this->manager
, 0);
150 e1
= gateway
->query_ikesalist(gateway
);
153 r
->set(r
, "title", "Error");
154 r
->set(r
, "error", "querying the gateway failed");
155 r
->render(r
, "templates/error.cs");
159 r
->set(r
, "title", "IKE SA overview");
161 while (e1
->enumerate(e1
, &xml
, &name
, &value
))
163 if (streq(name
, "ikesa"))
165 e2
= xml
->children(xml
);
166 process_ikesa(this, e2
, r
);
172 r
->render(r
, "templates/ikesa/list.cs");
176 METHOD(fast_controller_t
, get_name
, char*,
177 private_ikesa_controller_t
*this)
182 METHOD(fast_controller_t
, handle
, void,
183 private_ikesa_controller_t
*this, fast_request_t
*request
, char *action
,
184 char *p2
, char *p3
, char *p4
, char *p5
)
186 if (!this->manager
->logged_in(this->manager
))
188 return request
->redirect(request
, "auth/login");
190 if (this->manager
->select_gateway(this->manager
, 0) == NULL
)
192 return request
->redirect(request
, "gateway/list");
196 if (streq(action
, "list"))
198 return list(this, request
);
201 return request
->redirect(request
, "ikesa/list");
204 METHOD(fast_controller_t
, destroy
, void,
205 private_ikesa_controller_t
*this)
213 fast_controller_t
*ikesa_controller_create(fast_context_t
*context
, void *param
)
215 private_ikesa_controller_t
*this;
220 .get_name
= _get_name
,
225 .manager
= (manager_t
*)context
,
228 return &this->public.controller
;