]> git.ipfire.org Git - people/stevee/network.git/blob - functions.aiccu
aiccu: Rename variables for credentials to username and password.
[people/stevee/network.git] / functions.aiccu
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2013 IPFire Network Development Team #
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 aiccu_start() {
23 local device=${1}
24 assert isset device
25
26 # Tell systemd to start aiccu on this device.
27 service_start "aiccu@${device}.service"
28 local ret=$?
29
30 if [ ${ret} -eq ${EXIT_OK} ]; then
31 log DEBUG "aiccu was successfully started on '${device}'."
32 else
33 log ERROR "Could not start aiccu properly on '${device}': ${ret}"
34 return ${EXIT_ERROR}
35 fi
36
37 return ${EXIT_OK}
38 }
39
40 function aiccu_stop() {
41 local device=${1}
42 assert isset device
43
44 # Tell sysemd to stop aiccu on this device.
45 service_stop "aiccu@${device}.service"
46 }
47
48 function aiccu_write_config() {
49 local device=${1}
50 local file=${2}
51 shift 2
52
53 assert isset device
54 assert isset file
55
56 local username
57 local password
58 local server
59 local protocol="tic"
60 local tunnel_id
61 local require_tls
62
63 while [ $# -gt 0 ]; do
64 case "${1}" in
65 --username=*)
66 username="$(cli_get_val ${1})"
67 ;;
68 --password=*)
69 password="$(cli_get_val ${1})"
70 ;;
71 --server=*)
72 server="$(cli_get_val ${1})"
73 ;;
74 --protocol=*)
75 protocol="$(cli_get_val ${1})"
76 ;;
77 --tunnel-id=*)
78 tunnel_id="$(cli_get_val ${1})"
79 ;;
80 --require-tls=*)
81 require_tls="$(cli_get_val ${1})"
82
83 if enabled val; then
84 require_tls="true"
85 else
86 require_tls="false"
87 fi
88 ;;
89 esac
90 shift
91 done
92
93 assert isset username
94 assert isset password
95 assert isset server
96 assert isset protocol
97 assert isset require_tls
98 assert isoneof protocol tic tsp l2tp
99
100 # Write configuration file header.
101 config_header "aiccu configuration file for ${zone}" > ${file}
102
103 (
104 print "# Server info"
105 print "server ${server}"
106 print "protocol ${protocol}"
107 print
108
109 if isset tunnel_id; then
110 print "# Tunnel ID"
111 print "tunnel_id ${tunnel_id}"
112 print
113 fi
114
115 print "# Credentials"
116 print "username ${username}"
117 print "password ${password}"
118 print
119
120 print "ipv6_interface ${device}"
121 print
122
123 print "# Security"
124 print "requiretls ${require_tls}"
125 print
126
127 # Misc.
128 print "verbose true"
129 print "daemonize false"
130 print "automatic true"
131 ) >> ${file}
132
133 return ${EXIT_OK}
134 }