Community discussions

MikroTik App
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Hotspot cookie/active problem

Sun Jul 17, 2022 3:14 am

Hey gys... can someone tell me why this isn't working properly:

Don't mind the EpochTime and Comments - they all working properly.
:foreach i in=[ip hotspot user find where name!=admin and name!=default-trial and ! disabled ] do={
    :global EpochTime;
    :local epoch [$EpochTime];

    :local ts [ip hotspot user get $i comment];
    :local user [ip hotspot user get $i name];

    #:log info message=("DEBUG User: ".$user.", Expires: ".$ts.", Epoch: ".$epoch);

    :if ($ts!="") do={
        :local ts1 [:tonum [ip hotspot user get $i comment]];
        :if ($epoch >= $ts1) do={
            :log info message=("EXPIRED user: ".$user.", Expires: ".$ts1.", Epoch: ".$epoch);
            # Works OK:
            /ip hotspot user set disabled=yes $i;
            
            # PROBLEM - Instead of removing only that user's cookies (if any) - removes all cookies:
            /ip hotspot cookie remove [/ip hotspot cookie find user=$user];
            
            # PROBLEM - Instead of removing only that user's active sessions (if any) - removes all sessions:
            /ip hotspot active remove [/ip hotspot active find user=$user];

        }
    }
}
I don't know if I'm doing this wrong or it's just broken.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 1:47 am

the syntax errors also must be ignored?

I have recently suggested to another user to use epoch on comment... :roll:


/ip hotspot
:foreach i in=[user find where name!="admin" and name!="default-trial" and disabled=no] do={
    :local epoch (([/tool fetch url="https://helloacm.com/api/unix-timestamp-converter/\3Fs=now" as-value output=user])->"data")
    :set   epoch [:pick $epoch 1 ([:len $epoch] - 1)]
    :local ts    [user get $i comment]
    :local user  [user get $i name]
#   :log   info  "DEBUG User: $user, Expires: $ts, Epoch: $epoch"
    :if ($ts!="") do={
        :local ts1 [:tonum $ts]
        :if ($epoch >= $ts1) do={
            :log   info    "EXPIRED user: $user, Expires: $ts1, Epoch: $epoch"
            user   disable $i
            cookie remove  [find where user=$user]
            active remove  [find where user=$user]
        }
    }
}

EDIT: fixed typos
 
eldoncito2019
Member
Member
Posts: 333
Joined: Fri Jun 14, 2019 1:07 pm

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 4:20 am

and where is this placed?


EL DONCITO.
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 10:13 am

Found your typo, now the script is:
/ip hotspot
:foreach i in=[user find where name!="admin" and name!="default-trial" and disabled=no] do={
    :global EpochTime;
    :local epoch [$EpochTime];

    :local ts [user get $i comment];
    :local user [user get $i name];

    :if ($ts!="") do={
        :local ts1 [:tonum $ts];
        :log info "DEBUG User: $user, Expires: $ts1, Epoch: $epoch"

        :if ($epoch >= $ts1) do={
            :log info "EXPIRED user: $user, Expires: $ts1, Epoch: $epoch"
            user disable $i
            cookie remove [find where user=$user]
            active remove [find where user=$user]
        }
    } else={
        :log info "Checked user: $user, Expires: $ts1, Epoch: $epoch"
    }
}
However:
cookie remove  [find where user=$user]
active remove  [find where user=$user]

Still remove all cookies and all active users which is *SUPER* annoying because it gets us nowhere... same thing happens with my script.
So, either this is broken on purpose by Mikrotik to make it supper annoying to manage users without User-Manager (which costs 200$ to use), or we're doing it wrong...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 11:49 am

Found your typo, now the script is:
Thanks, fixed
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 11:54 am

Found your typo, now the script is:
Thanks, fixed
What's not fixed is that cookie/active still removes *all* entries, not just the ones needed.
Any ideas?
Last edited by DoubleDB on Mon Jul 18, 2022 11:54 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 11:54 am

cookie remove  [find where user=$user]
active remove  [find where user=$user]
Still remove all cookies and all active users [...]
It seems absurd to me that they delete everything ... the commands are clear.
I believe it.

Honestly I don't use the hotspot with the users inside the routerboard, but with an external radius and therefore I don't have the possibility to test it.

Can you email support@mikrotik.com about this?
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 12:02 pm

cookie remove  [find where user=$user]
active remove  [find where user=$user]
Still remove all cookies and all active users [...]
It seems absurd to me that they delete everything ... the commands are clear.
I believe it.

Honestly I don't use the hotspot with the users inside the routerboard, but with an external radius and therefore I don't have the possibility to test it.

Can you email support@mikrotik.com about this?
Done, let's see what they'd say. Bug or feature...
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Re: Hotspot cookie/active problem

Mon Jul 18, 2022 9:31 pm

They don't seem to be in a hurry to answer...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot cookie/active problem

Tue Jul 19, 2022 12:01 pm

One day only???
You are too much optimistic...
 
DoubleDB
newbie
Topic Author
Posts: 25
Joined: Thu Feb 20, 2020 12:53 am

Re: Hotspot cookie/active problem

Sun Jul 24, 2022 2:08 am

apparently using user as a variable isn't such a good idea ....
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot cookie/active problem

Sun Jul 24, 2022 2:21 am

Yes... I only realize it now ...
The $variable must do not have the same name as a property of the object.
user is a property of the object...
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Hotspot cookie/active problem

Sun Jul 24, 2022 9:12 am

From the manual

Reserved variable names
All built in RouterOS properties are reserved variables. Variables which will be defined the same as the RouterOS built in properties can cause errors. To avoid such errors, use custom designations.

For example, following script will not work:
{
:local type "ether1"
/interface print where name=$type
} 
But will work with different defined variable:
{
:local customname "ether1"
/interface print where name=$customname
} 
But if you like to use "type", you can use uppercase like this "Type" and it will not be an internal properties:
{
:local Type "ether1"
/interface print where name=$Type
} 
 
kvocha
just joined
Posts: 13
Joined: Sat Apr 01, 2023 9:13 pm

Re: Hotspot cookie/active problem

Tue Aug 22, 2023 8:15 pm

Can anybody explain how to put epoch in comments?
 
kvocha
just joined
Posts: 13
Joined: Sat Apr 01, 2023 9:13 pm

Re: Hotspot cookie/active problem

Tue Aug 22, 2023 9:31 pm

Can anybody explain how to put epoch in comments?
not epoch, timestamp. But also I can't call epoch :)
 
kvocha
just joined
Posts: 13
Joined: Sat Apr 01, 2023 9:13 pm

Re: Hotspot cookie/active problem

Tue Aug 22, 2023 10:24 pm

[admin@MikroTik] > :put [:timestamp]
bad command name timestamp (line 1 column 8)
is it normal?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Hotspot cookie/active problem

Wed Aug 23, 2023 3:35 am

is it normal?
Does it seem normal to you to hijack topics and unnecessarily resurrect old topics?

Can anybody explain how to put epoch in comments?
Don't hijack the topic.
If you're using RouterOS v6 there's no that command.
For v6 there are my scripts, for example.
If you use v7 :timestamp do not give epoch, but a... MikroTik concept of timestamp...
For v7 there are my scripts, again...
 
kvocha
just joined
Posts: 13
Joined: Sat Apr 01, 2023 9:13 pm

Re: Hotspot cookie/active problem

Wed Aug 23, 2023 7:35 am

Thanks for answer!
As I can see this theme isn't closed. Anyway I've created a new one. viewtopic.php?t=198881

Who is online

Users browsing this forum: jaclaz and 20 guests