##########
# Input: file name
:local fn $1
#:local fn "text.txt"
:local content [/file get $fn contents]
:local datalen [:len $content]
:local fi 0
:local idx 0
:local res [:toarray ""]
#:put $datalen
do {
:local cr [:find $content "\n" $fi]
if ([:typeof $cr] = "nil") do={
:set cr $datalen
}
# :put "fi: $fi, cr: $cr, idx: $idx"
:local line [:pick $content $fi $cr]
# :put $line
:set ($res->$idx) $line
:set fi ($cr + 1)
:set idx ($idx + 1)
} while ($fi <= $datalen)
:return $res
:local file2array [:parse [/system script get func_file2array source]]; local lines [$file2array text.txt]; :foreach i in=$lines do={ :put $i }
########## func_date2days - count days from base to given date.
# Input: two dates like "jan/1/2017"
########## uncomment for testing
:local date $1
#:local date "sep/13/2017"
#:put $date
# Base MUST BE lower of any given date. Mikrotik counts from jan/01/1970.
#correct only for years>1918
:local base 1970
########################################
:local mdays {31;28;31;30;31;30;31;31;30;31;30;31}
:local months {"jan"=1;"feb"=2;"mar"=3;"apr"=4;"may"=5;"jun"=6;"jul"=7;"aug"=8;"sep"=9;"oct"=10;"nov"=11;"dec"=12}
#date
:local dd [:tonum [:pick $date 4 6]]
:local yy [:tonum [:pick $date 7 11]]
:local mm [:pick $date 0 3]
:set mm ($months->$mm)
#0. We have dd/mm/yy
:local res 0
#1. Move to 01/mm/yy
:set res ($res+$dd-1)
#2. Move to 01/01/yy
:while ($mm>1) do={
:set mm ($mm-1)
:local dm [:pick $mdays ($mm-1)]
:if ($mm=2 && (($yy&3=0 && $yy/100*100 != $yy) || $yy/400*400=$yy) ) do={ :set dm 29 }
:set res ($res+$dm)
}
#3. Move to 01/01/1900
:while ($yy>$base) do={
:set yy ($yy-1)
:set res ($res+365)
:if ( ( ($yy&3=0) && ($yy/100*100 != $yy)) || $yy/400*400=$yy ) do={
:set res ($res+1)
}
}
:return $res
########## func_days2date - convert days from base to date string
# Input: days like 18762 (may/15/2021)
########## uncomment for testing
:local days $1
#:local days 789
#:put $days
#days starts from 1
:set days ($days + 1)
# Base MUST BE lower of any given date. Mikrotik counts from jan/01/1970.
#correct only for years>1918
:local base 1970
########################################
:local mdays {31;28;31;30;31;30;31;31;30;31;30;31}
:local months {1="jan";2="feb";3="mar";4="apr";5="may";6="jun";7="jul";8="aug";9="sep";10="oct";11="nov";12="dec"}
#date
:local yy $base
:local mm 0
# base year is not leap
:local daydiff 365
:local isleap false
#1. Move to 01/01/yy
:while ($days > $daydiff) do={
:set days ($days - $daydiff)
:set yy ($yy + 1)
:if ( ( ($yy & 3 = 0) && ($yy/100*100 != $yy)) || $yy/400*400=$yy ) do={
:set daydiff 366
:set isleap true
# :put "adjust: $yy, days: $days"
} else={
:set daydiff 365
:set isleap false
}
# :put "yy: $yy, days: $days"
}
#2. Adjust feb 29 if leap year
#:put "mmm: $mm, days: $days, isleap: $isleap"
:if ($isleap) do={
# :put "adjust month days"
:set ($mdays->1) 29
}
#3. Move to 01/mm/yy
:while ($days > $mdays->$mm) do={
# :put ($mdays->$mm)
:set days ($days-($mdays->$mm))
:set mm ($mm + 1)
# :put "mm: $mm, days: $days"
}
:local month [:tostr ($mm + 1)]
:set month ($months->$month)
:if ($days < 10) do={ :set days ("0".(:tostr $days)) } else={ :set days (:tostr $days) }
:local res "$month/$days/$yy"
#:put $res
:return $res
:local date2days [:parse [/system script get func_date2days source]]; :local today "may/12/2023"; :local days [$date2days $today]; :put $days;
:local days2date [:parse [/system script get func_days2date source]]; :put [$days2date ($days-1)]
/ip dhcp-server lease add address=1.2.3.4 mac-address=112233445566
Важно понимать, что мы настроили только доступ к самому устройству через оба wan интерфейса, а не работу через обоих провайдеров клиентов локальной сети, если mikrotik выступает в качестве шлюза