]> git.ipfire.org Git - people/stevee/network.git/blame - functions.aiccu
aiccu: Rename variables for credentials to username and password.
[people/stevee/network.git] / functions.aiccu
CommitLineData
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
22function aiccu_start() {
23 local device=${1}
671fa0bd
MT
24 assert isset device
25
bfebc08f
SS
26 # Tell systemd to start aiccu on this device.
27 service_start "aiccu@${device}.service"
671fa0bd
MT
28 local ret=$?
29
bfebc08f
SS
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}
671fa0bd
MT
38}
39
40function aiccu_stop() {
41 local device=${1}
671fa0bd
MT
42 assert isset device
43
bfebc08f
SS
44 # Tell sysemd to stop aiccu on this device.
45 service_stop "aiccu@${device}.service"
671fa0bd
MT
46}
47
bfebc08f 48function aiccu_write_config() {
671fa0bd 49 local device=${1}
bfebc08f
SS
50 local file=${2}
51 shift 2
671fa0bd
MT
52
53 assert isset device
bfebc08f 54 assert isset file
671fa0bd 55
5bb66bbe
SS
56 local username
57 local password
671fa0bd
MT
58 local server
59 local protocol="tic"
60 local tunnel_id
20ecb48c 61 local require_tls
671fa0bd
MT
62
63 while [ $# -gt 0 ]; do
64 case "${1}" in
5bb66bbe
SS
65 --username=*)
66 username="$(cli_get_val ${1})"
671fa0bd 67 ;;
5bb66bbe
SS
68 --password=*)
69 password="$(cli_get_val ${1})"
671fa0bd
MT
70 ;;
71 --server=*)
20ecb48c 72 server="$(cli_get_val ${1})"
671fa0bd
MT
73 ;;
74 --protocol=*)
20ecb48c 75 protocol="$(cli_get_val ${1})"
671fa0bd
MT
76 ;;
77 --tunnel-id=*)
20ecb48c
SS
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
671fa0bd
MT
88 ;;
89 esac
90 shift
91 done
92
5bb66bbe
SS
93 assert isset username
94 assert isset password
671fa0bd
MT
95 assert isset server
96 assert isset protocol
20ecb48c 97 assert isset require_tls
671fa0bd
MT
98 assert isoneof protocol tic tsp l2tp
99
bfebc08f
SS
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"
5bb66bbe
SS
116 print "username ${username}"
117 print "password ${password}"
bfebc08f
SS
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}
671fa0bd
MT
132
133 return ${EXIT_OK}
134}