New Mikrotik user. Please help with hotspot script.

Hi all, I run a small WISP in Cyprus and i am taking the plunge to switch over to RouterOS. Please bear with me, i have a programming background but RouterOS script is new to me. From what i have read on the forum, User Manager is not a very reliable option. What i want to do is, when a user logs in with a voucher code, the user is added to a mac bypass list and a date comment is added to the entry. This bit i have done by borrowing some code found on the forum.

:foreach user in=[/ip hotspot active find] do={
:local date [ /system clock get date ]
:local ip [/ip hotspot active get $user address];
:local mac [/ip hotspot active get $user mac-address];
:local username [/ip hotspot active get $user user];
:foreach binding in=[/ip hotspot ip-binding find address=$ip] do={
/ip hotspot ip-binding remove $binding;
}
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;
}

What i would like to do is have a scheduled script that runs once per day that removes users and ip bindings that are older than 1 month, in effect giving the user one month internet access without showing the login screen until the month is up. Can anyone here help me with this?

Best regards

Andy Georgiades.

Is there a way i can modify this to remove the ip binding as well as the user?

{
 :local offset 7
 :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 [ :pick $date 0 3 ]
  :local year [ :pick $date 7 11 ]
  :local months ([ :find $montharray $monthtxt]  )
  :for nodays from=0 to=$months do={
   :set days ( $days + [ :pick $monthdays $nodays ] )
  }
  :set days ($days + $year * 365) 
  :set today $days
 }
 
 :foreach i in [ /ip hotspot user find where disabled=no ] 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=$months do={
    :set days ( $days + [ :pick $monthdays $nodays ] )
   }
   :set days ($days + $year * 365)
   :if ( ($days + $offset) < $today ) do={ 
    :local name [/ip hotspot user get $i name]
    :log info "HOTSPOT EXPIRE SCRIPT: Disabling Hotspot user $name first logged in $date"
    [ /ip hotspot user disable $i ]
    [ /ip hotspot active remove [find where user=$user] ]
   }
  }
 }
}

No reply’s? No one willing to help? The learning curve is pretty steep. Can someone at least help me add the mac address as a comment to a user that logs in?

The code below works fine. It disables the user once logged in and puts them in the ip binding list. I just need to add the mac address as a comment to the disabled user so that i can tell which user belongs to an ip binding.

:foreach user in=[/ip hotspot active find] do={
:local date [ /system clock get date ];
:local ip [/ip hotspot active get $user address];
:local mac [/ip hotspot active get $user mac-address];
:local username [/ip hotspot active get $user user];
# help add mac to user comment here
/ip hotspot user disable $username;
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;
}

I managed to do my first script the hard way since no one came forward.

:foreach users in=[/ip hotspot active find] do={
:local date [ /system clock get date ];
:local ip [/ip hotspot active get $users address];
:local mac [/ip hotspot active get $users mac-address];
:local username [/ip hotspot active get $users user];
/ip hotspot user set $username comment=$mac;
/ip hotspot ip-binding add type=bypassed mac-address=$mac address=0.0.0.0 comment=$date;
/ip hotspot user disable $username;
}

Any help on alter the scheduled script i posted in the second post to deleted the ip binding+user every 30 days?