I am new to mtik scripting so in advance I`m sorry for my newbie questions.
I made a script that checks the active connections in PPP, and when it detects a connection it sends an email.
foreach i in=[ppp active find ] do={
local name [ppp active get value-name=name $i];
local ipaddr [ppp active get value-name=caller $i];
:log info "Active PPTP connection with username: $name, IP Address of caller: $ipaddr";
/tool e-mail send to="example@gmail.com" tls=yes body="Active PPTP connection with username: $name, IP Address of caller: $ipaddr" subject="PPTP connection";
}
Now my goal is to run this script ONLY when a new connection appears, and it sends one email only.
I thought of scheduling the script to run every minute or so, but then it will send an email everytime with the active connections… which is no good for me.
So I would like to ask for some help on an idea for this, and most likely a bit of coding too.
Now we got a new request that they want to get a mail when someone tries to connect.
On an unsuccessfull connection to fire off a mail. I managed do do that, but I get three mails instead because of the three log inserts:
: waiting for call…
: terminating… - user test.attack authentication failed
: disconnected
Is there a way to filter out only the middle part (: terminating… - user test.attack authentication failed) and send it in mail?
My current added setting is
I have little bit advanced question. I use CAPsMAN. And I wan to receive email when my mobile MAC address is connected to one of my AP’s… (just ti get status, than I am at home). But I don’t want to receive emails when I switch between AP’s.
Additional question, is there any possibility to send API request from my home automation system, to check if now MAC is visible as connected in CAPsMAN?
I just set this up so that I receive emails when a user (dis)connects. Many thanks to Josh since his post was simple and crystal clear!
Even though the action works fine, for some reason the IP I get is not the desired one. To be more specific, once a user logs in, I receive an email with the local IP that was assigned to this connection (192.168.x.x - which is of no use), and when a user disconnects I get a weird query of numbers (eg 451 xxxxxxx xxxxxxx xxxx 5197 - where “x” random numbers) that has nothing to do with the user’s public IP.
Try removing “account” from the log rule topics and see if that gives you the desired data. It may result in more notifications however it should contain the true IP when they connect.
I’s using L2TP, so added this (“l2tp”) entry too but it’s still the same. When connecting I get the local IP, and when disconnecting I get this weird number sequence.
In “ppp profile scripts on the profile your L2TP server is set to use” place the following into the “On Up”:
:local FromEmail "myfromaddress@mydomain.com"
:local ToEmail "mytoaddress@mydomain.com"
:foreach i in=[/ppp active find where uptime <1m] do={
:local Addr [/ppp active get $i caller-id]
/tool e-mail send user="$FromEmail" from="$FromEmail" to="$ToEmail" subject="$[/system identity get name] - New L2TP Connection" body="New L2TP connection from $Addr at $[/system clock get time] $[/system clock get date]";
}
If your tool email is setup you will get an email similar to this when there is a new connection: New L2TP connection from x.x.x.x at 09:28:58 oct/11/2017