2023-05-01 16:55:45 +03:00
|
|
|
# openvpn-management
|
2023-05-01 11:56:22 +03:00
|
|
|
|
2023-05-01 16:55:45 +03:00
|
|
|
OpenVPN management and monitoring utils.
|
2023-05-01 11:56:22 +03:00
|
|
|
|
2023-07-27 13:53:33 +03:00
|
|
|
* [`ovpn_status`.py](https://git.hmp.today/pavel.muhortov/openvpn-management#ovpn_status-py)
|
2023-05-01 16:55:45 +03:00
|
|
|
* [`ovpn-client-management`.sh](https://git.hmp.today/pavel.muhortov/openvpn-management#ovpn-client-management-sh)
|
2023-05-01 11:56:22 +03:00
|
|
|
|
|
|
|
____
|
|
|
|
|
2023-07-27 13:53:33 +03:00
|
|
|
## `ovpn_status`.py
|
2023-05-01 11:56:22 +03:00
|
|
|
|
|
|
|
**Description:**
|
2023-07-27 13:53:33 +03:00
|
|
|
> OpenVPN server status parser.
|
2023-05-01 11:56:22 +03:00
|
|
|
|
|
|
|
**Dependencies:**
|
|
|
|
>
|
2023-05-01 16:55:45 +03:00
|
|
|
> * privileged rights
|
2023-07-27 13:53:33 +03:00
|
|
|
> * [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
|
|
|
> * Existing `status`, `server`, `ca`, `cert` options in [server.conf](https://openvpn.net/community-resources/reference-manual-for-openvpn-2-5/#options)
|
2023-05-01 11:56:22 +03:00
|
|
|
|
|
|
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
|
|
|
|-----------|--------------|------------------------|---------------|
|
2023-07-27 13:53:33 +03:00
|
|
|
|**[-s, --server_conf]**|path to OpenVPN server configuration file|**REQUIRED**|
|
|
|
|
|**[-f, --filter]**|client names filter by regex|`.*`|
|
|
|
|
|**[-g, --geo]**|check client real ip geo location (may be slow)|`.*`|
|
2023-05-01 11:56:22 +03:00
|
|
|
|
2023-07-27 13:53:33 +03:00
|
|
|
Example usage with Zabbix agent:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# add options to openvpn server config file
|
|
|
|
sudo tee -a /etc/openvpn/server/server.conf > /dev/null <<'EOF'
|
|
|
|
status /var/log/openvpn/openvpn-status.log
|
|
|
|
status-version 2
|
|
|
|
server 10.0.0.0 255.0.0.0
|
|
|
|
ca /etc/openvpn/easy-rsa/pki/ca.crt
|
|
|
|
cert /etc/openvpn/easy-rsa/pki/issued/server.crt
|
|
|
|
EOF
|
|
|
|
sudo systemctl restart openvpn@server
|
|
|
|
```
|
2023-05-01 11:56:22 +03:00
|
|
|
|
|
|
|
```bash
|
2023-05-01 16:55:45 +03:00
|
|
|
# download
|
2023-07-27 13:53:33 +03:00
|
|
|
sudo wget https://git.hmp.today/pavel.muhortov/openvpn-management/raw/branch/master/ovpn_status.py -O /etc/openvpn/server/ovpn_status.py
|
|
|
|
sudo chmod +x /etc/openvpn/server/ovpn_status.py
|
2023-05-01 11:56:22 +03:00
|
|
|
```
|
|
|
|
|
2023-05-01 16:55:45 +03:00
|
|
|
```bash
|
2023-07-27 13:53:33 +03:00
|
|
|
# edit sudoers
|
|
|
|
sudo sh -c "echo '
|
|
|
|
zabbix ALL=(ALL) NOPASSWD:/etc/openvpn/server/ovpn_status.py -s /etc/openvpn/server/server.conf
|
|
|
|
' > /etc/sudoers.d/zabbix_agentd"
|
|
|
|
# check permission
|
|
|
|
sudo -u zabbix sudo /etc/openvpn/server/ovpn_status.py -s /etc/openvpn/server/server.conf
|
2023-05-01 16:55:45 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
2023-07-27 13:53:33 +03:00
|
|
|
# add UserParameter to Zabbix agent
|
|
|
|
sudo sh -c "echo '
|
|
|
|
Timeout=30
|
|
|
|
AllowRoot=0
|
|
|
|
UserParameter=discovery.ovpn, sudo /etc/openvpn/server/ovpn_status.py -s /etc/openvpn/server/server.conf
|
|
|
|
' >> /etc/zabbix/zabbix_agentd.conf"
|
|
|
|
sudo systemctl restart zabbix-agent
|
2023-05-01 16:55:45 +03:00
|
|
|
```
|
|
|
|
|
2023-07-27 13:53:33 +03:00
|
|
|
Download [OpenVPN_by_Zabbix_agent.yaml](https://git.hmp.today/pavel.muhortov/openvpn-management/raw/branch/master/OpenVPN_by_Zabbix_agent.yaml) template
|
|
|
|
Zabbix Server -> Configuration -> Templates -> Import template
|
|
|
|
|
2023-05-01 16:55:45 +03:00
|
|
|
____
|
|
|
|
|
|
|
|
## `ovpn-client-management`.sh
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
> Creating or deleting client config for openvpn and sending config and info to email.
|
|
|
|
|
|
|
|
**Dependencies:**
|
|
|
|
>
|
|
|
|
> * privileged rights
|
|
|
|
> * chpasswd
|
|
|
|
> * [openvpn](https://openvpn.net/) (tested version 2.5.1 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
|
|
|
> * [easy-rsa](https://github.com/OpenVPN/easy-rsa) (tested version 3.0.8 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
|
|
|
> * tar
|
|
|
|
> * [Python 3](https://www.python.org/downloads/) (tested version 3.9.5 on [Debian GNU/Linux 11](http://ftp.debian.org/debian/dists/bullseye/))
|
|
|
|
> * existing [/usr/local/bin/sendmail.py](https://git.hmp.today/pavel.muhortov/utils#sendmail-py)
|
|
|
|
|
|
|
|
| POSITION | PARAMETERS | DESCRIPTION | DEFAULT |
|
|
|
|
|-----------|--------------|------------------------|---------------|
|
|
|
|
| 1 |**add\|del**|add or delete client config|**REQUIRED**|
|
|
|
|
| 2 |**\<username\>**|client username|**REQUIRED**|
|
|
|
|
| 3 |**\<password\>**|client password||
|
|
|
|
| 4 |**[-f]**,**[--force]**|service will restart after username delete||
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# download
|
|
|
|
sudo wget https://git.hmp.today/pavel.muhortov/openvpn-management/raw/branch/master/ovpn-client-management.sh -O /etc/openvpn/server/ovpn-client-management.sh
|
|
|
|
sudo chmod +x /etc/openvpn/server/ovpn-client-management.sh
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# create link
|
|
|
|
ln -s /etc/openvpn/server/ovpn-client-management.sh ./ovpn
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# create client
|
|
|
|
sudo ./ovpn add username password
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# delete client (and restart service for applying changes)
|
|
|
|
sudo ./ovpn del username -f
|
|
|
|
```
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# check journal
|
|
|
|
tail -f /var/log/openvpn/ovpn.log
|
|
|
|
```
|