Skip to content

Instantly share code, notes, and snippets.

@cpswan
Last active February 5, 2016 16:01
Show Gist options
  • Save cpswan/01132a75b55e8c9244bd to your computer and use it in GitHub Desktop.
Save cpswan/01132a75b55e8c9244bd to your computer and use it in GitHub Desktop.
Get a VNS3 clientpack
#!/bin/bash
command -v openvpn >/dev/null 2>&1 || { echo "OpenVPN should be installed first. Aborting." >&2; exit 1; }
command -v curl >/dev/null 2>&1 || { echo "This script requires curl, but it's not installed. Aborting." >&2; exit 1; }
MGRIP=10.0.0.10
APIPW=pa55Word
NAME=$1
if [ -e /etc/openvpn/clientpack.ip ]; then
echo "VNS3 Clientpack already installed"
else
CLIENTPACKJSON=`curl -k -X POST -u api:$APIPW -H 'Content-Type: application/json' https://$MGRIP:8000/api/clientpacks/next_available`
CLIENTPACKNAME=$(echo $CLIENTPACKJSON | grep -Po '"name":.*?[^\\]"' | awk '{split($0,a,":"); print a[2]}')
CLIENTPACKIP=$(echo $CLIENTPACKJSON | grep -Po '"overlay_ipaddress":.*?[^\\]"' | awk '{split($0,a,":"); print a[2]}')
curl -k -X GET -H 'Content-Type: application/json' -d '{"name":'$CLIENTPACKNAME',"format":"conf"}' https://api:$APIPW@$MGRIP:8000/api/clientpack -o /etc/openvpn/"${CLIENTPACKNAME//\"}".conf
if [ "$NAME" != "" ]; then
curl -k -X POST -u api:$APIPW -d '{"key":"name", "value":"'$NAME'"}' -H 'Content-Type: application/json' https://$MGRIP:8000/api/clientpack/${CLIENTPACKNAME//\"}
fi
echo "${CLIENTPACKIP//\"}" > /etc/openvpn/clientpack.ip
service openvpn stop && service openvpn start
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment