Skip to content

Commit

Permalink
Trim generated .ovpn files and add cli
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Jun 2, 2024
1 parent fae4b3f commit 9c50bb2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 50 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,18 @@ The pihole admin dashboard can only be reached through the vpn under [http://pi.
> This file will be used as base-configuration for each `.ovpn` file! You probably at least want to change the IP address to your public one.
```sh
sudo docker exec openvpn bash /opt/app/bin/genclient.sh <name> <password?>
```

You can find you `.ovpn` file under `/openvpn/clients/<name>.ovpn`, make sure to change the remote ip-address / port / protocol.

#### Generating a list of certificates

This repo contains a script [genclients](genclients.sh) that can be used to generate a list of clients with the current year as suffix:

```sh
./genclients <password> <username1> [<username2> ... <usernameN>]
./clients.sh add <password> <names...>
```

### Revoking `.ovpn` files

```sh
sudo docker exec openvpn bash /opt/app/bin/rmclient.sh <name>
./clients.sh remove <name>
```

Revoked certificates won't kill active connections, you'll have to restart the service if you want the user to immediately disconnect:
> [!WARNING]
> Revoked certificates won't kill active connections, you'll have to restart the service if you want the user to immediately disconnect:
```sh
sudo docker compose restart openvpn
```
Expand Down
41 changes: 41 additions & 0 deletions clients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

SCRIPT_NAME='./clients'

# Function to add clients
add_clients() {
local password=$1
shift
for name in "$@"; do
sudo docker exec openvpn bash /opt/app/bin/genclient.sh "$name" "$password"
done
}

# Function to remove clients
remove_clients() {
for name in "$@"; do
sudo docker exec openvpn bash /opt/app/bin/rmclient.sh "$name"
done
}

# Main script logic
case "$1" in
add)
if [ "$#" -lt 3 ]; then
echo "Usage: $SCRIPT_NAME add <password> <names...>"
exit 1
fi
add_clients "$2" "${@:3}"
;;
remove)
if [ "$#" -lt 2 ]; then
echo "Usage: $SCRIPT_NAME remove <names...>"
exit 1
fi
remove_clients "${@:2}"
;;
*)
echo "Usage: $SCRIPT_NAME {add|remove} <arguments>"
exit 1
;;
esac
35 changes: 0 additions & 35 deletions genclients.sh

This file was deleted.

2 changes: 1 addition & 1 deletion openvpn-docker/bin/genclient.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ echo 'Sync pki directory...'
cp -r ./pki/. /etc/openvpn/pki

echo 'Generate .ovpn file...'
echo "$(cat /etc/openvpn/config/client.conf)
echo "$(grep -vE '^#|^$|^;' /etc/openvpn/config/client.conf)
<ca>
$CA
</ca>
Expand Down
2 changes: 1 addition & 1 deletion openvpn/config/client.conf
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,5 @@ verb 3
# Silence repeating messages
;mute 20

# Use the inlined key
# Specify key direction for tls-auth
key-direction 1
3 changes: 3 additions & 0 deletions openvpn/config/server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,6 @@ explicit-exit-notify 1
# Instruct the OpenVPN server to check the certificate revocation list
# every time a user tries to connect to this instance.
crl-verify pki/crl.pem

# Specify key direction for tls-auth
key-direction 0

0 comments on commit 9c50bb2

Please sign in to comment.