Community discussions

MikroTik App
 
User avatar
Halfeez92
Member Candidate
Member Candidate
Topic Author
Posts: 101
Joined: Tue Oct 30, 2012 12:58 pm
Location: 127.0.0.1
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: 231
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? :)
 
User avatar
Halfeez92
Member Candidate
Member Candidate
Topic Author
Posts: 101
Joined: Tue Oct 30, 2012 12:58 pm
Location: 127.0.0.1
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: 231
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 :).
 
shion
just joined
Posts: 2
Joined: Mon Dec 05, 2016 9:33 am

Re: VPN connected script

Sat Jul 24, 2021 6:08 pm

Restore topic)
How can I use variables as "remote-address" "local-address"?
As I see RouterOS can't understand variables with "-" , "_" , etc
 
SP5WIT
just joined
Posts: 1
Joined: Tue Aug 21, 2018 10:11 am

Re: VPN connected script

Mon Aug 16, 2021 10:57 am

How can I use variables as "remote-address" "local-address"?
As I see RouterOS can't understand variables with "-" , "_" , etc
You have to add ", so in code use variables like $"local-address" $"caller-id"

Best regards,
Wit

Who is online

Users browsing this forum: Bing [Bot] and 14 guests