2 * Copyright (C) 2007 Martin Willi
3 * HSR 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 "config_controller.h"
17 #include "../manager.h"
18 #include "../gateway.h"
25 typedef struct private_config_controller_t private_config_controller_t
;
28 * private data of the task manager
30 struct private_config_controller_t
{
35 config_controller_t
public;
44 * read XML of a peerconfig element and fill template
46 static void process_peerconfig(private_config_controller_t
*this,
47 enumerator_t
*e
, fast_request_t
*r
)
50 enumerator_t
*e1
, *e2
, *e3
;
51 char *name
, *value
, *config
= "", *child
= "", *section
= "";
53 while (e
->enumerate(e
, &xml
, &name
, &value
))
55 if (streq(name
, "name"))
59 else if (streq(name
, "ikeconfig"))
61 e1
= xml
->children(xml
);
62 while (e1
->enumerate(e1
, &xml
, &name
, &value
))
64 if (streq(name
, "local") || streq(name
, "remote"))
66 if (streq(value
, "0.0.0.0") || streq(value
, "::"))
70 r
->setf(r
, "peercfgs.%s.ikecfg.%s=%s", config
, name
, value
);
75 else if (streq(name
, "childconfiglist"))
77 e1
= xml
->children(xml
);
78 while (e1
->enumerate(e1
, &xml
, &name
, &value
))
80 if (streq(name
, "childconfig"))
84 e2
= xml
->children(xml
);
85 while (e2
->enumerate(e2
, &xml
, &name
, &value
))
87 if (streq(name
, "name"))
91 else if (streq(name
, "local") || streq(name
, "remote"))
94 e3
= xml
->children(xml
);
95 while (e3
->enumerate(e3
, &xml
, &name
, &value
))
97 if (streq(name
, "network"))
99 r
->setf(r
, "peercfgs.%s.childcfgs.%s.%s.networks.%d=%s",
100 config
, child
, section
, ++num
, value
);
113 r
->setf(r
, "peercfgs.%s.%s=%s", config
, name
, value
);
118 static void list(private_config_controller_t
*this, fast_request_t
*r
)
122 enumerator_t
*e1
, *e2
;
125 gateway
= this->manager
->select_gateway(this->manager
, 0);
126 e1
= gateway
->query_configlist(gateway
);
129 r
->set(r
, "title", "Error");
130 r
->set(r
, "error", "querying the gateway failed");
131 r
->render(r
, "templates/error.cs");
135 r
->set(r
, "title", "Configuration overview");
137 while (e1
->enumerate(e1
, &xml
, &name
, &value
))
139 if (streq(name
, "peerconfig"))
141 e2
= xml
->children(xml
);
142 process_peerconfig(this, e2
, r
);
148 r
->render(r
, "templates/config/list.cs");
152 METHOD(fast_controller_t
, get_name
, char*,
153 private_config_controller_t
*this)
158 METHOD(fast_controller_t
, handle
, void,
159 private_config_controller_t
*this, fast_request_t
*request
, char *action
,
160 char *p2
, char *p3
, char *p4
, char *p5
)
162 if (!this->manager
->logged_in(this->manager
))
164 return request
->redirect(request
, "auth/login");
166 if (this->manager
->select_gateway(this->manager
, 0) == NULL
)
168 return request
->redirect(request
, "gateway/list");
172 if (streq(action
, "list"))
174 return list(this, request
);
177 return request
->redirect(request
, "config/list");
180 METHOD(fast_controller_t
, destroy
, void,
181 private_config_controller_t
*this)
189 fast_controller_t
*config_controller_create(fast_context_t
*context
,
192 private_config_controller_t
*this;
197 .get_name
= _get_name
,
202 .manager
= (manager_t
*)context
,
205 return &this->public.controller
;