Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Hotspot

Sat Jul 16, 2022 4:54 pm

Greetings friends, I have the following script
:local time 6m
:local atime [ /system clock get time ]
:local adate [ /system clock get date ]
:local comment "$user  conect: $adate  at: $atime"
:local thours ($atime + $time)
: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 user=\"$user\"] \r\
  \n/system scheduler remove [find name=\"$user\"] \r\
  \n\r\
" start-date=$adate start-time=$thours]
the problem is that when there is a electric cut of several hours, the script does not delete the user, because the date has already passed, I don't know if you understand me. Thanks for your help.


EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot

Sat Jul 16, 2022 6:06 pm

I see that you have constant problems with dates.

For me, you are really wrong in approaching things...

And again, if the user register @2022/07/16 23:54:00 and you give it 6min,
is never disconnected because the scheduler on your script is scheduled @2022/07/16 00:00:00... in the past....
You just don't want to understand that anything you do that adds time to the system time is always a wrong thing???

Instead of creating a scheduled event for each user,
use a recursive scheduled event that checks users every minute.

Do not put the date and time in the comment, but use the script I already made for you to get the current Unix Epoch, adding the seconds that the user can navigate.

Whenever the event fires, it reads the current Epoch and closes all users who have an expired Epoch...

So even if everything remains stationary for hours, when it starts again all the expired ones are canceled.


But if you like soluction that do not are really a soluction, but a walktrough for a wrong idea,
set the repat time to 1 min, when routerboard is restarted, it executes all scripts because are scheduled for be repeated after a given date.
But the problem from 23:54:00 to 23:59:59 still exist...
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Sat Jul 16, 2022 6:25 pm

Thanks for your answer friend Rextended, but I didn't understand anything.





EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot

Sat Jul 16, 2022 6:28 pm

[...] I didn't understand anything [...]
:shock:
...
...
...


from
" start-date=$adate start-time=$thours]

to
"  interval=1m start-date=$adate start-time=$thours]
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Sat Jul 16, 2022 6:45 pm

I already did it friend REX, but you say that I'm wrong in this way, what would be the correct way to avoid problems?




EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot

Sat Jul 16, 2022 6:47 pm

 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Sat Jul 16, 2022 7:04 pm

This is what I don't understand, how do I scropt using this?:

(Do not put the date and time in the comment, but use the script I already made for you to get the current Unix Epoch, adding the seconds that the user can navigate.

Whenever the event fires, it reads the current Epoch and closes all users who have an expired Epoch...

So even if everything remains stationary for hours, when it starts again all the expired ones are canceled.)



EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot

Sat Jul 16, 2022 7:14 pm

Ok, I can write something, but not today, if you do not find a solution, monday I have time to write and test the script
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Sat Jul 16, 2022 7:24 pm

Sure friend REX, anyway here I have the script that you made for me days ago

:local file "firtsstartup.txt"
:local intGoff [:tonum [/system clock get gmt-offset]]
:if ($intGoff > 86400) do={:set intGoff ((4294967296 - $intGoff) * -1)}
:local epochNow (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=now" as-value output=user])->"data")
:local upTime [/system resource get uptime]
:local wPos   [:find $upTime "w" -1]
:local dPos   [:find $upTime "d" -1]
:local utLen  [:len $upTime]
:local utSec  [:pick $upTime ($utLen - 2) $utLen]
:local utMin  [:pick $upTime ($utLen - 5) ($utLen - 3)]
:local utHou  [:pick $upTime ($utLen - 8) ($utLen - 6)]
:local utDay  0
:local utWee  0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set utWee [:pick $upTime 0 $wPos] }
:local totUtSec ($utSec + (60 * $utMin) + (60 * 60 * $utHou) + (60 * 60 * 24 * $utDay) + (60 * 60 * 24 * 7 * $utWee))
:local epochStart ($epochNow - $totUtSec + $intGoff)
:local datetimeStart (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=$epochStart" as-value output=user])->"data")
:set datetimeStart [:pick $datetimeStart 1 ([:len $datetimeStart] - 1)]
:local year   [:pick $datetimeStart 0 4]
:local month  [:pick $datetimeStart 5 7]
:local day    [:pick $datetimeStart 8 10]
:local hms    [:pick $datetimeStart 11 19]
:local mhours [:tonum [:pick $hms 0 2]]
:local minsec [:pick $hms 2 8]
:local msymbl "AM"
:if ($mhours > 11) do={:set msymbl "PM"}
:set mhours ($mhours % 12)
:if ($mhours = 0) do={:set mhours 12}
:if ($mhours < 10) do={:set mhours "0$mhours"}
:local date "$day/$month/$year"
:local time "$mhours$minsec $msymbl"
:local started "****************************\r\n FIRTSSTARTUP: $date\r\n     AT: $time\r\n****************************"
/file
:if ([:len [find where name=$file]] = 0) do={print file=$file; :delay 5; set $file contents=""}
set $file contents=$started


EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot

Mon Jul 18, 2022 2:14 am

You can schedule simply this, every 10 minutes (I hope 6min are just for test...)
viewtopic.php?t=187680#p945876

when you create a user, simply add $epoch + <wanted time on seconds> on comment.
for example 6 minutes are (6 × 60) = 360 seconds:
/ip hotspot user
:if ([get $user comment]="") do={
    :local epoch (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=now" as-value output=user])->"data")
    :set   epoch ($epoch + 360)
    set $user comment=$epoch
}
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Mon Jul 18, 2022 4:01 am

ok REX, great job, but what about this part of the script
[/system scheduler add name=$user on-event="/ip hotspot user remove \"$user\" \r\
  \n/ip hotspot cookie remove [find user=\"$user\"] \r\
  \n/system scheduler remove [find name=\"$user\"] \r\
  \n\r\
" start-date=$adate start-time=$thours] 

to eliminate that user when the 360 ​​seconds have elapsed, and it does not matter that the equipment does not have electricity for many hours and when it starts again, it automatically eliminates it?





EL DOMCITO:
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot

Mon Jul 18, 2022 12:03 pm

only if you add interval=1m as already wroten
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Mon Jul 18, 2022 1:40 pm

and then how do we delete the expired user.....
I don't understand anything.




EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot

Mon Jul 18, 2022 1:43 pm

This is not good, it is I who do not understand...
Are they scripts that you post in the forum, and you don't know how they work?
the problem is that when there is a electric cut of several hours, the script does not delete the user, because the date has already passed,
and I have already provided the soluction, add interval=1m to the scheduled event.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Mon Jul 18, 2022 4:39 pm

I speak Spanish and my English is through the google translator, this is one of the user profiles that I use:
add address-pool=dhcp_pool0 keepalive-timeout=5s mac-cookie-timeout=4h name=2hours on-login=":local time 4h\r\
    \n:local atime [ /system clock get time ]\r\
    \n:local adate [ /system clock get date ]\r\
    \n:local comment \"\$user  conected: \$adate  at: \$atime\"\r\
    \n:local thours (\$atime + \$time)\r\
    \n:if ([ /ip hotspot user get \$user comment ]=\"\") do={ [ /ip hotspot user set \$user comment=\$comment ] }\r\
    \n\r\
    \n[/system scheduler add name=\$user on-event=\"/ip hotspot user remove \\\"\$user\\\" \\r\\\r\
    \n  \\n/ip hotspot cookie remove [find user=\\\"\$user\\\"] \\r\\\r\
    \n  \\n/system scheduler remove [find name=\\\"\$user\\\"] \\r\\\r\
    \n  \\n\\r\\\r\
    \n\"  start-date=\$adate start-time=\$thours]\r\
    \n" rate-limit=256k/1024k
users have 4 hours to spend the internet that I give them, which is two hours, since as you can see in the user profile I use what I call "PAUSED TIME", that is to say that if for some reason the user decides to leave the hotspot area before his 2 hours are up, when he returns I have the time in which he left, the problem is that if for some reason reason there is an electrc cut and it lasts more than four hours the user will lose his time, so he has not spent his 2 hours, I don't know if you understand me.


EL DONCITO.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Tue Jul 19, 2022 5:23 pm

Friends, how do I write the mac cookie timeout in interval of this script and also in interval:


add address-pool=dhcp_pool0 keepalive-timeout=5s mac-cookie-timeout=4h name=2hours on-login=":local time [/ip hotspot user profile get mac-cookie-timeput]
]\r\
    \n:local atime [ /system clock get time ]\r\
    \n:local adate [ /system clock get date ]\r\
    \n:local comment \"\$user  conected: \$adate  at: \$atime\"\r\
    \n:local thours (\$atime + \$time)\r\
    \n:if ([ /ip hotspot user get \$user comment ]=\"\") do={ [ /ip hotspot user set \$user comment=\$comment ] }\r\
    \n\r\
    \n[/system scheduler add name=\$user on-event=\"/ip hotspot user remove \\\"\$user\\\" \\r\\\r\
    \n  \\n/ip hotspot cookie remove [find user=\\\"\$user\\\"] \\r\\\r\
    \n  \\n/system scheduler remove [find name=\\\"\$user\\\"] \\r\\\r\
    \n  \\n\\r\\\r\
    \n\"  interval=[/ip hotspot user profile get mac-cookie-timeput] start-date=\$adate start-time=\$thours]\r\
    \n" rate-limit=256k/1024k


EL DONCITO.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Tue Jul 19, 2022 10:52 pm

Can anybody help me?







EL DONCITO.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot

Thu Jul 21, 2022 2:09 am

I need your help please.
 interval=[/ip hotspot user profile find  mac-cookie-timeout name=""]


EL DONCITO.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot  [SOLVED]

Fri Jul 22, 2022 12:11 am

I already solved

[/ip hotspot user profile get [find where name="XXXX"] mac-cookie-timeout]

Thanks everyone for your help.


EL DONCITO.

Who is online

Users browsing this forum: No registered users and 25 guests