]>
Commit | Line | Data |
---|---|---|
671fa0bd MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
20ecb48c | 5 | # Copyright (C) 2013 IPFire Network Development Team # |
671fa0bd MT |
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 | ||
671fa0bd MT |
22 | function aiccu_config_dir() { |
23 | local device=${1} | |
24 | ||
25 | echo "${RUN_DIR}/aiccu/${device}" | |
26 | } | |
27 | ||
28 | function aiccu_start() { | |
29 | local device=${1} | |
30 | shift | |
31 | ||
32 | assert isset device | |
33 | ||
34 | local config_dir=$(aiccu_config_dir ${device}) | |
35 | mkdir -p ${config_dir} | |
36 | ||
37 | local config_file=${config_dir}/config | |
38 | aiccu_configure ${device} $@ > ${config_file} | |
39 | ||
40 | aiccu start ${config_file} &>/dev/null | |
41 | local ret=$? | |
42 | ||
43 | case "${ret}" in | |
44 | 0) | |
45 | log DEBUG "Aiccu was successfully started for '${device}'." | |
46 | return ${EXIT_OK} | |
47 | ;; | |
48 | *) | |
49 | error_log "Could not start aiccu properly for '${device}'." | |
50 | ||
51 | error_log "Configuration file dump:" | |
52 | local line | |
53 | while read line; do | |
54 | error_log " ${line}" | |
55 | done < ${config_file} | |
56 | ||
57 | return ${EXIT_ERROR} | |
58 | ;; | |
59 | esac | |
60 | } | |
61 | ||
62 | function aiccu_stop() { | |
63 | local device=${1} | |
64 | ||
65 | assert isset device | |
66 | ||
67 | aiccu stop $(aiccu_config_dir ${device})/config | |
68 | ||
69 | rm -rf $(aiccu_config_dir ${device}) | |
70 | } | |
71 | ||
72 | function aiccu_configure() { | |
73 | local device=${1} | |
74 | ||
75 | assert isset device | |
76 | ||
77 | local user | |
78 | local secret | |
79 | local server | |
80 | local protocol="tic" | |
81 | local tunnel_id | |
20ecb48c | 82 | local require_tls |
671fa0bd MT |
83 | |
84 | while [ $# -gt 0 ]; do | |
85 | case "${1}" in | |
86 | --user=*) | |
20ecb48c | 87 | user="$(cli_get_val ${1})" |
671fa0bd MT |
88 | ;; |
89 | --secret=*) | |
20ecb48c | 90 | secret="$(cli_get_val ${1})" |
671fa0bd MT |
91 | ;; |
92 | --server=*) | |
20ecb48c | 93 | server="$(cli_get_val ${1})" |
671fa0bd MT |
94 | ;; |
95 | --protocol=*) | |
20ecb48c | 96 | protocol="$(cli_get_val ${1})" |
671fa0bd MT |
97 | ;; |
98 | --tunnel-id=*) | |
20ecb48c SS |
99 | tunnel_id="$(cli_get_val ${1})" |
100 | ;; | |
101 | --require-tls=*) | |
102 | require_tls="$(cli_get_val ${1})" | |
103 | ||
104 | if enabled val; then | |
105 | require_tls="true" | |
106 | else | |
107 | require_tls="false" | |
108 | fi | |
671fa0bd MT |
109 | ;; |
110 | esac | |
111 | shift | |
112 | done | |
113 | ||
114 | assert isset user | |
115 | assert isset secret | |
116 | assert isset server | |
117 | assert isset protocol | |
20ecb48c | 118 | assert isset require_tls |
671fa0bd MT |
119 | assert isoneof protocol tic tsp l2tp |
120 | ||
121 | cat <<EOF | |
122 | ## AICCU configuration for ${zone} | |
123 | ||
124 | username ${user} | |
125 | password ${secret} | |
126 | ||
127 | server ${server} | |
128 | protocol ${protocol} | |
129 | ||
130 | $(isset tunnel_id && echo "tunnel_id ${tunnel_id}") | |
131 | ||
132 | ipv6_interface ${device} | |
133 | ||
134 | verbose true | |
135 | daemonize true | |
136 | automatic true | |
137 | ||
20ecb48c SS |
138 | requiretls ${require_tls} |
139 | ||
671fa0bd MT |
140 | pidfile $(aiccu_config_dir ${zone})/pid |
141 | ||
142 | #setupscript /tmp/aiccu.sh | |
143 | ||
144 | EOF | |
145 | ||
146 | return ${EXIT_OK} | |
147 | } |