Community discussions

MikroTik App
 
jose300792
just joined
Topic Author
Posts: 7
Joined: Sat Jan 27, 2024 5:22 am

Adaptation to RouterOS 7.13.3

Sat Feb 03, 2024 2:44 am

Hi guys,

I need you to please help me adapt the following code to OS 7.13.3

:local tminutos 0
:local thoras 0
:local tdias 0
:local atime [ /system clock get time ];
:local adate [ /system clock get date ];
:local temp1 [:pick $adate 0 3];
:local temp2 [:pick $adate 4 6];
:local temp3 [:pick $atime 0 5];
:local folio [/ip hotspot user get $user comment];
:local comentario1 "El Usuario $user Ha Iniciado Session";
:local comentario2 "El Usuario $user Se Eliminara Automáticamente";
:if ([ /ip hotspot user get $user comment ]="") do={ [ /ip hotspot user set $user comment="$comentario1" ]}

:local mesarray ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
:local diaarray ("31","28","31","30","31","30","31","31","30","31","30","31")
:local day [:pick $adate 4 6];
:local monthtxt [:pick $adate 0 3];
:local year [:pick $adate 7 11];
:local months ([:find $mesarray $monthtxt])
:local dia ([:pick $diaarray $months])
:local fhora [:pick $atime 0 2];
:local fminutos [:pick $atime 3 5];
:local fsegundos [:pick $atime 6 9];
:local mayormin (($fminutos+$tminutos)-60)
:local mayorhora (($fhora+$thoras)-24)

:if (($fminutos+$tminutos)>59) do={
:set $thoras ($thoras+1);
:set $fminutos ($mayormin);
} else={
:set $fminutos ($fminutos+$tminutos) ;
}
#si fhoras + thoras(1) es mayor que 23
:if (($fhora+$thoras)>23) do={
#seteo la variable atime por
:set atime ("0".$mayorhora.":".$fminutos.":".fsegundos);
:set $tdias ($tdias+1);
} else={
:set atime (($fhora+$thoras).":".$fminutos.":".fsegundos) ;
}
#si day + tdias es mayo que los dias del mes
:if (($day+$tdias)>$dia) do={
:if ($months=11) do={
:set months 0;
:set year ($year+1);
:set day (($day+$tdias)-$dia);
:local mes ([:pick $mesarray $months]);
:set adate ($mes."/".$day."/".$year);
} else={

:set months ($months+1);
:set day (($day+$tdias)-$dia);
:local mes ([:pick $mesarray $months]);
:set adate ($mes."/".$day."/".$year);
}

} else={

:set day ($day+$tdias);
:local mes ([:pick $mesarray $months]);
:set adate ($mes."/".$day."/".$year);
}

[/system scheduler add interval=1m comment="$comentario2" name=$user on-event="/ip hotspot user disable [find name=$user] \r\
\n/ip hotspot active remove [find user=$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=$atime]

I would be very grateful to you.

Greetings
 
jonah1810
Frequent Visitor
Frequent Visitor
Posts: 98
Joined: Tue Jul 30, 2019 10:19 pm

Re: Adaptation to RouterOS 7.13.3

Sat Feb 03, 2024 3:34 am

Could you explain what the script does? Possibly translate the comments and variables names to English?
 
jose300792
just joined
Topic Author
Posts: 7
Joined: Sat Jan 27, 2024 5:22 am

Re: Adaptation to RouterOS 7.13.3

Sat Feb 03, 2024 8:21 pm

Hi Thanks for answering.

Basically what it does is validate the times established in each case, for example, when a user requests 1 hour of usage time, 1 day or 1 month. The Schedule at the end ensures that when the user logs in it begins to validate that any time set for the user is met and when this happens, it disables the user. Don't worry about the comments

:local comment1 "User $user Has Logged In";
:local comment2 "User $user Will Be Disabled Automatically";
:if ([ /ip hotspot user get $user comment ]="") do={ [ /ip hotspot user set $user comment="$comment1" ]}

[/system scheduler add interval=1m comment="$comment2" name=$user on-event="/ip hotspot user disable [search name=$user] \r\
\n/ip hotspot active delete [search user=$user] \r\
\n/delete hotspot cookie ip [search user=$user] \r\
\n/remove system scheduler [search name=$user] \r\
\n/\r\
" start-date=$ adate start-time=$atime]
 
jose300792
just joined
Topic Author
Posts: 7
Joined: Sat Jan 27, 2024 5:22 am

Re: Adaptation to RouterOS 7.13.3  [SOLVED]

Sun Feb 11, 2024 4:14 am

In case anyone comes here interested in the thread, I leave you the appropriate script:
:local tminutos 1
:local thoras 0 
:local tdias 0
:local atime [ /system clock get time ]
:local adate [ /system clock get date ]
:local task ($atime . "_" . $adate)
:local temp1 [:pick $adate 0 4]
:local temp2 [:pick $adate 5 7]
:local temp3 [:pick $adate 8 10]
:local temp4 [:pick $atime 0 9]
:local temp5 ($temp3."/".$temp2."/".$temp1." - ".$temp4."  Dias: ".$tdias)
:local comentario1 "El usuario $user ha iniciado sesion el: $temp5"
:if ([/ip hotspot user find name="$user"] != "") do={
    :if ([/ip hotspot user get "$user" comment] = "") do={ 
        /ip hotspot user set "$user" comment="$comentario1"
    }
} else={
    :log error "El usuario $user no existe"
    :error "El usuario $user no existe"
}
:local mesarray ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
:local diaarray ("31","28","31","30","31","30","31","31","30","31","30","31")
:local day [:pick $adate 8 10]
:local monthtxt [:pick $adate 5 7]
:local year [:pick $adate 0 4]
:local monthnum (([:find $mesarray $monthtxt]) + 1)
:local months ([:pick $mesarray $monthnum])
:local dia ([:pick $diaarray $monthnum])
:local fhora [:pick $atime 0 2]
:local fminutos [:pick $atime 3 5]
:local fsegundos [:pick $atime 6 9]
:local mayormin (($fminutos+$tminutos)-60)
:local mayorhora (($fhora+$thoras)-24)
:if (($fminutos+$tminutos)>59) do={
    :set thoras ($thoras+1)
    :set fminutos ($mayormin)
} else={
    :set fminutos ($fminutos+$tminutos)
}
:if (($fhora+$thoras)>23) do={
    :set atime ("0".$mayorhora.":".$fminutos.":".fsegundos)
    :set tdias ($tdias+1)
} else={
    :set atime (($fhora+$thoras).":".$fminutos.":".fsegundos)
}
:if (($day+$tdias)>$dia) do={
    :if ($monthnum=11) do={
        :set monthnum 0
        :set year ($year+1)
        :set day (($day+$tdias)-$dia)
        :local mes ([:pick $mesarray $monthnum])
        :set adate ($mes."/".$day."/".$year)
    } else={
        :set monthnum ($monthnum+1)
        :set day (($day+$tdias)-$dia)
        :local mes ([:pick $mesarray $monthnum])
        :set adate ($mes."/".$day."/".$year)
:log info "else monts $adate"
    }
} else={
    :set day ($day+$tdias)
    :local mes ([:pick $mesarray $monthnum])
    :set adate ($mes."/".$day."/".$year)
}
:local comentario2 "El usuario $user se deshabilitara automáticamente el: $adate $atime"
:local comentario3 "Se ha cumplido el tiempo solicitado desde:$temp5 hasta: $adate $atime"

/system scheduler add interval=1s comment="$comentario2" name="$task" on-event="
        /ip hotspot user disable [find name=\"$user\"] \r
        /ip hotspot active remove [find user=\"$user\"] \r
        /ip hotspot cookie remove [find user=\"$user\"] \r
        /ip hotspot user reset-counter [find name=\"$user\"] \r
:if ([/ip hotspot user get [find name=\"$user\"] comment] = \"$comentario1\") do={
            /ip hotspot user set [find name=\"$user\"] comment=\"$comentario3\"
        } \r
        /system scheduler remove [find name=\"$task\"] \r
" start-date=$adate start-time=$atime

Who is online

Users browsing this forum: No registered users and 8 guests