Community discussions

MikroTik App
 
marwan001
just joined
Topic Author
Posts: 8
Joined: Tue Dec 15, 2020 7:22 pm

Can anyone help me please. I need to Script to disable mikrotik hotpot user when time is up

Sat Aug 26, 2023 12:43 pm

after i up upgrad RB960PGS to firmware 7.11
The script I used was working but after the upgrad it is not working
I think because the date format changed As shown in the image

# 2023-08-26 12:35:50 by RouterOS 7.11
# software id = 7JS9-I6SJ
#
# model = RB960PGS
# serial number = D52F0E49A6C8
/interface bridge
add name=bridge1
/interface ethernet
set [ find default-name=ether1 ] name=ether1-WAN
/interface lte apn
set [ find default=yes ] ip-type=ipv4 use-network-apn=no
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip hotspot profile
set [ find default=yes ] hotspot-address=192.168.1.1 login-by=\
http-chap,https,http-pap,mac-cookie use-radius=yes
add dns-name=www.a.net hotspot-address=192.168.2.1 html-directory=\
flash/hotspot http-cookie-lifetime=4w2d login-by=\
cookie,http-chap,https,http-pap,mac-cookie name=hsprof2 use-radius=yes
add dns-name=www.a.net hotspot-address=192.168.3.1 html-directory=\
flash/hotspot http-cookie-lifetime=4w2d login-by=\
cookie,http-chap,https,http-pap,mac-cookie name=hsprof3 use-radius=yes
add dns-name=www.a.net hotspot-address=192.168.4.1 html-directory=\
flash/hotspot http-cookie-lifetime=4w2d login-by=\
cookie,http-chap,https,http-pap,mac-cookie name=hsprof4 use-radius=yes
add dns-name=www.a.net hotspot-address=192.168.5.1 html-directory=\
flash/hotspot http-cookie-lifetime=4w2d login-by=\
cookie,http-chap,https,http-pap,mac-cookie name=hsprof5 use-radius=yes
/ip hotspot user profile
set [ find default=yes ] keepalive-timeout=1m mac-cookie-timeout=4w2d
add idle-timeout=15m !keepalive-timeout mac-cookie-timeout=4w2d name=mumpro \
on-login="{:local date [ /system clock get date ];:if ( [ /ip hotspot user\
\_get \$user comment ] = \"\" ) do={[ /ip hotspot user set \$user comment=\
\$date];}}" open-status-page=http-login transparent-proxy=yes
/ip pool
add name=dhcp_pool0 ranges=192.168.1.20-192.168.1.254
add name=dhcp_pool1 ranges=192.168.2.2-192.168.2.254
add name=dhcp_pool2 ranges=192.168.3.2-192.168.3.254
add name=dhcp_pool3 ranges=192.168.4.2-192.168.4.254
add name=dhcp_pool4 ranges=192.168.5.2-192.168.5.254
/ip dhcp-server
add address-pool=dhcp_pool1 interface=ether2 lease-time=10m name=dhcp1
add address-pool=dhcp_pool2 interface=ether3 lease-time=10m name=dhcp2
add address-pool=dhcp_pool3 interface=ether4 lease-time=10m name=dhcp3
add address-pool=dhcp_pool4 interface=ether5 lease-time=10m name=dhcp4
/ip hotspot
add address-pool=dhcp_pool1 disabled=no interface=ether2 name=hs-ether2 \
profile=hsprof2
add address-pool=dhcp_pool2 disabled=no interface=ether3 name=hs-ether3 \
profile=hsprof3
add address-pool=dhcp_pool3 disabled=no interface=ether4 name=hs-ether4 \
profile=hsprof4
add address-pool=dhcp_pool4 disabled=no interface=ether5 name=hs-ether5 \
profile=hsprof5
/queue type
add kind=pcq name="1M uploade" pcq-limit=1000000KiB pcq-rate=1M \
pcq-total-limit=1024KiB
add kind=pcq name="10M download" pcq-limit=10000000KiB pcq-rate=10M \
pcq-total-limit=10240KiB
/ip neighbor discovery-settings
set discover-interface-list=!dynamic
/ip settings
set max-neighbor-entries=8192
/ipv6 settings
set disable-ipv6=yes max-neighbor-entries=8192
/interface ovpn-server server
set auth=sha1,md5
/ip address
add address=192.168.2.1/24 interface=ether2 network=192.168.2.0
add address=192.168.3.1/24 interface=ether3 network=192.168.3.0
add address=192.168.4.1/24 interface=ether4 network=192.168.4.0
add address=192.168.5.1/24 interface=ether5 network=192.168.5.0
/ip dhcp-client
add interface=ether1-WAN
/ip dhcp-server network
add address=192.168.1.0/24 gateway=192.168.1.1
add address=192.168.2.0/24 dns-server=192.168.2.1 gateway=192.168.2.1
add address=192.168.3.0/24 dns-server=192.168.3.1 gateway=192.168.3.1
add address=192.168.4.0/24 dns-server=192.168.4.1 gateway=192.168.4.1
add address=192.168.5.0/24 dns-server=192.168.5.1 gateway=192.168.5.1
/ip dns
set servers=8.8.8.8
/ip firewall filter
add action=passthrough chain=unused-hs-chain comment=\
"place hotspot rules here" disabled=yes
/ip firewall nat
add action=passthrough chain=unused-hs-chain comment=\
"place hotspot rules here" disabled=yes
add action=masquerade chain=srcnat out-interface=ether1-WAN
add action=masquerade chain=srcnat comment="masquerade hotspot network" \
src-address=192.168.2.0/24
add action=masquerade chain=srcnat comment="masquerade hotspot network" \
src-address=192.168.3.0/24
add action=masquerade chain=srcnat comment="masquerade hotspot network" \
src-address=192.168.4.0/24
add action=masquerade chain=srcnat comment="masquerade hotspot network" \
src-address=192.168.5.0/24
/ip hotspot user
add name=Mar@0556
add comment=2023-07-26 email=5@0_5.ptd limit-uptime=5d name=0557 profile=\
mumpro
add comment=aug/10/2023 email=5@0_5.ptd limit-uptime=5d name=055571737 \
profile=mumpro
add email=5@0_5.ptd limit-uptime=5d name=055337073 profile=mumpro
add email=5@0_5.ptd limit-uptime=5d name=055376002 profile=mumpro
add email=5@0_5.ptd limit-uptime=5d name=055578471 profile=mumpro
add email=5@0_5.ptd limit-uptime=5d name=055174381 profile=mumpro
add email=5@0_5.ptd limit-uptime=5d name=055229176 profile=mumpro
add email=5@0_5.ptd limit-uptime=5d name=055743753 profile=mumpro
add email=10@0_10.ptd limit-uptime=1w3d name=010194993 profile=mumpro
add email=10@0_10.ptd limit-uptime=1w3d name=010486397 profile=mumpro
/ip service
set telnet disabled=yes
set ftp disabled=yes
set ssh disabled=yes
set api port=8725
set api-ssl port=8726
/radius
add address=192.168.10.2 service=ppp,hotspot
/radius incoming
set accept=yes
/routing bfd configuration
add disabled=no
/system clock
set time-zone-name=Asia/Riyadh
/system note
set show-at-login=no
/system scheduler
add interval=6h name=ex_dis_new on-event="/system script run ex_dis_user_new" \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-time=startup
add interval=1d name="system reboor" on-event="/system reboot" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=2022-10-25 start-time=19:00:00
add interval=1d1h name=expire_users_sched on-event="{:global today;{:local dat\
e [ /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 ye\
ar [ :pick \$date 7 11 ];:local months ([ :find \$montharray \$monthtxt]);\
:for nodays from=0 to=\$months do={:set days ( \$days + [ :pick \$monthday\
s \$nodays ] )};:set days (\$days + \$year * 365);:set today \$days;};:for\
each i in [ /ip hotspot user find where disabled=no ] do={:if ([ :find [ /\
ip hotspot user get \$i comment ] ] = 0 && [ :find [ /ip hotspot user get \
\$i email ] ] = 0) do={:local date [ /ip hotspot user get \$i comment ];:l\
ocal oldemail [ /ip hotspot user get \$i email ];:local atmark [ :find \$o\
ldemail \"@\" ];:local dotmark [ :find \$oldemail \".\" ];:if ( \$atmark >\
= 0 && \$dotmark >= 0 ) do={:local validity [ :pick \$oldemail 0 \$atmark]\
;:local rest [ :pick \$oldemail (\$atmark + 1) [ :len \$oldemail] ];:if ( \
[:tonum \$validity] != \"\" ) do={:if ( [:tonum \$validity] != \"0\" ) do=\
{: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 ];:l\
ocal monthtxt [ :pick \$date 0 3 ];:local year [ :pick \$date 7 11 ];:loca\
l months ( [ :find \$montharray \$monthtxt ] );:for nodays from=0 to=\$mon\
ths do={:set days ( \$days + [ :pick \$monthdays \$nodays ] )};:set days (\
\$days + \$year * 365);:if ( (\$days + \$validity) < \$today ) do={ :local\
\_name [/ip hotspot user get \$i name];:log info \"HOTSPOT VALITITY EXPIRE\
: Disabling Hotspot user \$name first logged in \$date\";[ /ip hotspot use\
r disable \$i ];[ /ip hotspot active remove [find where user=\$user] ];}}}\
}}}}" policy=read,write start-date=2022-12-26 start-time=00:04:00
add interval=50m name=ex_dis on-event="/system script run ex_dis_user" \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=2022-12-27 start-time=05:41:30
/system script
add dont-require-permissions=no name=ex_dis_user_new owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="{\
:global today;{: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 [ :pic\
k \$date 0 3 ];:local year [ :pick \$date 7 11 ];:local months ([ :find \$\
montharray \$monthtxt]);:for nodays from=0 to=\$months do={:set days ( \$d\
ays + [ :pick \$monthdays \$nodays ] )};:set days (\$days + \$year * 365);\
:set today \$days;};:foreach i in [ /ip hotspot user find where disabled=n\
o ] do={:if ([ :find [ /ip hotspot user get \$i comment ] ] = 0 && [ :find\
\_[ /ip hotspot user get \$i email ] ] = 0) do={:local datee [ /ip hotspot\
\_user get \$i comment ];:local mums [ :pick \$datee 0 4 ]; :if ( \$mums =\
\_\"mums\" ) do={ :local date [ :pick \$datee 5 16 ];:local oldemail [ /ip\
\_hotspot user get \$i email ];:local atmark [ :find \$oldemail \"@\" ];:l\
ocal dotmark [ :find \$oldemail \".\" ];:if ( \$atmark >= 0 && \$dotmark >\
= 0 ) do={:local validity [ :pick \$oldemail 0 \$atmark];:local rest [ :pi\
ck \$oldemail (\$atmark + 1) [ :len \$oldemail] ];:if ( [:tonum \$validity\
] != \"\" ) do={:if ( [:tonum \$validity] != \"0\" ) do={: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 ( [ :fi\
nd \$montharray \$monthtxt ] );:for nodays from=0 to=\$months do={:set day\
s ( \$days + [ :pick \$monthdays \$nodays ] )};:set days (\$days + \$year \
* 365);:if ( (\$days + \$validity) < \$today ) do={ :local name [/ip hotsp\
ot user get \$i name];:log info \"HOTSPOT VALITITY EXPIRE: Disabling Hotsp\
ot user \$name first logged in \$date\";[ /ip hotspot user disable \$i ];}\
}}}}}}}"
/tool netwatch
add disabled=no down-script=\
"/ip hotspot profile set html-directory=hotspot numbers=3" host=\
192.168.4.1 http-codes="" test-script="" type=simple up-script=\
"/ip hotspot profile set html-directory=hotspot numbers=3"
add disabled=no down-script=\
"/ip hotspot profile set html-directory=hotspot numbers=3" host=\
192.168.3.1 http-codes="" test-script="" type=simple up-script=\
"/ip hotspot profile set html-directory=hotspot numbers=3"
add disabled=no down-script=\
"/ip hotspot profile set html-directory=hotspot numbers=5" host=\
192.168.5.1 http-codes="" test-script="" type=simple up-script=\
"/ip hotspot profile set html-directory=hotspot numbers=5"
add disabled=no down-script=\
"/ip hotspot profile set html-directory=hotspot numbers=2" host=\
192.168.2.1 http-codes="" test-script="" type=simple up-script=\
"/ip hotspot profile set html-directory=hotspot numbers=2"

Thank you for your help my friends
You do not have the required permissions to view the files attached to this post.
 
eldoncito2019
Member
Member
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Can anyone help me please. I need to Script to disable mikrotik hotpot user when time is up

Sat Aug 26, 2023 12:49 pm

I use this script in V 6
:local userprofile [ip hotspot user get [find where name="$user"] profile]

:if ([/ip hotspot user get $user comment]="") do={[/ip hotspot user set $user comment=$comment]}

[/system scheduler add name=$user on-event="/ip hotspot user remove \"$user\" \r\
\n/ip hotspot cookie remove [find where user=\"$user\"] \r\
\n/system scheduler remove [find where name=\"$user\"] \r\
\n\r\
" interval= [/ip hotspot user profile get [find where name="$userprofile"] mac-cookie-timeout]]
 
marwan001
just joined
Topic Author
Posts: 8
Joined: Tue Dec 15, 2020 7:22 pm

Re: Can anyone help me please. I need to Script to disable mikrotik hotpot user when time is up

Sat Aug 26, 2023 1:24 pm

Do use it here
You do not have the required permissions to view the files attached to this post.

Who is online

Users browsing this forum: No registered users and 5 guests