-
Notifications
You must be signed in to change notification settings - Fork 0
/
semp_activate_vpn.sh
105 lines (93 loc) · 2.15 KB
/
semp_activate_vpn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# ------------------------------------------------------------------------------
# (c) Copyright by SBB, 2018 - Alle Rechte vorbehalten
#
# @author PEng Team
#
# @purpose
# Create a vpn at solace broker via sempV1
# -------------------------------------------------------------------------
# Defaults
SEMP_API_PATH="http://localhost:8080/SEMP"
SEMP_USER="admin"
SEMP_PASSWORD="admin"
VPN_NAME=""
VPN_STATE="active"
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-a|--api-url)
SEMP_API_PATH="$2"
shift # past argument
shift # past value
;;
-u|--semp-user)
SEMP_USER="$2"
shift # past argument
shift # past value
;;
-p|--semp-password)
SEMP_PASSWORD="$2"
shift # past argument
shift # past value
;;
--name)
VPN_NAME="$2"
shift # past argument
shift # past value
;;
--state)
VPN_STATE="$2" # active|disabled
shift # past argument
shift # past value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# Validate parameter
if [[ "$VPN_NAME" == "" ]]; then
echo "The paramater --name is required. Please specifiy a name for the new vpn"
exit 1
fi
if [[ "$VPN_STATE" != "active" && "$VPN_STATE" != "disabled" ]]; then
echo "The paramater --state is required. Please choose \"active\" or \"disabled\""
exit 1
fi
# Set it active
if [[ "$VPN_STATE" == "active" ]]; then
PAYLOAD=$(cat <<-EndOfMessage
<rpc>
<message-vpn>
<vpn-name>$VPN_NAME</vpn-name>
<no>
<shutdown></shutdown>
</no>
</message-vpn>
</rpc>
EndOfMessage
)
else
PAYLOAD=$(cat <<-EndOfMessage
<rpc>
<message-vpn>
<vpn-name>$VPN_NAME</vpn-name>
<shutdown></shutdown>
</message-vpn>
</rpc>
EndOfMessage
)
fi
RESPONSE=$(curl -sS --user $SEMP_USER:$SEMP_PASSWORD -X POST -H 'Content-Type: text/xml' --data "$PAYLOAD" $SEMP_API_PATH)
if [[ $RESPONSE != *"execute-result code=\"ok\""* ]]; then
echo "Unable to set VPN up"
echo $PAYLOAD
echo $RESPONSE
exit 1
fi
exit 0