Community discussions

 
User avatar
BrasDeutscher
newbie
Topic Author
Posts: 43
Joined: Sat Sep 03, 2016 12:31 am
Location: Brazil

EXPIRE Hotspot User Advanced Script

Sun Sep 11, 2016 6:34 pm

## The script sets the date in the user comment ##
## Place it in system Script and enter the path to the script in user-profile by-login ##
## Written by: BrasDeutscher,PA,Brazil ##
## Testet under RouterOS v6.37rc32 ##
{
## !!-- Enter the Hotspot server name here --!! ##
:global sv "1"


## !!-- PLEASE CHANGE NOTHING MORE BELOW --!! ##
:global mac
:global ip
:global date [/system clock get date ]
:global action1
:global action2
:foreach i in=[/ip hotspot active find where server="$sv" ] do={
:set mac [/ip hotspot active get $i mac-address ];
:set ip [/ip hotspot active get $i address ];
:if ([/ip hotspot user get [find where ! default ! dynamic ! disabled \
mac-address=$mac ] comment ] = "" ) do={
:set action1 [/ip hotspot user set [find where mac-address=$mac ] comment="$date" ];
:set action2 [/ip hotspot active remove [find where mac-address=$mac ]];
:log warning ("New Login Mac:$mac mit der IP:$ip");
}}}




## Expire Hotspot User ##
## One script for all profiles ##
## Written by: BrasDeutscher,PA,Brazil ##
## Testet under RouterOS v6.37rc32 ##
## Enter the script in the Schedule and let it run with daily Interval ##
{
:global today
:global prof
:global offset
{
:local date [/system clock get date ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $date 4 6 ]
:local monthtxt [ :pick $date 0 3 ]
:local year [ :pick $date 7 11 ]
:local months ( [ :find $montharray $monthtxt] )
:for nodays from=0 to=[ :tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
}
:set days ( $days + $year * 365)
:set today $days
}
#########!!-- In this line, the script check's two user profiles --!!############
:foreach i in=[/ip hotspot user find where ! default ! disabled ( profile=1 || profile=2 ) ] do={

:if ([ :find [/ip hotspot user get $i comment ]] = 0 ) do={
:local Date [/ip hotspot user get $i comment ]
:local montharray ( "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec" )
:local monthdays ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
:local days [ :pick $Date 4 6 ]
:local monthtxt [:pick $Date 0 3 ]
:local year [ :pick $Date 7 11 ]
:local months ([:find $montharray $monthtxt ] )
:for nodays from=0 to=[ :tonum $months] do={
:set days ( $days + [ :pick $monthdays $nodays ] )
:set prof [/ip hotspot user get $i profile ]
### !!-- Offset mean's the validity period of the Hotspot user e.g. 31 days etc. --!! ###
:if ("$prof" = 1 ) do={
:set offset 31
} else={
:if ("$prof" = 2 ) do={
:set offset 90
}}}
:set days ($days + $year * 365)
:if (($days + $offset) < $today ) do={
:local name [/ip hotspot user get $i name]
:local mac [/ip hotspot user get $i mac-address]
:log warning "EXPIRE PROFIL $prof : Offset:$offset : Hotspot Nutzer:$name Mac:$mac 1. Login am $Date"
[/ip hotspot user remove $i ]
[/ip hotspot active remove [ find where mac-address=$mac ]]
}}}}
 
kraker
Frequent Visitor
Frequent Visitor
Posts: 88
Joined: Thu Aug 02, 2012 9:34 am

Re: EXPIRE Hotspot User Advanced Script

Fri Jul 07, 2017 3:59 pm

hi;

it's working on terminal but not in script.Is there any sensitive point in script? 6.39.2 and 6.38.7 v.

also we have more than 2 user profile ,can you give us some example with day offset?

thank you..
 
Mlodys
just joined
Posts: 1
Joined: Tue Apr 26, 2011 7:01 pm

Re: EXPIRE Hotspot User Advanced Script

Tue Jul 24, 2018 10:31 pm

hello,
can someone help me to run this script?
i cant figure why it wont write comment

.
.
:if ([/ip hotspot user get [find where ! default ! dynamic ! disabled \
mac-address=$mac ] comment ] = "" ) do={
:set action1 [/ip hotspot user set [find where mac-address=$mac ] comment="$date" ];
:set action2 [/ip hotspot active remove [find where mac-address=$mac ]];
:log warning ("New Login Mac:$mac mit der IP:$ip");

i thing there must be mistake.
Sorry about my bad english

Who is online

Users browsing this forum: No registered users and 13 guests