Index: src/webservice/htdocs/SiWeather/Webservice/DataDirectoryChecks.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/DataDirectoryChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/DataDirectoryChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,34 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+
+namespace SiWeather\Webservice;
+
+abstract class DataDirectoryChecks
+{
+	const Success = 0;
+	const Error = 1;
+	const NoConfiguration = 2;
+	const NoDirectoryPath = 3;
+    const NotExist = 4;
+    const DirectoryNotWritable = 5;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/DatabaseChecks.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/DatabaseChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/DatabaseChecks.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,35 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+
+namespace SiWeather\Webservice;
+
+abstract class DatabaseChecks
+{
+	const Success = 0;
+	const Error = 1;
+    const NoDatabaseFile = 2;
+    const NoDirectoryPath = 3;
+    const DirectoryDoesNotExist = 4;
+    const DirectoryNotWritable = 5;
+    const DatabaseFileNotWritable = 6;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,163 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace SiWeather\Webservice;
+
+/**
+	* @brief Manages the database connection for SiWeather webservice
+	* @note This class needs to load the SpatialLite SQLite extension.
+	*       Therefore the sqlite3.extension_dir in php.ini must be set
+  *       to a path, where this extension could be found!
+	*/
+class DatabaseHandler {
+	function __construct()
+	{
+		$this->_config = new WebserviceConfig();
+	
+		$this->_lastErrorMessage = "";
+		$this->_database = null;
+		if(!$this->_config->dataDirectory()){
+			$this->_lastErrorMessage = "No data directory set!";
+			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
+			$this->databaseFile = null;
+		}
+		else{
+			$this->_databaseFile = $this->_config->dataDirectory() ."/siweather.sqlite";
+		}
+	}
+
+	function __destruct()
+	{
+		if(!is_null($this->_database)){
+			$this->close();
+		}
+	}
+
+	public function databaseFile()
+	{
+		return $this->_databaseFile;
+	}
+
+	public function lastErrorMessage()
+	{
+		return $this->_lastErrorMessage;
+	}
+
+	public function connect()
+	{
+		if(!is_null($this->_database)){
+			return true;
+		}
+		if(is_null($this->_databaseFile)){
+			$this->_lastErrorMessage = "No database file given";
+			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
+			return false;
+		}
+		try {
+			$db = new \SQLite3($this->_databaseFile);
+		}
+		catch(PDOException $exception){
+			$this->_lastErrorMessage = $exception->getMessage();
+			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
+			return false;
+		}
+		# loading SpatiaLite as an extension
+		$extension = $this->_config->getConfig("spatialiteExtension");
+		if(empty($extension)){
+			$this->_lastErrorMessage("No spatialiteExtension set!");
+			error_log($this->lastErrorMessage());
+			return false;
+		}
+		if(!$db->loadExtension($extension)){
+			$this->_lastErrorMessage = "Could not load SpatialLite extension: ". $db->lastErrorMsg();
+			error_log($this->lastErrorMessage());
+			return false;
+		}
+		$this->_database = $db;
+		return true;
+	}
+
+	public function close()
+	{
+		if(is_null($this->_database)){
+			return true;
+		}
+		if($this->_database->close()){
+			$this->_database = null;
+			return true;
+		}
+		$this->_lastErrorMessage = $this->_database->lastErrorMsg();
+		error_log("Failed to close the database: "+ $this->lastErrorMessage());
+		return false;
+	}
+	
+	public function exec($query)
+	{
+		if(!$this->connect()){
+			return false;
+		}
+		return $this->_database->exec($query);
+	}
+	
+	public function prepare($query)
+	{
+		if(!$this->connect()){
+			return false;
+		}
+		return $this->_database->prepare($query);
+	}
+	
+	public function versionSpatialite(){
+		if(is_null($this->_database)){
+			$this->_lastErrorMessage("Unknown (No database connection)");
+			return 0;
+		}
+		if(!$this->connect()){
+			return 0;
+		}
+		$result = $this->_database->query("SELECT spatialite_version()");
+		while($row = $result->fetchArray()){
+			return $row[0];
+		}
+		return 0;
+	}
+	
+	public function versionSqlite(){
+		if(is_null($this->_database)){
+			$this->_lastErrorMessage("Unknown (No database connection)");
+			return 0;
+		}
+		if(!$this->connect()){
+			return 0;
+		}
+		$result = $this->_database->query("SELECT sqlite_version()");
+ 		while($row = $result->fetchArray()){
+			return $row[0];
+		}
+		return 0;
+	}
+	
+	private $_database;
+	private $_databaseFile;
+	private $_lastErrorMessage;
+	private $_config;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/Setup.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/Setup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/Setup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,290 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace SiWeather\Webservice;
+
+/**
+  * @brief Configures the Webservice and creates all needed files and directories (e.g. Databases)
+  *
+  * @note Requires php-posix!
+  */
+class Setup {
+
+	public function __construct(){
+		$this->_webserviceConfig = new WebserviceConfig();
+		$this->_dataDirectory = $this->_webserviceConfig->getConfig("dataDirectory");
+		$this->_databaseHandler = new DatabaseHandler();
+		$this->_databaseFile = $this->_databaseHandler->databaseFile();
+		$this->_databaseDirectory = pathinfo($this->_databaseFile, PATHINFO_DIRNAME);
+	}
+	
+	/**
+	  * @brief Checks if data directory is present and writable  and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DataDirectoryChecks
+	  * @see dataDirectoryCreate()
+	  */
+	public function dataDirectoryCheck(&$errorMessage){
+		if(!is_object($this->_webserviceConfig)){
+			$errorMessage = "Could not load the webservice configuration";
+			return DataDirectoryChecks::NoConfiguration;
+		}
+		if(!$this->_dataDirectory || empty($this->_dataDirectory)){
+			$errorMessage = "Could not determine dataDirectory setting";
+			return DataDirectoryChecks::NoDirectoryPath;
+		}
+		if(!is_dir($this->_dataDirectory)){
+			$errorMessage = "Data directory does not exists";
+			return DataDirectoryChecks::NotExist;
+		}
+		if(!is_writable($this->_dataDirectory)){
+			$errorMessage = "Data directory is not writable for ". $this->getProcessUser() .":". $this->getProcessGroup() ." (". $this->_dataDirectory .")";
+			return DataDirectoryChecks::NotWritable;
+		}
+		return DataDirectoryChecks::Success;
+	}
+	
+	/**
+	  * @brief Creates the data directory and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DataDirectoryChecks
+	  * @see dataDirectoryCreate()
+	  */
+	public function dataDirectoryCreate(&$errorMessage){
+		$result = $this->dataDirectoryCheck($errorMessage);
+		if($result == DataDirectoryChecks::Success){
+			return DataDirectoryChecks::Success;
+		}
+		if($result == DataDirectoryChecks::NoConfiguration || $result == DataDirectoryChecks::NoDirectoryPath || $result == DataDirectoryChecks::DirectoryNotWritable){
+			return $result;
+		}
+		if(!mkdir($this->_dataDirectory)){
+			$errorMessage = "Could not create data directory (". $this->_dataDirectory .")";
+			return DataDirectoryChecks::Error;
+		}
+		return DataDirectoryChecks::Success;
+	}
+	
+	/**
+	  * @brief Checks everything related to the database path and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DatabaseDirectoryChecks
+	  * @see databaseDirectoryCreate()
+	  */
+	public function databaseDirectoryCheck(&$errorMessage){
+		if(is_null($this->_databaseDirectory) || empty($this->_databaseDirectory)){
+			$errorMessage = "Failed to extract directory from database file path ("+ $this->_databaseFile +")";
+			return DatabaseChecks::NoDirectoryPath;
+		}
+		if(!is_dir($this->_databaseDirectory)){
+			$errorMessage = "Database directory does not exists (". $this->_databaseDirectory .")";
+			return DatabaseChecks::DirectoryDoesNotExist;
+		}
+		if(!is_writable($this->_databaseDirectory)){
+			$errorMessage = "Database directory is not writable  for ". $this->getProcessUser() .":". $this->getProcessGroup() ." (". $this->_databaseDirectory .")";
+			return DatabaseChecks::DirectoryNotWritable;
+		}
+		return DatabaseChecks::Success;
+	}
+	
+	/**
+	  * @brief Creates the database directory  and returns a value from DatabaesChecks
+	  *
+	  * If an error occurs, the error message is stored into @p $errorMessage.
+	  *
+	  * @see DatabaseDirectoryChecks
+	  * @see databaseDirectoryCheck()
+	  */
+	public function databaseDirectoryCreate(&$errorMessage){
+		$result = $this->databaseDirectoryChecks($errorMessage);
+		if($result == DatabaseChecks::Success){
+			return DatabaseChecks::Success;
+		}
+		if($result == DatabaseChecks::NoDatabaseFile || $result == DatabaseChecks::NoDirectoryPath || $result == DatabaseChecks::DirectoryNotWritable){
+			return $result;
+		}
+		if(!mkdir($this->_databaseDirectory)){
+			$errorMessage = "Could not create database directory (". $this->_databaseDirectory .")";
+			return DatabaseChecks::Error;
+		}
+		return DatabaseChecks::Success;
+	}
+	
+	/**
+	  * @brief Checks, if the database file is given and is in a writable path
+	  *
+	  * The database file itself is created by the DatabaseHandler. Therefore
+	  * this function only checks, if the database directory exists, and it must be
+	  * writable.
+	  *
+	  * @see DatabaseChecks
+	  * @see databaseDirectoryCheck()
+	  */
+	public function databaseFileCheck(&$errorMessage){
+		if(is_null($this->_databaseFile) || empty($this->_databaseFile)){
+			$errorMessage = "No database file given (". $this->_databaseHandler->lastErrorMessage() .")";
+			return DatabaseChecks::NoDatabaseFile;
+		}
+		if(file_exists($this->_databaseFile)){
+			if(!is_writable($this->_databaseFile)){
+				$errorMessage = "Database file is not writable for ". $this->getProcessUser() .":". $this->getProcessGroup() ." (". $this->_databaseFile .")";
+				return DatabaseChecks::DatabaseFileNotWritable;
+			}
+			return DatabaseChecks::Success;
+		}
+		// if the databaseDirectoryCheck function return something other than success,
+		// we probably have a problem (like no write permission, ...)
+		if($this->databaseDirectoryCheck($errorMessage) != DatabaseChecks::Success){
+			return DatabaseChecks::Error;
+		}
+		return DatabaseChecks::Success;
+	}
+
+	public function databaseConnection(&$errorMessage){
+		if(!is_object($this->_databaseHandler)){
+			$errorMessage = "No database handler";
+			return false;
+		}
+		if(!$this->_databaseHandler->connect()){
+			$errorMessage = "Could not connect to the database (". $db->lastErrorMessage() .")";
+			return false;
+		}
+		
+		// prepare Spatalite
+		if(!$this->_databaseHandler->exec("BEGIN")){
+			$errorMessage = "Could not start transaction to init Spatialite";
+			return false;
+		}
+		if(!$this->_databaseHandler->exec("SELECT InitSpatialMetadata()")){
+			$errorMessage = "Could not initiate Spatialite metadata";
+			return false;
+		}
+		if(!$this->_databaseHandler->exec("COMMIT")){
+			$errorMessage = "Could not commit transaction to init Spatialite";
+			return false;
+		}
+		
+		return true;
+	}
+	
+	public function databaseVersionSqlite(&$errorMessage){
+		if(!is_object($this->_databaseHandler)){
+			return 0;
+		}
+		$result =  $this->_databaseHandler->versionSqlite();
+		if($result == 0){
+			$errorMessage = $this->_databaseHandler->lastErrorMessage();
+		}
+		return $result;
+	}
+	
+	public function databaseVersionSpatalite(&$errorMessage){
+		if(!is_object($this->_databaseHandler)){
+			return 0;
+		}
+		$result = $this->_databaseHandler->versionSpatialite();
+		if($result == 0){
+			$errorMessage = $this->_databaseHandler->lastErrorMessage();
+		}
+		return $result;
+	}
+	
+	public function apiCheckWithoutRewrite(&$errorMessage){
+		return $this->apiCheck("index.php/stations", $errorMessage);
+	}
+	
+	public function apiCheckWithRewrite(&$errorMessage){
+		$apiVersion = $this->_webserviceConfig->getConfig("webserviceApiVersion");
+		if(!$apiVersion || empty($apiVersion)){
+			$errorMessage = "Could not determine API version";
+			return false;
+		}
+		
+		return $this->apiCheck($apiVersion ."/stations", $errorMessage);
+	}
+
+	private function getProcessUser(){
+		$processUser = posix_getpwuid(posix_getuid());
+		return $processUser["name"];
+	}
+	
+	private function getProcessGroup(){
+		$processGroup = posix_getgrgid(posix_getgid());
+		return $processGroup["name"];
+	}
+	
+	private function apiCheck($url, &$errorMessage){
+		$baseUrl = $this->_webserviceConfig->getConfig("webserviceBaseUrl");
+		if(!$baseUrl || empty($baseUrl)){
+			$errorMessage = "No webservice base url given!";
+			return false;
+		}
+
+		$client = new \GuzzleHttp\Client
+		(
+			[
+				"base_uri" => $baseUrl,
+				"timeout" => 2.0,
+				"http_errors" => false,
+			]
+		);
+		$response = $client->get($url);
+		if(is_null($response)){
+			$errorMessage = "Webservice has not answered at url ". $baseUrl ."!";
+			return false;
+		}
+		$result = $response->getStatusCode();
+		if($result != 200){
+			$errorMessage = "Got http error ". $result ." (". $response->getReasonPhrase() .")";
+			return false;
+		}
+		$result = $response->getReasonPhrase();
+		if($result != "OK"){
+			$errorMessage = "Got a http error reason with http code 200: ". $result;
+			return false;
+		}
+
+		$body = $response->getBody();
+		if(empty($body)){
+			$errorMessage = "Got empty return value";
+			return false;
+		}
+		
+		$json = json_decode($body);
+		if(is_null($json)){
+			$errorMessage = "Could not decode json message body";
+			return false;
+		}
+		return true;
+	}
+
+	private $_webserviceConfig;
+	private $_dataDirectory;
+	private $_databaseHandler;
+	private $_databaseFile;
+}
+
+?>
Index: src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php
===================================================================
--- src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/SiWeather/Webservice/WebserviceConfig.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,60 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+namespace SiWeather\Webservice;
+
+class WebserviceConfig {
+
+	function __construct(){
+		require(__DIR__ ."/../../config/config.php");
+		$this->_config = $config;
+		$this->loadAdditionalConfiguration();
+
+		if($this->getConfig("mode") == "development"){
+			error_reporting(E_ALL);
+		}
+	}
+	
+	private function loadAdditionalConfiguration(){
+		$this->_config["dataDirectory"] = "data";
+	}
+
+	public function getConfig($key){
+		if(!array_key_exists($key, $this->_config)){
+			error_log("Expected config value ". $key ." does not exists");
+			return FALSE;
+		}
+		
+		if($key == "dataDirectory"){
+// 			error_log("Use dataDirectory() function to access this value");
+			return $this->dataDirectory();
+		}
+		
+		return $this->_config[$key];
+	}
+
+	public function dataDirectory(){
+		return __DIR__ ."/../../". $this->_config["dataDirectory"];
+	}
+
+	private $_config;
+}
+
+?>
Index: src/webservice/htdocs/inc/DatabaseHandler.php
===================================================================
--- src/webservice/htdocs/inc/DatabaseHandler.php	(revision 92c9c7cf0efa1759b51ecb3e58d804f77ebdcbf0)
+++ 	(revision )
@@ -1,109 +1,0 @@
-<?php
-/*
-    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
-
-    This library is free software; you can redistribute it and/or
-    modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    This library 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
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-    MA 02110-1301  USA.
-*/
-
-require_once("config/config.php");
-
-/**
-	* @brief Manages the database connection for SiWeather webservice
-	* @note This class needs to load the SpatialLite SQLite extension.
-	*       Therefore the sqlite3.extension_dir in php.ini must be set
-  *       to a path, where this extension could be found!
-	*/
-class DatabaseHandler {
-	private $_database;
-	private $_databaseFile;
-	private $_lastErrorMessage;
-
-	function __construct()
-	{
-		$this->_lastErrorMessage = "";
-		$this->_database = null;
-		if(!getConfig("dataDirectory")){
-			$this->_lastErrorMessage = "No data directory set!";
-			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
-			$this->databaseFile = null;
-		}
-		else{
-			$this->_databaseFile = getConfig("dataDirectory") ."/siweather.sqlite";
-		}
-	}
-
-	function __destruct()
-	{
-		if(!is_null($this->_database)){
-			$this->close();
-		}
-	}
-
-	public function databaseFile()
-	{
-		return $this->_databaseFile;
-	}
-
-	public function lastErrorMessage()
-	{
-		return $this->_lastErrorMessage;
-	}
-
-	public function connect()
-	{
-		if(!is_null($this->_database)){
-			echo "database is not null";
-			return true;
-		}
-		if(is_null($this->_databaseFile)){
-			$this->_lastErrorMessage = "No database file given";
-			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
-			return false;
-		}
-		try {
-			$db = new SQLite3($this->_databaseFile);
-		}
-		catch(PDOException $exception){
-			$this->_lastErrorMessage = $exception->getMessage();
-			error_log("Could not connect to the database: "+ $this->lastErrorMessage());
-			return false;
-		}
-		# loading SpatiaLite as an extension
-		if(!$db->loadExtension("libspatialite.so.7")){
-			$this->_lastErrorMessage = "Could not load SpatialLite extension: ". $db->lastErrorMsg();
-			error_log($this->lastErrorMessage());
-			return false;
-		}
-		$this->_database = $db;
-		return true;
-	}
-
-	public function close()
-	{
-		if(is_null($this->_database)){
-			return true;
-		}
-		if($this->_database->close()){
-			$this->_database = null;
-			return true;
-		}
-		$this->_lastErrorMessage = $this->_database->lastErrorMsg();
-		error_log("Failed to close the database: "+ $this->lastErrorMessage());
-		return false;
-	}
-}
-
-?>
Index: src/webservice/htdocs/inc/envsetup.php
===================================================================
--- src/webservice/htdocs/inc/envsetup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/inc/envsetup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,30 @@
+<?php
+/*
+    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+    MA 02110-1301  USA.
+*/
+
+// set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ ."/../../vendor/");
+$composerAutoloader = require(__DIR__ ."/../../vendor/autoload.php");
+if(is_object($composerAutoloader)){
+	$composerAutoloader->add("SiWeather\\Webservice\\", __DIR__ ."/../");
+	$composerAutoloader->register();
+}
+
+require_once(__DIR__ ."/translate.php");
+
+?>
Index: src/webservice/htdocs/inc/translate.php
===================================================================
--- src/webservice/htdocs/inc/translate.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
+++ src/webservice/htdocs/inc/translate.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -0,0 +1,89 @@
+<?php
+######################
+#
+#    Copyright (C) 2015 EngSaS - Engineering Soluations and Services Langenbach. All rights reserved.
+#
+#    This library is free software; you can redistribute it and/or
+#    modify it under the terms of the GNU Lesser General Public
+#    License as published by the Free Software Foundation; either
+#    version 2.1 of the License, or (at your option) any later version.
+#
+#    This library 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
+#    Lesser General Public License for more details.
+#
+#    You should have received a copy of the GNU Lesser General Public
+#    License along with this library; if not, write to the Free Software
+#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+#    MA 02110-1301  USA.
+#
+######################
+
+define("LOCALE_SESSION_KEY", "gyl_locale");
+define("LOCALE_DEFAULT", "en_US");
+define("LOCALE_REQUEST_PARAN", "lang");
+define("LOCALE_DOMAIN", "messages"); // Must be the same name, as the po and mo files and the directory they are in
+
+require_once("HTTP2.php");
+
+$config = new SiWeather\Webservice\WebserviceConfig();
+
+$numberDelimiterDecimal = array();
+$numberDelimiterDecimal["en_US"] = ".";
+$numberDelimiterDecimal["de_DE"] = ",";
+
+$_localeCurrent = LOCALE_DEFAULT;
+if(isset($_SESSION)){
+	if(array_key_exists(LOCALE_REQUEST_PARAN, $_REQUEST)){
+		$_localeCurrent = $_REQUEST[LOCALE_REQUEST_PARAN];
+		$_SESSION[LOCALE_SESSION_KEY] = $_localeCurrent;
+	}
+	elseif(array_key_exists(LOCALE_SESSION_KEY, $_SESSION)){
+		$_localeCurrent = $_SESSION[LOCALE_SESSION_KEY];
+	}
+	else{
+		$supportedLanguages = Array(LOCALE_DEFAULT);
+		$transDirHandle = opendir($config->getConfig("translationdirectory"));
+		if($transDirHandle){
+			while(false !== ($entry = readdir($transDirHandle))){
+				if($entry != "." && $entry != ".."){
+					$supportedLanguages[str_replace("_", "-", $entry)] = true;
+				}
+			}
+			
+			closedir($transDirHandle);
+		}
+		$http = new HTTP2();
+		$_localeCurrent = str_replace("-", "_", $http->negotiateLanguage($supportedLanguages, LOCALE_DEFAULT));
+		$_SESSION[LOCALE_SESSION_KEY] = $_localeCurrent;
+	}
+}
+
+$results = putenv("LC_ALL0=". $_localeCurrent);
+if(!$results){
+	error_log("putenv failed (". $result .")");
+}
+$result = setlocale(LC_ALL, $_localeCurrent);
+if(!$results){
+	error_log("setlocale failed (". $result .")");
+}
+$results = bindtextdomain(LOCALE_DOMAIN, $config->getConfig("translationdirectory"));
+if(!$results){
+	error_log("bindtextdomain failed (". $result .")");
+}
+$results = bind_textdomain_codeset(LOCALE_DOMAIN, "UTF-8");
+if(!$results){
+	error_log("bind_textdomain_codeset failed (". $result .")");
+}
+$results = textdomain(LOCALE_DOMAIN);
+if(!$results){
+	error_log("textdomain failed (". $result .")");
+}
+
+class Translator {
+	public static function swGettext($id)
+	{
+		return vsprintf(gettext($id), array_slice(func_get_args(), 1));
+	}
+}
Index: src/webservice/htdocs/index.php
===================================================================
--- src/webservice/htdocs/index.php	(revision 92c9c7cf0efa1759b51ecb3e58d804f77ebdcbf0)
+++ src/webservice/htdocs/index.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -19,5 +19,7 @@
 */
 
-include("config/config.php");
+require(__DIR__ ."/inc/envsetup.php");
+
+$settings = new SiWeather\Webservice\WebserviceConfig();
 
 /**
@@ -76,3 +78,2 @@
 
 ?>
-
Index: src/webservice/htdocs/resources/css/webservice.css
===================================================================
--- src/webservice/htdocs/resources/css/webservice.css	(revision 92c9c7cf0efa1759b51ecb3e58d804f77ebdcbf0)
+++ src/webservice/htdocs/resources/css/webservice.css	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -8,2 +8,23 @@
 	font-weight: bold;
 }
+
+.footer {
+	margin-top: 1em;
+	padding-top: 0.5em;
+	color: #C6C6C6;
+	text-align: center;
+	font-size: 9pt;
+	border-width: 0;
+	border-top-width: 2px;
+	border-color: #E6E6E6;
+	border-style: solid;
+}
+
+.footnotes {
+	font-size: 8pt;
+	margin-top: 0.5em;
+}
+
+.footnotes a {
+	color: #C6C6C6;
+}
Index: src/webservice/htdocs/setup.php
===================================================================
--- src/webservice/htdocs/setup.php	(revision 92c9c7cf0efa1759b51ecb3e58d804f77ebdcbf0)
+++ src/webservice/htdocs/setup.php	(revision 8c356c136998b9a3dcbd43e23688c189ef78f80f)
@@ -19,6 +19,5 @@
 */
 
-require_once("config/config.php");
-require_once("inc/DatabaseHandler.php");
+require(__DIR__ ."/inc/envsetup.php");
 
 function printError($message)
@@ -46,5 +45,5 @@
 	<head>
 		<title>SiWeather Webservice Configuration</title>
-		<link rel="stylesheet" type="text/css" link="resources/css/webservice.css"/>
+		<link rel="stylesheet" type="text/css" href="resources/css/webservice.css"/>
 	</head>
 	<body>
@@ -53,40 +52,82 @@
 <?php
 
-$db = new DatabaseHandler();
-$dbFile = $db->databaseFile();
-if(is_null($dbFile)){
-	printResult(false, "No database file given (". $db->lastErrorMessage() .")");
+$setup = new SiWeather\Webservice\Setup();
+
+$errorMessage = "";
+$result = $setup->dataDirectoryCheck($errorMessage);
+if($result == SiWeather\Webservice\DataDirectoryChecks::NotExist && $result != SiWeather\Webservice\DataDirectoryChecks::Success){
+	$result = $setup->dataDirectoryCreate($errorMessage);
 }
 
-$dbDirectory = pathinfo($dbFile, PATHINFO_DIRNAME);
-if(empty($dbDirectory)){
-	printResult(false, "Failed to extract directory from database file path ("+ $dbFile +")");
+if($result != SiWeather\Webservice\DataDirectoryChecks::Success){
+	printResult(false, myGettext("Data directory not accessible (%s)", $errorMessage));
 }
 else{
-	if(is_dir($dbDirectory)){
-		printResult(true, "Database directory exists (". $dbDirectory .")!");
+	printResult(true, _("Data directory checked"));
+	$result = $setup->databaseDirectoryCheck($errorMessage);
+	if($result != SiWeather\Webservice\DatabaseChecks::Success){
+		printResult(false, $errorMessage);
 	}
 	else{
-		if(!mkdir($dbDirectory)){
-			printResult(false, "Failed to create database directory (". $dbDirectory .")!");
+		printResult(true, _("Database directory checked"));
+		$result = $setup->databaseFileCheck($errorMessage);
+		if($result != SiWeather\Webservice\DatabaseChecks::Success){
+			printResult(false, $errorMessage);
 		}
 		else{
-			printResult(true, "Created directory ". $dbDirectory ." as database directory");
+			printResult(true, _("Database file checked"));
+			if(!$setup->databaseConnection($errorMessage)){
+				printResult(false, $errorMessage);
+			}
+			else{
+				$prefix = "Database up and running";
+				$versionSqlite = $setup->databaseVersionSqlite($errorMessage);
+				if($versionSqlite <= 0){
+					printResult(false,  Translator::swGettext("%s (Could not determine SQLite version: %s)", $prefix, $errorMessage));
+				}
+				else{
+					$versionSpatalite = $setup->databaseVersionSpatalite($errorMessage);
+					if($versionSpatalite <= 0){
+						printResult(false, Translator::swGettext("%s (Could not determine Spatalite version: %s)", $prefix, $errorMessage));
+					}
+					else{
+						printResult(true, Translator::swGettext("%s (SQLite: %s, Spatalite: %s)", $prefix, $versionSqlite, $versionSpatalite));
+					}
+				}
+			}
 		}
 	}
+}
 
-	if(!is_writable($dbDirectory)){
-		printResult(false, "Database directory is not writable (". $dbDirectory .")!");
-	}
-	if($db->connect()){
-		printResult(true, "Connection to database established!");
-	}
-	else{
-		printResult(false, "Could not connect to the database (". $db->lastErrorMessage() .")");
-	}
+$webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
+if(!$setup->apiCheckWithoutRewrite($errorMessage)){
+	printResult(false, Translator::swGettext("Could not connect to webservice without rewrite (%s)", $errorMessage));
+}
+else{
+	$url = $webserviceConfig->getConfig("webserviceBaseUrl") ."/index.php/";
+	printResult(true, Translator::swGettext("Webservice withpout rewrite accessible at %s", "<a href=\"". $url ."\">". $url ."</a>"));
+}
+if(!$setup->apiCheckWithRewrite($errorMessage)){
+	printResult(false, Translator::swGettext("Could not connect to webservice with rewrite (%s)", $errorMessage));
+}
+else{
+	$url = $webserviceConfig->getConfig("webserviceBaseUrl") ."/". $webserviceConfig->getConfig("webserviceApiVersion");
+	printResult(true, Translator::swGettext("Webservice withp rewrite accessible at %s", "<a href=\"". $url ."\">". $url ."</a>"));
 }
 
 ?>
 		</ul>
+<?php
+// 	$webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
+	$apiVersion = $webserviceConfig->getConfig("webserviceApiVersion");
+	echo "		<div class=\"footer\">\n";
+	echo "			". Translator::swGettext("SiWeather webservice %s with API version %s), ", $webserviceConfig->getConfig("version"), $apiVersion) ."<br/>\n";
+	echo "			". Translator::swGettext("Webservice accessible at %s/%s/ or", $webserviceConfig->getConfig("webserviceBaseUrl"), $apiVersion) ."<br/>\n";
+	echo "			". $webserviceConfig->getConfig("webserviceBaseUrl") ."/index.php/\n";
+	echo "			<div class=\"footnotes\">\n";
+	echo "				". _("This site uses icons from Oxygen icon theme &#40;License: LGPLv3,") ."<a href=\"http://www.kde.org/\">http://www.kde.org</a>&#41;\n";
+	echo "			</div>\n";
+	echo "		</div>\n";
+?>
 	</body>
 </html>
