first revision of new manager webapp
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* @file auth_controller.c
|
||||
*
|
||||
* @brief Implementation of auth_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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 "auth_controller.h"
|
||||
#include "../manager.h"
|
||||
|
||||
#include <template.h>
|
||||
|
||||
#include <library.h>
|
||||
|
||||
|
||||
typedef struct private_auth_controller_t private_auth_controller_t;
|
||||
|
||||
/**
|
||||
* private data of the task manager
|
||||
*/
|
||||
struct private_auth_controller_t {
|
||||
|
||||
/**
|
||||
* public functions
|
||||
*/
|
||||
auth_controller_t public;
|
||||
|
||||
/**
|
||||
* manager instance
|
||||
*/
|
||||
manager_t *manager;
|
||||
};
|
||||
|
||||
static void login(private_auth_controller_t *this,
|
||||
request_t *request, response_t *response)
|
||||
{
|
||||
template_t *t = template_create("templates/auth/login.cs");
|
||||
t->set(t, "action", "check");
|
||||
t->render(t, response);
|
||||
t->destroy(t);
|
||||
}
|
||||
|
||||
static void check(private_auth_controller_t *this,
|
||||
request_t *request, response_t *response)
|
||||
{
|
||||
char *username, *password;
|
||||
|
||||
username = request->get_post_data(request, "username");
|
||||
password = request->get_post_data(request, "password");
|
||||
if (username && password &&
|
||||
this->manager->login(this->manager, username, password))
|
||||
{
|
||||
response->redirect(response, "status/test");
|
||||
}
|
||||
else
|
||||
{
|
||||
response->redirect(response, "auth/login");
|
||||
}
|
||||
}
|
||||
|
||||
static void logout(private_auth_controller_t *this,
|
||||
request_t *request, response_t *response)
|
||||
{
|
||||
this->manager->logout(this->manager);
|
||||
response->redirect(response, "auth/login");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.get_name
|
||||
*/
|
||||
static char* get_name(private_auth_controller_t *this)
|
||||
{
|
||||
return "auth";
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.get_handler
|
||||
*/
|
||||
static controller_handler_t get_handler(private_auth_controller_t *this, char *name)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.destroy
|
||||
*/
|
||||
static void destroy(private_auth_controller_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* see header file
|
||||
*/
|
||||
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.destroy = (void(*)(controller_t*))destroy;
|
||||
|
||||
this->manager = (manager_t*)context;
|
||||
|
||||
return &this->public.controller;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file auth_controller.h
|
||||
*
|
||||
* @brief Interface of auth_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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 AUTH_CONTROLLER_H_
|
||||
#define AUTH_CONTROLLER_H_
|
||||
|
||||
|
||||
#include <controller.h>
|
||||
|
||||
typedef struct auth_controller_t auth_controller_t;
|
||||
|
||||
/**
|
||||
* @brief Authentication controller.
|
||||
*/
|
||||
struct auth_controller_t {
|
||||
|
||||
/**
|
||||
* Implements controller_t interface.
|
||||
*/
|
||||
controller_t controller;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create a auth_controller controller instance.
|
||||
*/
|
||||
controller_t *auth_controller_create(context_t *context, void *param);
|
||||
|
||||
#endif /* AUTH_CONTROLLER_H_ */
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* @file gateway_controller.c
|
||||
*
|
||||
* @brief Implementation of gateway_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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 "gateway_controller.h"
|
||||
#include "../manager.h"
|
||||
#include "../gateway.h"
|
||||
|
||||
#include <template.h>
|
||||
|
||||
#include <library.h>
|
||||
|
||||
|
||||
typedef struct private_gateway_controller_t private_gateway_controller_t;
|
||||
|
||||
/**
|
||||
* private data of the gateway_controller
|
||||
*/
|
||||
struct private_gateway_controller_t {
|
||||
|
||||
/**
|
||||
* public functions
|
||||
*/
|
||||
gateway_controller_t public;
|
||||
|
||||
/**
|
||||
* manager instance
|
||||
*/
|
||||
manager_t *manager;
|
||||
|
||||
};
|
||||
|
||||
static void list(private_gateway_controller_t *this,
|
||||
request_t *request, response_t *response)
|
||||
{
|
||||
template_t *t;
|
||||
enumerator_t *enumerator;
|
||||
char *name, *address;
|
||||
int id, port;
|
||||
|
||||
t = template_create("templates/gateway/list.cs");
|
||||
enumerator = this->manager->create_gateway_enumerator(this->manager);
|
||||
while (enumerator->enumerate(enumerator, &id, &name, &port, &address))
|
||||
{
|
||||
t->setf(t, "gateways.%d.name=%s", id, name);
|
||||
if (port)
|
||||
{
|
||||
t->setf(t, "gateways.%d.address=tcp://%s:%d", id, address, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
t->setf(t, "gateways.%d.address=unix://%s", id, address);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
t->set(t, "action", "select");
|
||||
t->render(t, response);
|
||||
t->destroy(t);
|
||||
}
|
||||
|
||||
static void _select(private_gateway_controller_t *this,
|
||||
request_t *request, response_t *response)
|
||||
{
|
||||
char *id;
|
||||
|
||||
id = request->get_post_data(request, "gateway");
|
||||
if (id)
|
||||
{
|
||||
if (this->manager->select_gateway(this->manager, atoi(id)))
|
||||
{
|
||||
response->redirect(response, "status/ikesalist");
|
||||
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");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.get_name
|
||||
*/
|
||||
static char* get_name(private_gateway_controller_t *this)
|
||||
{
|
||||
return "gateway";
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.get_handler
|
||||
*/
|
||||
static controller_handler_t get_handler(private_gateway_controller_t *this, char *name)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.destroy
|
||||
*/
|
||||
static void destroy(private_gateway_controller_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* see header file
|
||||
*/
|
||||
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.destroy = (void(*)(controller_t*))destroy;
|
||||
|
||||
this->manager = (manager_t*)context;
|
||||
|
||||
return &this->public.controller;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file gateway_controller.h
|
||||
*
|
||||
* @brief Interface of gateway_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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 GATEWAY_CONTROLLER_H_
|
||||
#define GATEWAY_CONTROLLER_H_
|
||||
|
||||
|
||||
#include <controller.h>
|
||||
|
||||
typedef struct gateway_controller_t gateway_controller_t;
|
||||
|
||||
/**
|
||||
* @brief Status controller.
|
||||
*/
|
||||
struct gateway_controller_t {
|
||||
|
||||
/**
|
||||
* Implements controller_t interface.
|
||||
*/
|
||||
controller_t controller;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create a gateway_controller controller instance.
|
||||
*/
|
||||
controller_t *gateway_controller_create(context_t *context, void *param);
|
||||
|
||||
#endif /* GATEWAY_CONTROLLER_H_ */
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* @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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 <template.h>
|
||||
|
||||
#include <library.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 <controller.h>
|
||||
|
||||
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_ */
|
||||
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* @file status_controller.c
|
||||
*
|
||||
* @brief Implementation of status_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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 "status_controller.h"
|
||||
#include "../manager.h"
|
||||
#include "../gateway.h"
|
||||
|
||||
#include <template.h>
|
||||
|
||||
#include <library.h>
|
||||
|
||||
|
||||
typedef struct private_status_controller_t private_status_controller_t;
|
||||
|
||||
/**
|
||||
* private data of the task manager
|
||||
*/
|
||||
struct private_status_controller_t {
|
||||
|
||||
/**
|
||||
* public functions
|
||||
*/
|
||||
status_controller_t public;
|
||||
|
||||
/**
|
||||
* manager instance
|
||||
*/
|
||||
manager_t *manager;
|
||||
|
||||
int count;
|
||||
|
||||
};
|
||||
|
||||
static void ikesalist(private_status_controller_t *this,
|
||||
request_t *request, response_t *response)
|
||||
{
|
||||
char *str;
|
||||
gateway_t *gateway;
|
||||
|
||||
gateway = this->manager->select_gateway(this->manager, 0);
|
||||
str = gateway->request(gateway, "<message type=\"request\" id=\"1\">"
|
||||
"<query>"
|
||||
"<ikesalist/>"
|
||||
"</query>"
|
||||
"</message>");
|
||||
|
||||
response->set_content_type(response, "text/xml");
|
||||
template_t *t = template_create("templates/status/ikesalist.cs");
|
||||
t->set(t, "xml", str);
|
||||
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
|
||||
*/
|
||||
static char* get_name(private_status_controller_t *this)
|
||||
{
|
||||
return "status";
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.get_handler
|
||||
*/
|
||||
static controller_handler_t get_handler(private_status_controller_t *this, char *name)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of controller_t.destroy
|
||||
*/
|
||||
static void destroy(private_status_controller_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* see header file
|
||||
*/
|
||||
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.destroy = (void(*)(controller_t*))destroy;
|
||||
|
||||
this->count = 0;
|
||||
this->manager = (manager_t*)context;
|
||||
|
||||
return &this->public.controller;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file status_controller.h
|
||||
*
|
||||
* @brief Interface of status_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 <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* 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 STATUS_CONTROLLER_H_
|
||||
#define STATUS_CONTROLLER_H_
|
||||
|
||||
|
||||
#include <controller.h>
|
||||
|
||||
typedef struct status_controller_t status_controller_t;
|
||||
|
||||
/**
|
||||
* @brief Status controller.
|
||||
*/
|
||||
struct status_controller_t {
|
||||
|
||||
/**
|
||||
* Implements controller_t interface.
|
||||
*/
|
||||
controller_t controller;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Create a status_controller controller instance.
|
||||
*/
|
||||
controller_t *status_controller_create(context_t *context, void *param);
|
||||
|
||||
#endif /* STATUS_CONTROLLER_H_ */
|
||||
Reference in New Issue
Block a user