User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
en:public:openvpn_client_connect_notification [2018/04/30 09:55]
stix created
en:public:openvpn_client_connect_notification [2018/07/19 17:01] (current)
robertguerra
Line 1: Line 1:
 ======OpenVPN - client connect / disconnect notification====== ======OpenVPN - client connect / disconnect notification======
  
-In tutorial, we use function ''​create_notification'',​ which sends the message according to the settings in the administration //Foris//, section //​Maintenance//​+In this updated ​tutorial, which is a result of a discussion in the [[https://​forum.turris.cz/​t/​openvpn-client-notification-connected-disconnected/​7780|Turris Forum]] ​, we use the function ''​create_notification'',​ which sends the message according to the settings in the administration //Foris//, section //​Maintenance//​
  
 <WRAP center important 60%> <WRAP center important 60%>
Line 9: Line 9:
  
 **1)** in file ''/​etc/​config/​openvpn''​ add following lines: **1)** in file ''/​etc/​config/​openvpn''​ add following lines:
 +
 +//If you are using Foris openVPN plugin, add it to the section
 +//config openvpn '​server_turris
 +
 <​code>​ <​code>​
 option script_security '​2'​ option script_security '​2'​
Line 18: Line 22:
 <file bash up.sh> <file bash up.sh>
 #!/bin/bash #!/bin/bash
-time=$(echo ​$(date +"%c"​)) +message="$(echo ​-e "${common_name} ​connected ​     to: ${HOSTNAME} ​\\nRemote: ​ ${untrusted_ip} \\nVirtual: ${ifconfig_pool_remote_ip}")" 
-message=$(echo "​Client has connected to OpenVPN: \n\nConnected Since: $time \nRemote ​IP: $untrusted_ip\nVirtual ​IP: $ifconfig_pool_remote_ip\nClient name: $common_name") +/​usr/​bin/​create_notification -s news "${message}" 
-/​usr/​bin/​create_notification -s news "​$message"​+/​usr/​bin/​notifier 
 +exit 0
 </​file>​ </​file>​
  
Line 26: Line 31:
 <file bash down.sh> <file bash down.sh>
 #!/bin/bash #!/bin/bash
-time=$(echo ​$(date +"%c"​)) +message="$(echo ​-e "${common_name} ​disconnected from: ${HOSTNAME} ​\\nRemote: ​ ${untrusted_ip} \\nVirtual: ${ifconfig_pool_remote_ip}")" 
-message=$(echo "​Client has disconnected from OpenVPN: \n\nConnected Since: $time \nRemote ​IP: $untrusted_ip\nVirtual ​IP: $ifconfig_pool_remote_ip\nClient name: $common_name") +/​usr/​bin/​create_notification -s news "${message}" 
-/​usr/​bin/​create_notification -s news "​$message"​+/​usr/​bin/​notifier 
 +exit 0
 </​file>​ </​file>​
  
-**4)** set permission ​0777 for scripts+**4)** set permission ​0755 for scripts 
 + 
 +''​chmod 0755 /​etc/​openvpn/​up.sh''​ 
 + 
 +''​chmod 0755 /​etc/​openvpn/​down.sh''​ 
 + 
 +**5)** make sure files are backed-up 
 + 
 +If you want to include these extra scripts in the backups of the router, add ///​etc/​openvpn//​ directory to the **/​etc/​config/​backups**. Something like:
  
-''​chmod 0777 /​etc/​openvpn/​up.sh''​ 
  
-''​chmod 0777 /​etc/​openvpn/​down.sh''​+    config generate generate 
 +         list dirs "/​etc/​openvpn"
  
-**5)** restart OpenVPN+**6)** restart OpenVPN
  
 ''/​etc/​init.d/​openvpn restart''​ ''/​etc/​init.d/​openvpn restart''​