]> git.ipfire.org Git - people/ms/network.git/commitdiff
vpn: Move VPN CLI functions into separate files
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Jul 2017 13:24:12 +0000 (15:24 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 30 Jul 2017 13:24:12 +0000 (15:24 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/functions/functions.ipsec
src/functions/functions.vpn [new file with mode: 0644]
src/functions/functions.vpn-security-policies
src/network

index 2ce7a34140f80ea81e6a6dbbbcec2f144965a1b7..1cdf0ea30a6659e3729d3cee071cf3bd5cacf90f 100644 (file)
@@ -161,6 +161,7 @@ dist_network_SCRIPTS = \
        src/functions/functions.util \
        src/functions/functions.vlan \
        src/functions/functions.ipsec \
+       src/functions/functions.vpn \
        src/functions/functions.vpn-security-policies \
        src/functions/functions.wireless \
        src/functions/functions.wpa_supplicant \
index 5e9327b39f5d08c91d6522f0928f045319e7774e..11e2e9aee6f414d78ff6ae059637a367337426a7 100644 (file)
@@ -33,6 +33,58 @@ IPSEC_DEFAULT_SECURITY_POLICY="system"
 IPSEC_VALID_MODES="gre-transport tunnel vti"
 IPSEC_VALID_AUTH_MODES="PSK psk"
 
+cli_ipsec() {
+       local action=${1}
+       shift 1
+
+       case "${action}" in
+               connection)
+                       cli_ipsec_connection $@
+                       ;;
+               *)
+                       error "Unrecognized argument: ${action}"
+                       exit ${EXIT_ERROR}
+                       ;;
+       esac
+}
+
+cli_ipsec_connection() {
+       if ipsec_connection_exists ${1}; then
+               local connection=${1}
+               local key=${2}
+               key=${key//-/_}
+               shift 2
+
+               case "${key}" in
+                       authentication|inactivity-timout|local|mode|peer|remote|security-policy)
+                               ipsec_connection_${key} ${connection} $@
+                               ;;
+                       *)
+                               error "Unrecognized argument: ${key}"
+                               exit ${EXIT_ERROR}
+                               ;;
+               esac
+       else
+               local action=${1}
+               shift
+
+               case "${action}" in
+                       new)
+                               ipsec_connection_new $@
+                               ;;
+                       destroy)
+                               ipsec_connection_destroy $@
+                               ;;
+                       ""|*)
+                               if [ -n "${action}" ]; then
+                                       error "Unrecognized argument: '${action}'"
+                               fi
+                               exit ${EXIT_ERROR}
+                               ;;
+               esac
+       fi
+}
+
 # This function writes all values to a via ${connection} specificated VPN IPsec configuration file
 ipsec_connection_write_config() {
        assert [ $# -ge 1 ]
diff --git a/src/functions/functions.vpn b/src/functions/functions.vpn
new file mode 100644 (file)
index 0000000..6d62f17
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2017  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/>.       #
+#                                                                             #
+###############################################################################
+
+cli_vpn() {
+       local action=${1}
+       shift 1
+
+       case "${action}" in
+               ipsec)
+                       cli_ipsec $@
+                       ;;
+               security-policies)
+                       cli_vpn_security_policies $@
+                       ;;
+               *)
+                       error "Unrecognized argument: ${action}"
+                       exit ${EXIT_ERROR}
+                       ;;
+       esac
+}
index 79a217aab8098502c3fb54fccebb827727b1e6b8..8bb9065b382a744baf376bfc131ce93419ee9742 100644 (file)
@@ -252,6 +252,51 @@ declare -A GROUP_TYPE_TO_STRONGSWAN=(
        [CURVE25519]="curve25519"
 )
 
+cli_vpn_security_policies() {
+       local action
+       local security_policy
+
+       if vpn_security_policy_exists ${1}; then
+               security_policy=${1}
+               key=${2}
+               shift 2
+
+               case "${key}" in
+                       cipher|compression|integrity|lifetime|pfs|show)
+                               vpn_security_policies_${key} ${security_policy} $@
+                               ;;
+                       group-type)
+                               vpn_security_policies_group_type ${security_policy} $@
+                               ;;
+                       key-exchange)
+                               vpn_security_policies_key_exchange ${security_policy} $@
+                               ;;
+                       *)
+                               error "Unrecognized argument: ${key}"
+                               exit ${EXIT_ERROR}
+                               ;;
+               esac
+       else
+               action=${1}
+               shift
+
+               case "${action}" in
+                       new)
+                               vpn_security_policies_new $@
+                               ;;
+                       destroy)
+                               vpn_security_policies_destroy $@
+                               ;;
+                       ""|*)
+                               if [ -n "${action}" ]; then
+                                       error "Unrecognized argument: '${action}'"
+                               fi
+                               exit ${EXIT_ERROR}
+                               ;;
+               esac
+       fi
+}
+
 # This functions checks if a policy is readonly
 # returns true when yes and false when no
 vpn_security_policies_check_readonly() {
index 65bfcdc608abc1af7b26bf14f86d2e090f19e82c..288f4beddb9d89095a39e8f0a417651aae055578 100644 (file)
@@ -1334,123 +1334,6 @@ cli_raw() {
        exit ${EXIT_OK}
 }
 
-cli_vpn() {
-       local action=${1}
-       shift 1
-
-       case "${action}" in
-               security-policies)
-                       cli_vpn_security_policies $@
-                       ;;
-               ipsec)
-                       cli_vpn_ipsec $@
-                       ;;
-               *)
-                       error "Unrecognized argument: ${action}"
-                       exit ${EXIT_ERROR}
-                       ;;
-       esac
-}
-
-cli_vpn_ipsec() {
-       local action=${1}
-       shift 1
-
-       case "${action}" in
-               connection)
-                       cli_vpn_ipsec_connection $@
-                       ;;
-               *)
-                       error "Unrecognized argument: ${action}"
-                       exit ${EXIT_ERROR}
-                       ;;
-       esac
-}
-
-cli_vpn_ipsec_connection() {
-       if ipsec_connection_exists ${1}; then
-               local connection=${1}
-               local key=${2}
-               key=${key//-/_}
-               shift 2
-
-               case "${key}" in
-                       authentication|inactivity-timout|local|mode|peer|remote|security-policy)
-                               ipsec_connection_${key} ${connection} $@
-                               ;;
-                       *)
-                               error "Unrecognized argument: ${key}"
-                               exit ${EXIT_ERROR}
-                               ;;
-               esac
-       else
-               local action=${1}
-               shift
-
-               case "${action}" in
-                       new)
-                               ipsec_connection_new $@
-                               ;;
-                       destroy)
-                               ipsec_connection_destroy $@
-                               ;;
-                       ""|*)
-                               if [ -n "${action}" ]; then
-                                       error "Unrecognized argument: '${action}'"
-                               fi
-                               exit ${EXIT_ERROR}
-                               ;;
-               esac
-       fi
-}
-
-cli_vpn_security_policies() {
-
-       local action
-       local security_policy
-
-       if vpn_security_policy_exists ${1}; then
-
-               security_policy=${1}
-               key=${2}
-               shift 2
-
-               case "${key}" in
-                       cipher|compression|integrity|lifetime|pfs|show)
-                               vpn_security_policies_${key} ${security_policy} $@
-                               ;;
-                       group-type)
-                               vpn_security_policies_group_type ${security_policy} $@
-                               ;;
-                       key-exchange)
-                               vpn_security_policies_key_exchange ${security_policy} $@
-                               ;;
-                       *)
-                               error "Unrecognized argument: ${key}"
-                               exit ${EXIT_ERROR}
-                               ;;
-               esac
-       else
-               action=${1}
-               shift
-
-               case "${action}" in
-                       new)
-                               vpn_security_policies_new $@
-                               ;;
-                       destroy)
-                               vpn_security_policies_destroy $@
-                               ;;
-                       ""|*)
-                               if [ -n "${action}" ]; then
-                                       error "Unrecognized argument: '${action}'"
-                               fi
-                               exit ${EXIT_ERROR}
-                               ;;
-               esac
-       fi
-}
-
 # Process the given action
 case "${action}" in
        init)