Hi,
i used some scripts to get an email if a client connect or disconnect from OpenVPN and so i would share my experience with you:
first of all you need 2 scripts which will be stored in /jffs/scripts:
connect script: /jffs/scripts/up.sh
Fill in 'your SMTP address', 'email sender address', 'from name' and 'recipient mail address' with your own credentials.
disconnect script: /jffs/scripts/down.sh
Fill in 'your SMTP address', 'email sender address', 'from name' and 'recipient mail address' with your own credentials.
Access your ROUTER via Browser and move to VPN --> VPN Details and add custom configuration:
and click apply.
Each time a client connects/disconnects, it will send an email notification to the recipient. You can play around with the message formatting in up.sh or down.sh if you want to customize the email.
The provided formatting will send a message looking like this:
connect:
disconnect:
Hope you find this useful. If anyone needs help they are welcome.
regards Boy1979
i used some scripts to get an email if a client connect or disconnect from OpenVPN and so i would share my experience with you:
first of all you need 2 scripts which will be stored in /jffs/scripts:
connect script: /jffs/scripts/up.sh
Code:
#!/bin/sh
SMTP="<[B][COLOR="Red"]your SMTP address[/COLOR][/B]>"
FROM="<[B][COLOR="red"]email sender address[/COLOR][/B]>"
FROMNAME="<[B][COLOR="red"]from name[/COLOR][/B]>"
TO="<[B][COLOR="red"]recipient mail address[/COLOR][/B]>"
time=$(echo $(date +"%c"))
message=$(echo "<b>Connected Since:</b> $time<br><b>Real Address:</b> \
$untrusted_ip<br><b>Virtual Address:</b> \
$ifconfig_pool_remote_ip<br><b>Common \
Name:</b> $common_name<br><br>")
echo "Subject: OpenVPN CONNECT" >/tmp/mail.txt
echo "Content-Type: text/html" >>/tmp/mail.txt
echo "From: $FROMNAME<$FROM>" >>/tmp/mail.txt
echo "Date: `date -R`" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "Client has connected to <b>OpenVPN</b>:<br>" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "<br>$message" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "---<br>" >>/tmp/mail.txt
echo "Your friendly router." >>/tmp/mail.txt
echo "<br>" >>/tmp/mail.txt
/usr/sbin/sendmail -S"$SMTP" -f"$FROM" $TO < /tmp/mail.txt
rm /tmp/mail.txt
Fill in 'your SMTP address', 'email sender address', 'from name' and 'recipient mail address' with your own credentials.
disconnect script: /jffs/scripts/down.sh
Code:
#!/bin/sh
SMTP="<[B][COLOR="Red"]your SMTP address[/COLOR][/B]>"
FROM="<[B][COLOR="red"]email sender address[/COLOR][/B]>"
FROMNAME="<[B][COLOR="red"]from name[/COLOR][/B]>"
TO="<[B][COLOR="red"]recipient mail address[/COLOR][/B]>"
time=$(echo $(date +"%c"))
message=$(echo "<b>Connected Since:</b> $time<br><b>Real Address:</b> \
$untrusted_ip<br><b>Virtual Address:</b> \
$ifconfig_pool_remote_ip<br><b>Common \
Name:</b> $common_name<br><br>")
echo "Subject: OpenVPN DISCONNECT" >/tmp/mail.txt
echo "Content-Type: text/html" >>/tmp/mail.txt
echo "From: $FROMNAME<$FROM>" >>/tmp/mail.txt
echo "Date: `date -R`" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "Client has disconnected from <b>OpenVPN</b>:<br>" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "<br>$message" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "---<br>" >>/tmp/mail.txt
echo "Your friendly router." >>/tmp/mail.txt
echo "<br>" >>/tmp/mail.txt
/usr/sbin/sendmail -S"$SMTP" -f"$FROM" $TO < /tmp/mail.txt
rm /tmp/mail.txt
Fill in 'your SMTP address', 'email sender address', 'from name' and 'recipient mail address' with your own credentials.
Access your ROUTER via Browser and move to VPN --> VPN Details and add custom configuration:
Code:
script-security 2
--client-connect /jffs/scripts/up.sh
--client-disconnect /jffs/scripts/down.sh
and click apply.
Each time a client connects/disconnects, it will send an email notification to the recipient. You can play around with the message formatting in up.sh or down.sh if you want to customize the email.
The provided formatting will send a message looking like this:
connect:
Code:
Client has connected to [B]OpenVPN[/B]:
[B]Connected since:[/B] Wed Nov 19 19:53:20 2014
[B]Real Address:[/B] 192.168.1.102
[B]Virtual Address:[/B] 10.8.0.4
[B]Common Name:[/B] client5
---
Your friendly router.
disconnect:
Code:
Client has disconnected from [B]OpenVPN[/B]:
[B]Connected since:[/B] Wed Nov 19 19:53:20 2014
[B]Real Address:[/B] 192.168.1.102
[B]Virtual Address:[/B] 10.8.0.4
[B]Common Name:[/B] client5
---
Your friendly router.
Hope you find this useful. If anyone needs help they are welcome.
regards Boy1979
Last edited: