first commit

This commit is contained in:
Johan Koke 2021-01-20 20:51:52 +00:00
commit c47160dbe6
6 changed files with 123 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/ovpn/*.ovpn
/data/*
vars

0
README.md Normal file
View File

27
clients.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
clear
. vars
. functions.sh
echo $OVPN_DATA
# Start by listing all clients first
echo " ------------------------ "
docker run --rm -it -v $OVPN_DATA:/etc/openvpn kylemanna/openvpn ovpn_listclients
echo " ------------------------ "
read -p " Enter client name : " client
if [ ! $client = /dev/null ]
then
read -p " Remove or Add? [r/a] : " call
case $call in
[aA])
new_client $client
client_conf $client
;;
[rR])
del_client $client
;;
esac
fi

41
functions.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
function start_OVPN () {
docker stop $appname
docker rm $appname
# run docker container
docker run -v $OVPN_DATA:/etc/openvpn -d \
-p 1194:1194/udp \
--cap-add=NET_ADMIN \
--name=$appname \
kylemanna/openvpn
}
function init_OVPN () {
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$servername
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
}
function new_client() {
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full $1 nopass
}
function del_client () {
read -p " You are about to delete $1, are you sure you want to continue? [y/n] " del
case $del in
[yY])
docker run --rm -it -v $OVPN_DATA:/etc/openvpn kylemanna/openvpn ovpn_revokeclient $1
docker run --rm -it -v $OVPN_DATA:/etc/openvpn kylemanna/openvpn ovpn_revokeclient $1 remove
;;
[nN])
exit
;;
esac
}
function client_conf () {
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient $1 > $(pwd)/ovpn/$1.ovpn
}

48
init.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# lets import the constant variables
. vars
. functions.sh
clear
# make sure the variables.sh file has been created and updated
if [ ! -f $(pwd)/vars ]
then
mv $(pwd)/vars.sample $(pwd)/vars
nano vars
fi
# check if this is a clean install
if [ -f $OVPN_DATA/crl.pem ]
then
# The OpenVPN data has been installed already
read -p " Do you want to re-initialize the OpenVPN data and certificates? [y/n/] : " reinit
case $reinit in
[yY])
init_OVPN
;;
[nN])
read -p " Do you want to restart the container for OpenVPN? [y/n] : " restart
case $restart in
[yY])
start_OVPN
;;
[nN])
read -p " Enter a username for a new client to be configured: " user
if [ ! $user = /dev/null ]
then
echo " ... Creating new config for $user"
new_client $user
else
echo " No username entered"
fi
;;
esac
;;
esac
else
# initialize the OVPN instance
mkdir data
init_OVPN
fi

4
vars.sample Normal file
View File

@ -0,0 +1,4 @@
#!/bin/bash
appname="OpenVPN"
OVPN_DATA="$(pwd)/data"
servername="vpn.server.com"