From 49104abddf3d71d5abf5cf75dc7f95fa6c55fa63 Mon Sep 17 00:00:00 2001 From: Rene Mayrhofer Date: Fri, 26 Oct 2007 14:10:02 +0000 Subject: [svn-upgrade] Integrating new upstream version, strongswan (4.1.8) --- src/manager/Makefile.am | 53 + src/manager/Makefile.in | 783 ++++++ src/manager/controller/auth_controller.c | 132 + src/manager/controller/auth_controller.h | 47 + src/manager/controller/gateway_controller.c | 148 ++ src/manager/controller/gateway_controller.h | 47 + src/manager/controller/status_controller.c | 238 ++ src/manager/controller/status_controller.h | 47 + src/manager/database.c | 183 ++ src/manager/database.h | 69 + src/manager/gateway.c | 253 ++ src/manager/gateway.h | 74 + src/manager/lib/context.h | 47 + src/manager/lib/controller.h | 84 + src/manager/lib/dispatcher.c | 402 +++ src/manager/lib/dispatcher.h | 95 + src/manager/lib/request.c | 305 +++ src/manager/lib/request.h | 127 + src/manager/lib/session.c | 175 ++ src/manager/lib/session.h | 73 + src/manager/lib/xml.c | 169 ++ src/manager/lib/xml.h | 63 + src/manager/main.c | 68 + src/manager/manager.c | 167 ++ src/manager/manager.db | Bin 0 -> 12288 bytes src/manager/manager.h | 93 + src/manager/templates/auth/login.cs | 17 + src/manager/templates/error.cs | 3 + src/manager/templates/footer.cs | 4 + src/manager/templates/gateway/list.cs | 15 + src/manager/templates/header.cs | 24 + src/manager/templates/static/client-left.png | Bin 0 -> 10228 bytes src/manager/templates/static/client-right.png | Bin 0 -> 10349 bytes src/manager/templates/static/gateway-left.png | Bin 0 -> 12206 bytes src/manager/templates/static/gateway-right.png | Bin 0 -> 12180 bytes src/manager/templates/static/jquery.js | 2965 ++++++++++++++++++++++ src/manager/templates/static/pipe-bad.png | Bin 0 -> 4905 bytes src/manager/templates/static/pipe-good.png | Bin 0 -> 322 bytes src/manager/templates/static/pipe-thin-left.png | Bin 0 -> 345 bytes src/manager/templates/static/pipe-thin-right.png | Bin 0 -> 357 bytes src/manager/templates/static/pipe-thin.png | Bin 0 -> 256 bytes src/manager/templates/static/pipe.png | Bin 0 -> 322 bytes src/manager/templates/static/router.png | Bin 0 -> 3300 bytes src/manager/templates/static/script.js | 8 + src/manager/templates/static/strongswan.png | Bin 0 -> 19837 bytes src/manager/templates/static/style.css | 122 + src/manager/templates/status/ikesalist.cs | 101 + 47 files changed, 7201 insertions(+) create mode 100644 src/manager/Makefile.am create mode 100644 src/manager/Makefile.in create mode 100644 src/manager/controller/auth_controller.c create mode 100644 src/manager/controller/auth_controller.h create mode 100644 src/manager/controller/gateway_controller.c create mode 100644 src/manager/controller/gateway_controller.h create mode 100644 src/manager/controller/status_controller.c create mode 100644 src/manager/controller/status_controller.h create mode 100644 src/manager/database.c create mode 100644 src/manager/database.h create mode 100644 src/manager/gateway.c create mode 100644 src/manager/gateway.h create mode 100644 src/manager/lib/context.h create mode 100644 src/manager/lib/controller.h create mode 100644 src/manager/lib/dispatcher.c create mode 100644 src/manager/lib/dispatcher.h create mode 100644 src/manager/lib/request.c create mode 100644 src/manager/lib/request.h create mode 100644 src/manager/lib/session.c create mode 100644 src/manager/lib/session.h create mode 100644 src/manager/lib/xml.c create mode 100644 src/manager/lib/xml.h create mode 100644 src/manager/main.c create mode 100644 src/manager/manager.c create mode 100644 src/manager/manager.db create mode 100644 src/manager/manager.h create mode 100644 src/manager/templates/auth/login.cs create mode 100644 src/manager/templates/error.cs create mode 100644 src/manager/templates/footer.cs create mode 100644 src/manager/templates/gateway/list.cs create mode 100644 src/manager/templates/header.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/pipe-bad.png create mode 100644 src/manager/templates/static/pipe-good.png create mode 100644 src/manager/templates/static/pipe-thin-left.png create mode 100644 src/manager/templates/static/pipe-thin-right.png create mode 100644 src/manager/templates/static/pipe-thin.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 create mode 100644 src/manager/templates/static/style.css create mode 100644 src/manager/templates/status/ikesalist.cs (limited to 'src/manager') diff --git a/src/manager/Makefile.am b/src/manager/Makefile.am new file mode 100644 index 000000000..17eecdbab --- /dev/null +++ b/src/manager/Makefile.am @@ -0,0 +1,53 @@ +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/status_controller.c controller/status_controller.h \ +controller/gateway_controller.c controller/gateway_controller.h + +manager_fcgi_LDADD = $(top_builddir)/src/manager/libappserv.la -lsqlite3 + + + +lib_LTLIBRARIES = libappserv.la + +libappserv_la_SOURCES = \ +lib/context.h lib/dispatcher.c lib/request.h lib/session.h \ +lib/controller.h lib/dispatcher.h lib/request.c lib/session.c \ +lib/xml.h lib/xml.c + +libappserv_la_LIBADD = $(top_builddir)/src/libstrongswan/libstrongswan.la -lfcgi -lpthread -lneo_cgi -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 = manager.db + +# Don't forget to add templates to EXTRA_DIST !!! How to automate? +ipsec_templatesdir = ${ipsecdir}/templates +ipsec_templates_DATA = templates/header.cs templates/footer.cs templates/error.cs + +ipsec_templates_authdir = ${ipsec_templatesdir}/auth +ipsec_templates_auth_DATA = templates/auth/login.cs + +ipsec_templates_gatewaydir = ${ipsec_templatesdir}/gateway +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 templates/static/jquery.js \ +templates/static/pipe.png templates/static/pipe-good.png templates/static/pipe-bad.png \ +templates/static/pipe-thin.png templates/static/pipe-thin-left.png templates/static/pipe-thin-right.png \ +templates/static/gateway-left.png templates/static/client-left.png templates/static/strongswan.png \ +templates/static/router.png templates/static/gateway-right.png templates/static/client-right.png + +EXTRA_DIST = manager.db templates/header.cs templates/footer.cs templates/error.cs \ +templates/auth/login.cs templates/gateway/list.cs templates/status/ikesalist.cs \ +templates/static/style.css templates/static/script.js templates/static/jquery.js \ +templates/static/pipe.png templates/static/pipe-good.png templates/static/pipe-bad.png \ +templates/static/pipe-thin.png templates/static/pipe-thin-left.png templates/static/pipe-thin-right.png \ +templates/static/gateway-left.png templates/static/client-left.png templates/static/strongswan.png \ +templates/static/router.png templates/static/gateway-right.png templates/static/client-right.png diff --git a/src/manager/Makefile.in b/src/manager/Makefile.in new file mode 100644 index 000000000..5c09c22d4 --- /dev/null +++ b/src/manager/Makefile.in @@ -0,0 +1,783 @@ +# Makefile.in generated by automake 1.10 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + + +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +ipsec_PROGRAMS = manager.fcgi$(EXEEXT) +subdir = src/manager +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/configure.in +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_CLEAN_FILES = +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(ipsecdir)" \ + "$(DESTDIR)$(ipsecdir)" "$(DESTDIR)$(ipsec_templatesdir)" \ + "$(DESTDIR)$(ipsec_templates_authdir)" \ + "$(DESTDIR)$(ipsec_templates_gatewaydir)" \ + "$(DESTDIR)$(ipsec_templates_staticdir)" \ + "$(DESTDIR)$(ipsec_templates_statusdir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libappserv_la_DEPENDENCIES = \ + $(top_builddir)/src/libstrongswan/libstrongswan.la \ + $(am__DEPENDENCIES_1) +am_libappserv_la_OBJECTS = dispatcher.lo request.lo session.lo xml.lo +libappserv_la_OBJECTS = $(am_libappserv_la_OBJECTS) +ipsecPROGRAMS_INSTALL = $(INSTALL_PROGRAM) +PROGRAMS = $(ipsec_PROGRAMS) +am_manager_fcgi_OBJECTS = main.$(OBJEXT) manager.$(OBJEXT) \ + gateway.$(OBJEXT) database.$(OBJEXT) auth_controller.$(OBJEXT) \ + status_controller.$(OBJEXT) gateway_controller.$(OBJEXT) +manager_fcgi_OBJECTS = $(am_manager_fcgi_OBJECTS) +manager_fcgi_DEPENDENCIES = $(top_builddir)/src/manager/libappserv.la +DEFAULT_INCLUDES = -I.@am__isrc@ +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ +SOURCES = $(libappserv_la_SOURCES) $(manager_fcgi_SOURCES) +DIST_SOURCES = $(libappserv_la_SOURCES) $(manager_fcgi_SOURCES) +ipsecDATA_INSTALL = $(INSTALL_DATA) +ipsec_templatesDATA_INSTALL = $(INSTALL_DATA) +ipsec_templates_authDATA_INSTALL = $(INSTALL_DATA) +ipsec_templates_gatewayDATA_INSTALL = $(INSTALL_DATA) +ipsec_templates_staticDATA_INSTALL = $(INSTALL_DATA) +ipsec_templates_statusDATA_INSTALL = $(INSTALL_DATA) +DATA = $(ipsec_DATA) $(ipsec_templates_DATA) \ + $(ipsec_templates_auth_DATA) $(ipsec_templates_gateway_DATA) \ + $(ipsec_templates_static_DATA) $(ipsec_templates_status_DATA) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GPERF = @GPERF@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +IPSEC_ROUTING_TABLE = @IPSEC_ROUTING_TABLE@ +IPSEC_ROUTING_TABLE_PRIO = @IPSEC_ROUTING_TABLE_PRIO@ +LDFLAGS = @LDFLAGS@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LINUX_HEADERS = @LINUX_HEADERS@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAKEINFO = @MAKEINFO@ +MKDIR_P = @MKDIR_P@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PERL = @PERL@ +PKG_CONFIG = @PKG_CONFIG@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VERSION = @VERSION@ +YACC = @YACC@ +YFLAGS = @YFLAGS@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +backenddir = @backenddir@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +confdir = @confdir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +dbus_CFLAGS = @dbus_CFLAGS@ +dbus_LIBS = @dbus_LIBS@ +docdir = @docdir@ +dvidir = @dvidir@ +eapdir = @eapdir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +interfacedir = @interfacedir@ +ipsecdir = @ipsecdir@ +ipsecgid = @ipsecgid@ +ipsecuid = @ipsecuid@ +libdir = @libdir@ +libexecdir = @libexecdir@ +linuxdir = @linuxdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +piddir = @piddir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +xml_CFLAGS = @xml_CFLAGS@ +xml_LIBS = @xml_LIBS@ +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/status_controller.c controller/status_controller.h \ +controller/gateway_controller.c controller/gateway_controller.h + +manager_fcgi_LDADD = $(top_builddir)/src/manager/libappserv.la -lsqlite3 +lib_LTLIBRARIES = libappserv.la +libappserv_la_SOURCES = \ +lib/context.h lib/dispatcher.c lib/request.h lib/session.h \ +lib/controller.h lib/dispatcher.h lib/request.c lib/session.c \ +lib/xml.h lib/xml.c + +libappserv_la_LIBADD = $(top_builddir)/src/libstrongswan/libstrongswan.la -lfcgi -lpthread -lneo_cgi -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 = manager.db + +# Don't forget to add templates to EXTRA_DIST !!! How to automate? +ipsec_templatesdir = ${ipsecdir}/templates +ipsec_templates_DATA = templates/header.cs templates/footer.cs templates/error.cs +ipsec_templates_authdir = ${ipsec_templatesdir}/auth +ipsec_templates_auth_DATA = templates/auth/login.cs +ipsec_templates_gatewaydir = ${ipsec_templatesdir}/gateway +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 templates/static/jquery.js \ +templates/static/pipe.png templates/static/pipe-good.png templates/static/pipe-bad.png \ +templates/static/pipe-thin.png templates/static/pipe-thin-left.png templates/static/pipe-thin-right.png \ +templates/static/gateway-left.png templates/static/client-left.png templates/static/strongswan.png \ +templates/static/router.png templates/static/gateway-right.png templates/static/client-right.png + +EXTRA_DIST = manager.db templates/header.cs templates/footer.cs templates/error.cs \ +templates/auth/login.cs templates/gateway/list.cs templates/status/ikesalist.cs \ +templates/static/style.css templates/static/script.js templates/static/jquery.js \ +templates/static/pipe.png templates/static/pipe-good.png templates/static/pipe-bad.png \ +templates/static/pipe-thin.png templates/static/pipe-thin-left.png templates/static/pipe-thin-right.png \ +templates/static/gateway-left.png templates/static/client-left.png templates/static/strongswan.png \ +templates/static/router.png templates/static/gateway-right.png templates/static/client-right.png + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/manager/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu src/manager/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(MKDIR_P) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libappserv.la: $(libappserv_la_OBJECTS) $(libappserv_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libappserv_la_OBJECTS) $(libappserv_la_LIBADD) $(LIBS) +install-ipsecPROGRAMS: $(ipsec_PROGRAMS) + @$(NORMAL_INSTALL) + test -z "$(ipsecdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsecdir)" + @list='$(ipsec_PROGRAMS)'; for p in $$list; do \ + p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + if test -f $$p \ + || test -f $$p1 \ + ; then \ + f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(ipsecPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(ipsecdir)/$$f'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) --mode=install $(ipsecPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(ipsecdir)/$$f" || exit 1; \ + else :; fi; \ + done + +uninstall-ipsecPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_PROGRAMS)'; for p in $$list; do \ + f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ + echo " rm -f '$(DESTDIR)$(ipsecdir)/$$f'"; \ + rm -f "$(DESTDIR)$(ipsecdir)/$$f"; \ + done + +clean-ipsecPROGRAMS: + @list='$(ipsec_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +manager.fcgi$(EXEEXT): $(manager_fcgi_OBJECTS) $(manager_fcgi_DEPENDENCIES) + @rm -f manager.fcgi$(EXEEXT) + $(LINK) $(manager_fcgi_OBJECTS) $(manager_fcgi_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/auth_controller.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/database.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dispatcher.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gateway.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gateway_controller.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/manager.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/request.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/session.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/status_controller.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xml.Plo@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +dispatcher.lo: lib/dispatcher.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dispatcher.lo -MD -MP -MF $(DEPDIR)/dispatcher.Tpo -c -o dispatcher.lo `test -f 'lib/dispatcher.c' || echo '$(srcdir)/'`lib/dispatcher.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/dispatcher.Tpo $(DEPDIR)/dispatcher.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib/dispatcher.c' object='dispatcher.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o dispatcher.lo `test -f 'lib/dispatcher.c' || echo '$(srcdir)/'`lib/dispatcher.c + +request.lo: lib/request.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT request.lo -MD -MP -MF $(DEPDIR)/request.Tpo -c -o request.lo `test -f 'lib/request.c' || echo '$(srcdir)/'`lib/request.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/request.Tpo $(DEPDIR)/request.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib/request.c' object='request.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o request.lo `test -f 'lib/request.c' || echo '$(srcdir)/'`lib/request.c + +session.lo: lib/session.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT session.lo -MD -MP -MF $(DEPDIR)/session.Tpo -c -o session.lo `test -f 'lib/session.c' || echo '$(srcdir)/'`lib/session.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/session.Tpo $(DEPDIR)/session.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib/session.c' object='session.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o session.lo `test -f 'lib/session.c' || echo '$(srcdir)/'`lib/session.c + +xml.lo: lib/xml.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xml.lo -MD -MP -MF $(DEPDIR)/xml.Tpo -c -o xml.lo `test -f 'lib/xml.c' || echo '$(srcdir)/'`lib/xml.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/xml.Tpo $(DEPDIR)/xml.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='lib/xml.c' object='xml.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o xml.lo `test -f 'lib/xml.c' || echo '$(srcdir)/'`lib/xml.c + +auth_controller.o: controller/auth_controller.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT auth_controller.o -MD -MP -MF $(DEPDIR)/auth_controller.Tpo -c -o auth_controller.o `test -f 'controller/auth_controller.c' || echo '$(srcdir)/'`controller/auth_controller.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/auth_controller.Tpo $(DEPDIR)/auth_controller.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='controller/auth_controller.c' object='auth_controller.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o auth_controller.o `test -f 'controller/auth_controller.c' || echo '$(srcdir)/'`controller/auth_controller.c + +auth_controller.obj: controller/auth_controller.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT auth_controller.obj -MD -MP -MF $(DEPDIR)/auth_controller.Tpo -c -o auth_controller.obj `if test -f 'controller/auth_controller.c'; then $(CYGPATH_W) 'controller/auth_controller.c'; else $(CYGPATH_W) '$(srcdir)/controller/auth_controller.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/auth_controller.Tpo $(DEPDIR)/auth_controller.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='controller/auth_controller.c' object='auth_controller.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o auth_controller.obj `if test -f 'controller/auth_controller.c'; then $(CYGPATH_W) 'controller/auth_controller.c'; else $(CYGPATH_W) '$(srcdir)/controller/auth_controller.c'; fi` + +status_controller.o: controller/status_controller.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT status_controller.o -MD -MP -MF $(DEPDIR)/status_controller.Tpo -c -o status_controller.o `test -f 'controller/status_controller.c' || echo '$(srcdir)/'`controller/status_controller.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/status_controller.Tpo $(DEPDIR)/status_controller.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='controller/status_controller.c' object='status_controller.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o status_controller.o `test -f 'controller/status_controller.c' || echo '$(srcdir)/'`controller/status_controller.c + +status_controller.obj: controller/status_controller.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT status_controller.obj -MD -MP -MF $(DEPDIR)/status_controller.Tpo -c -o status_controller.obj `if test -f 'controller/status_controller.c'; then $(CYGPATH_W) 'controller/status_controller.c'; else $(CYGPATH_W) '$(srcdir)/controller/status_controller.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/status_controller.Tpo $(DEPDIR)/status_controller.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='controller/status_controller.c' object='status_controller.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o status_controller.obj `if test -f 'controller/status_controller.c'; then $(CYGPATH_W) 'controller/status_controller.c'; else $(CYGPATH_W) '$(srcdir)/controller/status_controller.c'; fi` + +gateway_controller.o: controller/gateway_controller.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT gateway_controller.o -MD -MP -MF $(DEPDIR)/gateway_controller.Tpo -c -o gateway_controller.o `test -f 'controller/gateway_controller.c' || echo '$(srcdir)/'`controller/gateway_controller.c +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/gateway_controller.Tpo $(DEPDIR)/gateway_controller.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='controller/gateway_controller.c' object='gateway_controller.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o gateway_controller.o `test -f 'controller/gateway_controller.c' || echo '$(srcdir)/'`controller/gateway_controller.c + +gateway_controller.obj: controller/gateway_controller.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT gateway_controller.obj -MD -MP -MF $(DEPDIR)/gateway_controller.Tpo -c -o gateway_controller.obj `if test -f 'controller/gateway_controller.c'; then $(CYGPATH_W) 'controller/gateway_controller.c'; else $(CYGPATH_W) '$(srcdir)/controller/gateway_controller.c'; fi` +@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/gateway_controller.Tpo $(DEPDIR)/gateway_controller.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='controller/gateway_controller.c' object='gateway_controller.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o gateway_controller.obj `if test -f 'controller/gateway_controller.c'; then $(CYGPATH_W) 'controller/gateway_controller.c'; else $(CYGPATH_W) '$(srcdir)/controller/gateway_controller.c'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +install-ipsecDATA: $(ipsec_DATA) + @$(NORMAL_INSTALL) + test -z "$(ipsecdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsecdir)" + @list='$(ipsec_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(ipsecDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(ipsecdir)/$$f'"; \ + $(ipsecDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(ipsecdir)/$$f"; \ + done + +uninstall-ipsecDATA: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(ipsecdir)/$$f'"; \ + rm -f "$(DESTDIR)$(ipsecdir)/$$f"; \ + done +install-ipsec_templatesDATA: $(ipsec_templates_DATA) + @$(NORMAL_INSTALL) + test -z "$(ipsec_templatesdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsec_templatesdir)" + @list='$(ipsec_templates_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(ipsec_templatesDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(ipsec_templatesdir)/$$f'"; \ + $(ipsec_templatesDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(ipsec_templatesdir)/$$f"; \ + done + +uninstall-ipsec_templatesDATA: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_templates_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(ipsec_templatesdir)/$$f'"; \ + rm -f "$(DESTDIR)$(ipsec_templatesdir)/$$f"; \ + done +install-ipsec_templates_authDATA: $(ipsec_templates_auth_DATA) + @$(NORMAL_INSTALL) + test -z "$(ipsec_templates_authdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsec_templates_authdir)" + @list='$(ipsec_templates_auth_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(ipsec_templates_authDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(ipsec_templates_authdir)/$$f'"; \ + $(ipsec_templates_authDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(ipsec_templates_authdir)/$$f"; \ + done + +uninstall-ipsec_templates_authDATA: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_templates_auth_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(ipsec_templates_authdir)/$$f'"; \ + rm -f "$(DESTDIR)$(ipsec_templates_authdir)/$$f"; \ + done +install-ipsec_templates_gatewayDATA: $(ipsec_templates_gateway_DATA) + @$(NORMAL_INSTALL) + test -z "$(ipsec_templates_gatewaydir)" || $(MKDIR_P) "$(DESTDIR)$(ipsec_templates_gatewaydir)" + @list='$(ipsec_templates_gateway_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(ipsec_templates_gatewayDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(ipsec_templates_gatewaydir)/$$f'"; \ + $(ipsec_templates_gatewayDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(ipsec_templates_gatewaydir)/$$f"; \ + done + +uninstall-ipsec_templates_gatewayDATA: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_templates_gateway_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(ipsec_templates_gatewaydir)/$$f'"; \ + rm -f "$(DESTDIR)$(ipsec_templates_gatewaydir)/$$f"; \ + done +install-ipsec_templates_staticDATA: $(ipsec_templates_static_DATA) + @$(NORMAL_INSTALL) + test -z "$(ipsec_templates_staticdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsec_templates_staticdir)" + @list='$(ipsec_templates_static_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(ipsec_templates_staticDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(ipsec_templates_staticdir)/$$f'"; \ + $(ipsec_templates_staticDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(ipsec_templates_staticdir)/$$f"; \ + done + +uninstall-ipsec_templates_staticDATA: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_templates_static_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(ipsec_templates_staticdir)/$$f'"; \ + rm -f "$(DESTDIR)$(ipsec_templates_staticdir)/$$f"; \ + done +install-ipsec_templates_statusDATA: $(ipsec_templates_status_DATA) + @$(NORMAL_INSTALL) + test -z "$(ipsec_templates_statusdir)" || $(MKDIR_P) "$(DESTDIR)$(ipsec_templates_statusdir)" + @list='$(ipsec_templates_status_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(ipsec_templates_statusDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(ipsec_templates_statusdir)/$$f'"; \ + $(ipsec_templates_statusDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(ipsec_templates_statusdir)/$$f"; \ + done + +uninstall-ipsec_templates_statusDATA: + @$(NORMAL_UNINSTALL) + @list='$(ipsec_templates_status_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(ipsec_templates_statusdir)/$$f'"; \ + rm -f "$(DESTDIR)$(ipsec_templates_statusdir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(DATA) +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(ipsecdir)" "$(DESTDIR)$(ipsecdir)" "$(DESTDIR)$(ipsec_templatesdir)" "$(DESTDIR)$(ipsec_templates_authdir)" "$(DESTDIR)$(ipsec_templates_gatewaydir)" "$(DESTDIR)$(ipsec_templates_staticdir)" "$(DESTDIR)$(ipsec_templates_statusdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-ipsecPROGRAMS clean-libLTLIBRARIES \ + clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-ipsecDATA install-ipsecPROGRAMS \ + install-ipsec_templatesDATA install-ipsec_templates_authDATA \ + install-ipsec_templates_gatewayDATA \ + install-ipsec_templates_staticDATA \ + install-ipsec_templates_statusDATA + +install-dvi: install-dvi-am + +install-exec-am: install-libLTLIBRARIES + +install-html: install-html-am + +install-info: install-info-am + +install-man: + +install-pdf: install-pdf-am + +install-ps: install-ps-am + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-ipsecDATA uninstall-ipsecPROGRAMS \ + uninstall-ipsec_templatesDATA \ + uninstall-ipsec_templates_authDATA \ + uninstall-ipsec_templates_gatewayDATA \ + uninstall-ipsec_templates_staticDATA \ + uninstall-ipsec_templates_statusDATA uninstall-libLTLIBRARIES + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-ipsecPROGRAMS clean-libLTLIBRARIES clean-libtool ctags \ + distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-ipsecDATA install-ipsecPROGRAMS \ + install-ipsec_templatesDATA install-ipsec_templates_authDATA \ + install-ipsec_templates_gatewayDATA \ + install-ipsec_templates_staticDATA \ + install-ipsec_templates_statusDATA install-libLTLIBRARIES \ + install-man install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \ + uninstall-am uninstall-ipsecDATA uninstall-ipsecPROGRAMS \ + uninstall-ipsec_templatesDATA \ + uninstall-ipsec_templates_authDATA \ + uninstall-ipsec_templates_gatewayDATA \ + uninstall-ipsec_templates_staticDATA \ + uninstall-ipsec_templates_statusDATA uninstall-libLTLIBRARIES + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/src/manager/controller/auth_controller.c b/src/manager/controller/auth_controller.c new file mode 100644 index 000000000..fd4a3c7a5 --- /dev/null +++ b/src/manager/controller/auth_controller.c @@ -0,0 +1,132 @@ +/** + * @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 . + * + * 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 + + +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) +{ + request->set(request, "action", "check"); + request->set(request, "title", "Login"); + request->render(request, "templates/auth/login.cs"); +} + +static void check(private_auth_controller_t *this, request_t *request) +{ + char *username, *password; + + username = request->get_query_data(request, "username"); + password = request->get_query_data(request, "password"); + if (username && password && + this->manager->login(this->manager, username, password)) + { + request->redirect(request, "status/ikesalist"); + } + else + { + request->redirect(request, "auth/login"); + } +} + +static void logout(private_auth_controller_t *this, request_t *request) +{ + this->manager->logout(this->manager); + request->redirect(request, "auth/login"); +} + +/** + * Implementation of controller_t.get_name + */ +static char* get_name(private_auth_controller_t *this) +{ + return "auth"; +} + +/** + * Implementation of controller_t.handle + */ +static void handle(private_auth_controller_t *this, + request_t *request, char *action) +{ + if (action) + { + if (streq(action, "login")) + { + return login(this, request); + } + else if (streq(action, "check")) + { + return check(this, request); + } + else if (streq(action, "logout")) + { + return logout(this, request); + } + } + request->redirect(request, "auth/login"); +} + +/** + * 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.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; + this->public.controller.destroy = (void(*)(controller_t*))destroy; + + this->manager = (manager_t*)context; + + return &this->public.controller; +} + diff --git a/src/manager/controller/auth_controller.h b/src/manager/controller/auth_controller.h new file mode 100644 index 000000000..c90546a17 --- /dev/null +++ b/src/manager/controller/auth_controller.h @@ -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 . + * + * 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 + +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_ */ diff --git a/src/manager/controller/gateway_controller.c b/src/manager/controller/gateway_controller.c new file mode 100644 index 000000000..bdc779256 --- /dev/null +++ b/src/manager/controller/gateway_controller.c @@ -0,0 +1,148 @@ +/** + * @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 . + * + * 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 + + +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) +{ + enumerator_t *enumerator; + char *name, *address; + int id, port; + + enumerator = this->manager->create_gateway_enumerator(this->manager); + while (enumerator->enumerate(enumerator, &id, &name, &port, &address)) + { + request->setf(request, "gateways.%d.name=%s", id, name); + if (port) + { + request->setf(request, "gateways.%d.address=tcp://%s:%d", + id, address, port); + } + else + { + request->setf(request, "gateways.%d.address=unix://%s", + id, IPSEC_PIDDIR"/charon.xml"); + } + } + enumerator->destroy(enumerator); + request->set(request, "action", "select"); + request->set(request, "title", "Choose gateway"); + request->render(request, "templates/gateway/list.cs"); +} + +static void _select(private_gateway_controller_t *this, request_t *request) +{ + char *id; + + id = request->get_query_data(request, "gateway"); + if (id) + { + if (this->manager->select_gateway(this->manager, atoi(id))) + { + request->redirect(request, "status/ikesalist"); + return; + } + } + request->redirect(request, "gateway/list"); +} + +/** + * Implementation of controller_t.get_name + */ +static char* get_name(private_gateway_controller_t *this) +{ + return "gateway"; +} + +/** + * Implementation of controller_t.handle + */ +static void handle(private_gateway_controller_t *this, + request_t *request, char *action) +{ + if (!this->manager->logged_in(this->manager)) + { + return request->redirect(request, "auth/login"); + } + if (action) + { + if (streq(action, "list")) + { + return list(this, request); + } + else if (streq(action, "select")) + { + return _select(this, request); + } + } + request->redirect(request, "gateway/list"); +} + + +/** + * 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.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; + this->public.controller.destroy = (void(*)(controller_t*))destroy; + + this->manager = (manager_t*)context; + + return &this->public.controller; +} + diff --git a/src/manager/controller/gateway_controller.h b/src/manager/controller/gateway_controller.h new file mode 100644 index 000000000..5872e20e2 --- /dev/null +++ b/src/manager/controller/gateway_controller.h @@ -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 . + * + * 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 + +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_ */ diff --git a/src/manager/controller/status_controller.c b/src/manager/controller/status_controller.c new file mode 100644 index 000000000..bcdbd26ea --- /dev/null +++ b/src/manager/controller/status_controller.c @@ -0,0 +1,238 @@ +/** + * @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 . + * + * 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 + +#include + + +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; +}; + +/** + * read XML of a childsa element and fill template + */ +static void process_childsa(private_status_controller_t *this, char *id, + enumerator_t *e, request_t *r) +{ + xml_t *xml; + enumerator_t *e1, *e2; + char *name, *value, *reqid = "", *section = ""; + int num = 0; + + while (e->enumerate(e, &xml, &name, &value)) + { + if (streq(name, "reqid")) + { + reqid = value; + } + else if (streq(name, "local") || streq(name, "remote")) + { + section = name; + e1 = xml->children(xml); + while (e1->enumerate(e1, &xml, &name, &value)) + { + if (streq(name, "networks")) + { + e2 = xml->children(xml); + while (e2->enumerate(e2, &xml, &name, &value)) + { + if (streq(name, "network")) + { + r->setf(r, "ikesas.%s.childsas.%s.%s.networks.%d=%s", + id, reqid, section, ++num, value); + } + } + e2->destroy(e2); + } + else + { + r->setf(r, "ikesas.%s.childsas.%s.%s.%s=%s", + id, reqid, section, name, value); + } + } + e1->destroy(e1); + } + else + { + r->setf(r, "ikesas.%s.childsas.%s.%s=%s", + id, reqid, name, value); + } + } +} + +/** + * read XML of a ikesa element and fill template + */ +static void process_ikesa(private_status_controller_t *this, + enumerator_t *e, request_t *r) +{ + xml_t *xml; + enumerator_t *e1, *e2; + char *name, *value, *id = "", *section = ""; + + while (e->enumerate(e, &xml, &name, &value)) + { + if (streq(name, "id")) + { + id = value; + } + else if (streq(name, "local") || streq(name, "remote")) + { + section = name; + e1 = xml->children(xml); + while (e1->enumerate(e1, &xml, &name, &value)) + { + r->setf(r, "ikesas.%s.%s.%s=%s", id, section, name, value); + } + e1->destroy(e1); + } + else if (streq(name, "childsalist")) + { + e1 = xml->children(xml); + while (e1->enumerate(e1, &xml, &name, &value)) + { + if (streq(name, "childsa")) + { + e2 = xml->children(xml); + process_childsa(this, id, e2, r); + e2->destroy(e2); + } + } + e1->destroy(e1); + } + else + { + r->setf(r, "ikesas.%s.%s=%s", id, name, value); + } + } +} + +static void ikesalist(private_status_controller_t *this, request_t *r) +{ + gateway_t *gateway; + xml_t *xml; + enumerator_t *e1, *e2; + char *name, *value; + + gateway = this->manager->select_gateway(this->manager, 0); + e1 = gateway->query_ikesalist(gateway); + if (e1 == NULL) + { + r->set(r, "title", "Error"); + r->set(r, "error", "querying the gateway failed"); + r->render(r, "templates/error.cs"); + } + else + { + r->set(r, "title", "IKE SA overview"); + + while (e1->enumerate(e1, &xml, &name, &value)) + { + if (streq(name, "ikesa")) + { + e2 = xml->children(xml); + process_ikesa(this, e2, r); + e2->destroy(e2); + } + } + e1->destroy(e1); + + r->render(r, "templates/status/ikesalist.cs"); + } +} + +/** + * Implementation of controller_t.get_name + */ +static char* get_name(private_status_controller_t *this) +{ + return "status"; +} + +/** + * Implementation of controller_t.handle + */ +static void handle(private_status_controller_t *this, + request_t *request, char *action) +{ + if (!this->manager->logged_in(this->manager)) + { + return request->redirect(request, "auth/login"); + } + if (this->manager->select_gateway(this->manager, 0) == NULL) + { + return request->redirect(request, "gateway/list"); + } + if (action) + { + if (streq(action, "ikesalist")) + { + return ikesalist(this, request); + } + } + return request->redirect(request, "status/ikesalist"); +} + +/** + * 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.handle = (void(*)(controller_t*,request_t*,char*,char*,char*,char*,char*))handle; + this->public.controller.destroy = (void(*)(controller_t*))destroy; + + this->manager = (manager_t*)context; + + return &this->public.controller; +} + diff --git a/src/manager/controller/status_controller.h b/src/manager/controller/status_controller.h new file mode 100644 index 000000000..a736dda83 --- /dev/null +++ b/src/manager/controller/status_controller.h @@ -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 . + * + * 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 + +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_ */ diff --git a/src/manager/database.c b/src/manager/database.c new file mode 100644 index 000000000..a7776c81e --- /dev/null +++ b/src/manager/database.c @@ -0,0 +1,183 @@ +/** + * @file database.c + * + * @brief Implementation of database_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 "database.h" + +#include +#include +#include + + +typedef struct private_database_t private_database_t; + +/** + * private data of database + */ +struct private_database_t { + + /** + * public functions + */ + database_t public; + + /** + * SQLite database handle + */ + sqlite3 *db; +}; + +/** + * database enumerator implements enumerator_t + */ +typedef struct { + enumerator_t enumerator; + sqlite3_stmt *stmt; +} db_enumerator_t; + +/** + * destroy a database enumerator + */ +static void db_enumerator_destroy(db_enumerator_t* this) +{ + sqlite3_finalize(this->stmt); + free(this); +} + +/** + * create a database enumerator + */ +static enumerator_t *db_enumerator_create(bool(*enumerate)(db_enumerator_t*,void*,...), + sqlite3_stmt *stmt) +{ + db_enumerator_t *this = malloc_thing(db_enumerator_t); + this->enumerator.enumerate = (void*)enumerate; + this->enumerator.destroy = (void*)db_enumerator_destroy; + this->stmt = stmt; + return &this->enumerator; +} + +/** + * Implementation of database_t.login. + */ +static int login(private_database_t *this, char *username, char *password) +{ + sqlite3_stmt *stmt; + hasher_t *hasher; + chunk_t hash, data; + size_t username_len, password_len; + int uid = 0; + char *str; + + /* hash = SHA1( username | password ) */ + hasher = hasher_create(HASH_SHA1); + hash = chunk_alloca(hasher->get_hash_size(hasher)); + username_len = strlen(username); + password_len = strlen(password); + data = chunk_alloca(username_len + password_len); + memcpy(data.ptr, username, username_len); + memcpy(data.ptr + username_len, password, password_len); + hasher->get_hash(hasher, data, hash.ptr); + hasher->destroy(hasher); + str = chunk_to_hex(hash, FALSE); + + if (sqlite3_prepare_v2(this->db, + "SELECT oid FROM users WHERE username = ? AND password = ?;", + -1, &stmt, NULL) == SQLITE_OK) + { + if (sqlite3_bind_text(stmt, 1, username, -1, SQLITE_STATIC) == SQLITE_OK && + sqlite3_bind_text(stmt, 2, str, -1, SQLITE_STATIC) == SQLITE_OK && + sqlite3_step(stmt) == SQLITE_ROW) + { + uid = sqlite3_column_int(stmt, 0); + } + sqlite3_finalize(stmt); + } + free(str); + return uid; +} + +/** + * enumerate function for gateway enumrator + */ +static bool gateway_enumerate(db_enumerator_t* e, int *id, const char **name, + int *port, const char **address) +{ + if (sqlite3_step(e->stmt) == SQLITE_ROW) + { + *id = sqlite3_column_int(e->stmt, 0); + *name = sqlite3_column_text(e->stmt, 1); + *port = sqlite3_column_int(e->stmt, 2); + *address = sqlite3_column_text(e->stmt, 3); + return TRUE; + } + return FALSE; +} + +/** + * Implementation of database_t.create_gateway_enumerator. + */ +static enumerator_t* create_gateway_enumerator(private_database_t *this, int user) +{ + sqlite3_stmt *stmt; + + if (sqlite3_prepare_v2(this->db, + "SELECT gateways.oid AS gid, name, port, address FROM " + "gateways, user_gateway AS ug ON gid = ug.gateway WHERE ug.user = ?;", + -1, &stmt, NULL) == SQLITE_OK) + { + if (sqlite3_bind_int(stmt, 1, user) == SQLITE_OK) + { + return db_enumerator_create((void*)gateway_enumerate, stmt); + } + sqlite3_finalize(stmt); + } + return enumerator_create_empty(); +} + +/** + * Implementation of database_t.destroy + */ +static void destroy(private_database_t *this) +{ + sqlite3_close(this->db); + free(this); +} + +/* + * see header file + */ +database_t *database_create(char *dbfile) +{ + private_database_t *this = malloc_thing(private_database_t); + + this->public.login = (int(*)(database_t*, char *username, char *password))login; + this->public.create_gateway_enumerator = (enumerator_t*(*)(database_t*,int))create_gateway_enumerator; + this->public.destroy = (void(*)(database_t*))destroy; + + if (sqlite3_open(dbfile, &this->db) != SQLITE_OK) + { + destroy(this); + return NULL; + } + return &this->public; +} + diff --git a/src/manager/database.h b/src/manager/database.h new file mode 100644 index 000000000..228d1cb22 --- /dev/null +++ b/src/manager/database.h @@ -0,0 +1,69 @@ +/** + * @file database.h + * + * @brief Interface of database_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 DATABASE_H_ +#define DATABASE_H_ + +#include + + +typedef struct database_t database_t; + +/** + * @brief Persistent database. + */ +struct database_t { + + /** + * @brief Try to log in using specified credentials. + * + * @param username username + * @param password plaintext password + * @return user ID if login good, 0 otherwise + */ + int (*login)(database_t *this, char *username, char *password); + + /** + * @brief Create an iterator over the gateways. + * + * enumerate() arguments: int id, char *name, int port, char *address + * If port is 0, address is a Unix socket address. + * + * @param user user Id + * @return enumerator + */ + enumerator_t* (*create_gateway_enumerator)(database_t *this, int user); + + /** + * @brief Destroy a database instance. + */ + void (*destroy)(database_t *this); +}; + +/** + * @brief Create a database instance. + * + * @param dbfile SQLite database file + */ +database_t *database_create(char *dbfile); + +#endif /* DATABASE_H_ */ diff --git a/src/manager/gateway.c b/src/manager/gateway.c new file mode 100644 index 000000000..5f5a4b477 --- /dev/null +++ b/src/manager/gateway.c @@ -0,0 +1,253 @@ +/** + * @file gateway.c + * + * @brief Implementation of gateway_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 "gateway.h" + +#include +#include +#include +#include +#include +#include + +#include + +typedef struct private_gateway_t private_gateway_t; + +/** + * private data of gateway + */ +struct private_gateway_t { + + /** + * public functions + */ + gateway_t public; + + /** + * name of the gateway + */ + char *name; + + /** + * host to connect using tcp + */ + host_t *host; + + /** + * socket file descriptor, > 0 if connected + */ + int fd; +}; + +struct sockaddr_un unix_addr = { AF_UNIX, IPSEC_PIDDIR "/charon.xml"}; + +/** + * establish connection to gateway + */ +static bool connect_(private_gateway_t *this) +{ + int family, len; + struct sockaddr *addr; + + if (this->fd >= 0) + { + close(this->fd); + } + if (this->host) + { + family = AF_INET; + addr = this->host->get_sockaddr(this->host); + len = *this->host->get_sockaddr_len(this->host); + } + else + { + family = AF_UNIX; + addr = (struct sockaddr*)&unix_addr; + len = sizeof(unix_addr); + } + + this->fd = socket(family, SOCK_STREAM, 0); + if (this->fd < 0) + { + return FALSE; + } + if (connect(this->fd, addr, len) != 0) + { + close(this->fd); + this->fd = -1; + return FALSE; + } + return TRUE; +} + +/** + * Implementation of gateway_t.request. + */ +static char* request(private_gateway_t *this, char *xml) +{ + if (this->fd < 0) + { + if (!connect_(this)) + { + return NULL; + } + } + while (TRUE) + { + char buf[8096]; + ssize_t len; + + len = strlen(xml); + if (send(this->fd, xml, len, 0) != len) + { + return NULL; + } + len = recv(this->fd, buf, sizeof(buf) - 1, 0); + if (len < 0) + { + return NULL; + } + if (len == 0) + { + if (!connect_(this)) + { + return NULL; + } + continue; + } + buf[len] = 0; + return strdup(buf); + } +} + +/** + * Implementation of gateway_t.query_ikesalist. + */ +static enumerator_t* query_ikesalist(private_gateway_t *this) +{ + char *str, *name, *value; + xml_t *xml; + enumerator_t *e1, *e2, *e3, *e4 = NULL; + + str = request(this, "" + "" + "" + "" + ""); + if (str == NULL) + { + return NULL; + } + xml = xml_create(str); + if (xml == NULL) + { + return NULL; + } + + e1 = xml->children(xml); + free(str); + while (e1->enumerate(e1, &xml, &name, &value)) + { + if (streq(name, "message")) + { + e2 = xml->children(xml); + while (e2->enumerate(e2, &xml, &name, &value)) + { + if (streq(name, "query")) + { + e3 = xml->children(xml); + while (e3->enumerate(e3, &xml, &name, &value)) + { + if (streq(name, "ikesalist")) + { + e4 = xml->children(xml); + e1->destroy(e1); + e2->destroy(e2); + e3->destroy(e3); + return e4; + } + } + e3->destroy(e3); + } + } + e2->destroy(e2); + } + } + e1->destroy(e1); + return NULL; +} + +/** + * Implementation of gateway_t.destroy + */ +static void destroy(private_gateway_t *this) +{ + if (this->fd >= 0) + { + close(this->fd); + } + if (this->host) this->host->destroy(this->host); + free(this->name); + free(this); +} + +/** + * generic constructor + */ +static private_gateway_t *gateway_create(char *name) +{ + private_gateway_t *this = malloc_thing(private_gateway_t); + + this->public.request = (char*(*)(gateway_t*, char *xml))request; + this->public.query_ikesalist = (enumerator_t*(*)(gateway_t*))query_ikesalist; + this->public.destroy = (void(*)(gateway_t*))destroy; + + this->name = strdup(name); + this->host = NULL; + this->fd = -1; + + return this; +} + +/** + * see header + */ +gateway_t *gateway_create_tcp(char *name, host_t *host) +{ + private_gateway_t *this = gateway_create(name); + + this->host = host; + + return &this->public; +} + +/** + * see header + */ +gateway_t *gateway_create_unix(char *name) +{ + private_gateway_t *this = gateway_create(name); + + return &this->public; +} + diff --git a/src/manager/gateway.h b/src/manager/gateway.h new file mode 100644 index 000000000..1fe2aef4b --- /dev/null +++ b/src/manager/gateway.h @@ -0,0 +1,74 @@ +/** + * @file gateway.h + * + * @brief Interface of gateway_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 GATEWAY_H_ +#define GATEWAY_H_ + +#include +#include + +typedef struct gateway_t gateway_t; + +/** + * @brief A connection to a gateway. + */ +struct gateway_t { + + /** + * @brief Send an XML request to the gateway. + * + * @param xml xml request string + * @return allocated xml response string + */ + char* (*request)(gateway_t *this, char *xml); + + /** + * @brief Query the list of IKE_SAs and all its children. + * + * @return enumerator over ikesa XML elements + */ + enumerator_t* (*query_ikesalist)(gateway_t *this); + + /** + * @brief Destroy a gateway instance. + */ + void (*destroy)(gateway_t *this); +}; + +/** + * @brief Create a gateway instance using a TCP connection. + * + * @param name name of the gateway + * @param host gateway connection endpoint + * @param + */ +gateway_t *gateway_create_tcp(char *name, host_t *host); + +/** + * @brief Create a gateway instance using a UNIX socket. + * + * @param name name of the gateway + * @param + */ +gateway_t *gateway_create_unix(char *name); + +#endif /* GATEWAY_H_ */ diff --git a/src/manager/lib/context.h b/src/manager/lib/context.h new file mode 100644 index 000000000..23c979b8e --- /dev/null +++ b/src/manager/lib/context.h @@ -0,0 +1,47 @@ +/** + * @file context.h + * + * @brief Interface of context_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 CONTEXT_H_ +#define CONTEXT_H_ + +typedef struct context_t context_t; + +/** + * @brief Constructor function for a context + */ +typedef context_t *(*context_constructor_t)(void *param); + +/** + * @brief Custom session context + * + */ +struct context_t { + + /** + * @brief Destroy the context_t. + * + * @param this calling object + */ + void (*destroy) (context_t *this); +}; + +#endif /* CONTEXT_H_ */ diff --git a/src/manager/lib/controller.h b/src/manager/lib/controller.h new file mode 100644 index 000000000..5b39f559c --- /dev/null +++ b/src/manager/lib/controller.h @@ -0,0 +1,84 @@ +/** + * @file controller.h + * + * @brief Interface 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 CONTROLLER_H_ +#define CONTROLLER_H_ + +#include "request.h" +#include "context.h" + +typedef struct controller_t controller_t; + +/** + * @brief Controller action handle function + * + * @param request http request + * @param response http response + */ +typedef void *(*controller_handler_t)(controller_t *this, request_t *request); + +/** + * @brief Constructor function for a controller + * + * @param context session specific context + * @param param user supplied param + */ +typedef controller_t *(*controller_constructor_t)(context_t* context, void *param); + +/** + * @brief Controller interface, to be implemented by users controllers. + * + */ +struct controller_t { + + /** + * @brief Get the name of the controller. + * + * @return name of the controller + */ + char* (*get_name)(controller_t *this); + + /** + * @brief Handle a HTTP request for that controller. + * + * 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 p1 first parameter + * @param p2 second parameter + * @param p3 third parameter + * @param p4 forth parameter + * @param p5 fifth parameter + * @return + */ + void (*handle)(controller_t *this, request_t *request, + char *a1, char *a2, char *a3, char *a4, char *a5); + + /** + * @brief Destroy the controller instance. + */ + void (*destroy) (controller_t *this); +}; + +#endif /* CONTROLLER_H_ */ diff --git a/src/manager/lib/dispatcher.c b/src/manager/lib/dispatcher.c new file mode 100644 index 000000000..df669ceb6 --- /dev/null +++ b/src/manager/lib/dispatcher.c @@ -0,0 +1,402 @@ +/** + * @file dispatcher.c + * + * @brief Implementation of dispatcher_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 "dispatcher.h" + +#include "request.h" +#include "session.h" + +#include +#include +#include +#include + +#include + +typedef struct private_dispatcher_t private_dispatcher_t; + +/** + * private data of the task manager + */ +struct private_dispatcher_t { + + /** + * public functions + */ + dispatcher_t public; + + /** + * fcgi socket fd + */ + int fd; + + /** + * thread list + */ + pthread_t *threads; + + /** + * number of threads in "threads" + */ + int thread_count; + + /** + * session locking mutex + */ + pthread_mutex_t mutex; + + /** + * List of sessions + */ + linked_list_t *sessions; + + /** + * session timeout + */ + time_t timeout; + + /** + * List of controllers controller_constructor_t + */ + linked_list_t *controllers; + + /** + * constructor function to create session context (in constructor_entry_t) + */ + context_constructor_t context_constructor; + + /** + * user param to context constructor + */ + void *param; + + /** + * thread specific initialization handler + */ + void (*init)(void *param); + + /** + * argument to pass to thread intiializer + */ + void *init_param; + + /** + * thread specific deinitialization handler + */ + void (*deinit)(void *param); + + /** + * param tho thread specific deinitialization handler + */ + void *deinit_param; +}; + +typedef struct { + /** constructor function */ + controller_constructor_t constructor; + /** parameter to constructor */ + void *param; +} constructor_entry_t; + +typedef struct { + /** session instance */ + session_t *session; + /** condvar to wait for session */ + pthread_cond_t cond; + /** number of threads waiting for session */ + int waiting; + /** last use of the session */ + time_t used; +} session_entry_t; + +/** + * create a session and instanciate controllers + */ +static session_t* load_session(private_dispatcher_t *this) +{ + iterator_t *iterator; + constructor_entry_t *entry; + session_t *session; + context_t *context = NULL; + controller_t *controller; + + if (this->context_constructor) + { + context = this->context_constructor(this->param); + } + session = session_create(context); + + iterator = this->controllers->create_iterator(this->controllers, TRUE); + while (iterator->iterate(iterator, (void**)&entry)) + { + controller = entry->constructor(context, entry->param); + session->add_controller(session, controller); + } + iterator->destroy(iterator); + + return session; +} + +/** + * create a new session entry + */ +static session_entry_t *session_entry_create(private_dispatcher_t *this) +{ + session_entry_t *entry; + + entry = malloc_thing(session_entry_t); + entry->waiting = 1; + pthread_cond_init(&entry->cond, NULL); + entry->session = load_session(this); + entry->used = time(NULL); + + return entry; +} + +static void session_entry_destroy(session_entry_t *entry) +{ + entry->session->destroy(entry->session); + free(entry); +} + +/** + * Implementation of dispatcher_t.add_controller. + */ +static void add_controller(private_dispatcher_t *this, + controller_constructor_t constructor, void *param) +{ + constructor_entry_t *entry = malloc_thing(constructor_entry_t); + + entry->constructor = constructor; + entry->param = param; + this->controllers->insert_last(this->controllers, entry); +} + +/** + * Actual dispatching code + */ +static void dispatch(private_dispatcher_t *this) +{ + FCGX_Request fcgi_req; + + if (FCGX_InitRequest(&fcgi_req, this->fd, 0) == 0) + { + while (TRUE) + { + request_t *request; + session_entry_t *current, *found = NULL; + iterator_t *iterator; + time_t now; + char *sid; + int accepted; + + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + accepted = FCGX_Accept_r(&fcgi_req); + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + + if (accepted != 0) + { + break; + } + + /* prepare */ + request = request_create(&fcgi_req, TRUE); + if (request == NULL) + { + continue; + } + sid = request->get_cookie(request, "SID"); + now = time(NULL); + + /* find session */ + iterator = this->sessions->create_iterator_locked(this->sessions, &this->mutex); + while (iterator->iterate(iterator, (void**)¤t)) + { + /* 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); + + if (found) + { /* wait until session is unused */ + pthread_mutex_lock(&this->mutex); + while (found->waiting > 1) + { + pthread_cond_wait(&found->cond, &this->mutex); + } + pthread_mutex_unlock(&this->mutex); + } + else + { /* create a new session if not found */ + found = session_entry_create(this); + pthread_mutex_lock(&this->mutex); + this->sessions->insert_first(this->sessions, found); + pthread_mutex_unlock(&this->mutex); + } + + /* start processing */ + found->session->process(found->session, request); + found->used = time(NULL); + + /* release session */ + pthread_mutex_lock(&this->mutex); + found->waiting--; + pthread_cond_signal(&found->cond); + pthread_mutex_unlock(&this->mutex); + + /* cleanup */ + request->destroy(request); + + /* + FCGX_FPrintF(fcgi_req.out, "
    "); + char **env = fcgi_req.envp; + while (*env) + { + FCGX_FPrintF(fcgi_req.out, "
  • %s
  • ", *env); + env++; + } + FCGX_FPrintF(fcgi_req.out, "
"); + */ + } + } +} + +/** + * Setup thread and start dispatching + */ +static void start_dispatching(private_dispatcher_t *this) +{ + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); + if (this->init) + { + this->init(this->init_param); + } + if (this->deinit) + { + pthread_cleanup_push(this->deinit, this->deinit_param); + dispatch(this); + pthread_cleanup_pop(1); + } + else + { + dispatch(this); + } +} + +/** + * Implementation of dispatcher_t.run. + */ +static void run(private_dispatcher_t *this, int threads, + void(*init)(void *param), void *init_param, + void(*deinit)(void *param), void *deinit_param) +{ + this->init = init; + this->init_param = init_param; + this->deinit = deinit; + this->deinit_param = deinit_param; + this->thread_count = threads; + this->threads = malloc(sizeof(pthread_t) * threads); + while (threads) + { + if (pthread_create(&this->threads[threads - 1], + NULL, (void*)start_dispatching, this) == 0) + { + threads--; + } + } +} + +/** + * Implementation of dispatcher_t.waitsignal. + */ +static void waitsignal(private_dispatcher_t *this) +{ + sigset_t set; + int sig; + + sigemptyset(&set); + sigaddset(&set, SIGINT); + sigaddset(&set, SIGTERM); + sigaddset(&set, SIGHUP); + sigprocmask(SIG_BLOCK, &set, NULL); + sigwait(&set, &sig); +} + +/** + * Implementation of dispatcher_t.destroy + */ +static void destroy(private_dispatcher_t *this) +{ + FCGX_ShutdownPending(); + while (this->thread_count--) + { + pthread_cancel(this->threads[this->thread_count]); + pthread_join(this->threads[this->thread_count], NULL); + } + this->sessions->destroy_function(this->sessions, (void*)session_entry_destroy); + this->controllers->destroy_function(this->controllers, free); + free(this); +} + +/* + * see header file + */ +dispatcher_t *dispatcher_create(char *socket, int timeout, + context_constructor_t constructor, void *param) +{ + private_dispatcher_t *this = malloc_thing(private_dispatcher_t); + + this->public.add_controller = (void(*)(dispatcher_t*, controller_constructor_t, void*))add_controller; + this->public.run = (void(*)(dispatcher_t*, int threads,void(*)(void *),void *,void(*)(void *),void *))run; + this->public.waitsignal = (void(*)(dispatcher_t*))waitsignal; + this->public.destroy = (void(*)(dispatcher_t*))destroy; + + this->sessions = linked_list_create(); + this->controllers = linked_list_create(); + this->context_constructor = constructor; + pthread_mutex_init(&this->mutex, NULL); + this->param = param; + this->fd = 0; + this->timeout = timeout; + + FCGX_Init(); + + if (socket) + { + unlink(socket); + this->fd = FCGX_OpenSocket(socket, 10); + } + return &this->public; +} + diff --git a/src/manager/lib/dispatcher.h b/src/manager/lib/dispatcher.h new file mode 100644 index 000000000..274837838 --- /dev/null +++ b/src/manager/lib/dispatcher.h @@ -0,0 +1,95 @@ +/** + * @file dispatcher.h + * + * @brief Interface of dispatcher_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 DISPATCHER_H_ +#define DISPATCHER_H_ + +#include "controller.h" + +typedef struct dispatcher_t dispatcher_t; + +/** + * @brief Dispatcher, accepts connections using multiple threads. + * + * The dispatcher creates a session for each client (using SID cookies). In + * each session, a session context is created using the context constructor. + * Each controller is instanciated in the session using the controller + * constructor added with add_controller. + */ +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 + */ + void (*add_controller)(dispatcher_t *this, + controller_constructor_t constructor, void *param); + + /** + * @brief Start with dispatching. + * + * It may be necessary to call per-thread initialization functions. + * If init is not NULL, the handler is called right after thread + * creation (by the created thread) and the deinit function is called + * before the thread gets destroyed (again by the thread itself). + * + * @param thread number of dispatching threads + * @param init thread specific initialization function, or NULL + * @param init_param param to pass to init function + * @param deinit thread dpecific deinitialization function, or NULL + * @param deinit_param param to pass to deinit function + */ + void (*run)(dispatcher_t *this, int threads, + void(*init)(void *param), void *init_param, + void(*deinit)(void *param), void *deinit_param); + + /** + * @brief Wait for a relevant signal action. + */ + void (*waitsignal)(dispatcher_t *this); + + /** + * @brief Destroy the dispatcher_t. + */ + void (*destroy) (dispatcher_t *this); +}; + +/** + * @brief Create a dispatcher. + * + * The context constructor is invoked to create a session context for + * each session. + * + * @param socket FastCGI socket path, NULL for dynamic + * @param timeout session timeout + * @param constructor construction function for session context + * @param param parameter to supply to context constructor + */ +dispatcher_t *dispatcher_create(char *socket, int timeout, + context_constructor_t constructor, void *param); + +#endif /* DISPATCHER_H_ */ diff --git a/src/manager/lib/request.c b/src/manager/lib/request.c new file mode 100644 index 000000000..4623b3860 --- /dev/null +++ b/src/manager/lib/request.c @@ -0,0 +1,305 @@ +/** + * @file request.c + * + * @brief Implementation of request_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. + */ + +#define _GNU_SOURCE + +#include "request.h" + +#include +#include +#include +#include + +typedef struct private_request_t private_request_t; + +/** + * private data of the task manager + */ +struct private_request_t { + + /** + * public functions + */ + request_t public; + + /** + * FastCGI request object + */ + FCGX_Request *req; + + /** + * ClearSilver CGI Kit context + */ + CGI *cgi; + + /** + * ClearSilver HDF dataset for this request + */ + HDF *hdf; +}; + +/** + * thread specific FCGX_Request, used for ClearSilver cgiwrap callbacks. + * ClearSilver cgiwrap is not threadsave, so we use a private + * context for each thread. + */ +static __thread FCGX_Request *req; + +/** + * length of param list in req->envp + */ +static __thread int req_env_len; + +/** + * fcgiwrap read callback + */ +static int read_cb(void *null, char *buf, int size) +{ + return FCGX_GetStr(buf, size, req->in); +} + +/** + * fcgiwrap writef callback + */ +static int writef_cb(void *null, const char *format, va_list args) +{ + FCGX_VFPrintF(req->out, format, args); + return 0; +} +/** + * fcgiwrap write callback + */ +static int write_cb(void *null, const char *buf, int size) +{ + return FCGX_PutStr(buf, size, req->out); +} + +/** + * fcgiwrap getenv callback + */ +static char *getenv_cb(void *null, const char *key) +{ + char *value; + + value = FCGX_GetParam(key, req->envp); + return value ? strdup(value) : NULL; +} + +/** + * fcgiwrap getenv callback + */ +static int putenv_cb(void *null, const char *key, const char *value) +{ + /* not supported */ + return 1; +} + +/** + * fcgiwrap iterenv callback + */ +static int iterenv_cb(void *null, int num, char **key, char **value) +{ + *key = NULL; + *value = NULL; + + if (num < req_env_len) + { + char *eq; + + eq = strchr(req->envp[num], '='); + if (eq) + { + *key = strndup(req->envp[num], eq - req->envp[num]); + *value = strdup(eq + 1); + } + if (*key == NULL || *value == NULL) + { + free(*key); + free(*value); + return 1; + } + } + return 0; +} + +/** + * Implementation of request_t.get_cookie. + */ +static char* get_cookie(private_request_t *this, char *name) +{ + return hdf_get_valuef(this->hdf, "Cookie.%s", name); +} + +/** + * Implementation of request_t.get_path. + */ +static char* get_path(private_request_t *this) +{ + char * path = FCGX_GetParam("PATH_INFO", this->req->envp); + return path ? path : ""; +} + +/** + * Implementation of request_t.get_post_data. + */ +static char* get_query_data(private_request_t *this, char *name) +{ + return hdf_get_valuef(this->hdf, "Query.%s", name); +} + +/** + * Implementation of request_t.add_cookie. + */ +static void add_cookie(private_request_t *this, char *name, char *value) +{ + cgi_cookie_set (this->cgi, name, value, + FCGX_GetParam("SCRIPT_NAME", this->req->envp), + NULL, NULL, 0, 0); +} + +/** + * Implementation of request_t.redirect. + */ +static void redirect(private_request_t *this, char *location) +{ + FCGX_FPrintF(this->req->out, "Status: 303 See Other\n"); + FCGX_FPrintF(this->req->out, "Location: %s%s%s\n\n", + FCGX_GetParam("SCRIPT_NAME", this->req->envp), + *location == '/' ? "" : "/", location); +} + +/** + * Implementation of request_t.get_base. + */ +static char* get_base(private_request_t *this) +{ + return FCGX_GetParam("SCRIPT_NAME", this->req->envp); +} + +/** + * Implementation of request_t.render. + */ +static void render(private_request_t *this, char *template) +{ + NEOERR* err; + + err = cgi_display(this->cgi, template); + if (err) + { + cgi_neo_error(this->cgi, err); + nerr_log_error(err); + } + return; +} + +/** + * Implementation of request_t.set. + */ +static void set(private_request_t *this, char *key, char *value) +{ + hdf_set_value(this->hdf, key, value); +} + +/** + * Implementation of request_t.setf. + */ +static void setf(private_request_t *this, char *format, ...) +{ + va_list args; + + va_start(args, format); + hdf_set_valuevf(this->hdf, format, args); + va_end(args); +} + +/** + * Implementation of request_t.destroy + */ +static void destroy(private_request_t *this) +{ + cgi_destroy(&this->cgi); + free(this); +} + +/* + * see header file + */ +request_t *request_create(FCGX_Request *request, bool debug) +{ + NEOERR* err; + static bool initialized = FALSE; + private_request_t *this = malloc_thing(private_request_t); + + this->public.get_path = (char*(*)(request_t*))get_path; + this->public.get_base = (char*(*)(request_t*))get_base; + this->public.add_cookie = (void(*)(request_t*, char *name, char *value))add_cookie; + this->public.get_cookie = (char*(*)(request_t*,char*))get_cookie; + this->public.get_query_data = (char*(*)(request_t*, char *name))get_query_data; + this->public.redirect = (void(*)(request_t*, char *location))redirect; + this->public.render = (void(*)(request_t*,char*))render; + this->public.set = (void(*)(request_t*, char *, char*))set; + this->public.setf = (void(*)(request_t*, char *format, ...))setf; + this->public.destroy = (void(*)(request_t*))destroy; + + if (!initialized) + { + cgiwrap_init_emu(NULL, read_cb, writef_cb, write_cb, + getenv_cb, putenv_cb, iterenv_cb); + initialized = TRUE; + } + + this->req = request; + req = request; + req_env_len = 0; + while (req->envp[req_env_len] != NULL) + { + req_env_len++; + } + + err = hdf_init(&this->hdf); + if (!err) + { + hdf_set_value(this->hdf, "base", get_base(this)); + hdf_set_value(this->hdf, "Config.NoCache", "true"); + if (!debug) + { + hdf_set_value(this->hdf, "Config.TimeFooter", "0"); + hdf_set_value(this->hdf, "Config.CompressionEnabled", "1"); + hdf_set_value(this->hdf, "Config.WhiteSpaceStrip", "2"); + } + + err = cgi_init(&this->cgi, this->hdf); + if (!err) + { + err = cgi_parse(this->cgi); + if (!err) + { + return &this->public; + } + cgi_destroy(&this->cgi); + } + } + nerr_log_error(err); + free(this); + return NULL; +} + diff --git a/src/manager/lib/request.h b/src/manager/lib/request.h new file mode 100644 index 000000000..e6fd71e71 --- /dev/null +++ b/src/manager/lib/request.h @@ -0,0 +1,127 @@ +/** + * @file request.h + * + * @brief Interface of request_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 REQUEST_H_ +#define REQUEST_H_ + +#include +#include + +typedef struct request_t request_t; + +/** + * @brief A HTTP request, encapsulates FCGX_Request. + * + */ +struct request_t { + + /** + * @brief Add a cookie to the reply (Set-Cookie header). + * + * @param name name of the cookie to set + * @param value value of the cookie + */ + void (*add_cookie)(request_t *this, char *name, char *value); + + /** + * @brief Get a cookie the client sent in the request. + * + * @param name name of the cookie + * @return cookie value, NULL if no such cookie found + */ + char* (*get_cookie)(request_t *this, char *name); + + /** + * @brief Get the request path relative to the application. + * + * @return path + */ + char* (*get_path)(request_t *this); + + /** + * @brief Get the base path of the application. + * + * @return base path + */ + char* (*get_base)(request_t *this); + + /** + * @brief Get a post/get variable included in the request. + * + * @param name name of the POST/GET variable + * @return value, NULL if not found + */ + char* (*get_query_data)(request_t *this, char *name); + + /** + * @brief Redirect the client to another location. + * + * @param location location to redirect to + */ + void (*redirect)(request_t *this, char *location); + + /** + * @brief Set a template value. + * + * @param key key to set + * @param value value to set key to + */ + void (*set)(request_t *this, char *key, char *value); + + /** + * @brief Set a template value using format strings. + * + * Format string is in the form "key=value", where printf like format + * substitution occurs over the whole string. + * + * @param format printf like format string + * @param ... variable argument list + */ + void (*setf)(request_t *this, char *format, ...); + + /** + * @brief Render a template. + * + * The render() function additionally sets a HDF 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 template clearsilver template file location + * @return rendered template string + */ + void (*render)(request_t *this, char *template); + + /** + * @brief Destroy the request_t. + */ + void (*destroy) (request_t *this); +}; + +/** + * @brief Create a request from the fastcgi struct. + * + * @param request the FCGI request + * @param debug no stripping, no compression, timing information + */ +request_t *request_create(FCGX_Request *request, bool debug); + +#endif /* REQUEST_H_ */ diff --git a/src/manager/lib/session.c b/src/manager/lib/session.c new file mode 100644 index 000000000..fe260b887 --- /dev/null +++ b/src/manager/lib/session.c @@ -0,0 +1,175 @@ +/** + * @file session.c + * + * @brief Implementation of session_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. + */ + +#define _GNU_SOURCE + +#include "session.h" + +#include +#include +#include + +#include +#include + +typedef struct private_session_t private_session_t; + +/** + * private data of the task manager + */ +struct private_session_t { + + /** + * public functions + */ + session_t public; + + /** + * session ID + */ + char *sid; + + /** + * list of controller instances controller_t + */ + linked_list_t *controllers; + + /** + * user defined session context + */ + context_t *context; +}; + +/** + * Implementation of session_t.load_controller. + */ +static void add_controller(private_session_t *this, controller_t *controller) +{ + this->controllers->insert_last(this->controllers, controller); +} + +/** + * Create a session ID and a cookie + */ +static void create_sid(private_session_t *this, request_t *request) +{ + char buf[16]; + chunk_t chunk = chunk_from_buf(buf); + randomizer_t *randomizer = randomizer_create(); + + randomizer->get_pseudo_random_bytes(randomizer, sizeof(buf), buf); + this->sid = chunk_to_hex(chunk, FALSE); + request->add_cookie(request, "SID", this->sid); + randomizer->destroy(randomizer); +} + +/** + * Implementation of session_t.process. + */ +static void process(private_session_t *this, request_t *request) +{ + char *pos, *start, *param[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; + iterator_t *iterator; + bool handled = FALSE; + controller_t *current; + int i = 0; + + if (this->sid == NULL) + { + create_sid(this, request); + } + + start = request->get_path(request); + if (start) + { + if (*start == '/') start++; + while ((pos = strchr(start, '/')) != NULL && i < 5) + { + param[i++] = strndup(start, pos - start); + start = pos + 1; + } + param[i] = strdup(start); + iterator = this->controllers->create_iterator(this->controllers, TRUE); + while (iterator->iterate(iterator, (void**)¤t)) + { + if (streq(current->get_name(current), param[0])) + { + current->handle(current, request, param[1], param[2], param[3], + param[4], param[5]); + handled = TRUE; + break; + } + } + iterator->destroy(iterator); + for (i = 0; i < 6; i++) + { + free(param[i]); + } + } + if (!handled) + { + if (this->controllers->get_first(this->controllers, + (void**)¤t) == SUCCESS) + { + request->redirect(request, current->get_name(current)); + } + } +} + +/** + * Implementation of session_t.get_sid. + */ +static char* get_sid(private_session_t *this) +{ + return this->sid; +} + +/** + * Implementation of session_t.destroy + */ +static void destroy(private_session_t *this) +{ + this->controllers->destroy_offset(this->controllers, offsetof(controller_t, destroy)); + if (this->context) this->context->destroy(this->context); + free(this->sid); + free(this); +} + +/* + * see header file + */ +session_t *session_create(context_t *context) +{ + private_session_t *this = malloc_thing(private_session_t); + + this->public.add_controller = (void(*)(session_t*, controller_t*))add_controller; + this->public.process = (void(*)(session_t*,request_t*))process; + this->public.get_sid = (char*(*)(session_t*))get_sid; + this->public.destroy = (void(*)(session_t*))destroy; + + this->sid = NULL; + this->controllers = linked_list_create(); + this->context = context; + + return &this->public; +} + diff --git a/src/manager/lib/session.h b/src/manager/lib/session.h new file mode 100644 index 000000000..d18545876 --- /dev/null +++ b/src/manager/lib/session.h @@ -0,0 +1,73 @@ +/** + * @file session.h + * + * @brief Interface of session_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 SESSION_H_ +#define SESSION_H_ + +#include "request.h" +#include "controller.h" + +typedef struct session_t session_t; + +/** + * @brief A session, identified by a session ID. + * + */ +struct session_t { + + /** + * @brief Get the session ID of the session. + * + * @return session ID + */ + char* (*get_sid)(session_t *this); + + /** + * @brief Add a controller instance to the session. + * + * @param controller controller to add + */ + void (*add_controller)(session_t *this, controller_t *controller); + + /** + * @brief Process a request in this session. + * + * @param request request to process + */ + void (*process)(session_t *this, request_t *request); + + /** + * @brief Destroy the session_t. + * + * @param this calling object + */ + void (*destroy) (session_t *this); +}; + +/** + * @brief Create a session. + * + * @param context user defined session context instance + */ +session_t *session_create(context_t *context); + +#endif /* SESSION_H_ */ diff --git a/src/manager/lib/xml.c b/src/manager/lib/xml.c new file mode 100644 index 000000000..008235b69 --- /dev/null +++ b/src/manager/lib/xml.c @@ -0,0 +1,169 @@ +/** + * @file xml.c + * + * @brief Implementation of xml_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 "xml.h" + +#include +#include + + +typedef struct private_xml_t private_xml_t; + +/** + * private data of xml + */ +struct private_xml_t { + + /** + * public functions + */ + xml_t public; + + /** + * root node of this xml (part) + */ + xmlNode *node; + + /** + * document, only for root xml_t + */ + xmlDoc *doc; + + /** + * Root xml_t* + */ + private_xml_t *root; + + /** + * number of enumerator instances + */ + int enums; +}; + +/** + * child element enumerator + */ +typedef struct { + /** enumerator interface */ + enumerator_t e; + /** current child context (returned to enumerate() caller) */ + private_xml_t child; + /** currently processing node */ + xmlNode *node; +} child_enum_t; + +/** + * Implementation of xml_t.children().enumerate(). + */ +static bool child_enumerate(child_enum_t *e, private_xml_t **child, + char **name, char **value) +{ + while (e->node && e->node->type != XML_ELEMENT_NODE) + { + e->node = e->node->next; + } + if (e->node) + { + xmlNode *text; + + text = e->node->children; + *value = NULL; + + while (text && text->type != XML_TEXT_NODE) + { + text = text->next; + } + if (text) + { + *value = text->content; + } + *name = (char*)e->node->name; + *child = &e->child; + e->child.node = e->node->children; + e->node = e->node->next; + return TRUE; + } + return FALSE; +} + +/** + * Implementation of xml_t.get_attribute. + */ +static char* get_attribute(private_xml_t *this, char *name) +{ + return NULL; +} + +/** + * destroy enumerator, and complete tree if this was the last enumerator + */ +static void child_destroy(child_enum_t *this) +{ + if (--this->child.root->enums == 0) + { + xmlFreeDoc(this->child.root->doc); + free(this->child.root); + } + free(this); +} + +/** + * Implementation of xml_t.children. + */ +static enumerator_t* children(private_xml_t *this) +{ + child_enum_t *ce = malloc_thing(child_enum_t); + ce->e.enumerate = (void*)child_enumerate; + ce->e.destroy = (void*)child_destroy; + ce->node = this->node; + ce->child.public.children = (void*)children; + ce->child.public.get_attribute = (void*)get_attribute; + ce->child.node = NULL; + ce->child.doc = this->doc; + ce->child.root = this->root; + this->root->enums++; + return &ce->e; +} + +/* + * see header file + */ +xml_t *xml_create(char *xml) +{ + private_xml_t *this = malloc_thing(private_xml_t); + + this->public.get_attribute = (char*(*)(xml_t*,char*))get_attribute; + this->public.children = (enumerator_t*(*)(xml_t*))children; + + this->doc = xmlReadMemory(xml, strlen(xml), NULL, NULL, 0); + if (this->doc == NULL) + { + free(this); + return NULL; + } + this->node = xmlDocGetRootElement(this->doc); + this->root = this; + this->enums = 0; + + return &this->public; +} + diff --git a/src/manager/lib/xml.h b/src/manager/lib/xml.h new file mode 100644 index 000000000..738a8e1b3 --- /dev/null +++ b/src/manager/lib/xml.h @@ -0,0 +1,63 @@ +/** + * @file xml.h + * + * @brief Interface of xml_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 XML_H_ +#define XML_H_ + +#include + +typedef struct xml_t xml_t; + +/** + * @brief Simple enumerator based XML parser. + * + * An xml_t is a single node of the XML tree, but also serves as root node + * and therefore the document. + * This object has no destructor, the tree gets destroyed when all enumerator + * instances get destroyed. + */ +struct xml_t { + + /** + * @brief Create an enumerator over all children. + * + * Enumerated values must not be manipulated or freed. + * + * @return enumerator over (xml_t* child, char *name, char *value) + */ + enumerator_t* (*children)(xml_t *this); + + /** + * @brief Get an attribute value by its name. + * + * @param name name of the attribute + * @return attribute value, NULL if not found + */ + char *(*get_attribute)(xml_t *this, char *name); +}; + +/** + * @brief Create a xml instance. + */ +xml_t *xml_create(char *xml); + +#endif /* XML_H_ */ diff --git a/src/manager/main.c b/src/manager/main.c new file mode 100644 index 000000000..bbe07cbf3 --- /dev/null +++ b/src/manager/main.c @@ -0,0 +1,68 @@ +/** + * @file main.c + * + * @brief Implementation of dispatcher_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 +#include + +#include "manager.h" +#include "database.h" +#include "controller/auth_controller.h" +#include "controller/status_controller.h" +#include "controller/gateway_controller.h" + +#define DBFILE IPSECDIR "/manager.db" +#define SESSION_TIMEOUT 180 +#define THREADS 10 + +int main (int arc, char *argv[]) +{ + dispatcher_t *dispatcher; + database_t *database; + char *socket = NULL; + +#ifdef FCGI_SOCKET + socket = FCGI_SOCKET; +#endif /* FCGI_SOCKET */ + + database = database_create(DBFILE); + if (database == NULL) + { + fprintf(stderr, "opening database '%s' failed.\n", DBFILE); + return 1; + } + + dispatcher = dispatcher_create(socket, 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, THREADS, NULL, NULL, NULL, NULL); + + dispatcher->waitsignal(dispatcher); + + dispatcher->destroy(dispatcher); + database->destroy(database); + + return 0; +} + diff --git a/src/manager/manager.c b/src/manager/manager.c new file mode 100644 index 000000000..39c8d995a --- /dev/null +++ b/src/manager/manager.c @@ -0,0 +1,167 @@ +/** + * @file manager.c + * + * @brief Implementation of manager_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 "manager.h" + +#include "gateway.h" + +#include + +typedef struct private_manager_t private_manager_t; + +/** + * private data of manager + */ +struct private_manager_t { + + /** + * public functions + */ + manager_t public; + + /** + * underlying database + */ + database_t *db; + + /** + * user id, if we are logged in + */ + int user; + + /** + * selected gateway + */ + gateway_t *gateway; +}; + +/** + * Implementation of manager_t.create_gateway_enumerator. + */ +static enumerator_t* create_gateway_enumerator(private_manager_t *this) +{ + return this->db->create_gateway_enumerator(this->db, this->user); +} + +/** + * Implementation of manager_t.select_gateway. + */ +static gateway_t* select_gateway(private_manager_t *this, int select_id) +{ + if (select_id != 0) + { + enumerator_t *enumerator; + int id, port; + char *name, *address; + host_t *host; + + if (this->gateway) this->gateway->destroy(this->gateway); + this->gateway = NULL; + + enumerator = this->db->create_gateway_enumerator(this->db, this->user); + while (enumerator->enumerate(enumerator, &id, &name, &port, &address)) + { + if (select_id == id) + { + if (port == 0) + { + this->gateway = gateway_create_unix(name); + } + else + { + host = host_create_from_string(address, port); + if (host) + { + this->gateway = gateway_create_tcp(name, host); + } + } + break; + } + } + enumerator->destroy(enumerator); + } + return this->gateway; +} + +/** + * Implementation of manager_t.logged_in. + */ +static bool logged_in(private_manager_t *this) +{ + return this->user != 0; +} + +/** + * Implementation of manager_t.login. + */ +static bool login(private_manager_t *this, char *username, char *password) +{ + if (!this->user) + { + this->user = this->db->login(this->db, username, password); + } + return this->user != 0; +} + +/** + * Implementation of manager_t.logout. + */ +static void logout(private_manager_t *this) +{ + if (this->gateway) + { + this->gateway->destroy(this->gateway); + this->gateway = NULL; + } + this->user = 0; +} + +/** + * Implementation of manager_t.destroy + */ +static void destroy(private_manager_t *this) +{ + if (this->gateway) this->gateway->destroy(this->gateway); + free(this); +} + +/* + * see header file + */ +manager_t *manager_create(database_t *database) +{ + private_manager_t *this = malloc_thing(private_manager_t); + + this->public.login = (bool(*)(manager_t*, char *username, char *password))login; + this->public.logged_in = (bool(*)(manager_t*))logged_in; + this->public.logout = (void(*)(manager_t*))logout; + this->public.create_gateway_enumerator = (enumerator_t*(*)(manager_t*))create_gateway_enumerator; + this->public.select_gateway = (gateway_t*(*)(manager_t*, int id))select_gateway; + this->public.context.destroy = (void(*)(context_t*))destroy; + + this->user = 0; + this->db = database; + this->gateway = NULL; + + return &this->public; +} + diff --git a/src/manager/manager.db b/src/manager/manager.db new file mode 100644 index 000000000..23b6ed2e0 Binary files /dev/null and b/src/manager/manager.db differ diff --git a/src/manager/manager.h b/src/manager/manager.h new file mode 100644 index 000000000..4235618cd --- /dev/null +++ b/src/manager/manager.h @@ -0,0 +1,93 @@ +/** + * @file manager.h + * + * @brief Interface of manager_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 MANAGER_H_ +#define MANAGER_H_ + +#include "database.h" +#include "gateway.h" + +#include + +#include + +typedef struct manager_t manager_t; + +/** + * @brief The manager, manages multiple gateways. + */ +struct manager_t { + + /** + * implements context_t interface + */ + context_t context; + + /** + * @brief Create an iterator over all configured gateways. + * + * enumerate() arguments: int id, char *name, int port, char *address + * If port is 0, address is a Unix socket address. + * + * @return enumerator + */ + enumerator_t* (*create_gateway_enumerator)(manager_t *this); + + /** + * @brief Select a gateway. + * + * If id is 0, the previously selected gateway is returned. If none has + * been selected yet, NULL is returned. + * + * @param id id of the gateway (from enumerate), or 0 + * @return selected gateway, or NULL + */ + gateway_t* (*select_gateway)(manager_t *this, int id); + + /** + * @brief Try to log in. + * + * @param username username + * @param password cleartext password + * @return TRUE if login successful + */ + bool (*login)(manager_t *this, char *username, char *password); + + /** + * @brief Check if user logged in. + * + * @return TRUE if logged in + */ + bool (*logged_in)(manager_t *this); + + /** + * @brief Log out. + */ + void (*logout)(manager_t *this); +}; + +/** + * @brief Create a manager instance. + */ +manager_t *manager_create(database_t *database); + +#endif /* MANAGER_H_ */ diff --git a/src/manager/templates/auth/login.cs b/src/manager/templates/auth/login.cs new file mode 100644 index 000000000..49a8ec6e0 --- /dev/null +++ b/src/manager/templates/auth/login.cs @@ -0,0 +1,17 @@ + +
+
+ + + + + + + + + + +
Username
Password
+
+
+ diff --git a/src/manager/templates/error.cs b/src/manager/templates/error.cs new file mode 100644 index 000000000..be9b1a3a1 --- /dev/null +++ b/src/manager/templates/error.cs @@ -0,0 +1,3 @@ + +
+ diff --git a/src/manager/templates/footer.cs b/src/manager/templates/footer.cs new file mode 100644 index 000000000..db3601961 --- /dev/null +++ b/src/manager/templates/footer.cs @@ -0,0 +1,4 @@ + + + + diff --git a/src/manager/templates/gateway/list.cs b/src/manager/templates/gateway/list.cs new file mode 100644 index 000000000..b93364d6f --- /dev/null +++ b/src/manager/templates/gateway/list.cs @@ -0,0 +1,15 @@ + +
+
+

+ +

+ +

+

+
+ diff --git a/src/manager/templates/header.cs b/src/manager/templates/header.cs new file mode 100644 index 000000000..64a859a9a --- /dev/null +++ b/src/manager/templates/header.cs @@ -0,0 +1,24 @@ + + + + <?cs var:title ?> - strongSwan Manager + +