]>
Commit | Line | Data |
---|---|---|
1848564d MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | function hook_exists() { | |
23 | local hook=${1} | |
24 | ||
25 | [ -d "${HOOKS_DIR}/${hook}" ] && return ${EXIT_ERROR} | |
26 | ||
27 | [ -x "${HOOKS_DIR}/${hook}" ] | |
28 | } | |
29 | ||
30 | function hook_port_exists() { | |
31 | local hook_zone=${1} | |
32 | local hook_port=${2} | |
33 | ||
34 | hook_exists ${hook_zone} || return ${EXIT_ERROR} | |
35 | ||
36 | [ -x "${HOOKS_DIR}/${hook_zone}.ports/${hook_port}" ] | |
37 | } | |
38 | ||
39 | function hook_config_exists() { | |
40 | local hook_zone=${1} | |
41 | local hook_config=${2} | |
42 | ||
43 | hook_exists ${hook_zone} || return ${EXIT_ERROR} | |
44 | ||
45 | [ -x "${HOOKS_DIR}/${hook_zone}.configs/${hook_config}" ] | |
46 | } | |
47 | ||
48 | function hook_has_ports() { | |
49 | local hook=${1} | |
50 | ||
51 | [ -d "${HOOKS_DIR}/${hook}.ports" ] | |
52 | } | |
53 | ||
54 | function hook_has_configs() { | |
55 | local hook=${1} | |
56 | ||
57 | [ -d "${HOOKS_DIR}/${hook}.configs" ] | |
58 | } | |
59 | ||
60 | function hook_exec() { | |
61 | local hook=${1} | |
62 | shift | |
63 | ||
64 | if ! hook_exists ${hook}; then | |
65 | error "Hook '${hook}' does not exist." | |
66 | return ${EXIT_ERROR} | |
67 | fi | |
68 | ||
69 | ${SHELL} ${HOOKS_DIR}/${hook} $@ | |
70 | } | |
71 | ||
72 | function hook_port_exec() { | |
73 | local hook_zone=${1} | |
74 | local hook_port=${2} | |
75 | shift 2 | |
76 | ||
77 | if ! hook_exists ${hook_zone}; then | |
78 | error "Hook '${hook_zone}' does not exist." | |
79 | return ${EXIT_ERROR} | |
80 | fi | |
81 | ||
82 | if ! hook_port_exists ${hook_zone} ${hook_port}; then | |
83 | error "Port hook '${hook_port}' does not exist." | |
84 | return ${EXIT_ERROR} | |
85 | fi | |
86 | ||
87 | ${SHELL} ${HOOKS_DIR}/${hook_zone}.ports/${hook_port} $@ | |
88 | } | |
89 | ||
90 | function hook_config_exec() { | |
91 | local hook_zone=${1} | |
92 | local hook_config=${2} | |
93 | shift 2 | |
94 | ||
95 | if ! hook_exists ${hook_zone}; then | |
96 | error "Hook '${hook_zone}' does not exist." | |
97 | return ${EXIT_ERROR} | |
98 | fi | |
99 | ||
100 | if ! hook_config_exists ${hook_zone} ${hook_config}; then | |
101 | error "Config hook '${hook_config}' does not exist." | |
102 | return ${EXIT_ERROR} | |
103 | fi | |
104 | ||
105 | ${SHELL} ${HOOKS_DIR}/${hook_zone}.configs/${hook_config} $@ | |
106 | } | |
107 | ||
108 | function hooks_get_all() { | |
109 | local type=${1} | |
110 | ||
111 | local hook | |
112 | for hook in ${HOOKS_DIR}/*; do | |
113 | hook=$(basename ${hook}) | |
114 | hook_exists ${hook} && echo "${hook}" | |
115 | done | sort | |
116 | } | |
117 | ||
118 | function hook_ports_get_all() { | |
119 | local hook=${1} | |
120 | ||
121 | if ! hook_exists ${hook}; then | |
122 | error "Hook '${hook}' does not exist." | |
123 | return ${EXIT_ERROR} | |
124 | fi | |
125 | ||
126 | local hook | |
127 | for hook in ${HOOKS_DIR}/${zone}.ports/*; do | |
128 | hook=$(basename ${hook}) | |
129 | ## XXX executeable? | |
130 | echo "${hook}" | |
131 | done | sort | |
132 | } | |
133 | ||
134 | function config_get_hook() { | |
135 | local config=${1} | |
136 | ||
137 | ( | |
138 | . ${config} | |
139 | echo "${HOOK}" | |
140 | ) | |
141 | } |