Community discussions

 
Halfeez92
newbie
Topic Author
Posts: 36
Joined: Tue Oct 30, 2012 12:58 pm
Contact:

VPN connected script

Tue May 29, 2018 6:34 am

Hi, I want to create a script to notify me if any of the openvpn user is connected and disconnected through telegram api. I have already have the api code but I dont know how to create a code to get information if the user is connected or disconnect. Below is the telegram api code that I have. Only the part to get whether the vpn user is connected or disconnected I dont have. Need help from mikrotik coders out there, many thanks.

# ChatID from telegram that is going to receive reports
:local chat "telegram id";
# API code from Telegram BOT
:local bot "telegram api code";
# Defining message
:local initel "https://api.telegram.org/bot";
:local endtel "&text=";
:local newline "%0D%0A";
:local who "$[/system identity get name]";
:local datetime "$[/system clock get date] $[/system clock get time]";
:local message "User din (Haziruddin) is connected to VPN";

:local messagefinal " $who REPORT$newline $newline $message $newline $newline log date: $datetime \
$newline $newline";

/tool fetch url="$initel$bot/sendMessage\?chat_id=$chat$endtel$messagefinal" keep-result=no;
 
User avatar
dasiu
Trainer
Trainer
Posts: 232
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

Re: VPN connected script

Mon Jun 04, 2018 1:53 pm

In PPP profile you have "on-up" and "on-down" scripts. Cannot you use 2 different scripts? :)
 
Halfeez92
newbie
Topic Author
Posts: 36
Joined: Tue Oct 30, 2012 12:58 pm
Contact:

Re: VPN connected script

Fri Jun 08, 2018 10:21 am

In PPP profile you have "on-up" and "on-down" scripts. Cannot you use 2 different scripts? :)
I am aware of that, but to do that I have to create multiple profiles for each user instead of assigning them to multiple users. If there are any flexible solution, let me know.
 
User avatar
dasiu
Trainer
Trainer
Posts: 232
Joined: Fri Jan 30, 2009 11:41 am
Location: Reading, UK
Contact:

Re: VPN connected script

Fri Jun 08, 2018 10:30 am

I am aware of that, but to do that I have to create multiple profiles for each user instead of assigning them to multiple users. If there are any flexible solution, let me know.
You have 2 options:
1. Create 2 scripts (on-up and on-down) for each user separately
2. Read The ....... Manual :)
on-up (script; Default: ) Execute script on user login-event. These are available variables that are accessible for the event script:
user
local-address
remote-address
caller-id
called-id
interface
on-down (script; Default: ) Execute script on user logging off. See on-up for more details
So - inside the script executed "on-up" you just use the $user variable without declaring it (with :local or :global) before. Your script will know that $user is connected of $user is disconnected. 2 scripts is enough then :).

Who is online

Users browsing this forum: No registered users and 6 guests