--- /dev/null
+#!/bin/bash
+###############################################################################
+# #
+# IPFire.org - A linux based firewall #
+# Copyright (C) 2009 Michael Tremer & Christian Schmidt #
+# #
+# 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 3 of the License, or #
+# (at your option) any later version. #
+# #
+# 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. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+CONFIG_NONE=0
+CONFIG_TEXT=1
+CONFIG_SQLITE=2
+
+function config_type() {
+ if _config_is_sqlite $1; then
+ echo $CONFIG_SQLITE
+ else
+ echo $CONFIG_TEXT
+ fi
+}
+
+function config_load() {
+ local file
+ local type
+ file=$1
+
+ if ! [ -f "$file" ]; then
+ error "Cannot load config file $file. File does not exist!"
+ exit 1
+ fi
+
+ vecho "Loading config file: $file"
+
+ type=$(config_type $file)
+ if [ "$type" = "$CONFIG_SQLITE" ]; then
+ eval $(_config_load_sqlite $file)
+ else
+ eval $(_config_load_text $file)
+ fi
+}
+
+function _config_is_sqlite() {
+ file $1 2>/dev/null | grep -q "SQLite 3.x database"
+}
+
+function _config_dump_sqlite() {
+ sqlite3 -noheader -column $1 "SELECT * FROM config;"
+}
+
+function _config_load_sqlite() {
+ _config_dump_sqlite $1 | while read KEY VALUE; do
+ echo "$KEY=$VALUE"
+ done
+}
+
+function _config_load_text() {
+ readhash $1
+}