]> git.ipfire.org Git - network.git/commitdiff
Move config functions into seperate file.
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 May 2012 13:24:42 +0000 (13:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 May 2012 13:24:42 +0000 (13:24 +0000)
firewall
functions
functions.cli
functions.config [new file with mode: 0644]
functions.constants
functions.firewall
functions.util
network

index ca4d16cc0640448e4f798416010364d868f510d0..5b49ed14128306e90b74e92f1579314cb155562a 100755 (executable)
--- a/firewall
+++ b/firewall
@@ -29,6 +29,20 @@ function cli_stop() {
        firewall_stop
 }
 
+function cli_config() {
+       if cli_help_requested $@; then
+               cli_usage root-config
+               exit ${EXIT_OK}
+       fi
+
+       if [ -n "${1}" ]; then
+               config_set $@
+               firewall_config_write
+       else
+               firewall_config_print
+       fi
+}
+
 # Parse the command line
 while [ $# -gt 0 ]; do
        case "${1}" in
@@ -54,6 +68,10 @@ case "${action}" in
                cli_stop $@
                ;;
 
+       config)
+               cli_config $@
+               ;;
+
        ""|help|--help|-h)
                cli_usage root
                exit ${EXIT_OK}
index 3c966b9574c050a0bb6a3d19db0824143c9e3349..f948df228c0032843930b6119836e28fda3160a0 100644 (file)
--- a/functions
+++ b/functions
@@ -23,8 +23,8 @@ for file in /usr/lib/network/functions.*; do
        . ${file}
 done
 
-# Reading in network tool configuration
-network_config_read
+# Reading in global configuration files
+config_read_globals
 
 # Set colour mode
 case "${COLOURS}" in
index 554a6501dec12d66d67cc8975d4c43d8859b17be..0f6790a5f915b8fac9348fbae570ad766fc5767c 100644 (file)
@@ -26,7 +26,8 @@ function cli_config() {
        fi
 
        if [ -n "${1}" ]; then
-               network_config_set $@
+               config_set $@
+               network_config_write
        else
                network_config_print
        fi
diff --git a/functions.config b/functions.config
new file mode 100644 (file)
index 0000000..0d1bcf7
--- /dev/null
@@ -0,0 +1,126 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2012  IPFire Network Development Team                         #
+#                                                                             #
+# 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/>.       #
+#                                                                             #
+###############################################################################
+
+# Load all global configuration files.
+function config_read_globals() {
+       network_config_read
+       firewall_config_read
+}
+
+function config_read() {
+       local config_file=${1}
+
+       log DEBUG "Reading configuration: ${config_file}"
+
+       if [ -e "${config_file}" ]; then
+               . ${config_file}
+               config_check
+       fi
+}
+
+function config_write() {
+       local config_file=${1}
+       shift
+
+       # Check if all values to be written are sane
+       config_check
+
+       log DEBUG "Writing configuration file ${config_file}."
+
+       mkdir -p $(dirname ${config_file}) 2>/dev/null
+       > ${config_file}
+
+       local param
+       for param in $(listsort $@); do
+               echo "${param}=\"${!param}\"" >> ${config_file}
+       done
+}
+
+function config_print() {
+       local param
+
+       for param in $(listsort $@); do
+               printf "%-16s = %s\n" "${param}" "${!param}"
+       done
+}
+
+function config_check() {
+       # If there is a function defined that is called __check
+       # we call that function
+       [ -n "$(type -t _check)" ] && _check
+}
+
+function config_hostname() {
+       local hostname=${1}
+
+       if [ -n "${hostname}" ]; then
+               echo "${hostname}" > ${CONFIG_HOSTNAME}
+       else
+               echo "$(<${CONFIG_HOSTNAME})"
+       fi
+}
+
+function config_set() {
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       *=*)
+                               log INFO "Setting configuration option '${1}'".                 
+                               eval ${1}
+                               ;;
+                       *)
+                               warning "Invalid parameter given: ${1}"
+                               ;;
+               esac
+               shift
+       done
+}
+
+function network_config_read() {
+       # Save state of DEBUG and restore it later.
+       local debug=${DEBUG}
+
+       config_read ${CONFIG_FILE}
+
+       if [ -n "${debug}" ]; then
+               DEBUG=${debug}
+       fi
+}
+
+function network_config_write() {
+       config_write ${CONFIG_FILE} ${CONFIG_FILE_PARAMS}
+}
+
+function network_config_print() {
+       config_print ${CONFIG_FILE_PARAMS}
+}
+
+function firewall_config_read() {
+       config_read ${FIREWALL_CONFIG_FILE}
+}
+
+function firewall_config_write() {
+       config_write ${FIREWALL_CONFIG_FILE} \
+               ${FIREWALL_CONFIG_PARAMS}
+}
+
+function firewall_config_print() {
+       config_print ${FIREWALL_CONFIG_PARAMS}
+}
index 2c550b9fec3f3c424ddb6867c56b78cd0a17a3d3..b2ff868d19233cd356790b174708d5cab77dfcef 100644 (file)
@@ -90,4 +90,10 @@ PORT_PATTERN_WIRELESS="wN"
 # in which the iptables ruleset will be generated.
 IPTABLES_TMPDIR=
 
+FIREWALL_CONFIG_DIR="/etc/firewall"
+FIREWALL_CONFIG_FILE="${FIREWALL_CONFIG_DIR}/settings"
+FIREWALL_CONFIG_PORTFW="${FIREWALL_CONFIG_DIR}/portfw"
+
+FIREWALL_CONFIG_PARAMS=""
+
 FIREWALL_LOG_FACILITY="syslog"
index 8032a3386058bb01591a76be13bce06e64e3cd50..f8fe70af41d513ef651fdf5c9b74fbd97a400402 100644 (file)
@@ -116,3 +116,42 @@ function firewall_connection_tracking() {
        iptables -A OUTPUT  -j CONNTRACK
        iptables -A FORWARD -j CONNTRACK
 }
+
+function firewall_import_portfw() {
+       local zone=${1}
+       shift
+
+       local protocol="ipv6"
+       local chain="filter"
+
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --chain=*)
+                               chain=$(cli_get_val ${1})
+                               ;;
+                       --protocol=*)
+                               protocol=$(cli_get_val ${1})
+                               ;;
+               esac
+       done
+
+       assert isoneof protocol ipv4 ipv6
+
+       local allowed_chains="filter"
+       if [ "${protocol}" = "ipv4" ]; then
+               allowed_chains="${allowed_chains} nat"
+       fi
+       assert isoneof chain ${allowed_chains}
+
+       # XXX TODO
+
+       local src dst proto
+       while read src dst proto; do
+               case "${chain}" in
+                       filter)
+                               ;;
+                       nat)
+                               ;;
+               esac
+       done < ${FIREWALL_CONFIG_PORTFW}
+}
index 6aee47d108cf6bbcd1c42351e36d5e4a8963a8a7..694c7a408672ad2770026a5c0c04b6e12a0dfb3a 100644 (file)
@@ -70,95 +70,6 @@ function listlength() {
        echo "${length}"
 }
 
-function config_read() {
-       local config_file=${1}
-
-       log DEBUG "Reading configuration: ${config_file}"
-
-       if [ -e "${config_file}" ]; then
-               . ${config_file}
-               config_check
-       fi
-}
-
-function config_write() {
-       local config_file=${1}
-       shift
-
-       # Check if all values to be written are sane
-       config_check
-
-       log DEBUG "Writing configuration file ${config_file}."
-
-       > ${config_file}
-
-       local param
-       for param in $(listsort $@); do
-               echo "${param}=\"${!param}\"" >> ${config_file}
-       done
-}
-
-function config_print() {
-       local param
-
-       for param in $(listsort $@); do
-               printf "%-16s = %s\n" "${param}" "${!param}"
-       done
-}
-
-function config_check() {
-       # If there is a function defined that is called __check
-       # we call that function
-       [ -n "$(type -t _check)" ] && _check
-}
-
-function config_hostname() {
-       local hostname=${1}
-
-       if [ -n "${hostname}" ]; then
-               echo "${hostname}" > ${CONFIG_HOSTNAME}
-       else
-               echo "$(<${CONFIG_HOSTNAME})"
-       fi
-}
-
-function network_config_set() {
-       while [ $# -gt 0 ]; do
-               case "${1}" in
-                       *=*)
-                               log INFO "Setting configuration option '${1}'".                 
-                               eval ${1}
-                               ;;
-                       *)
-                               warning "Invalid parameter given: ${1}"
-                               ;;
-               esac
-               shift
-       done
-
-       # Write configuration to disk
-       network_config_write
-}
-
-function network_config_read() {
-       # Save state of DEBUG and restore it later.
-       local debug=${DEBUG}
-
-       config_read ${CONFIG_FILE}
-
-       if [ -n "${debug}" ]; then
-               DEBUG=${debug}
-       fi
-}
-
-function network_config_write() {
-       config_write ${CONFIG_FILE} ${CONFIG_FILE_PARAMS}
-}
-
-function network_config_print() {
-       config_print ${CONFIG_FILE_PARAMS}
-}
-
 # Speedup function to avoid a call of the basename binary
 function basename() {
        echo "${1##*/}"
diff --git a/network b/network
index 54ad808657b0ced0813894489ddcc3d10ea39043..a3b08c6d78b5b613e983d420957bf6968ce8546f 100755 (executable)
--- a/network
+++ b/network
 #                                                                             #
 ###############################################################################
 
-. /lib/network/functions
-
 # Parse the command line
 while [ $# -gt 0 ]; do
        case "${1}" in
                -d|--debug)
                        DEBUG=1
-                       log DEBUG "Enabled debugging mode"
                        ;;
                *)
                        action=${1}
@@ -36,6 +33,8 @@ while [ $# -gt 0 ]; do
        [ -n "${action}" ] && break
 done
 
+. /usr/lib/network/functions
+
 # Process the given action
 case "${action}" in
        init)