/ip cloud set ddns-enabled=yes
/ip firewall address-list # адрес основной локальной сети за MikroTik, # IP-адреса из которой он раздаёт через DHCP add address=192.168.11.0/24 list="Local subnet" # адрес сети, в которую будет мапиться основная локальная сеть MikroTik # при организации VPN-туннеля с Kerio Control #1 # (мы её определили когда настраивали VPN-интерфейсы на Kerio Control #1, # на закладке "Удалённые сети") add address=192.168.22.0/24 list="Local subnet" # адрес сети, в которую будет мапиться основная локальная сеть MikroTik # при организации VPN-туннеля с Kerio Control #2 # (мы её определили когда настраивали VPN-интерфейсы на Kerio Control #2, # на закладке "Удалённые сети") add address=192.168.33.0/24 list="Local subnet"
add action=accept chain=input comment="VPN Allow IKE" dst-port=500 protocol=udp
/ip firewall filter add action=accept chain=forward comment="VPN In IpSec" dst-address-list=\ "Local subnet" ipsec-policy=in,ipsec src-address=192.168.0.0/16 \ src-address-list="!Local subnet" add action=accept chain=forward comment="VPN Out" dst-address=192.168.0.0/16 \ dst-address-list="!Local subnet" src-address-list="Local subnet"
/ip firewall mangle # перехватываем входящий трафик из головного офиса, # маркируем соединение... add action=mark-connection chain=prerouting comment="VPN In" \ new-connection-mark=VPN_conn_in passthrough=no src-address=192.168.0.0/16 \ src-address-list="!Local subnet" # ...и обратный маршрут add action=mark-routing chain=output comment="VPN In" connection-mark=\ VPN_conn_in new-routing-mark=VPN_route_in passthrough=yes # перехватываем исходящий трафик с MikroTik в головной офис и маркируем соединение. # Этот маркер используется в NAT. add action=mark-connection chain=postrouting comment="VPN Out" dst-address=\ 192.168.0.0/16 dst-address-list="!Local subnet" new-connection-mark=\ VPN_conn_out passthrough=no
/ip firewall nat # мапим весь исходящий с MikroTik в головной офис трафик # по маркеру соединения на адрес сети, # определённый для используемого Kerio-сервера (напоминаю: для Kerio Control #1 - 192.168.22.0/24, для Kerio Control #2 - 192.168.33.0/24) # Внимание! # comment=KerioVpnNatOut используется в скриптах! add action=netmap chain=srcnat comment=KerioVpnNatOut connection-mark=\ VPN_conn_out to-addresses=192.168.22.0/24 # мапим весь входящий на MikroTik из головного офиса трафик # по маркеру соединения на адрес основной локальной сети за MikroTik add action=netmap chain=dstnat comment=KerioVpnNatIn connection-mark=\ VPN_conn_in to-addresses=192.168.11.0/24 # разрешаем MikroTik пинговать Kerio-сервера add action=accept chain=srcnat comment=KerioVpnNatPing out-interface-list=WAN protocol=icmp
/ip ipsec proposal add enc-algorithms=3des name=KerioVPNProposal#01 pfs-group=modp2048
/ip ipsec policy group add name=1 add name=2 add name=3 add name=4
/ip ipsec peer add address=11.11.11.111/32 comment=vs01-i01-01.domain.ru exchange-mode=\ main-l2tp local-address=33.33.33.111 my-id=\ fqdn:mikrotik.sn.mynetname.net policy-template-group=1 profile=\ profile_4 secret=pass1111
/ip ipsec policy add comment=KerioVPNPolicy dst-address=192.168.77.0/24 proposal=KerioVPNProposal#01 \ sa-dst-address=11.11.11.111 sa-src-address=33.33.33.111 src-address=\ 192.168.22.0/24 tunnel=yes
/system script add dont-require-permissions=no name=scriptSetIPSecSADstAddrFromDNS owner=\ admin policy=read,write
:if ([:len [/system script job find script=SetIPSecSADstAddrFromDNS]]>1) do={ :error } :local DnsNameFromComment :local ResolvedIpFromComment :local ResolvedIpWithMaskFromComment :local IpPeerAddr :foreach IpSecPeerCount in=[/ip ipsec peer find] do={ :set DnsNameFromComment [/ip ipsec peer get $IpSecPeerCount comment] :if ($DnsNameFromComment!="") do={ :do { :set ResolvedIpFromComment [:resolve $DnsNameFromComment] :set ResolvedIpWithMaskFromComment ($ResolvedIpFromComment . "/32") :set IpPeerAddr [/ip ipsec peer get $IpSecPeerCount address] :if ($ResolvedIpWithMaskFromComment!=$IpPeerAddr) do={ :log warning ("[SetIPSecSADstAddrFromDNS] В пире на сервер " . DnsNameFromComment . " изменён IP-адрес с " . $IpPeerAddr . " на " . $ResolvedIpFromComment) #:log warning ("[SetIPSecSADstAddrFromDNS] In the peer to the server " . DnsNameFromComment . " changed IP address from " . $IpPeerAddr . " on " . $ResolvedIpFromComment) /ip ipsec peer set $IpSecPeerCount address=$ResolvedIpWithMaskFromComment } } on-error={ :set ResolvedIpFromComment "unknown" :log error ("[SetIPSecSADstAddrFromDNS] Не удалось разрешить имя " . $DnsNameFromComment) #:log error ("[SetIPSecSADstAddrFromDNS] Cant resolve name " . $DnsNameFromComment) } } } :log warning ("[SetIPSecSADstAddrFromDNS] Проверка IP-адресов VPN-серверов произведена") #:log warning ("[SetIPSecSADstAddrFromDNS] The IP-addresses of the VPN-servers are checked")
/ip firewall address-list add address=192.168.22.0/24 list=vs01 add address=192.168.33.0/24 list=vs02
/system script add dont-require-permissions=no name=scriptFunctionsList owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
# Процедура синхронизации IP --> Cloud с внешними DNS-серверами # входящий параметр: # # $start (true/false); # # возвращает "" или "updated" :global subUpdateCloudDns do={ put ($start); :if ($start=false) do={ set $CloudDnsStatus; # Определяем переменную для счётчика set $m 1; log warning ("[subUpdateCloudDns] ---> DDNS статус ---> ЗАПУЩЕНА ПРОВЕРКА"); #log warning ("[subUpdateCloudDns] ---> DDNS status ---> CHECK STARTED"); do { log warning ("[subUpdateCloudDns] ---> DDNS проверка, попытка ---> " . $m); [/ip cloud force-update]; delay 30000ms; set $CloudDnsStatus ([/ip cloud get status]); set $m ($m+1); :if ($CloudDnsStatus="updated") do={ log warning ("[subUpdateCloudDns] ---> DDNS статус ---> " . $CloudDnsStatus); #log warning ("[subUpdateCloudDns] ---> DDNS status ---> " . $CloudDnsStatus); } else={ log error ("[subUpdateCloudDns] ---> DDNS статус ---> " . $CloudDnsStatus); #log error ("[subUpdateCloudDns] ---> DDNS status ---> " . $CloudDnsStatus); } } while=(($CloudDnsStatus!="updated") and ($m<10)); return ($CloudDnsStatus); } } # Процедура проверки состояния IP --> Cloud # возвращает код состояния: # # 0 - деактивировано; # 1 - активно, но не обновлено; # 2 - активно и обновлено :global subCheckCloudDDNS do={ set $CloudDnsActive ([/ip cloud get ddns-enabled]); # Значение по-умолчанию ( $m=0 ) set $m 0; :if ($CloudDnsActive=yes) do { # Если IP--->Cloud активировано ( $m=1 ) set $m ($m+1); set $CloudDnsStatus ([/ip cloud get status]); # Проверяем синхронизацию внешних IP-адресов (сохранённого в IP--->Cloud и на внешних DNS) set $CloudDnsIP ([/ip cloud get public-address]); set $CheckIpAddr ([resolve [/ip cloud get dns-name]]); :if ($CloudDnsIP!=$CheckIpAddr) do={ # Если IP разные (изменилось подключение MikroTik к провайдеру)... set $CloudDnsStatus "updating..."; } :if ($CloudDnsStatus="updated") do { # Если IP--->Cloud активировано и обновлено ( $m=2 ) set $m ($m+1); } } return ($m); } # Процедура повторного вызова скрипта на выполнение # входящий параметр: # # $ScriptName (имя скрипта) :global subRepeatScript do={ put ($ScriptName); :if ($ScriptName!="") do { [/system script run $ScriptName]; } } # Процедура формирования списка внешних VPN-серверов из пиров # # возвращает список IP-адресов VPN-серверов с привязкой к группам :global subGetVpnServers do={ # Получаем группы и IP-адреса VPN-серверов из пиров и считаем общее количество пиров :foreach IpSecPeerId in=[/ip ipsec peer find passive!=yes] do={ set $CheckIpAddr [/ip ipsec peer get $IpSecPeerId address]; :if ($CheckIpAddr!="") do={ set $MaskPos [find $CheckIpAddr "/"]; set $GroupFromPeer ([/ip ipsec peer get $IpSecPeerId policy-template-group]); set $IpFromPeer ([pick $CheckIpAddr 0 $MaskPos]); set $VpnServersList ($VpnServersList, {{$GroupFromPeer; $IpFromPeer}}); } } return ($VpnServersList); } # Процедура выключения активных пиров и связанных политик # # процедура возвращает список ID всех политик :global subDisableIpSecPeers do={ # ...выключаем все включённые, активные (passive=false) пиры... :foreach IpSecPeerId in=[/ip ipsec peer find passive!=yes] do={ log warning ("[IP IPSec Peer] ---> обрабатывается пир на ---> " . [/ip ipsec peer get $IpSecPeerId comment]); #log warning ("[IP IPSec Peer] ---> processed peer on ---> " . [/ip ipsec peer get $IpSecPeerId comment]); # Получаем address из текущего пира... set $CheckIpAddr [/ip ipsec peer get $IpSecPeerId address]; :if ($CheckIpAddr!="") do={ # Если address не пустой, отрезаем IP-адрес от маски... set $MaskPos ([find $CheckIpAddr "/"]); set $CheckIpAddr ([pick $CheckIpAddr 0 $MaskPos]); # ...и выключаем связанные IPSec-политики :foreach IpSecPolicyId in=[/ip ipsec policy find sa-dst-address=$CheckIpAddr] do={ :if ($IpSecPolicyId!="") do={ :if ([/ip ipsec policy get $IpSecPolicyId disabled]!=yes) do={ [/ip ipsec policy disable $IpSecPolicyId]; log warning ("[IP IPSec Policy] ---> политика " . [/ip ipsec policy get $IpSecPolicyId comment] . " деактивирована"); #log warning ("[IP IPSec Policy] ---> policy " . [/ip ipsec policy get $IpSecPolicyId comment] . " deactivated"); } # Заполняем массив списком ID политик для дальнейшего изменения set $IdList ($IdList, $IpSecPolicyId); } } } # Примечание: пиры выключаются после деактивации политик, чтобы не возникали системные ошибки :if ([/ip ipsec peer get $IpSecPeerId disabled]!=yes) do={ [/ip ipsec peer disable $IpSecPeerId]; log warning ("[IP IPSec Peer] ---> " . [/ip ipsec peer get $IpSecPeerId comment] . " ---> деактивирован"); #log warning ("[IP IPSec Peer] ---> " . [/ip ipsec peer get $IpSecPeerId comment] . " ---> deactivated"); } } return ($IdList); } # Процедура включения активных пиров и связанных политик # входящие параметры: # # $PeerID (ID пира на VPN-сервер); # $PolIdList (список ID из $subDisableIpSecPeers); # $CloudIP (IP MikroTik из DDNS); # $SrcIP (src-address для обращения к VPN-серверу) :global subEnableIpSecPeers do={ put ($PeerID); put ($PolIdList); put ($CloudIP); :if (($PeerID!="")&&($PeerID!=nil)&&($PolIdList!="")&&($PolIdList!=nil)&&($CloudIP!="")&&($CloudIP!=nil)) do={ # Получаем адрес VPN-сервера set $ActiveVPN [/ip ipsec peer get $PeerID address]; :if ($ActiveVPN!="") do={ # Если найден, отрезаем IP-адрес от маски set $MaskPos [find $ActiveVPN "/"]; set $ActiveVPN ([pick $ActiveVPN 0 $MaskPos]); } # Если пир выключен, делаем задержку исполнения и включаем :if ([/ip ipsec peer get $PeerID disabled]=yes) do={ delay 5000ms; [/ip ipsec peer enable $PeerID]; log warning ("[IP IPSec Peer] ---> активирован peer на ---> " . [/ip ipsec peer get $PeerID address]); #log warning ("[IP IPSec Peer] ---> activated peer on ---> " . [/ip ipsec peer get $PeerID address]); } # Ищем политики по ID из массива PolIdList, проверяем, при необходимости изменяем Src. Address, SA Src. Address и SA Dst. Address, и активируем :foreach IpSecPolicyId in=$PolIdList do={ :if ($IpSecPolicyId!="") do={ :if ([/ip ipsec policy get $IpSecPolicyId src-address]!=$SrcIP) do={ [/ip ipsec policy set $IpSecPolicyId src-address=$SrcIP]; log warning ("[IP IPSec Policy] ---> изменён src-address"); #log warning ("[IP IPSec Policy] ---> src-address changed"); } :if ([/ip ipsec policy get $IpSecPolicyId sa-src-address]!=$CloudIP) do={ [/ip ipsec policy set $IpSecPolicyId sa-src-address=$CloudIP]; log warning ("[IP IPSec Policy] ---> изменён sa-src-address"); #log warning ("[IP IPSec Policy] ---> sa-src-address changed"); } :if ([/ip ipsec policy get $IpSecPolicyId sa-dst-address]!=$ActiveVPN) do={ [/ip ipsec policy set $IpSecPolicyId sa-dst-address=$ActiveVPN]; log warning ("[IP IPSec Policy] ---> изменён sa-dst-address"); #log warning ("[IP IPSec Policy] ---> sa-dst-address changed"); } :if ([/ip ipsec policy get $IpSecPolicyId disabled]=yes) do={ delay 3000ms; [/ip ipsec policy enable $IpSecPolicyId]; log warning ("[IP IPSec Policy] ---> политика активирована"); #log warning ("[IP IPSec Policy] ---> policy activated"); # Очищаем DNS-кэш [/ip dns cache flush] } } } } } # Процедура формирования списка политик по ID пира # входящие параметры: # # $PeerIP (IP из пира БЕЗ МАСКИ); # $CloudIP (IP MikroTik из DDNS); # $action (enable/disable/skip) # # процедура возвращает список ID, связанных с пиром, политик :global subGetPoliciesByPeer do={ put ($PeerIP); put ($CloudIP); put ($action); :if (($action="")||($action=nil)) do={ set $action "skip"; } :foreach IpSecPolicyId in=[/ip ipsec policy find sa-dst-address=$PeerIP] do={ :if ($IpSecPolicyId!="") do={ # Если политика включена И $action=disable, выключить политику :if (([/ip ipsec policy get $IpSecPolicyId disabled]!=yes)&&($action="disable")) do={ [/ip ipsec policy disable $IpSecPolicyId]; log warning ("[IP IPSec Policy] ---> политика деактивирована"); #log warning ("[IP IPSec Policy] ---> policy deactivated"); } # Если получен не пустой $CloudIP И sa-src-address!=$CloudIP (изменился ISP), выключить политику и изменить sa-src-address :if (($CloudIP!="")&&($CloudIP!=nil)&&([/ip ipsec policy get $IpSecPolicyId sa-src-address]!=$CloudIP)) do={ [/ip ipsec policy disable $IpSecPolicyId]; [/ip ipsec policy set $IpSecPolicyId sa-src-address=$CloudIP]; log warning ("[IP IPSec Policy] ---> политика деактивирована ---> новый sa-src-address ---> " . $CloudIP); #log warning ("[IP IPSec Policy] ---> policy deactivated ---> new sa-src-address ---> " . $CloudIP); # Делаем задержку исполнения, чтобы Kerio разорвал канал delay 30000ms; } # Если политика выключена И $action=enable, включить политику :if (([/ip ipsec policy get $IpSecPolicyId disabled]=yes)&&($action="enable")) do={ [/ip ipsec policy enable $IpSecPolicyId]; log warning ("[IP IPSec Policy] ---> политика активирована"); #log warning ("[IP IPSec Policy] ---> policy activated"); # Очищаем DNS-кэш [/ip dns cache flush] } # Заполняем массив списком ID политик для дальнейшего изменения set $IdList ($IdList, $IpSecPolicyId); } } return ($IdList); } # Процедура проверки local-address пира # входящие параметры: # # $PeerID (ID пира на VPN-сервер); # $CloudIP (IP MikroTik из DDNS) :global subCheckPeerLocalIp do={ put ($PeerID); put ($CloudIP); :if (($PeerID!="")&&($PeerID!=nil)&&($CloudIP!="")&&($CloudIP!=nil)) do={ # Проверяем изменение DDNS-IP :if ([/ip ipsec peer get $PeerID local-address]!=$CloudIP) do={ [/ip ipsec peer set $PeerID local-address=$CloudIP]; log warning ("[IP IPSec Peer] ---> изменён local-address"); #log warning ("[IP IPSec Peer] ---> local-address changed"); } } }
/system script add dont-require-permissions=no name=scriptCheckActiveVpnServer owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
:if ([:len [/system script job find script=scriptCheckActiveVpnServer]]>1) do={ :error } # Библиотеку процедур инициализируем в скрипте scheduleStartup # и объявляем процедуры, которые будут использованы в этом скрипте :global subCheckCloudDDNS :global subCheckPeerLocalIp :global subDisableIpSecPeers :global subEnableIpSecPeers :global subGetPoliciesByPeer :global subGetVpnServers :global subUpdateCloudDns :local CheckIP :local CheckPeer # Заполняем переменную статусом активации DDNS (внешняя процедура) :local CloudDnsStatus ([:put [$subCheckCloudDDNS]]) :local Exit false :local DefMikroTikSrcNet 192.168.11.0/24 :local DefKerioDstNet 192.168.77.0/24 :local DefKerioPropName KerioVPNProposal#01 :local DefKerioPolName KerioVPNPolicy :local IpSecPolicyId :local KerioName :local KerioVpnNatRuleName KerioVpnNatOut :local m :local n 1 :local PeerCount 0 :local PeerDisabled :local PingCount 3 :local PingResult :local PoliciesList :local PublicIp :local VpnServersList # Проверяем активацию DDNS и, если активирован, считываем активный внешний IP-адрес MikroTik :if ($CloudDnsStatus=0) do={ # Если Cloud DDNS не активно, записываем сообщение в журнал и выходим из скрипта :log error ("[schedule CheckActiveVpnServer] ---> для подключения к VPN-серверу требуется активировать Cloud DDNS! (IP -> Cloud)") # :log error ("[schedule CheckActiveVpnServer] ---> to connect to the VPN server, you need to activate Cloud DDNS! (IP -> Cloud)") :error } :if ($CloudDnsStatus=1) do={ # Если Cloud DDNS активно, но не обновлено, запускаем обновление (внешняя процедура) :set CloudDnsStatus [:put [$subUpdateCloudDns start=false]] :if ($CloudDnsStatus="updated") do={ :set CloudDnsStatus 2 } } :if ($CloudDnsStatus=2) do { # Если Cloud DDNS активно и обновлено ... # Получаем IP из DDNS :set PublicIp [/ip cloud get public-address] # Получаем список VPN-серверов с группами, определяющими приоритет подключения (внешняя процедура) :set VpnServersList ([:put [$subGetVpnServers]]) # Считаем общее количество пиров :foreach VpnIpId in=$VpnServersList do={ :set PeerCount ($PeerCount+1) } # Ищем активный VPN-сервер пингом с внешнего DDNS-IP (для этого, на стороне VPN-сервера необходимо создать разрешающее правило) :while (($Exit!=true)&&$n<=$PeerCount) do={ :foreach VpnIpId in=$VpnServersList do={ # Перебираем IP-адреса VPN-серверов с учётом приоритета :if (($VpnIpId->0)=$n) do={ :set CheckIP ($VpnIpId->1) :if ($CheckIP!="") do={ # Проверяем доступность найденного IP :set PingResult ([:put [/ping address=$CheckIP count=$PingCount src-address=$PublicIp]]) :if ($PingResult=$PingCount) do={ :log warning ("[schedule CheckActiveVpnServer] ---> DDNS-IP ---> " . $PublicIp . " ---> VPN-IP ---> " . $CheckIP . " ---> Ping Result ---> " . $PingResult) # Если IP доступен, ищем пир на этот IP-адрес :set CheckPeer (:put [/ip ipsec peer find address=($CheckIP . "/32")]) :if ($CheckPeer!="") do={ # Если пир найден, проверяем наличие в конфигурации src-адреса (IP ---> Firewall ---> Address Lists), использующегося для соединения с Kerio # Получаем имя сервера Kerio из комментария пира :set KerioName [/ip ipsec peer get $CheckPeer comment] # Обрабатываем полученное имя (ИЗМЕНИТЬ АЛГОРИТМ обработки, если FQDN сервера Kerio отличается от KerioName-Parameter1-...-Parameter_n :if ($KerioName!="") do={ # Находим первый дефис :set m ([find $KerioName "-"]) # Отрезаем KerioName от всего остального :set KerioName ([pick $KerioName 0 $m]) # Ищем адрес в Firewall -> Address List (соответственно там должны быть необходимые записи в формате: # Name ---> KerioName (eg srv1) # Address ---> DefMikroTikSrcNet (eg 192.168.99.0/24)) :set m [/ip firewall address-list find list=$KerioName] :set DefMikroTikSrcNet ([/ip firewall address-list get $m address]) } # ... проверяем наличие в конфигурации политик настроенных на соединение с Kerio :set IpSecPolicyId (:put [/ip ipsec policy find comment="$DefKerioPolName"]) # Если ни одной политики не найдено, создаём политику с настройками по умолчанию # (задаются в разделе объявления переменных) и размещаем её в самом верху списка политик :if ($IpSecPolicyId="") do={ [/ip ipsec policy add disabled=yes dst-address=$DefKerioDstNet proposal=$DefKerioPropName sa-dst-address=$CheckIP sa-src-address=$PublicIp src-address=$DefMikroTikSrcNet tunnel=yes comment=$DefKerioPolName place-before=0] :log warning ("[schedule CheckActiveVpnServer] ---> создана политика " . $DefKerioPolName . " ---> использованы параметры по умолчанию") #:log warning ("[schedule CheckActiveVpnServer] ---> created policy " . $DefKerioPolName . " ---> default parameters used") } else={ # Если политика есть, проверяем указанный в ней src-address, при необходимости меняем. :if ($DefMikroTikSrcNet!=[/ip ipsec policy get $IpSecPolicyId src-address]) do={ [/ip ipsec policy set $IpSecPolicyId src-address=$DefMikroTikSrcNet]; :log warning ("[schedule CheckActiveVpnServer] ---> политика " . $DefKerioPolName . " изменена ---> src-address изменён на ---> " . $DefMikroTikSrcNet) #:log warning ("[schedule CheckActiveVpnServer] ---> policy " . $DefKerioPolName . " changed ---> src-address changed to ---> " . $DefMikroTikSrcNet) } } # очищаем переменную :set m # ищем NAT-правило для мапинга исходящего в сторону Kerio трафика :set m [/ip firewall nat find comment=$KerioVpnNatRuleName] :if ($m!="") do={ # Если изменился src-address в политике ipsec, изменяем правило мапинга исходящего в сторону Kerio трафика :if ([/ip firewall nat get $m to-addresses]!=$DefMikroTikSrcNet) do={ [/ip firewall nat set $m to-addresses $DefMikroTikSrcNet] :log warning ("[IP Firewall NAT] ---> изменено правило мапинга ---> " . $KerioVpnNatRuleName) #:log warning ("[IP Firewall NAT] ---> netmap rule changed ---> " . $KerioVpnNatRuleName) } } # ...сравниваем local-address найденного пира с текущим внешним IP MikroTik, при необходимости изменяем (внешняя процедура) :put [$subCheckPeerLocalIp PeerID=$CheckPeer CloudIP=$PublicIp] # ...проверяем состояние найденного пира :set PeerDisabled ([/ip ipsec peer get $CheckPeer disabled]) :if ($PeerDisabled=true) do={ # Если пир выключен... # Выключаем все другие пиры и политики (внешняя процедура) :set PoliciesList ([:put [$subDisableIpSecPeers]]) # Находим пир на активный VPN-сервер и включаем (внешняя процедура) :put [$subEnableIpSecPeers PeerID=$CheckPeer PolIdList=$PoliciesList CloudIP=$PublicIp SrcIP=$DefMikroTikSrcNet] } else={ # Если пир включен... # Находим все связанные с пиром политики, проверяем и включаем (внешняя процедура) :set PoliciesList ([:put [$subGetPoliciesByPeer PeerIP=$CheckIP CloudIP=$PublicIp SrcIP=$DefMikroTikSrcNet action="enable"]]) } :set Exit true } } else={ :log error ("[schedule CheckActiveVpnServer] ---> DDNS-IP ---> " . $PublicIp . " ---> VPN-IP ---> " . $CheckIP . " ---> Ping Result ---> " . $PingResult) } } } } :set n ($n+1) } }
/system scheduler add interval=1h name=scheduleCheckIPSecSADstAddrFromDNS on-event=\ "/system script run scriptSetIPSecSADstAddrFromDNS" policy=read,write \ start-date=oct/30/2017 start-time=00:10:00 add name=scheduleStartup on-event=":global StartupScript true :global RepeatRun false /system script run scriptFunctionsList" policy=\ ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \ start-time=startup add interval=5m name=scheduleCheckActiveVpnServer on-event=\ "/system script run scriptCheckActiveVpnServer" policy=\ ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \ start-date=nov/29/2017 start-time=00:00:00
:global StartupScript true :global RepeatRun false /system script run scriptFunctionsList
/system script run scriptSetIPSecSADstAddrFromDNS
/system script run scriptCheckActiveVpnServer
Source: https://habr.com/ru/post/439736/